Fme Extensions Blog

Latest news, tutorials, and best practices for Magento

December 11, 2023Top Magento Alternatives and Competitors in 2024

Hey, savvy e-commerce wizards! Are you ready for a whirlwind adventure into the vibrant world of online selling? Picture this: you're about to embark on a quest to find the ultimate e-commerce platform that'll skyrocket your business to the stars. Today, we're spilling the beans on the hottest topic around – the top alternatives to Magento in 2024.

December 6, 2023Magento Security: Measures & Best Practices

Hey there, fellow Magento store managers!

June 13, 2024How to Override Magento 2 Helper, Block, Model and Controller

As a leading Magento extensions company, our experience tells us that the topmost reason most people opt for Magento 2 is because of the customisability. With the right Magento development team, there is nothing you cannot customise in your store. This allows you to create a store that is personalised to your requirements and target audience preferences. While customisability is a core feature in Magento 2, there are certain points to keep in mind. For example, it is never recommended to modify the core files of Magento community or enterprise version. Instead, our Magento experts recommend override block, model, and controller in Magento 2 if needed. Today, we will guide you about overriding helper, model, block and controller in Magento 2. In this article, we will be overriding Magento helper, list product block, product model and product view controller. You can use the similar approach to override other block, model and controllers in Magento. You can also contact FME Extensions for Magento custom development or hire a dedicated Magento developer to handle your store management and customization tasks. Why You Should Avoid Editing Magento 2 Core Files? There are several reasons, including: Updates Override Customisations Suppose you have made customisations to the core files. These customisations are a core part of your website. Now, if you upgrade to the latest Magento version or even install a patch, the core files will be overwritten. It means that all your customisations will be removed. This can break your site. Read More: How to Check Your Current Magento Version Website Maintenance When you change the core files, it can be difficult to track the changes. If you change your Magento team, the new team won’t have any idea why and where the changes were made. On top of it, since the code is interrelated to other parts, it can be difficult to ascertain how the custom code interacts with others or what was done to ensure seamless integration. Compromises Store Security Magento 2 is one of the most secure eCommerce platforms. You’ll notice that updates always introduce new security features. Besides this, the team behind the platform is always issuing patches to overcome vulnerabilities. When you make changes to the core file, you can introduce security vulnerabilities. Hackers can exploit this vulnerability to wreak havoc on your store and customers. Incompatibility With Extensions Lastly, a Magento extensions company does not know what changes you have made to the core files. Instead, all extension developers assume that the core files are behaving in a standard manner i.e. how the platform intended them to. Therefore, all the code in the extension is based on standard core files. If you have made changes to the core file, the extension may become unusable. Overriding Magento Helper Let's start with overriding a core Magneto 2 product helper. Suppose you need to make some additions in Magento 2 Product helper. Step # 1 – Create a di.xml file in a folder FME/Test/etc <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Catalog\Helper\Product" type="FME\Test\Helper\Rewrite\Product" /> </config> Step # 2 - The next step to overriding Magento2 Helper is to create a Product.php Block file in the folder FME/Test/Helper/Rewrite/Product <php /** * Catalog Product Rewrite Helper * * @category FME * @package FME_Test * @author Fme Extensions Development Company * */ namespace FME\Test\Helper\Rewrite; class Product extends \Magento\Catalog\Helper\Product { public function __construct() { echo "Helper Rewrite Working"; die(); } } You can rewrite other Magento 2 helper using the same method. Overriding Magento 2 Blocks Lets start with overriding core ListProduct block. Suppose you need to make some additions in Magento 2 ListProduct block. Step # 1 – Create a di.xml file in a folder FME/Test/etc <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Catalog\Block\Product\ListProduct" type="FME\Test\Block\Rewrite\Product\ListProduct" /> </config> Step # 2 - The next step to overriding Magento2 block is to create a ListProduct.php Block file in the folder FME/Test/Block/Rewrite/Product <php /** * Rewrite Product ListProduct Block * @category FME * @package FME_Test * @author Fme Extensions Development Company */ namespace FME\Test\Block\Rewrite\Product; class ListProduct extends \Magento\Catalog\Block\Product\ListProduct { public function __construct() { echo "Block Rewrite Working"; die(); } } You can rewrite other Magento 2 blocks using the same method. Overriding Magento 2 Model Overriding Magento2 models is not very different from overriding blocks. However, there is a simple method to override models in Magento 2. In the following example we will override Magento2 product model. You can follow the same method to override any other Magento2 Model. Step#1 Create a di.xml file in Folder FME/Test/etc <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Catalog\Model\Product" type="FME\Test\Model\Rewrite\Catalog\Product" /> </config> Step # 2 Create Product.php Model file in Folder FME/Test/Model/Rewrite/Catalog <php /** * Catalog Product Rewrite Model * @category FME * @package FME_Test * @author Fme Extensions Development Company */ namespace FME\Test\Model\Rewrite\Catalog; class Product extends \Magento\Catalog\Model\Product { public function __construct() { echo "Model Rewrite Working"; die(); } } You can rewrite other Magento 2 model using the same method. Overriding Magento 2 Controller Overriding Magento2 controllers in not exactly same as overriding Magento2 blocks and Models. In the following example will be override product view controller of Magento2. Using the same approach you can override other controllers in Magento2. Step # 1: Just like for Models and Blocks create di.xml file in folder FME/Test/etc <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Catalog\Controller\Product\View" type="FME\Test\Controller\Rewrite \ Product\View" /> </config> Step # 2: In the second step of overriding controller in Magento 2, create a View.php Controller file in Folder Fme/Test/Controller/Rewrite/Product <?php /** * Rewrite Product View Controller * @category FME * @package FME_Test * @author Fme Extensions Development Company */ namespace FME\Test\Controller\Rewrite\Product; class View extends \Magento\Catalog\Controller\Product\View { public function execute() { echo "Controller Rewrite Working"; die(); } } You can rewrite other Magento 2 controller using the same method. Conclusion This concludes our article on how to override Magento 2 helper, block, model and controller. We acknowledge that the instructions can be tricky to follow. If you run into any trouble, contact us . Our Magento 2 development experts will resolve your query right away. Recommended Articles: Generate URL Rewrites in Magento 2 How To Enable Developer Mode in Magento 2? Reindexing Magento 2 - Complete Guide

June 13, 2024How to Configure Price Per Unit in Magento 2?

In this article, we are going to discuss everything there is to know about Magento price per unit, including its benefits and how to configure it. What is Magento 2 Price Per Unit? The price per unit is simply the price of a single unit of product or service. For example, a store is offering 100 T-shirts for $500. It means that the price per unit is: $500 ÷ 100=$5 When it comes to services, most providers charge by the hour. In that case, the price per unit (per hour) is calculated by dividing the total cost by the total hours. For example, a cleaning company charges $200 for 8 hours work. Thus, the price per unit (per hour) is: $200 ÷ 8=$25 Importance of Magento 2 Price Per Unit There are several reasons you should consider setting up the Magento price per unit feature, including: Customer Convenience Users can easily compare the price per unit offered by different stores to ascertain which store is offering the best value for money. By offering this feature, you can boost chances of successful conversion and benefit from enhanced engagement. Pricing Strategy Determining the right price per unit is important from the store owner’s perspective. It helps them determine the break-even point for every product. It ensures that the cost per unit is covered, thereby protecting the business against a loss. Cost Analysis As a store owner, you may have multiple vendors. In case you have a single vendor, it is always wise to explore new options. After all, the entire purpose of running a business is to generate wealth. Calculating the price per unit allows you to compare prices across all vendors. Thus, you can choose a vendor that offers the least priced product, thereby maximising your profitability. Factors Affecting the Magento Price Per Unit There are various factors affecting the price per unit. As a store owner, it is imperative that you understand these factors for quality decision-making. Bulk Orders When you buy in bulk from the vendor, the price per unit is already reduced. You can easily pass these savings onto your customers. By pursuing a low-cost strategy, businesses can easily penetrate the market. Packaging If a customer buys only a handful of items, the packaging costs would be high since the rest of the packaging space is wasted. In comparison, larger orders reduce the packaging costs. Thus, consider this aspect when calculating the price per unit. Economies of Scale If you manufacture the products yourself, then increasing the production volume can bring down the costs. This concept is referred to as the economies of scale. Magento 2 Price Per Unit In Magento 2, you can easily set the price per unit for a product by installing a third-party pricing calculator extension. If you want to set pricing based on each unit quantity, area, volume or weight then you must use the “Per Unit Price” for each product. Per Unit Price is best fit for selling variable size products like tiles, flooring, fabric, blinds, carpet, liquids, sugar, etc. Setup Products Price Per Unit in Magento 2 In order to configure Price Per Unit in Magento 2, download & install Pricing Calculator Extension by FME . After Installation, Login to Admin Panel > Tap FME extensions > Click Configurations In General Settings , Select Yes to enable the extension Now Expand Basic Tab and set following configurations: Fields Label – Set fields labels to be displayed on product page, e.g. length, width, height, volume, meter, etc. Discount – Enter title for discount, e.g. Discount, etc. Keyword for Minimum Quantity - Enter text for minimum value like min, etc. Keyword for Minimum Quantity - Enter text for maximum value like max, etc. Now Expand Product Page Tab Show Base Price – You can show/hide base price on frontend Show Discount Price - You can show/hide discount amount on frontend Customizable Options Settings Now, when you’re done with the Configurations General settings, you need to display input fields like length, width, height, weight, volume etc. on product page in order to take input value from customers. For this, Open a Product in editor mode Click & Expand Customizable Options Tab Now Click Add Option on right side Set Option Title – Make sure the option title matches the labels in the Configurations General settings Option Type – Select Field type Required - Check if you want to make the field mandatory Note: Create input fields according to your requirements, e.g. create 2 fields (length, width) for area-based pricing, 3 fields for volume (length, width, height) or 1 field for single dimension volume like liter, etc. Price Per Unit Volume (cubic meter, cubic ft, cubic inches, liter, ml, gallon etc.) Now to Setup Price Per Unit Volume, open a product in editor mode Click Catalog on left sidebar > Click Products Now click & expand Pricing Calculator Tab Active – Select Yes to Active the Price calculator for the product Measure By – Select Measurement Type - select Volume Discount Size – Setup discount size, set min & max value and setup discount as Fixed or Percentage amount Units – Select Input & Output Units like meter, foot, inch, etc. (will be calculated as cubic meter, cubic foot, cubic inches,) Unit Price – Select Per Unit price Pricing Limit – Set Pricing Limit, e.g. minimum & maximum values Save the Product Note: You can also price & sell single dimension products like oil in litres, diesel in gallons, etc. Price Per Weight Unit (gram, kg, ounce, pound, ton, etc.) Now to Setup Price Per Weight Unit, open a product in editor mode Click Catalog on left sidebar > Click Products Now click  Pricing Calculator Tab Active – Select Yes to Active the Price calculator for the product Measure By – select Weight Discount Size – Setup discount size, set min & max value and setup discount as Fixed or Percentage amount Units – Select Input & Output Units e.g. Kg, gram, ton, etc. Unit Price – Select Per Unit price Pricing Limit – Set Pricing Limit, e.g. minimum & maximum values Save the Product Area Based Price Per Unit (sq ft, sq meter, sq yard, sq inches, etc.) Now to Setup Price Per Unit Area, open a product in editor mode & click  Pricing Calculator Tab Active – Select Yes to Active the Price calculator for the product Measure By – Select Area Discount Size – Setup discount size, set min & max value and setup discount as Fixed or Percentage amount Units – Select Input & Output Units like meter, foot, inch, etc. (will be calculated as square meter, sq ft, sq yard, etc.) Unit Price – Select Per Unit price Pricing Limit – Set Pricing Limit, e.g. minimum & maximum values Save the Product Note: You can also price & sell single dimension products like fabric in yards, nylon ropes in meter. You can then use a shipping extension to set up Magento 2 dimensional weight shipping feature. Dimensional weight means the weight based on the product’s volume. There is no built-in Magento 2 dimension weight feature, meaning you’ll have to use a custom extension for it. Coming back to our topic, the Price Per Unit extension also performs complex pricing calculations like: Calculate Price by Length Calculate Price by Meter Calculate Price by Gram, kg Calculate Price by Square Foot Calculate Price by Yards Calculate Price per KG Set Weight Units in Gram Calculate Price by Volume Calculate Price by Weight View Extension Demos:   Frontend Demo      Backend Demo      Buy Extension Conclusion This concludes our article on Magento 2 price per unit feature. While this customisation more than gets the job done, we can even customise it to suit your unique requirements. If you need any help, feel free to contact our support team .