2016-10-11 10 views
0

にカートページに追加している間、私は、製品ページで製品の異なる価格を追加するためにカスタマイズされたコードを書かれています中変更価格Magentoの

<?xml version="1.0"?> 
<config> 
    <global> 
    <models> 
     <price> 
      <class>custom_price_Model</class> 
     </price> 
    </models> 
    <events> 
     <checkout_cart_product_add_after> 
      <observers> 
       <custom_price_observer> 
       <class>price/observer</class> 
       <method>modifyPrice</method> 
       </custom_price_observer> 
      </observers> 
     </checkout_cart_product_add_after> 
    </events> 
    </global> 
</config> 

コード:アプリ/コード/ローカル/カスタム/価格/モデル/ Observer.php

class custom_price_Model_Observer 
{ 
    public function modifyPrice(Varien_Event_Observer $obs) 
    { 
     // Get the quote item 
     $item = $obs->getQuoteItem(); 
     // Ensure we have the parent item, if it has one 
     $item = ($item->getParentItem() ? $item->getParentItem() : $item); 
     // Load the custom price 
     $price = "30"; 
     // Set the custom price 
     $item->setCustomPrice($price); 
     $item->setOriginalCustomPrice($price); 
     // Enable super mode on the product. 
     $item->getProduct()->setIsSuperMode(true); 
    } 

まだその作業はありません。親切に助けてください。

+0

magentoはその特定の商品(製品)IDを使用して商品価格を取得するので、このためにオブザーバーを使用する必要があります。 –

+0

私は、製品の価格だけでなく、すべての電子メールを更新したいと思います。どのようにこれを達成することができます..? @NewBeeInMagento –

+0

あなたはオブザーバーを使用する必要があります –

答えて

0

カスタム価格を保存するには、次の手順を実行する必要があります。

class custom_price_Model_Observer 
{ 
    public function modifyPrice(Varien_Event_Observer $obs) 
    { 
     // Get the quote item 
     $item = $obs->getQuoteItem(); 
     // Ensure we have the parent item, if it has one 
     $item = ($item->getParentItem() ? $item->getParentItem() : $item); 
     // Load the custom price 
     $price = "30"; 
     // Set the custom price 
     $item->setCustomPrice($price); 
     $item->setOriginalCustomPrice($price); 
     // Enable super mode on the product. 
     $item->getProduct()->setIsSuperMode(true); 
     $item>save(); 
    } 
} 
+0

これは動作していません –

+0

** Mage:ログ**あなたのカスタム価格を試しましたか? –

0

以下は、カートに追加された後の製品の適用割引に使用されるコードです。カートに追加された製品の50%割引を適用しています。

function modifyPrice(Varien_Event_Observer $observer){ 
    $event = $observer->getEvent(); 
    $quote_item = $event->getQuoteItem(); 
    $product_id=$quote_item->getProductId(); 
    $product_price = Mage::getModel('catalog/product') 
         ->load($product_id) 
         ->getPrice();   
    if($product_price != 0){   
     $percentDiscount = 0.50; 
     $specialPrice = $product_price - ($product_price * $percentDiscount); 
     $quote_item->setOriginalCustomPrice($specialPrice);   
    } 
} 
関連する問題