Home » Magento, Magento 219 February 2016

Magento 2: Set Unset Get Session

This article shows how to create and destroy different types (Checkout, Customer, Catalog) of sessions in Magento 2.

As you can see below, there are different types of session classes present in Magento 2.

In below example code, I will be dealing with Catalog, Customer, and Checkout sessions.

Both Dependency Injection and Object Manager way of coding are shown below.

Using Dependency Injection (DI)

Now, we set and get session from template (.phtml) file.

Unset session

From customer session, we can also fetch customer information like customer name and email.

From checkout session, we can fetch quote information.

Using Object Manager

Hope this helps. Thanks

Magento 2

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed