Magento 2: Get Attribute Id, Name, Value from Attribute Code

This article shows how you can get attribute name or label, id, entity_type, etc. by attribute code in Magento 2. If you would like get attribute name and value in Magento 1 then you may refer to this article: Magento: How to get attribute name and value? I will be showing both Dependency Injection (DI) … Read more

Magento 2: Get Payment Methods (All/Active/Used)

This article shows how to get payment methods in Magento 2. We will be fetching 3 types of payment methods. They are: 1) All Payment Methods 2) Active/Enabled Payment Methods 3) Payment Methods that have been used while placing orders I will be showing both ways (Dependency Injection & Object Manager way) to get payment … Read more

Magento 2: Install via Composer and Command Line (CLI)

This article/tutorial show how to download and install Magento 2 through command line interface (CLI). We will be using Composer to download Magento 2 from Magento’s repository. Here is the step-by-step guide on installing Magento 2 via command line: 1) Check & Verify System Requirements Before, downloading and installing Magento 2, we need to make … Read more

Magento 2: Get Product’s Custom Option Value from Cart & Order

This article shows how to get custom option values of products/items added to cart or products of any order in Magento 2. I will simply be using ObjectManager for this example. Get custom options of products present in shopping cart $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $cart = $objectManager->get('\Magento\Checkout\Model\Cart'); // get cart items $items = $cart->getItems(); // get … Read more

Magento 2: Get all Categories of any/current Product

This article shows how we can get list of all categories from current product or any particular product as well. Both ways (Dependency Injection & Object Manager way) are shown below: Using Dependency Injection (DI) Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory, \Magento\Catalog\Model\ProductRepository and \Magento\Framework\Registry classes … Read more

Magento 2: Get all shopping cart items, subtotal, grand total, billing & shipping address

This article shows how to get shopping cart items/products, subtotal and grand total of cart, and shipping and billing address entered while doing checkout in Magento 2. I will be using both Dependency Injection (DI) and Object Manager in the below example code. Using Object Manager – Get products id, name, price, quantity, etc. present … Read more

Magento 2: Run Custom SQL Query

This article shows how to write/run/execute custom SQL queries in Magento 2. We need to instantiate class Magento\Framework\App\ResourceConnection for this. You have to inject this resource class in your module’s Block/Model/Controller class constructor. After that, you can use that object to run custom sql queries. In this example, I will simply be using object manager … Read more