7

I have check the core how magento install the label and I found code in below file vendor/magento/module-eav/Setup/EavSetup.php in this file I got addAttributeOption method. After seeing the code I got your answer, create attribute like below You can create multiselect and dropdown attribute option label different on store basis like below $...


6

Suppose, you have an product attribute called "color" in Magento. You have the attribut admin value (e.g. Purple), and you want to find it’s value. The below code will help you get the value for it. $_product = Mage::getModel('catalog/product'); $attr = $_product->getResource()->getAttribute("color"); if ($attr->usesSource()) { echo $color_id = $...


5

Assuming you have $optionId ( that's the value you get when calling $product->getData('your_attribute') ), you can get the position (sort_order) this way $options = Mage::getResourceModel('eav/entity_attribute_option_collection') ->setIdFilter($optionId); This will return a simple object, something like... Array ( [option_id] => 624 [...


5

Have a look in /var/log/ and see if Magento is logging any exceptions or errors that might give you a clue as to the cause of the problem. I once had a problem updating a category with a large amount of products where magento was throwing an error concerning input variables exceeding a configured limit. This turned out to be the max_input_variable setting ...


5

Try following way: protected $eavAttributeFactory; protected $attributeOptionManagement; public function __construct( \Magento\Eav\Model\Entity\AttributeFactory $eavAttributeFactory, \Magento\Eav\Api\AttributeOptionManagementInterface $attributeOptionManagement ) { $this->eavAttributeFactory = $eavAttributeFactory; $this->...


4

If you have the admin value : echo $color_id = $attr->setStoreId(0)->getSource()->getOptionId("purple");


4

Try this: $_product = $block->getProduct(); foreach ($_product->getOptions() as $o) { if ($o->getTitle() != 'Color') { // or another title of option continue; } foreach ($o->getValues() as $value) { print_r($value->getData()); } } You should search for your option by the title because the option ID is unknown.


3

This is your problem 'source' => 'catalog/product_attribute_source_layout', It should not be there. remove the attribute from your db and reinstall your module. Or simply edit the attribute from the eav_attribute table and remove the value of the column source_model. Let's take a look at the method getSource that you mentioned. public ...


3

Code below checks if the attribute already have an option then return its id other wise add new option and return its id function addAttributeOption($attributeCode, $argValue) { $attribute = Mage::getModel('eav/config') ->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode); if ($attribute->usesSource()) { ...


3

i was face same problem the solution work for me. because the frontend store values were not added. this code work for me. $attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product','color'); $attr = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId); if ($attr->usesSource()) { $...


3

Ok so it turns out I was being silly. The function addAttributeOption allows you to add and update options. To add a new option you simply need an array with the following format. $option['attribute_id'] = $attributeId; $option['value'][] = $storeValues; Where $storeValues is simply an array where the key is the store id and the value is the value ...


3

Assuming that you aren't kitting these 10/50/100 packs together when an order is placed), the simplest option which will work natively is to use two options: type_qty color In this approach the type_qty attribute would have the following nine options: 10 pack Removable 50 pack Removable 100 pack Removable 10 pack Permanent 50 pack Permanent 100 pack ...


3

You Can get all the swatches attribute option data with below code. <?php $attributes = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product); foreach ($attributes as $attribute){ foreach($attribute['values'] as $data){ echo "<pre>"; print_r($data); } }


2

Please note that this code you can apply only to the configurable product: $productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product); $attributeOptions = array(); foreach ($productAttributeOptions as $productAttribute) { foreach ($productAttribute['values'] as $attribute) { $attributeOptions[$...


2

No answer but another option. Use Avs_FastSimpleImport to update product data with the attribute values. In the FastSimpleImport settings you can define missing options should be created Check out the module here


2

I increased the value of max_input_variable to 2500 and luckily it worked. Now I can finally remove or update the options. In my .htaccess file (My Magento don't have a php.ini file so I used the .htaccess file) I added this line: php_value max_input_vars 2500


2

The default radio button is not a standard magento feature. Maybe you had some extension that is not available anymore. But I can recommend you this free extension. Among a lot of things it does something similar to what you need. It doesn't allow you to set a default value for each attribute, but it allows you to set a default configuration for the ...


2

Step1: First get the attribute id, for example by attibute code from the eav/entity_attribute model: $attributeModel = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', $YourattributeCode) Step2: Using the attribute id, load the catalog/entity_attribute attribute model: $attribute = Mage::getModel('catalog/product') -...


2

The issue was server related. I have checked the server log and found below message in there. PHP Warning: Unknown: Input variables exceeded 1000. So I went ahead and doubled the limit to 12000. I tried few other values in between as well but they were not working, but 12000 work. So I have kept max_input_vars to 12000. So, in my case the solution was ...


2

After some more trying, I came to the answer myself. Just call the setStoreId() method on each attribute. So the code to get the Admin labels looks like this: $coll = $this->_objectManager->create(\Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection::class); $coll->addIsFilterableFilter(); $layeredNavAttributes = $coll->load()->...


2

You can try below code to get options of configurable attributes within configurable.phtml $special_attr = false; foreach ($_attributes as $_attribute) { echo $_attribute->getLabel().'<br>'; if ($_attribute->getLabel() === 'FooBar') { $special_attr = $_attribute->getPrices(); } } As you can see, the trick lies in $...


2

$customOptions = $objectManager->get('Magento\Catalog\Model\Product\Option')->getProductOptionCollection($_product); foreach($customOptions as $optionKey => $optionVal): foreach($optionVal->getValues() as $valuesKey => $valuesVal) { echo $valuesVal->getId().' '.$valuesVal->getTitle(); ...


2

If you have the attribute, you can do this: $id = $attribute->getSource()->getOptionId($label);


2

To achieve what I wanted I did the following: In /skin/frontend/[Theme]/js/configurableswatches/swatches-product.js Change: // rewrite the fillselect method from /js/varien/configurable.js Product.Config.prototype.fillSelect = function (element) { return; }; To: // rewrite the fillselect method from /js/varien/configurable.js Product.Config....


2

Raul was almost correct, but his answer returns a collection, not a simple object. For a specific attribute option it would be: $option = Mage::getResourceModel('eav/entity_attribute_option_collection') ->setIdFilter($attrOptionId) ->getFirstItem(); Or to get the sort order (position) of the option directly: $position = Mage::...


2

Create a module Override the configurable model in VENDOR/MODULENAME/Model/Product/Type/Configurable.php namespace VENDOR\MODULENAME\Model\Product\Type; use Magento\ConfigurableProduct\Model\Product\Type\Configurable as ConfigurableProduct; class Configurable extends \Magento\ConfigurableProduct\Model\Product\Type\Configurable { public function ...


2

You can use $options = $item->getBuyRequest(); Instead of $options = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());


2

Please use below to get additional_options $options = $item->getOptionByCode('additional_options');


2

The issue here seems to be in the line with $option->setLabel($optionLabel); Given the fact that it needs to be an actual label, we're providing an object. vendor/magento/module-eav/Api/Data/AttributeOptionInterface.php says that * @param string $label


2

I also face this issue and i found the solution about this type of error. In Magento 2.2.X and Magento 2.3.X big different in this file - vendor/magento/module-eav/Model/Entity/Attribute/OptionManagement.php In Magento 2.2.X, $option->setLabel($optionLabel) function passing the optionLabel object. In Magento 2.3.X, $option->setLabel() function ...


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