获取

2014-03-26 46 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 –