2012-03-06 3 views
0

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

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

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

ответ

2

Вы просматриваете страницу?

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: [email protected] 
* 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); 
     } 
    } 
} 
?> 
Смежные вопросы