0

I am have been working on a payment method where I need Current Quote

So I used

\Magento\Checkout\Model\SessionFactory $checkoutSession

and then get Quote from the Checkout session using

$this->_checkoutSession->create()->getQuote()

one of my fellow developer who was reviewing my code has told me to use Session instead of SessionFactory

I know some differences but I am not sure why he changed it and what you guys prefer to use

I have checked This Question but haven't got a satisfactory answer

Thank you

1 Answer 1

0

You don't need to use a factory for the class \Magento\Checkout\Model\Session because factories are used when we want to get a completely new object without any data inside it and then fill it with data based on something (usually an ID).

In this case, each customer will have at most one active quote stored in the session and you are retrieving this active quote from the session.

You are not loading any object directly for avoiding any shared object instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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