Magento 2 catalog price rules based on session variable

357 Views Asked by At

I would like to apply catalog price rules based on a session variable that I will store for some customer segments. For example, if a customer visits the site with a specific URL parameter, I would apply some catalog price rules, that will accompany the customer throughout his visit in the site.

-- EDIT -- Another option, could be, to assign a guest customer to a customer group somehow, and the group can be associated with catalog price rule.

1

There are 1 best solutions below

2
Mavis Bacon On

This is a reasonable request however customers are familiar with websites that use coupons.

You can add a coupon by observing a landing page and applying a coupon to a basket, then showing a customer message that tells them coupon NNN has been applied and that they will get their discount at the checkout automatically.

    $quote = $this->checkoutSession->getQuote();
    $quote->setCouponCode($couponCode)->collectTotals()->save();

Works great, with Magento1 you needed to store a coupon in a cookie and apply it when something was added to the cart. With M2 there is no need for this, you can add an observer that just does the above.