Magento 2: Invalid Form Key. Please refresh the page. Error on Product Save

Problem: The following error occurred while saving a product from Magento 2 admin: Invalid Form Key. Please refresh the page. Cause: The cause of this error is related to the max_input_vars (Maximum Input Variables) directive in the PHP settings. The max_input_vars directive value is the maximum number of variables that can be used for a … Read more

Magento 2: Create Product Attribute, Attribute Group/Tab & Attribute Set Programmatically

This article shows how you can programmatically add or create a new product attribute, product attribute group, and product attribute set in Magento 2. In this article, we will be looking at the following: Create Product Attribute Update Product Attribute Remove Product Attribute Create Product Attribute Group/Tab Add Product Attributes to the Attribute Group/Tab Create … Read more

MailChimp API v3.0 – Add Store to List, Add Product to Store, Add Order to Campaign

This article shows how you can use MailChimp API v3.0 with PHP and CURL to add ecommerce data to your MailChimp campaign. When purchases happen in your shop then you can add your purchase order data to MailChimp to track purchases from your MailChimp Campaign. A MailChimp campaign is associated to any particular MailChimp list. … Read more

Magento: Add new column to Product Grid in Admin

This article shows how you can add new columns to product grid (Catalog -> Manage Products) in Magento 1.x admin. For this, you need to rewrite/override the Adminhtml’s catalog_product_grid block class. Here is the block override code to be written in your module’s config.xml file: YourCompany/YourModule/etc/config.xml <global> <blocks> <yourmodule> <class>YourCompany_YourModule_Block</class> </yourmodule> <adminhtml> <rewrite> <catalog_product_grid>YourCompany_YourModule_Block_Adminhtml_Catalog_Product_Grid</catalog_product_grid> </rewrite> … Read more

Magento 2: Get Attribute Id, Name, Value from Attribute Code

This article shows how you can get attribute name or label, id, entity_type, etc. by attribute code in Magento 2. If you would like get attribute name and value in Magento 1 then you may refer to this article: Magento: How to get attribute name and value? I will be showing both Dependency Injection (DI) … Read more

Magento 2: Get Product’s Custom Option Value from Cart & Order

This article shows how to get custom option values of products/items added to cart or products of any order in Magento 2. I will simply be using ObjectManager for this example. Get custom options of products present in shopping cart $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $cart = $objectManager->get('\Magento\Checkout\Model\Cart'); // get cart items $items = $cart->getItems(); // get … Read more

Magento 2: Get all Categories of any/current Product

This article shows how we can get list of all categories from current product or any particular product as well. Both ways (Dependency Injection & Object Manager way) are shown below: Using Dependency Injection (DI) Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory, \Magento\Catalog\Model\ProductRepository and \Magento\Framework\Registry classes … Read more