Magento 2: Get Related, UpSell & CrossSell Products

This article shows how we can get related products, upsell products, and cross-sell products in Magento 2. Check the product relation tables in MySQL database mysql> SELECT * FROM `catalog_product_link_type`; +————–+————+ | link_type_id | code | +————–+————+ | 1 | relation | | 3 | super | | 4 | up_sell | | 5 | … Read more

Magento 2: Get Current Category & Current Product

This article shows how we can get current category and current product data in Magento 2. Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of \Magento\Framework\Registry class in the constructor of my module’s block class. app/code/Chapagain/HelloWorld/Block/HelloWorld.php <?php namespace Chapagain\HelloWorld\Block; class HelloWorld extends \Magento\Framework\View\Element\Template { protected $_registry; public function __construct( … Read more

Product Tooltip: Magento Extension [FREE]

Product Tooltip is a FREE Magento Extension that shows product’s information as tooltip on category page (product listing page). This module is compatible with Magento version 1.5 and later (Magento 1.5, 1.6, 1.7, 1.8, 1.9). When users hover on the product image on category page (product listing page) then a tooltip will appear displaying product’s … Read more

Magento: Add / Delete / View Custom Options of Product Programmatically

Custom options on Magento products are designed to make simple products function like a configurable product with different choosing options like color, size, etc. before purchasing the product. In this tutorial, I present the code to create/add, view, and delete custom options of a product in Magento. ADD CUSTOM OPTIONS In the following example code, … Read more

Print Product & Cart Page: Magento Extension [FREE]

Print Product & Shopping Cart Page is a FREE Magento Extension that generates neat and clean print page of products and shopping cart, removing unnecessary header, footer & sidebar. This module is compatible with Magento version 1.5 and higher (Magento 1.5, 1.6, 1.7, 1.8, 1.9). A “Print Product” link is added to product page and … Read more

Magento: Get Product by SKU

Here is a quick code to get / load product by its SKU in Magento. Generally we load product by its ID. Assuming product id to be ‘166’. $_productId = '166'; $_product = Mage::getModel('catalog/product')->load($_productId); But, we can also load product by its attributes, like SKU. Assuming product sku to be ‘logitechcord’. $_sku = 'logitechcord'; $_product … Read more

Magento: Get Add to Cart URL of any Product

Here is a quick code to get add to cart url of any product. Suppose that we are fetching add to cart url of a product with id ‘166’. $_productId = '166'; $_product = Mage::getModel('catalog/product')->load($_productId); $_url = Mage::helper('checkout/cart')->getAddUrl($_product); Hope it helps. Thanks.

Magento: Unable to select custom attribute on product collection

Problem: I had added a new product attribute. Suppose the attribute code is ‘test’. I have been trying to fetch/select that newly added product attribute. Here is my Magento collection code:- $collection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect('test') ->addAttributeToFilter('url_key', 'SOME_URL_KEY') ->getFirstItem(); I don’t see the attribute ‘test’ when I print the collection data. echo "<pre>"; print_r($collection->getData()); echo … Read more

Magento: Solution of Invalid method Mage_Catalog_Block_Product_List_Toolbar :: isLastPage

While upgrading Magento, I got this error when I go to product list page. It says: Invalid method Mage_Catalog_Block_Product_List_Toolbar::isLastPage(Array()) Solution: I found 4 kinds of solution. This first one works & is easy. #1. – Open /app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php – Replace the parent class name From: class Mage_Catalog_Block_Product_List_Toolbar extends Mage_Core_Block_Template To: class Mage_Catalog_Block_Product_List_Toolbar extends Mage_Page_Block_Html_Pager This second … Read more