0

I am trying to hide prices when a specific customer attribute is set to "true". Because of FP-Caching, this has been very difficult to accomplish.

I can't update the FinalPriceBox directly with plugin, as this data gets cached and switching the value on / off on customer entity doesn't update on frontend with caching enabled. Attempting to disable cache for that block alone actually disables cache for the entire page which is no good.

I have also attempted to create my own component, that can hide or display the block and provide the customer attribute via plugin for Magento\Customer\CustomerData\Customer => Magento_Customer/js/view/customer-data. However this gives complications on first page loaded after login (data is not upto-date). Also this saves the field into the cookie storage, which would mean that variable can be controlled on client-side cookie.

Any suggestions of an approach to display the price when the customer attribute is "false" and display a custom block when customer attribute is "true"? Must maintain all cacheable blocks.

Maybe adding new section-data that will load specific to my module?

3
  • Hi, you should use a component to store/read from localstorage when possible and an ajax request when not possible ie after the login. Good luck!
    – SantiBM
    Mar 23, 2020 at 7:34
  • Do you have a tutorial or example of that?
    – user59268
    Mar 23, 2020 at 7:43
  • I never faced your situation so I don't know or have anything that could explain the approach, but I gave an answer here about the localstorage: magento.stackexchange.com/questions/277785/… It's a place to start, you will also need a controller for the ajax request
    – SantiBM
    Mar 24, 2020 at 8:45

1 Answer 1

0

try to make different customer groups instead giving each customer an attribute. Magento keeps different caches for different customer groups. So you can easily hide prices (or whatever) for one group and show to other, making check right in the price block. Please take a look at this example.

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.