Retrieve multiselect values for all products
-
07-10-2020 - |
Вопрос
I need to retrieve all values of some multiselect attributes that each of my products have. I found related posts but none of them seems to solve my problem.
For example I found the code
echo $_product->getResource()->getAttribute('car_options')->getFrontend()->getValue($_product);
But I don't know where should I get $_product from. I guess it's a simple task, but I am pretty new to Magento and I'm still discovering how it works.
I am using Magento 1.7. Any help is much appreciated :-)
Решение
You can use below code,
<?php
$productMultiSelectData = array();
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect("*");
foreach($collection as $_product){
$productMultiSelectData[$_product->getId()] = $_product->getResource()->getAttribute('car_options')->getFrontend()->getValue($_product);
}
echo "<pre>";
print_r($productMultiSelectData);
It will give you output like this, here key is product Id and value is your attribute option data.
[1] => 'Option 1, Option2',
[2] => 'Option 1, Option2, Option3',
[3] => 'Option 1, Option5',
[4] => 'Option 3, Option6'
Не связан с magento.stackexchange