2

I am trying to apply a shopping cart price rule to a bundled product, but without success. What I want to do is, create a coupon code that applies a discount of 10% on a bundled product with the SKU 'ABC'.

So, I set the SKU-attribute to 'Use for Promo Rule Conditions'->'Yes', and I create a rule like:

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

but with no success...

So I read something about bundled products and price rules only being applied on simple products (is that so?), so I changed my rule so it applies to the products in my bundled product:

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

No luck...

So I try to leave the whole SKU-thing, and I create a new attribute: give_discount, and set that also to 'Use for Promo Rule Conditions'->'Yes'. Yes, I'm that desperate at this point. I create the attribute, add it to my bundle as well as it's children products:

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 

Still... no... luck...

Now, does anyone know what's going on here? I just can't wrap my head around it! Are bundled products impossible to give discount to in this way? When I leave the conditions away, the discount gets given (as expected), but as soon as I apply the filter, I get the notion that the coupon code is not valid...

Edit:

My price rule works on other types of products. After some research I managed to get the code working by creating a hidden category, put the bundled product in it, and apply the price rule to the category. Is this the only way how something like above can be achieved?

Giel Berkers
  • 2,852
  • 3
  • 39
  • 58

2 Answers2

1

Give this a try:

Conditions:

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  

Actions:

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 
MB34
  • 4,210
  • 12
  • 59
  • 110
0

I have the same issue. It happened when you have bundle product with one virtual child.

I have fix for it:

Create new module dir app/code/MyCompany/MyModule/

And next files in this dir:

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;
    }
}
Nikolas Sumrak
  • 100
  • 2
  • 7