Problem During full reindex in CLI (Command Line Interface, SSH), Magento returns error message like “index is locked by another reindex process. Skipping.” Reason Error is possible if the previous reindex process wasn’t completed successfully. There are a few possible reasons for this issue: Fatal PHP error during reindexing Mysql Error (like timeout) Memory limit Full Article…
Magento – Delete Empty Null Attribute Options
By default, if you enter attribute options in the back end, you can’t add an empty option to the attribute. Maybe these empty options were added via a custom script. Here is the custom script that helps you to remove the empty options of the attributes 1.Create store_root/shell/empty.php file with code snippet: 2.Run this PHP script to Full Article…
Magento 2 – Get min price or max price from product collection
Today we learn about how to get min price and max price from product collection. First, you have to get a collection of the product. Then their two predefined functions for getting min price getMinPrice and get max price getMaxPrice Now we implement the code for getting min price and max price. protected $_productCollectionFactory; public Full Article…
Magento 2 – The resource from pub/ directory was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff)
When you deploy the source code to the live server, you may see the issue The resource from pub/ directory was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff)… You can solve it by the following ways Remove all files from var/ folder by using this command rm -rf var/* Check for .htaccess in Full Article…
Magento 2 – Write logs to the custom files
In Magento 2, you can use the following code to write logs to the custom files $writer = new \Zend\Log\Writer\Stream(BP . ‘/var/log/templog.log’); $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); $logger->info(“Log info: “. $e->getMessage());
Magento – Select all values of an attribute by using SQL
It is useful to be able to export lists of brands, whether you just need a quick list directly from PHPMyAdmin, or you need to pull this information into 3rd party app. To get all the attribute values for an attribute called brands, you can run the following query SELECT EAOV.VALUE FROM eav_attribute EA LEFT Full Article…
Magento – Convert attribute type from TEXT to DROPDOWN
This article will show you how to convert attribute type from TEXT (varchar) to DROPDOWN / SELECT (int) in Magento back end. Magento doesn’t have this in-built so we will have to do it in our own way. We will convert our existing attribute which is in TEXT type, to DROPDOWN (select). Let’s say our Full Article…
Magento – Get the last order ID
There are many ways to get the last order ID in Magento, here is the detail: 1. From the checkout session. $lastOrderId = Mage::getSingleton(‘checkout/session’) ->getLastRealOrderId(); $orderId = Mage::getModel(‘sales/order’) ->loadByIncrementId($lastOrderId) ->getEntityId(); This solution will not work in case you want to get the last order ID in the backend. 2. From the model. $orders = Full Article…
Magento – Set default value to custom attribute for all products
I have created the custom attribute (test) for products as a text field with default value('test') from admin panel And assign that attribute to default attribute set. Now I can able to see the new custom attribute in product edit page. When I try to filter with the product collection Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect('*') ->addAttributeToFilter('test', array('like' => 'test'))->getData(); It returns the Full Article…
Magento – Filter product collection by special price
To create a new page with products have special price only, you need to create a new block that filters discounted products. Let’s create this file, Special.php in local/Mage/Catalog/Product/Block/ directory. You will have to create this directory path if it’s not already there. Using below code to create new block <?php class Mage_Catalog_Block_Product_Special extends Mage_Catalog_Block_Product_List Full Article…