Magento:购物车中的相同产品,价格不同 [英] Magento : same product in shopping cart with different prices

查看:113
本文介绍了Magento:购物车中的相同产品,价格不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已通过编程方式允许客户编辑产品的价格.

I've programmaticaly allowed the customer to edit the price of a product.

问题是,当我添加价格为400美元的产品并再次添加价格为500美元的同一产品时,在购物车页面中会显示产品-|数量= 2-|总价= 1000 $

the problem is when i add product with 400$ and adding again the same product with 500$, in the shopping cart page it displays the product -| qty=2 -| total price=1000$

因此这不是逻辑,总价格必须为900 $,并且不应将数量设置为2

so this is not logic the total price must be 900$ and it should not set qty to 2

我知道问题出在SKU上,是否有解决方案,我不想修改SKU?

i know the problem is in the SKU is there a solution for this i don't wanna modify the SKU?

对于我的问题是:

应该是这样的:

这适用于自定义价格:

/**

 * @param Varien_Event_Observer $observer
 */

    public function applyCustomPrice(Varien_Event_Observer $observer) {

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

        Mage::app()->getRequest()->getPost();

        $customPrice = Mage::app()->getRequest()->getParam('custom_price');
        $defaultCp = $item->getProduct()->getData('min_price');

        $product = $observer->getEvent()->getProduct();
        //$product_id = Mage::registry('current_product')->getId();

        $product->addCustomOption('testpricez', '1078');

        if($customPrice >= $defaultCp){

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


    }

我做了很多搜索但没有结果

i've done many search but without result

如何与观察者一起做到这一点?

how to do this with the observer ?

推荐答案

因此,您将希望摆脱"sales_quote_save_before"

So, you'll want to piggy back off of "sales_quote_save_before"

在config.xml内部:

inside config.xml:

<sales_quote_save_before>
   <observers>
       <pricebuilder>
           <type>singleton</type>
           <class>pricebuilder/observer</class>
           <method>updateQuoteItems</method>
        </pricebuilder>
   </observers>
</sales_quote_save_before>

observer.php内部:

inside observer.php:

/**
 * @param Varien_Event_Observer $observer
 */
public function updateQuoteItems($observer)
{
    /** @var $quote Mage_Sales_Model_Quote */
    $quote = $observer->getQuote();

    /** @var $quoteItem Mage_Sales_Model_Quote_Item */
    foreach ($quote->getAllItems() as $quoteItem) {
        $this->processQuoteItem($quoteItem);
    }
}

/**
 * This is an example that sets all quote items to 123.55.
 * you would of course implement your logic here for the given quote item.
 *
 * @param $quoteItem Mage_Sales_Model_Quote_Item
 *
 * @return $this
 */
private function processQuoteItem($quoteItem)
{
    $finalPrice = 123.55;
    $quoteItem->setCustomPrice($finalPrice);
    $quoteItem->setOriginalCustomPrice($finalPrice);
    $quoteItem->getProduct()->setIsSuperMode(true);

    return $this;
}

这篇关于Magento:购物车中的相同产品,价格不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆