cancel
Showing results for 
Search instead for 
Did you mean: 

Is this appropriate use of CheckoutSession?

Is this appropriate use of CheckoutSession?

I have a custom value worked out in a shipping module which I need for the tax calculation, but when I am overriding the tax calculation you can't access the full quote just QuoteDetailsInterface,  

public function aroundCalculateTax(
        TaxCalculationInterface $subject,
        callable $super,
        QuoteDetailsInterface $quoteDetails,
        $storeId = null,
        $round = true
    )

 so in the shipping module I add my value to checkoutSession rather than go thru the process of adding it all the necessary places so that its accessible in that interface.

It doesn't look good, is there a better way of moving a custom value from shipping to tax/collecttotals? 

2 REPLIES 2

Re: Is this appropriate use of CheckoutSession?

Hello @silas3 

Please refer https://magento.stackexchange.com/questions/206347/which-method-i-should-use-while-using-plugin-in-m...

It will be helpful.

Thanks.

---
If you've found my answer useful, please give"Kudos" and "Accept as Solution"

Re: Is this appropriate use of CheckoutSession?

Thanks for suggesting that. Whilst that was link about tax, my question was really a general one about variables. 

Simply put, if you have a value that you're using in a custom module which you need to be persisted across multiple requests , i.e. calculated during shipping then used during checkout so multiple ajax calls in between, is it best practice to create a custom variable within the module that persists across postbacks, or just put it in the session object ?