Как обновить супер атрибуты в Magento? - PullRequest
0 голосов
/ 06 марта 2012

Я пытаюсь выяснить, как обновить супер-атрибут для настраиваемого продукта в Magento (в частности, цену начисления).

Мое первоначальное расследование привело меня к мысли, что мне придется сделатьчто-то с настраиваемым экземпляром типа продукта.Заглянув внутрь класса Mage_Catalog_Model_Product_Type_Configurable, я не вижу ничего, что могло бы быть связано с ценой, и кажется, что этот класс не имеет доступа к функции отладки, которую имеет большинство других объектов в Magento.

Может кто-нибудь сказать мнекак бы я обновлял цену супер атрибута?

1 Ответ

2 голосов
/ 07 марта 2012

Вы смотрели на этой странице?

http://www.ayasoftware.com/content/magento-update-fly-super-product-attributes-configuration

< ?php

require_once 'app/Mage.php';
umask(0);
Mage::app("admin");
ini_set("display_errors", 0);

/** This file will update The Super product attributes configuration
 *  The price for each color will be calculated based on the price
 *  of the simple product (PSP) and the price of the configurable product (PCP)
 *  price is  PSP - PCP (PCP < PSP)
 *  Need help contact us at:  support@ayasoftware.com
 *  author : EL HASSAN MATAR
 */
$model = Mage::getModel("catalog/product"); 
$products = $model->getColletction();
$products->addAttributeToFilter('status', 1);//enabled
$products->addAttributeToFilter('visibility', 4);//catalog, search
$products->addAttributeToSelect('*');
$prodIds=$products->getAllIds();
$product = Mage::getModel('catalog/product');

foreach($prodIds as $productid) {

/**
* Load Product you want to get Super attributes of
*/
    $product = Mage::getSingleton("catalog/Product")->load($productid);

    $configurablePrice = $product->getPrice();

    $associatedProducts=$product->getTypeInstance()->getUsedProducts();
    $stack = array();
    for($j=0; $j< sizeof($associatedProducts) ; $j++){
        array_push($stack,  Array("color"=>$associatedProducts[$j]['color'],"size"=>$associatedProducts[$j]['size'], "price"=>$associatedProducts[$j]['price']));
    }

    if ($data = $product->getTypeInstance()->getConfigurableAttributesAsArray(($product))) {

        foreach ($data as $attributeData) {

            $id = isset($attributeData['id']) ? $attributeData['id'] : null;
            $size = sizeof($attributeData['values']);
            for($j=0; $j< $size ; $j++){
                multiArrayValueSearch($stack, $attributeData['values'][$j]['value_index'], $match);
                reset($match); // make sure array pointer is at first element
                $firstKey = key($match);
                $match= array();
                $attributeData['values'][$j]['pricing_value'] = $stack[$firstKey]['price'] - $configurablePrice;
            }

            if($id == 7){   // Check your $id value
                $attribute = Mage::getModel('catalog/product_type_configurable_attribute')
                ->setData($attributeData)
                ->setId($id)
                ->setStoreId($product->getStoreId())
                ->setProductId($productid)
                ->save();
            }
        }
    }
}
function multiArrayValueSearch($haystack, $needle, &$result, &$aryPath=NULL, $currentKey='') {
    if (is_array($haystack)) {
        $count = count($haystack);
        $iterator = 0;
        foreach($haystack as $location => $straw) {
            $iterator++;
            $next = ($iterator == $count)?false:true;
            if (is_array($straw)) $aryPath[$location] = $location;
            multiArrayValueSearch($straw,$needle,$result,$aryPath,$location);
            if (!$next) {
                unset($aryPath[$currentKey]);
            }
        }
    } else {
        $straw = $haystack;
        if ($straw == $needle) {
            if (!isset($aryPath)) {
                $strPath = "\$result[$currentKey] = \$needle;";
            } else {
                $strPath = "\$result['".join("']['",$aryPath)."'][$currentKey] = \$needle;";
            }
            eval($strPath);
        }
    }
}
?>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...