亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在將產品添加到購物車時更改報價的價格:magento

在將產品添加到購物車時更改報價的價格:magento

哈士奇WWW 2019-12-03 10:48:48
我想在將產品添加到購物車時更改產品價格。怎么可能讓我知道...
查看完整描述

3 回答

?
月關寶盒

TA貢獻1772條經驗 獲得超5個贊

做到這一點的方法是添加一個觀察該事件的觀察者'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();

}


查看完整回答
反對 回復 2019-12-03
?
30秒到達戰場

TA貢獻1828條經驗 獲得超6個贊

您可以使用觀察者類來收聽checkout_cart_product_add_after,并使用產品的“超級模式”為報價項設置自定義價格。


在您的/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>

然后在/app/code/local/{namespace}/{yourmodule}/Model/Observer.php中創建一個Observer類


    <?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); 

            }


        }


查看完整回答
反對 回復 2019-12-03
?
慕田峪4524236

TA貢獻1875條經驗 獲得超5個贊

堅果湯。


文件:/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();

      }

 }

干杯,


查看完整回答
反對 回復 2019-12-03
  • 3 回答
  • 0 關注
  • 783 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號