1

Do you know why magento saves multiselect attribute type as varchar and relative product assocations in catalog_product_entity_varchar as array?

With array is not possible join between catalog_product_entity_varchar and eav_attribute_option_value on value=option_id

when value is varchar like 1,2,3, because option_id is int.

Isn't better considerer multiselect as multiple int and insert multiple record in catalog_product_entity_int?

So is possible join correctly catalog_product_entity_int and eav_attribute_option_value on value=option_id

  • 1
    I think that magento saves multiselect values in a string comma separated and not in multi int values, because it is stored in a single record and it is easier to handle. – KamL Apr 2 '19 at 13:24
0

Multiselect attributes can be set as a comma separated list (or also an array) containing the attribute value ids.

So first we have to convert the actual values to Magento's internal ids. try this code:-

$attrCode = 'color_base';
$sourceModel = Mage::getModel('catalog/product')->getResource()
    ->getAttribute($attrCode)->getSource();
$valuesText = explode(',', 'red,green,blue');
$valuesIds = array_map(array($sourceModel, 'getOptionId'), $valuesText);
$product->setData($attrCode, $valuesIds);
$product->save();

link:-http://swarminglabs.com/how-to-change-a-product-dropdown-attribute-to-a-multi-select/

  • is possible to avoid that magento saves it as a comma separeted list and save it directly as single int like dropdown? – LucScu Jul 3 '15 at 10:33
  • yes try it possible – Ashvin Monpara Jul 3 '15 at 10:34
  • and visit link swarminglabs.com/… – Ashvin Monpara Jul 3 '15 at 10:37
  • Ok, i try your code, but why magento don't has this logic by default and i have to do it with a custom code? My question was: why they use this logic to save multiselect in array? – LucScu Jul 3 '15 at 10:39
  • i have begin in magento – Ashvin Monpara Jul 3 '15 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.