Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento:将相同的产品以不同的价格添加到购物车中_Magento - Fatal编程技术网

Magento:将相同的产品以不同的价格添加到购物车中

Magento:将相同的产品以不同的价格添加到购物车中,magento,Magento,我已编程允许客户编辑产品的价格 问题是,当我在购物车页面中添加20$的产品并再次添加30$的相同产品时,它会显示产品-|数量=2-|总价=60$ 因此,这是不符合逻辑的总价格必须是50美元,它不应该设置数量为2 我知道问题出在SKU上有解决方案吗?我不想修改SKU 更多细节是我前面的问题,所以这是可行的,但不幸的是,如果不进行非常重要的重写,就没有办法做到这一点。我假设你有一些方法来识别两个报价项目之间的差异,除了价格。如果是这样的话: 销售/报价项目:representProduct() 模块

我已编程允许客户编辑产品的价格

问题是,当我在购物车页面中添加20$的产品并再次添加30$的相同产品时,它会显示产品
-|数量=2-|总价=60$

因此,这是不符合逻辑的总价格必须是50美元,它不应该设置数量为2

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


更多细节是我前面的问题

,所以这是可行的,但不幸的是,如果不进行非常重要的重写,就没有办法做到这一点。我假设你有一些方法来识别两个报价项目之间的差异,除了价格。如果是这样的话:

销售/报价项目:representProduct()

模块中的重写配置:

<?xml version="1.0"?>
<config>
    <global>
        <models>
            <sales>
                <rewrite>
                    <!--Your full class name should be specified-->
                    <quote_item>Namespace_Module_Model_Sales_Quote_Item</quote_item>
                </rewrite>
            </sales>
        </models>
    </global>
</config>
我们的职能:

public function representProduct($product) {
    $parentResult = parent::representProduct($product);

    //if parent result is already false, we already have a different product, exit.
    if ($parentResult === false) {
        return $parentResult;
    }

    $itemProduct = $this->getProduct();

    /*
     * do our check for 'same product' here.
     * Returns true if attribute is the same thus it is hte same product
     */
    if ($product->getSomeAttribute() == $itemProduct->getSomeAttribute()) {
        return true; //same product
    } else {
        return false; //different product
    }
}
如果此函数返回true,则产品将作为同一项目组合在购物车中,因此您只需按新的数量增加数量


如果此函数返回false,则产品将看起来不同,并在购物车中显示为不同的项目。

添加具有不同“SKU”的相同产品,您可以为这些产品提供不同的价格。

这是一个类:

<?php
class WebDirect_CustomPrice_Model_Sales_Quote_Item extends Mage_Sales_Model_Quote_Item
{
    public function representProduct($product) {
        $parentResult = parent::representProduct($product);

        //if parent result is already false, we already have a different product, exit.
        if ($parentResult === false) {
            return $parentResult;
        }

        $itemProduct = $this->getProduct();

        /*
         * do our check for 'same product' here.
        * Returns true if attribute is the same thus it is hte same product
        */
        if ($product->getPrice() == $itemProduct->getPrice()) {
            return true; //same product
        } else {
            return false; //different product
        }
    }




}

@lan我想我会使用observer来完成这项工作,当单击“添加到购物车”时,事件的名称是什么?您可能想退出的事件是“销售\报价\产品\添加\之后”。但是,该函数不能用事件触发。您必须重写Mage_Sales_Model_Quote_项,并用自己的函数重载该项。@lan如何重写Mage_Sales_Model_Quote_项?用rewrite更新了原始答案。因此,我添加了您所说的配置@lan查看我的答案
<?php
class WebDirect_CustomPrice_Model_Sales_Quote_Item extends Mage_Sales_Model_Quote_Item
{
    public function representProduct($product) {
        $parentResult = parent::representProduct($product);

        //if parent result is already false, we already have a different product, exit.
        if ($parentResult === false) {
            return $parentResult;
        }

        $itemProduct = $this->getProduct();

        /*
         * do our check for 'same product' here.
        * Returns true if attribute is the same thus it is hte same product
        */
        if ($product->getPrice() == $itemProduct->getPrice()) {
            return true; //same product
        } else {
            return false; //different product
        }
    }




}