75

There is no necessity to change any PHP code for doing this. You just need to create {MODULE_NAME}/etc/catalog_attributes.xml with such content: <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/catalog_attributes.xsd"> <group name="...


68

/app/code/local/Your/Customattribute/sql/your_customattribute_setup/install-0.1.0.php <?php $installer = $this; $installer->startSetup(); $setup = new Mage_Eav_Model_Entity_Setup('core_setup'); $entityTypeId = $setup->getEntityTypeId('customer'); $attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId); $attributeGroupId = $...


50

In addition to your code put this: $product = Mage::getModel('catalog/product') ->setStoreId($store_id) ->setBrand($brand_value); // not loading the product - just creating a simple instance $brandLabel = $product->getAttributeText('brand');


47

addAttributeToFilter() is used to filter EAV collections. addFieldToFilter() is used to filter Non-EAV collections. EAV-models are for example product, customer, sales, etc so you can use use addAttributeToFilter() for those entities. addFieldToFilter() is mapped to addAttributeToFilter() for EAV entities. So you can just use addFieldToFilter(). Edit: You ...


43

To fetch value of attribute Use: First get Your Product Collection and then $this->getProduct()->getAttributeText('attribute_text'); e.g: $this->getProduct()->getAttributeText('metal_pads'); Or $product = $this->getProduct(); $ressource = $product->getResource(); $store = $this->_storeManager->getStore(); $ressource->...


41

Give this a try and see if it fits: $collection->addAttributeToFilter('name', array( array('like' => '% '.$needle.' %'), //spaces on each side array('like' => '% '.$needle), //space before and ends with $needle array('like' => $needle.' %') // starts with needle and space after )); Passing the second parameter as an array of arrays ...


32

There are 2 ways to go about this, one is by getting the Magento catalog/product model and loading the product by ID which will give you the whole product, then setting the name and saving it. $product = Mage::getModel('catalog/product')->load(1); $product->setName('foobar!'); try { $product->save(); } catch(Exception $e) { echo "{$e}"; } As ...


28

As explained in the comments, I don't think there is a way to do this by using the cms pages because you have no layer model associated to the new products list. You only have layer models for the category context and the search context. My solution (tested and works) involves writing a module that will list all the products marked as new in a page and ...


27

I assume that in your example, yellow, small and china are options in dropdowns. You will need their ids first, but let's assume the are $yellowId, $smallId and $chinaId. You can try this filtering. ->addFieldToFilter(['color', 'size', 'country'], [ ['eq' => $yellowId], ['eq' => $smallId], ['neq' => $chinaId] ])...


26

Load product in foreach is a bad idea, though working. Better way: in config.xml <global> <sales> <quote> <item> <product_attributes> <dp_width/> <dp_height/> <dp_length/> </...


26

In general, these files contain a list of attributes that serve different purposes. The group used_in_autogeneration from the file in catalog module serves for listing attributes that have the value autogenerated. They are retrieved in \Magento\Catalog\Helper\Product::getAttributesAllowedForAutogeneration The group quote_item represents the attributes that ...


25

We can get custom attribute value like below Attribute Value <?php /* @escapeNotVerified */ echo $_product->getResource()->getAttribute('c_address')->getFrontend()->getValue($_product); ?> Label $address =$_product->getResource()->getAttribute('c_address')->getStoreLabel(); Note : in above line c_address is my custom ...


24

Extension attributes mechanism should be used in this case. It allows extension of core APIs by 3rd party modules. Generic steps for enabling new extension attribute: Declare extension attribute as described in the official docs. After clearing var and running <project_root>/bin/magento setup:di:compile, corresponding setter and getter for this new ...


23

Best practice in magento is to do it via xml. To get a standard attribute you do something like this in catalog_product_view.xml for example: <referenceContainer name="product.info.main"> <block class="Magento\Catalog\Block\Product\View\Description" name="product.info.brand" template="product/view/attribute.phtml" before="-"> <...


21

From what I understand you want to send 2 or more values and filter by them using OR. Something like this: ... WHERE FIND_IN_SET($v1, `some_field`) OR FIND_IN_SET($v2, `some_field`) OR ... $v1 & $v2 are the values of your checkboxes For that you need to pass to the addAttributeToFilter and array of arrays. ->addAttributeToFilter( ...


21

Try this: echo $_product->getResource()->getAttribute('car_options')->getFrontend()->getValue($_product);


21

Another way, for the custom attributes: we can simply get the value by using getCustomAttribute() if (null !== $product->getCustomAttribute('your_custom_attribute')) { echo $product->getCustomAttribute('your_custom_attribute')->getValue(); }


20

Use getStoreLabel() ,instead of getFrontendLabel()


20

I have used method updateAttributes of class \Magento\Catalog\Model\ResourceModel\Product\Action. Method can update multiple products and attribute values, but if you want to update just one product with one attribute value you can do it like this: $this->action->updateAttributes([$product->getId()], ['attribute_code' => $newValue], $storeId);


19

Get attribute value/id from attribute text/label: $attr = 'your_attribute'; $_product = Mage::getModel('catalog/product'); $attr = $_product->getResource()->getAttribute($attr); if ($attr->usesSource()) { echo $color_id = $attr->getSource()->getOptionId("Purple"); }


18

You are using the incorrect setup class. Mage_Eav_Model_Entity_Setup has never had access to catalog-specific properties, which reside in the additional table (catalog_eav_attribute). You either need to register catalog/setup as your module's setup resource or (more likely) instantiate it directly in your setup script: $installer = Mage::getResourceModel('...


18

Yes, this is possible. First, set these keys in your $data array to following values to avoid adding attribute to all attribute sets: 'user_defined' => true, 'group' => '' Then add attribute to your attribute set: $attributeSetId = $this->getAttributeSetId($entityTypeId, 'New Attr Set'); $this->addAttributeToSet($...


18

If you do not see the delete attribute button then that means the table column 'is_user_defined' in the eav_attribute table is set to 0. By changing this to 1 it will show the delete button. If you do not know where to go to find the attribute then you can follow the answers. In the admin Stores->Attributes->Products


18

For a mult select attribute, you can need to add below at your installer: source model: [VendorName]\[ModuleName]\Model\Category\Attribute\Source\Custom.php backend Model [VendorName]\[ModuleName]\Model\Category\Attribute\Backend\Custom.php input_renderer for admin html area [VendorName]\[ModuleName]\Block\Adminhtml\Category\Helper\Custom\Options.php ...


17

This is how it can be done with customer save method: /** @var \Magento\Customer\Model\CustomerFactory $customerFactory */ /** @var \Magento\Customer\Model\Customer $customer */ /** @var \Magento\Customer\Model\Data\Customer $customerData */ $customer = $customerFactory->create() $customerData = $customer->getDataModel(); $customerData->...


16

The short version Mage::getModel('catalog/product_attribute_set_api')->attributeRemove($attId, $set->getId()); Your error message isn't popping up due to your delete method call, it's popping up due to your collection use. For reasons lost to the mystery and smog of Los Angeles, the eav/entity_attribute resource model class is initialized with the ...


16

LuFFy's answer is technically incorrect as it has 3 issues: it will remove values for admin store view only leaving some store-views related garbage it will remove unused values of attributes of all entity types it will remove ALL values from attributes with "multiple select" type regardless if they are assigned to any products or not because they options ...


16

$productModel = Mage::getModel('catalog/product'); $str_attr_label = "color"; //or "size", etc... $int_attr_id = 8; // or any given id. $int_attr_value = 21; // or any given attribute value id. // Chose either if ($byLabel){ $attr = $productModel->getResource()->getAttribute($str_attr_label); } if ($byId){ $attr = Mage::getModel('catalog/...


15

Try to set default value as string 'default' => '0' or empty 'default' => '' Update The default values are added when you add new product for old ones it not affects. Try to fix that in Product management with mass action Inside manage products, there is a action called “Update Attributes”. Select all the products that you want to update and ...


15

You need to create a different upgrade script. If the install script has the version 0.1.0 create the file upgrade-0.1.0-0.1.1.php with this content: $installer = $this; $installer->removeAttribute('catalog_category', 'short_description'); $installer->removeAttribute('catalog_category', 'static_block'); Then go to config.xml and change the version ...


Only top voted, non community-wiki answers of a minimum length are eligible