2

I have a store with customer groups for different customer "levels". Each level has discounted pricing that is set up using tier pricing.

My problem is the tier pricing does not apply if a customer first adds an item to their cart and then logs in. I expect that when they log in their cart would update with their customer group discounts.

I want the cart pricing to apply immediately when the user logs in, including using the ajax login on the checkout page.

How can I write a module to update the pricing after a user logs in? I'm looking for a particular event to hook into for user login and the right command to 'refresh' the cart programatically. This would ideally include refreshing the pricing on the checkout page if the user logs in from there.

Update (first attempt)

I have tracked down a bit of code that refreshes the cart items' prices. In order to test this I made a simple controller that runs this code:

/** $this->checkoutSession \Magento\Checkout\Model\Session **/ 
$quote = $this->checkoutSession->getQuote()->collectTotals()->save();

When I log in and load a page that runs the above code, cart prices are properly refreshed. However, when I try this code inside of an Observer, I have no luck. For my observer I have tried a few different events in order to test, here is a list of those events:

  • customer_customer_authenticated
  • customer_login
  • customer_data_object_login
  • controller_action_postdispatch_customer_account_loginPost

I know the code works but I none of the above events are doing it. I think if I get the correct event I'll be close to figuring this out.

4
  • Did you find a solution to this? I am facing the same problem with catalog prices displaying the old customer group prices rather than the new ones
    – David
    Nov 29, 2018 at 10:45
  • This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. - From Review Nov 29, 2018 at 11:11
  • I couldn't comment on the original question
    – David
    Nov 29, 2018 at 12:21
  • @David - Unfortunately no, I tried copying bits of code from add to cart methods without actually adding to cart, and running them with an after login observer, but nothing I tried worked. Somehow this must be possible to do.
    – jamil
    Nov 29, 2018 at 18:34

1 Answer 1

0

I was facing the same problem but on a M2.3.5 and what worked for me was adding the following:

[YourProjectName]/Customer/etc/frontend/sections.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Customer:etc/sections.xsd">
    <action name="customer/account/loginPost">
        <section name="cart"/>
    </action>
</config>

Hope this helps

Regards

Your Answer

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

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