Magento 2: Delete Duplicate Product Attributes Options Programmatically

This article shows how you can delete duplicate product attribute options in Magento 2. I am using a standalone script for this purpose. You can use this code in your custom module as well. Initialize Object Manager and Set the Area Code The following things are done in the below code: – Initialize the object … Read more

Magento 2: Create, Edit, Delete Customer Attribute Programmatically

This article shows how you can programmatically add or create a new customer attribute in Magento 2. It also shows how you can update and delete/remove the customer attribute programmatically in Magento 2. I will also show how you can add the product attributes from both Install Script and Upgrade Script: – Add customer attribute … 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

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 All Product Attributes with Name and Value

This article shows how to load product by it’s ID and then get all attributes associated with that product in Magento 2. We print the attribute code, attribute name, and attribute value of all the attributes related to any particular product. We will be using Magento 2’s Service Layer for this task. Use of Service … Read more

Magento: Get all products by attribute id and attribute option

This article shows how to get / filter products based on it’s attribute id, or the attribute’s options id. Get all products by a single attribute option id Suppose, we have an attribute named ‘manufacturer’. Let’s say, this attribute has options like Samsung, Apple, Nokia, HTC, etc. Each option has certain ID. Suppose, we want … Read more

Magento: Filter Configurable Product by Child Product’s Attribute

This article shows how you can filter child products associated with a configurable product by the child product’s attribute value. Suppose, we have a configurable product with two attributes (‘size‘ and ‘color‘) and we want to select only those child products with certain size and/or certain color. Let’s say, we want to select only those … Read more

Magento: Get Customer Attribute

This article contains code snippet to get customer attributes in Magento. Get Customer Collection $collection = Mage::getResourceModel('customer/customer_collection'); Get Customer’s Name in Customer Collection $collection = Mage::getResourceModel('customer/customer_collection') ->addNameToSelect(); Get Custom Attribute in Customer Collection $collection = Mage::getResourceModel('customer/customer_collection') ->addAttributeToFilter('your_attribute_code', array('notnull' => true)); Thanks.

Magento: Get all attributes & attribute name value of a product

Here is a quick code to get all attributes and their name and value associated with any particular product. First of all we have to load the product by it’s ID. And then get all it’s attributes. Here is the code:- $productId = 52; $product = Mage::getModel('catalog/product')->load($productId); $attributes = $product->getAttributes(); Get Name and Value of … Read more