Jump to content

Cart rule with proportional gift products


Recommended Posts

Hello,

I would like to create a cart rule with a free gift product for every 10 products purchased:

for example if you buy 10 products X, you receive 1 additional product X. This is managed natively by the cart rule. What I would like to do is that from 20 products X, you don't receive 1 product X, but 2 products X, 3 from 30 etc...

Do you know how this can be managed ?

Here is a part of my current code that manages the addition of a cart rule

 

        $cartRule = new CartRule();

        if($id_customer) {
            $cartRule->id_customer = $id_customer;
        }

        $cartRule->name = array($this->langId => "test_promoX+Y");
        $cartRule->date_from = $date_formated;
        $cartRule->date_to = "2050-01-01";
        $cartRule->active = true;
        if($id_group) {
            $cartRule->group_restriction = true;
        }
        $cartRule->product_restriction = true;

        if($id_product) {
            $cartRule->gift_product = $id_product;
        }


        $cartRule->save();

        $id_cart_rule = $cartRule->id;

        if($id_group > 0)
        {
            $groupRestriction = \Db::getInstance()->getValue(
                "INSERT INTO
                "._DB_PREFIX_."cart_rule_group
                (id_cart_rule, id_group)
                VALUES ($id_cart_rule, $id_group)
                " );
        }
        if($id_product > 0)
        {
            $type = 1;

            Db::getInstance()->execute(
                "INSERT INTO " . _DB_PREFIX_ . "cart_rule_product_rule_group
                 (id_cart_rule, quantity)
				VALUES ($id_cart_rule, 1)");
            $id_product_rule_group = \Db::getInstance()->Insert_ID();

            Db::getInstance()->execute(
                "INSERT INTO " . _DB_PREFIX_ . "cart_rule_product_rule
                    (id_product_rule_group, type)
                    VALUES ($id_product_rule_group, $type)");
            $id_product_rule = Db::getInstance()->Insert_ID();

            Db::getInstance()->execute(
                "INSERT INTO " . _DB_PREFIX_ . "cart_rule_product_rule_value
                    (id_product_rule, id_item)
                    VALUES ($id_product_rule, $id_product)");

        }
        return true;
    }

Thank you for your time !

Link to comment
Share on other sites

I wonder why people don't use the opportunity to establish a sales funnel on the basis of a special perk?

 Client buys the first product and receives an email with welcome, thank you note and the tip that each 10th buy he receives an extra gift. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...