Magento: Solution of Warning: Invalid argument supplied for foreach() in …list.phtml

While upgrading Magento, I am getting this error when I go to product list page. Error: Warning: Invalid argument supplied for foreach() in …/template/catalog/product/list/toolbar.phtml Solution: Open layout/catalog.xml Find this: <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml"> Just below the above code, add the code below: <block type="page/html_pager" name="product_list_toolbar_pager" /> Open template/catalog/product/list/toolbar.phtml Comment out some lines of code and … Read more

Magento: Get Product by SKU

Here is a quick code to get product information with SKU value. Get product information by sku // Get product by sku $sku = "microsoftnatural"; $product = Mage::getModel('catalog/product') ->loadByAttribute('sku', $sku); // print product data echo "<pre>"; print_r($product->getData()); echo "</pre>"; Get product id by sku $productIdBySku = Mage::getModel('catalog/product') ->getIdBySku('microsoftnatural'); echo $productIdBySku; Hope it helps. Thanks.

Magento: Get all attributes & attribute name value of a product

Here is a quick code to get all attributes and their name and value associated with any particular product. First of all we have to load the product by it’s ID. And then get all it’s attributes. Here is the code:- $productId = 52; $product = Mage::getModel('catalog/product')->load($productId); $attributes = $product->getAttributes(); Get Name and Value of … Read more

Magento: How to get product stock quantity & other stock information?

Here is a quick code to get any product’s stock information like quantity (qty), minimum quantity (min_qty), stock availability (is_in_stock), minimum and maximum sale quantity (min_sale_qty and max_sale_qty), etc. First load the product. Product can be loaded in different ways. Here are the two different ways to load any product in Magento:- 1. Load product … Read more

Magento: How to get actual price and special price of a product?

Here is a quick and useful code on getting actual price and special price of any product in Magento. The actual price is the real price assigned to the product and special price is the price after any discount is applied to the product. Loading Product $_productId = 52; $_product = Mage::getModel('catalog/product')->load($_productId); Get Actual Price … Read more

Magento: Product is still visible in catalog and search even after changing visibility to nowhere

Scenario: I have changed my product’s Visibility to ‘Nowhere‘. But still the product is visible in both catalog and search. I have refreshed cache but the problem is still there. Cause: This problem arises because the Scope of Visibility attribute is Store View by default. This means that it’s value is set differently for each … Read more

Magento 1.4: No products displayed in category listing

Scenario: I have a fresh installation of Magento 1.4. I already have installed the sample data for Magento. Now, when I go to the category listing page, no products are displayed. It says “There are no products matching the selection.“. By category listing page, I mean the product listing page displayed when any category is … Read more

Magento: How to get most viewed products?

Here, I will show you the code to get the most viewed products in Magento. The function addViewsCount() filters the products with their views count. Here is the code:- Get overall Most viewed products public function getMostViewedProducts() { /** * Number of products to display * You may change it to your desired value */ … Read more