2016-05-18 11 views
1

商品の最終価格を変更する順序で各商品ごとに実施する必要のあるカスタム価格設定があります。見積もりループでの商品価格の更新

sales_quote_item_qty_set_afterイベントのオブザーバーを使用して、他のイベントから希望の結果を得ることができなかったため、製品が再構成されるたびに価格が確実に実行されるようにしています。

私が問題になっているのは、->getAllItems()を使用して見積もりを繰り返すと、見積もりで製品の価格を変更できないことです。

私は、製品の追加イベントで次のように価格を上書きできることを知っています。

$_item = $obs->getQuoteItem(); 
$_item = ($_item->getParentItem() ? $_item->getParentItem() : $_item); 
$new_price = 1000; 
$_item->setCustomPrice($new_price); 
$_item->setOriginalCustomPrice($new_price); 
$_item->getProduct()->setIsSuperMode(true); 

しかし、カート内の見積もり項目を実行しているときには実行できません。これは可能ですか、価格は別のオブザーバーで行う必要がありますか?その場合はどちらですか?

完全なコードは

public function adminAddProduct(Varien_Event_Observer $obs) { 
    $quote = $this->_getSession()->getQuote(); 
    foreach($quote->getAllItems() as $_item){ 
     $options = $_item->getProduct()->getTypeInstance(true)->getOrderOptions($_item->getProduct()); 
     $_product = $_item->getProduct(); 
     $sku = $options['simple_sku']; 
     if ($sku) { 
      $tierPrices = $_product->getTierPrice(); 
      $price = $_item->getPrice(); 
      $qty = $options['info_buyRequest']['qty']; 

      $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku); 
      $runspeed = $product->getResource()->getAttribute('runspeed')->getFrontend()->getValue($product); 

      $prodOpts = []; 
      foreach($options['options'] as $option) { 
       $prodOpts[$option['label']] = $option['value']; 
      } 

      $index = 0; 
      foreach($tierPrices as $tierPrice) { 
       if($tierPrice['price_qty'] <= $qty && $tierPrices[$index + 1]['price_qty'] > $qty) { 
        $price = $tierPrice['price']; 
       } 
       //$prodTiers[$tierPrice['price_qty']] = $tierPrice['price']; 
      } 

      if($prodOpts['Quantity'] == 'Fixed Quantity' && array_key_exists('Quantity Select', $prodOpts)){ 
       $qty = str_replace(',', '', explode(" ", $prodOpts['Quantity Select'])[0]); 
      } else { 
       $qty = 1; 
      } 

      $_item->setQty($qty); 
      $_item->setCustomPrice($customPrice)->setOriginalCustomPrice($customPrice); 

      $new_price = 999; 

      $_item->setPrice($new_price); 
      $_item->setCustomPrice($new_price); 
      $_item->setOriginalCustomPrice($new_price); 
      $_item->save(); 

      Mage::log($price); 
      Mage::log($prodOpts); 
     } 
    } 
} 

すべてのヘルプは高く評価されています...以下の通りです。

+0

これを受け入れるために回答として投稿してください。これは完全に機能します。 – Sidriel

答えて

1

機能の最後に$quote->save()を試してみるとよいでしょう。

関連する問題