0

I have a product attribute for delivery time akeneo_delivery_time, that's filled from a PIM (akeneo) by import. This is of type "Dropdown" with scope of "Store View" (We have two storeViews, with locales of de_DE and fr_FR). The options contain translations of the delivery time text for every locale.

I wanted to keep the delivery_time attribute that comes with magento (mage_setup), which is of type "text", in order to not break compatibility which 3rd party extensions.

My idea was to write an indexer that transferes the attribute frontend-values of the "Dropdown" to the text attribute "delivery_time". There is no problem with that, it works fine.

But i cannot get the locale specific value. getAttributeText gives my the correct option for the storeViews, but not in the locale of that storeView. I get the option text in "de", never in "fr".

    $stores = Mage::app()->getStores();
    foreach ($stores as $store) {
        Mage::app()->setCurrentStore($store);
        $productCollection = Mage::getModel('catalog/product')->getCollection();

        $resource = Mage::getResourceSingleton('catalog/product');
        foreach ($productCollection as $product) {
            $akeneoDeliveryTime = $product->getAttributeText('akeneo_delivery_time');
            $product->setData('delivery_time', $akeneoDeliveryTime);
            $resource->saveAttribute($product, 'delivery_time');
        }
    }

What am i doing wrong here? Do I need to set locale somewhere?


I have seen in Mage_Catalog_Block_Product_View_Attributes, it works like this:

   public function getAdditionalData(array $excludeAttr = array())
{
    $data = array();
    $product = $this->getProduct();
    $attributes = $product->getAttributes();
    foreach ($attributes as $attribute) {
        if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) {
            $value = $attribute->getFrontend()->getValue($product);

But here "$product" contains translates option values from the start.

0

Try replacing this

$productCollection = Mage::getModel('catalog/product')->getCollection();

with this

$productCollection = Mage::getModel('catalog/product')
                   ->setStoreId($store->getId())
                   ->getCollection()
                   ->addAttributeToSelect('akeneo_delivery_time');
  • like this, i get no values from "getAttributeText" at all. – hhein Mar 10 '16 at 13:56
  • I've updated the code. Give it an other try. – Marius Mar 10 '16 at 14:05
  • ok, this get´s me back to the previous state. I get the correct option, but in the wrong locale. always 'de", although the locale of the second storeView is 'fr". – hhein Mar 10 '16 at 14:11
  • any update on this issue? – Marcel Lange Jan 4 '18 at 17:32

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.