回答
做的方式是添加一個觀察者,看起來此事件'sales_quote_add_item'
:
<events>
<sales_quote_add_item>
<observers>
<priceupdate_observer>
<type>singleton</type>
<class>mymodule/observer</class>
<method>updatePrice</method>
</priceupdate_observer>
</observers>
</sales_quote_add_item>
</events>
觀察員應該有哪些不一樣的東西的方法這樣的:
public function updatePrice($observer) {
$event = $observer->getEvent();
$quote_item = $event->getQuoteItem();
$new_price = <insert logic>
$quote_item->setOriginalCustomPrice($new_price);
$quote_item->save();
}
您可以使用一個觀察者類聽checkout_cart_product_add_after,並使用產品的「超級模式」設置自定義價格AGA引述報價項目。
在你/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)
{
$customPrice = Mage::getSingleton(’core/session’)->getCustomPriceCalcuation(); // Provide you price i have set with session
$p = $obs->getQuoteItem();
$p->setCustomPrice($customPrice)->setOriginalCustomPrice($customPrice);
}
}
如用右手由革順Herczeg,爾根Thelen和古典的xman回答。您需要編寫一個sales_quote_add_item事件的觀察者。 當任何產品添加到購物車時,您的觀察者將被觸發。如果產品是可配置的,那麼這個事件將被觸發兩次,您將不得不這樣做,以獲得簡單的產品。
$item = $observer->getEvent()->getQuoteItem();
$quote = $item->getQuote();
$product = $item->getProduct();
if ($product->getTypeId() != "configurable") {
//Do your thing here
}
有關可配置產品的問題已解決。您只需刪除
$ quote_item-> save();
然後爲產品不會添加到購物車兩次。但是這個功能仍然存在很嚴重的問題。也就是說,使用此功能,我們可以更新購物車中的商品價格,但添加到購物車後,產品價格不會根據不同的貨幣進行更改。所以這個功能不能用於有多種貨幣的商店。
如果有人發現關於這個問題的任何解決方案,請與我們分享......
一應俱全。
文件:/app/etc/modules/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Ajax_ProductAdjust>
<codePool>local</codePool>
<active>true</active>
</Ajax_ProductAdjust>
</modules>
</config>
文件:/app/code/local/Ajax/ProductAdjust/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Ajax_ProductAdjust>
<version>1.0.1</version>
</Ajax_ProductAdjust>
</modules>
<global>
<models>
<Ajax_ProductAdjust>
<class>Ajax_ProductAdjust_Model</class>
</Ajax_ProductAdjust>
</models>
<events>
<sales_quote_add_item>
<observers>
<ajax_productadjust_model_observer>
<type>singleton</type>
<class>Ajax_ProductAdjust_Model_Observer</class>
<method>updatePrice</method>
</ajax_productadjust_model_observer>
</observers>
</sales_quote_add_item>
</events>
</global>
</config>
文件: /app/code/local/Ajax/ProductAdjust/Model/Observer.php
<?php
//Notes
class Ajax_ProductAdjust_Model_Observer
{
public function _construct()
{
}
public function getNewPrice()
{
//Your new functionality here
//
$newprice = "";
return $newprice;
}
public function updatePrice(Varien_Event_Observer $observer)
{
$event = $observer->getEvent();
$quote_item = $event->getQuoteItem();
$new_price = $this->getNewPrice();
$quote_item->setOriginalCustomPrice($new_price);
$quote_item->save();
}
}
乾杯,
這個問題並沒有說明是否應該通過向代碼中添加一些邏輯來完成。因此,既然你有開發者的答案,那麼也有一些被稱爲購物車價格規則的東西(在管理面板中去促銷>購物車價格規則),你可以創建不同的規則來製作銷售和折扣(帶或不帶優惠券)。
To change product price while adding product to cart, use an observer event.
Follow the steps given below
1. Add an observer in your module config.xml file.
2. Create an observer file in your model
3. add checkout_cart_product_add_after event
文件:應用程序/代碼/本地/命名空間/模塊的/ etc/config.xml中
例如:應用程序/代碼/本地/ MGS/Rileytheme的/ etc/config.xml中
<frontend>
<routers>
<routeurfrontend>
<use>standard</use>
<args>
<module>MGS_Rileytheme</module>
<frontName>rileytheme</frontName>
</args>
</routeurfrontend>
</routers>
<layout>
<updates>
<rileytheme>
<file>rileytheme.xml</file>
</rileytheme>
</updates>
</layout>
<events>
<checkout_cart_product_add_after>
<observers>
<rileytheme>
<class>rileytheme/observer</class>
<method>modifyPrice</method>
</rileytheme>
</observers>
</checkout_cart_product_add_after>
</events></b>
<frontend>
文件:應用程序/代碼/本地/ MGS/Rileytheme /型號/ Observer.php
class MGS_Rileytheme_Model_Observer {
public function modifyPrice(Varien_Event_Observer $observer) {
//$order = Mage::registry('current_order'); For getting current order
//$orderid = $order->getRealOrderId(); For getting orderid
$quote_item = $observer->getQuoteItem();
$payment = 30; //add your custom product price here and do your logic here
$quote_item->setOriginalCustomPrice($payment);
$quote_item->save();
return $this;
}
}
- 1. 更改產品的價格,同時添加到購物車woocommerce
- 2. Magento的:添加一個「假」的產品到購物車/報價
- 3. Magento的:添加產品到購物車定製價格
- 4. Magento:將可配置產品添加到購物車時的價格錯誤
- 5. 導入報價並將產品添加到購物車中Magento 2
- 6. WooCommerce:將產品添加到價格優先的購物車?
- 7. Python:將多個產品和價格添加到購物車
- 8. Magento如何更新購物車中的產品價格
- 9. 添加選項價值產品,然後到Magento購物車
- 10. 通過Magento API將產品添加到購物車導致0價格
- 11. 更改WooCommerce購物車中的產品價格並結帳
- 12. 添加產品選項價格到購物車頁面 - Opencart?
- 13. 與產品添加自定義價格到購物車Shopify
- 14. Magento:產品添加到購物車
- 15. 在Woocommerce更改購物車產品價格
- 16. Magento的添加到購物車價格更新
- 17. Magento的更改產品名稱添加到購物車
- 18. 將相關產品添加到報價中,但不包含購物車
- 19. 購物車價格不包括特殊產品的價格
- 20. 無法將產品添加到價格差異超過50的購物車中
- 21. Magento顯示購物車產品頁面上的價格規則
- 22. WooCommerce - 更改購物車中物品的價格
- 23. Magento購物車價格規則不適用於捆綁產品
- 24. 修改WooCommerce購物車中的產品價格
- 25. 將$ _POST價值添加到購物車
- 26. Magento Theme在IE(Javascript)中將產品2x添加到購物車
- 27. 跟蹤客戶在Magento中將產品添加到購物車
- 28. magento添加產品在multishipping報價
- 29. 打開購物車許多產品的相同產品價格?
- 30. 將產品添加到購物車
感謝分享信息!所以,XML將進入我們需要創建的本地模塊,是的? (我通過搜索找到了這個:http://goo.gl/UBFgS)然後公共函數可以在運行我正在考慮的購物車代碼的phtml中聲明嗎? – 2012-05-08 21:43:56
在這裏,這應該給你一個關於如何創建觀察者的概述:http://alturl.com/tja43 – 2012-05-08 22:02:23
回答了我的問題!感謝分享! – haifacarina 2012-12-05 20:30:10