As per my requirement am creating the cart rule programmatically, for that i am reviewed the following code and implemented in my local

public function createRule()
    $price = 100;
    $sku = '24-WG085';
    $discount = ($price - (($price + 1) / 2));
    $shoppingCartPriceRule = $this->ruleFactory->create();

    $shoppingCartPriceRule->setName('Add a second for $1 - ' . $sku)
        ->setDescription('Buy one item at regular price, and receive a second item for just $1.00 more!')

    $item_found = $this->foundProductRuleFactory->create()
        ->setValue(1) // 1 == FOUND
        ->setAggregator('all'); // match ALL conditions

    $conditions = $this->productRuleFactory->create()

    $actions = $this->productRuleFactory->create()


But, when i execute the code i am getting the 'Uncaught Error: Call to a member function setOperator() on null.

I am not sure what is the exact problem in that setOperator, the following operators are available in core

                '==' => __('is'),
                '!=' => __('is not'),
                '>=' => __('equals or greater than'),
                '<=' => __('equals or less than'),
                '>' => __('greater than'),
                '<' => __('less than'),
                '()' => __('is one of'),
                '!()' => __('is not one of'),

Thanks in advance for your support and suggestion


I got the answer for my question, instead of setAttribute i tried to setData('attribute','sku') it's working fine.

$conditions = $this->_productRuleFactory->create()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.