2014-03-25 118 views
0

首先我開發的自定義價格的延伸,我有產品頁面上的輸入,這是一個形象描述我做了什麼:Magento的:添加產品到購物車定製價格

enter image description here

當顧客輸入他想要的價格並點擊添加到購物車時,產品必須添加他添加的價格。

我知道可以在控制器中編碼,但我不知道如何?

這是控制器空類:

<?php 

class WebDirect_CustomPrice_savePriceController extends Mage_Core_Controller_Front_Action{ 
    //put your code here 
} 

的人都知道怎麼說添加到購物車按鈕作品(代碼)

+0

請發表您的代碼的其餘部分,當用戶點擊添加到購物籃被稱爲控制器用什麼方法和你有什麼樣的價值觀訪問嗎? (即自定義價格)。可以做你想做的事,但要讓基礎知識首先工作(即,產品實際上首先以正常價格加入購物車)。一旦你有這個工作看看這篇文章,我已經解釋瞭如何做到這一點之前:http://stackoverflow.com/questions/20949796/can-we-add-more-than-one-special-price-in -magento-using-price-type-attribute/20961884#comment31595731_20961884 – Ashley

+0

另外,我會嘗試使用觀察者來完成此操作,而不是使用全新的自定義控制器,並更改大量的magento默認行爲。想想未來的升級:-) – Ashley

+0

@AshleySwatton如果那麼如何做到這一點與觀察員?該擴展不會修改核心,這就是我想要的? – Souf

回答

7

您需要爲它調用final_price觀察者。需要按照波紋管的步驟:在等/ config.xml中你

<events> 
    <catalog_product_get_final_price> 
    <observers> 
     <xyz_catalog_price_observer> 
     <type>singleton</type> 
     <class>Xyz_Catalog_Model_Price_Observer</class> 
     <method>apply_customprice</method> 
     </xyz_catalog_price_observer> 
    </observers> 
    </catalog_product_get_final_price>  
</events> 
  1. Add方法

    1加觀察模型apply_customprice()

    public function apply_customprice($observer) 
    { 
        $event = $observer->getEvent(); 
        $product = $event->getProduct(); 
    // ADDD LOGIC HERE to get price added by customer 
        $product->setFinalPrice($specialPrice); // set the product final price 
        return $this; 
    } 
    

點擊下方比如在購物車中添加產品時,如何設置自定義價格。

http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/customizing_magento_using_event-observer_method

+0

好吧我要去嘗試這個希望它的作品 – Souf

+0

順便說一句Xyz是什麼名稱空間或模塊名稱? – Souf

+0

價格改變,但我不想畫正常價格 – Souf

1

作爲一個起點,你可以在開始:

class Mage_Checkout_CartController extends Mage_Core_Controller_Front_Action 
{ 

/** 
* Add product to shopping cart action 
* 
* @return Mage_Core_Controller_Varien_Action 
* @throws Exception 
*/ 
public function addAction() 
{ 

確保覆蓋添加到購物車的路線以指向您的路線(覆蓋上述Core路線的新路線)。

也從用戶的輸入中獲取價格也會影響結帳過程,特別是報價以及由此產生的所有內容(購物車,訂單等)。

另外,關於onepage checkout,小心BE邏輯和opcheckout.js在一起。

Chears

相關問題