search
top

First and Last collection item in Magento

We the Magento developers work mostly with data collections. For accessing the data we use ‘foreach’ to iterate over collection. $product_collection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect('*'); foreach ($product_collection as $k => $v) { echo $v->getName(); echo '<br/>'; } What if we need only...
read more

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

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

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

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()...
read more

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

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

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

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

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

« Previous Entries

top