2012-11-13 42 views
2

我已經創建了一個簡單的電子商務應用程序,可以根據許多選項計算價格。Magento - 動態定價

價格是基於PHP中存儲在MySQL中的一堆變量計算的。我已經將PHP編碼爲一個Web服務,我使用jQuery AJAX進行查詢。

我需要將其整合到客戶現有的使用Magento的電子商務網站中。

我想讓客戶將我的「動態定價產品」添加到他們的購物車中。我需要能夠添加自定義價格以及產品信息(我很高興在單個隱藏字段中)。

我熟悉編程(客戶端和服務器端,大多數語言),但我對Magento一點都不熟悉。有沒有簡單的方法來實現這一點?理想情況下,我會將這些信息添加到現有的表單中。

回答

1

我能想到的最簡單的方法是在magento中創建一個產品作爲模板。

然後在您的觀察方法創建一個觀察者

<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 to check if this is the custom product and to get value from ajax> 
    $quote_item->setOriginalCustomPrice($new_price); 
    $quote_item->save(); 
} 

(注意,用戶可以隨時假後,改變該項目的價格)

請參閱Customize Magento using Event/Observer

+0

謝謝,這似乎正是我想!我知道有人可以「欺騙」這個值,但是當管理員用戶查詢時,它會被重新檢查。 –