Magento Themes and Magento Extensions

Magento – Get Category Id from Product

Share
Posted on April 29th, 2013 | Posted by admin

Magento - Get Category Id from Product

$items = Mage::getSingleton(‘checkout/session’)->getQuote()->getAllItems();

foreach($items as $item)
{
$categoryIds = $item->getProduct()->getCategoryIds(); // returns category ids from product
}

Batch Product Entity Updates in Magento

Share
Posted on March 22nd, 2013 | Posted by admin

I’ve been writing scripts that interact directly with the database to modify products, etc., but today, I found a much better way to do things. Although direct DB modification is FAST, it’s also very unsafe, and I’m very wary of putting our clients’ sites at risk in order to do the updates they want. Magento, although very frustrating, offers some flexible functionality to alter its often immense database. Following is a PHP script I wrote to update products based on a CSV. The CSV contains product SKUs, but it can be easily modified to grab IDs from a CSV, and one can export their products and modify the fields they want, and then modify the script slightly to modify entities where needed, and grab the correct columns from the database. It will also resume if it needs to be terminated early (useful because it can take a long time for large updates), and reports percentage of completion. So, without further ado….

ini_set('memory_limit', '1024M');
ini_set("precision", 2);
error_reporting(E_ALL);
ini_set('display_errors', '1');

/* Path to resume key file */
$STATUS_FILE = ".importstatus";

/* FILE CONFIGURATION */
$MAGE_PATH = "www/app/Mage.php";

Change default sort order direction (ASC to DESC) for product listing in Magento

Share
Posted on March 21st, 2013 | Posted by admin

By default Magento shows products in category pages by ascending direction. For this reason, latest added product show at last in the Category page. If we want to show last added product at first in Category page we should change default product direction from ascending to descending. By changing direction you can also show your product as descending by its Name, Price and Position. I changed the default direction of my site. You can also change your product direction easily.

Change Direction from Ascending to Descending:

To change default product direction from ascending to descending-

go: app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php

Magento: Display a product image within Static Pages and Blocks

Share
Posted on March 16th, 2013 | Posted by admin

Magento: Display a product image within Static Pages and Blocks
In this particular instance I needed to add product thumbnails for reference on a front page.

First create a new .phtml file with the following under catalog/product/view/your_new_page.phtml

1 <?php
2 $productId = $this->getProduct_id();
3 $_product = Mage::getModel('catalog/product')->load($productId);//load the product
4 ?>
5 <img src="<? echo Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(75, 75); ?>" alt="<?php echo $this->htmlEscape($_product['name']); ?>" border="0" width="75" />

Configurable Product in Related Product

Share
Posted on March 11th, 2013 | Posted by admin

Magento Configurable Product and Simple Product with custom options in Related Product Feature

With Related Product listing, you will see a checkbox for each product, and you can click on it to add the product to cart, you can also use “select all” to add all related products to cart.

Recently a client told me some products in Related Product listing don’t have checkboxes, and asked me to look into the issue. I searched the Magento forum, scanned the bug tracking, found no one ever complaint about it. I then tried to load the original ‘related.phtml’ file to client’s, still not able to get the checkboxes shows up. The checkboxes also not showing up in a freshly installed default Magento Theme.

Page 1 of 3123»