4
我希望能夠以編程方式更改項目的價格(而不是通過目錄或車規則),當我將其添加到購物車當改變項目的價格。Magento的:如何將它添加到購物車
以下的答案Programmatically add product to cart with price change說明如何更新車,但不添加產品時,當做到這一點。
感謝
我希望能夠以編程方式更改項目的價格(而不是通過目錄或車規則),當我將其添加到購物車當改變項目的價格。Magento的:如何將它添加到購物車
以下的答案Programmatically add product to cart with price change說明如何更新車,但不添加產品時,當做到這一點。
感謝
您可以使用一個觀察者類聽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>
然後在創建/應用/代碼觀察員類/本地/ {命名空間}/{} yourmodule /Model/Observer.php
<?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;
}
}
如果我添加使用觀察者設置自定義價格到購物車,然後我得到以電子郵件模板乘以項目數量的單位價格。 我該如何解決這個問題 app \ design \ frontend \ default \ rfg \ template \ email \ order \ items \ order \ default.phtml <?php echo $ _order-> formatPrice($ _ item-> getRowTotal())? > – Muk
任何人都可以解釋從該行''setIsSuperMode' $用品 - > getProduct() - > setIsSuperMode(真);'?它有什麼作用? – mkutyba
這裏是超模的explantion: 「報價超級模式標誌是什麼意思,我們與報價工作,不受任何限制」 例如:如果超級模式設置爲true,磁不會檢查該產品是否在目錄中可見 – Nidheesh