獲取

2014-03-26 50 views
2

首先我創建了在Magento產品視圖頁面輸入描述戰時在Magento自定義輸入的值:獲取

enter image description here

,我已經做了觀察,因此設置自定義價格當添加到購物車(checkout_cart_product_add_after事件),這是功能:

public function applyCustomPrice(Varien_Event_Observer $observer) { 

     /* @var $item Mage_Sales_Model_Quote_Item */ 
     $item = $observer->getQuoteItem(); 
     if ($item->getParentItem()) { 
      $item = $item->getParentItem(); 
     } 

     $item->setCustomPrice(599.5); 
     $item->setOriginalCustomPrice(599.5); 
     $item->getProduct()->setIsSuperMode(true); 

    } 

就像你看到的,我已經把「599.5」,並且工作。 現在,我要的是得到的產品視圖頁面,輸入的值觀察者這是輸入:

<div class="price-box"> 

    <span id="product-price-27" class="price"> 
     <input id="CP_ID" class="input-text price" type="text" onmouseout="onChangeCP(this);" value="2699.9900" style="width:auto;" name="custom_price"></input> 
    </span> 
    <input id="custom_price_total" type="hidden" value="2699.9900" name="custom_price_total"></input> 

</div> 

任何人知道如何做到這一點?

+0

您必須創建一個自定義選項文本框並採取隱藏變量來設置您的自定義選項[價格]值,你可以使用getParams() –

+0

在觀察者中輕鬆獲得隱藏值我該怎麼做? @KeyurShah – Souf

+0

首先,你必須爲產品文本框定製選項後,採取一個隱藏的輸入類型和點擊addtocart你必須設置文本框值到您的隱藏變量使用JavaScript –

回答

5

如果能夠成功調用使用checkout_cart_product_add_after事件的觀察者,然後下面寫代碼來改變產品的價格

$event = $observer->getEvent(); 
     $quote_item = $event->getQuoteItem(); 
     $new_price = Mage::app()->getRequest()->getPost('pricecustom'); 

pricecustom是我隱變量

 if(!is_null($new_price)) 
     { 
      $quote_item->setCustomPrice($new_price); 
      $quote_item->setOriginalCustomPrice($new_price); 
      $quote_item->getProduct()->setIsSuperMode(true); 
     } 

讓我知道如果您有任何查詢

+0

完成它的工作謝謝! – Souf

+0

@keyur是否可以使用相同的代碼,如果需要從列表頁面設置定製產品價格? – Slimshadddyyy

+0

@Slimshadddyyy我認爲你也可以申請上市頁面,因爲這個事件執行時,產品被添加到購物車checkout_cart_product_add_after –