0

Need a help in this issue. I am trying to remove a MySQL condition from _initSelect from this Collection "Magento\SalesRule\Model\ResourceModel\Rule\Collection". This Collection has the following _initSelect.

public function _initSelect()
    {
        parent::_initSelect();
        $this->getSelect()->joinLeft(
            ['rule_coupons' => $this->getTable('salesrule_coupon')],
            'main_table.rule_id = rule_coupons.rule_id AND rule_coupons.is_primary = 1',
            ['code']
        );
        return $this;
    }

I am trying to modify the sql conditions using after_initSelect in a Plugin as follows.

namespace myModule\Promotion\Model\Plugin\Rule;

class RuleCollection
{
    public function after_initSelect(\Magento\SalesRule\Model\ResourceModel\Rule\Collection $subject, $result) {

        \Magento\Rule\Model\ResourceModel\Rule\Collection\AbstractCollection::_initSelect();
        $this->getSelect()->joinLeft(
            ['rule_coupons' => $this->getTable('salesrule_coupon')],
            'main_table.rule_id = rule_coupons.rule_id AND rule_coupons.is_primary = 0',
            ['code']
        );
        return $this;
    }
}

My Plugin is getting recognized but this line "\Magento\Rule\Model\ResourceModel\Rule\Collection\AbstractCollection::_initSelect();" is throwing me errors saying "Error: Call to protected method Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection::_initSelect()".

Can anyone help with what am I missing. TIA.

1 Answer 1

0

You are using plugin to override protected method. plugins cannot override protected method. So use preference instead of using plugin to override protected

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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