May 19, 2012
Optgroup in Magento
For a module I was working on in one of my project, I needed to display a select box, with optgroup, Magento has inbuilt function for this.
Kindly go through this post Select Box in Magento of mine for understanding how to generate select box before reading forward.
For option group you need to pass the ‘value’ also as an array.
Suppose your Category name is ‘Furniture’ and...
read more
Nov 28, 2011
Root Category in Magento
In Magento, products are assigned to Website, though we can disable the product in independent store, but this is very lengthy procedure as you need to edit each and every products.
So I came up with the solution to restrict the display of categories and products, though if you assign different Root Catalog to different store, Magento will display the categories as per the stores but not products as...
read more
Oct 13, 2011
Empty Cart in Magento
In one of my project, I needed to explicity delete the items from cart after order placed.
You can also use this script for making a functionlity for giving an option for empting the cart at once from cart page.
Here is the script for the same. Place it in function ‘successAction’ in app\code\local\Mage\Checkout\controllers\OnepageController.php (copy this file from app\code\core\Mage\Checkout\controllers\OnepageController.php)
/**
...
read more
Sep 18, 2011
Product Quantity in Magento
For one of my project I needed to display the total quantities ordered in Products lifetime in product view page.
Here is the code
$product_id = 1; // the id of the product for which the quantities is required
$current_storeid = Mage::app()->getStore()->getId();//get current store id, used for filtering the collection
$productCollection = Mage::getResourceModel('reports/product_collection')
->addOrderedQty()
->addAttributeToSelect(array('name'))
->addAttributeToFilter('entity_id',array('eq',...
read more
Jun 30, 2011
Select Box in Magento
Hello All,
I am listing here a useful topic related to Magento.
Below is the description to generate a select box using inbuilt functions of Magento.
Lets take an example of displaying a select box containing all the catalog products.
I am using the existing core files for better understanding, you are recommended make new module or override existing files
Lets use helper file of Catalog, app/code/core/Mage/Catalog/Helper/Data.php
Paste...
read more
Jun 15, 2011
Filters in Query in Magento
Hello All,
When we are filtering data in Magento, time occurs when we want to fetch result after filters like Not equal, greater than, less than, etc.
The addFieldToFilter method’s second parameter is used for this. It supports an alternate syntax where, instead of passing in a string, you pass in a single element Array.
The key of this array is the type of comparison you want to make. The value...
read more
Jun 8, 2011
Product Collection in Magento
Hello All,
I am writing here the script to get product collection of the store.
<?php
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addAttributeToFilter('status',1); //only enabled product
$collection->addAttributeToFilter('visibility',array("neq"=>1)); //except not visible individually
$collection->addAttributeToSelect(array('name','url','small_image'));...
read more
Jun 5, 2011
Specific Category Products Magento
Hello All,
I am writing here the script to get product collection of a required category.
For the below mentioned script we must have the category id for which the product collection is needed.
<?php
$catagory_model = Mage::getModel('catalog/category')->load($category_id); //where $category_id is the id of the category
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addCategoryFilter($catagory_model);...
read more
May 27, 2011
Get cart products in Magento
Hello All,
I am writing here a script for getting all the product’s id added into cart
<?php
$product_ids = Mage::getModel('checkout/cart')->getProductIds(); //get cart product ids
print_r($product_ids);
?>
Hope this is useful
read more
May 12, 2011
Get Products categories in Magento
Hello All,
I am writing here the script to get category ids , for the given product.
<?php
$product_model = Mage::getModel('catalog/product'); //get product model
$all_cats = array();
$product_model->reset();
$_product = $product_model->load($product_id); // $product_id is the given product id
$all_cats = $product_model->getCategoryIds($_product); // all the categories...
read more
