Magento购物车价格规则不适用于捆绑产品

时间:2013-10-17 12:02:50

标签: magento magento-1.7 discount coupon

我正在尝试将购物车价格规则应用于捆绑产品,但没有成功。我想要做的是,创建一个优惠券代码,使用SKU'ABC'对捆绑产品应用10%的折扣。

所以,我将SKU属性设置为'用于促销规则条件' - >'是',我创建了一个规则:

If ALL  of these conditions are TRUE :
If an item is FOUND  in the cart with ANY  of these conditions true: 
SKU is ABC

但没有成功......

所以我读了一些关于捆绑产品和价格规则只适用于简单产品的事情(是这样吗?),所以我改变了我的规则,因此它适用于我的捆绑产品中的产品:

If ALL  of these conditions are TRUE :
If an item is FOUND  in the cart with ANY  of these conditions true: 
SKU is one of ABC,ABC-1,ABC-2

没有运气......

所以我尝试离开整个SKU-thing,然后创建一个新属性:give_discount,并将其设置为'用于促销规则条件' - >'是'。是的,我现在非常绝望。我创建了属性,将其添加到我的捆绑包以及它的子产品中:

If ALL  of these conditions are TRUE :
If an item is FOUND  in the cart with ANY  of these conditions true: 
Give discount  is  Yes 

仍然......不......运气......

现在,有谁知道这里发生了什么?我只是无法绕过它!捆绑产品不可能以这种方式给予折扣吗?当我离开这些条件时,会给出折扣(如预期的那样),但是一旦我应用过滤器,我就会得到优惠券代码无效的概念......

修改

我的定价规则适用于其他类型的产品。经过一些研究,我设法通过创建一个隐藏的类别,将捆绑的产品放入其中,并将价格规则应用于该类别来使代码工作。这是如何实现上述目标的唯一方法吗?

2 个答案:

答案 0 :(得分:1)

尝试一下:

条件:

If ALL  of these conditions are TRUE :
    If an item is FOUND  in the cart with ALL  of these conditions true: 
        SKU  is  ABC  

    If an item is FOUND  in the cart with ALL  of these conditions true: 
        SKU  is  ABC-1

    If an item is FOUND  in the cart with ALL  of these conditions true: 
        SKU  is  ABC-2  

操作:

Update prices using the following information
    Apply: Fixed Amount discount
    Discount amount : 10%
    Maximum Qty Discount is Applied to: 1
    Discount Qty Step (Buy X): 0
    Apply to Shipping Amount: No
    Free shipping: No
    Stop further rules processing: No

Apply the rule only to cart items matching the following conditions (leave blank for all items)
    If ALL  of these conditions are TRUE :
        SKU  is  ABC  
        SKU  is  ABC-1
        SKU  is  ABC-2 

答案 1 :(得分:0)

我有同样的问题。当您将产品与一个虚拟孩子捆绑在一起时,就会发生这种情况。

我已解决此问题:

创建新的模块目录 应用/代码/ MyCompany / MyModule /

此目录中的下一个文件:

etc / module.xml

    <?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="MyCompany_MyModule" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Quote"/>
        </sequence>
    </module>
</config>

etc / di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <preference for="Magento\Quote\Model\Quote\Item" type="MyCompany\MyModule\Model\Quote\Item"/>

</config>

composer.json

{
  "name": "my-company/my-module",
  "description": "N/A",
  "require": {
    "php": "~7.0.0"
  },
  "type": "magento2-module",
  "version": "1.0.0",
  "license": "proprietary",
  "autoload": {
    "files": [
      "registration.php"
    ],
    "psr-4": {
      "MyCompany\\MyModule\\": ""
    }
  }
}

registration.json

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'MyCompany_MyModule',
    __DIR__
);

Model / Quote / Item.php

<?php
namespace MyCompany\MyModule\Model\Quote;

class Item extends \Magento\Quote\Model\Quote\Item
{

    /**
     * @return \Magento\Quote\Model\Quote\Address
     */
    public function getAddress()
    {
        /** start @override code */
        if ($this->getQuote()->isVirtual()) {
            /** end @override code */
            $address = $this->getQuote()->getBillingAddress();
        } else {
            $address = $this->getQuote()->getShippingAddress();
        }

        return $address;
    }
}