0

I'm writing a before plugin and i need to get from_date and to_date of cart_rule and catelog_rule in my plugin code


namespace Vendor\CouponBeforePlugin\Plugin;

use Magento\Quote\Model\Quote\Item\AbstractItem;

class CouponPlugin
{
    public function __construct()
    {
    }

    /**
     * Apply rules to current order item
     *
     * @param AbstractItem $item
     * @param array $rules
     * @param bool $skipValidation
     * @param mixed $couponCode
     * @return array
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
     */
    public function beforeApplyRules($item, $rules, $skipValidation, $couponCode)
    {
        $fromdate = $rules->getFromDate();
        $todate = $rules->getToDate();
        var_dump("Working inside plugin");
        var_dump($fromdate);
        var_dump($todate);
        // var_dump($couponCode);
        die;
    }
}```

1 Answer 1

0

$rules is array

    public function beforeApplyRules($item, $rules, $skipValidation, $couponCode)
    {
        foreach ($rules as $rule) {
            $fromdate = $rule->getFromDate();
            $todate = $rule->getToDate();
            var_dump("Working inside plugin");
            var_dump($fromdate);
            var_dump($todate);
            // var_dump($couponCode);
        }
        die;
    }

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.