カートにアイテムを追加するときに、プログラムで(カタログやカートのルールではなく)アイテムの価格を変更できるようにしたいと思います。
次の回答プログラムで価格を変更して商品をカートに追加する方法は、商品を追加するときではなく、カートを更新するときに行う方法を示しています。
ありがとう
カートにアイテムを追加するときに、プログラムで(カタログやカートのルールではなく)アイテムの価格を変更できるようにしたいと思います。
次の回答プログラムで価格を変更して商品をカートに追加する方法は、商品を追加するときではなく、カートを更新するときに行う方法を示しています。
ありがとう
オブザーバー クラスを使用して checkout_cart_product_add_after をリッスンし、製品の「スーパー モード」を使用して見積もりアイテムに対してカスタム価格を設定できます。
/app/code/local/{namespace}/{yourmodule}/etc/config.xml で:
<config>
...
<frontend>
...
<events>
<checkout_cart_product_add_after>
<observers>
<unique_event_name>
<class>{{modulename}}/observer</class>
<method>modifyPrice</method>
</unique_event_name>
</observers>
</checkout_cart_product_add_after>
</events>
...
</frontend>
...
</config>
そして /app/code/local/{namespace}/{yourmodule}/Model/Observer.php に Observer クラスを作成します
<?php
class <namespace>_<modulename>_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 = $this->_getPriceByItem($item);
// Set the custom price
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
// Enable super mode on the product.
$item->getProduct()->setIsSuperMode(true);
}
protected function _getPriceByItem(Mage_Sales_Model_Quote_Item $item)
{
$price;
//use $item to determine your custom price.
return $price;
}
}