1

I have a problem in magento 1.7 when I'm trying to check the "use default value" on a product attribute.

I would like to check programmaticaly the checkbox "use default value" when the global special_price is the same as the specific store special_price.

My problem is all "global values" going to be empty when I used my script.

Thanks you if somebody can help me.

Cordially.

Here my script :

     $oGlobalProduct = Mage::getModel('catalog/product')->setStoreId(0)->load($iProductId);
        $oProduct = $oProductModel->setStoreId($iStoreId)->load($iProductId);
         //standard price is a custom attribute
        if($oGlobalProduct->getSpecialPrice() == $oProduct->getStandardPrice())
        {
             $setId = $oProduct->getAttributeSetId();

            $aAttribute = array();

            if ($setId)
            {
    // get all attribute group of the product
                $groupCollection = Mage::getResourceModel('eav/entity_attribute_group_collection')
                    ->setAttributeSetFilter($setId)
                    ->setSortOrder()
                    ->load();

                foreach ($groupCollection as $group)
                {
                    $attributes = $oProduct->getAttributes($group->getId(), true);

                    foreach ($attributes as $key => $attribute)
                    {
                        if (!$attribute->getIsVisible())
                        {
                            unset($attributes[$key]);
                        }
                        else {
                            $aAttribute[$attribute->getId()] = array(
                                'attribute_code' => $attribute->getAttributeCode(),
                                'use_default' => $oProduct->getExistsStoreValueFlag($attribute->getAttributeCode()),
                                'global_value' => $oGlobalProduct->getData($attribute->getAttributeCode()),
                                'store_value' => $oProduct->getData($attribute->getAttributeCode())
                            );
                        }
                        try{

                            if($aAttribute[$attribute->getId()]['global_value'] == $aAttribute[$attribute->getId()]['store_value'])
                            {
                                $oProduct->setStoreId($iStoreId)
                                    ->setData($attribute->getAttributeCode(), false);
                            }
                        }
                        catch (Exception $e)
                        {
                            echo $e->getMessage();
                            continue;
                        }
                    }
                }
                $oProduct->save();
            }    
        }

Product view before the script (global) :

enter image description here

Product view before the script (store) :

enter image description here

Product view after the script (global)

enter image description here

Product view after the script (store)

enter image description here

Your Answer

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

Browse other questions tagged or ask your own question.