Category Product Collection
This snippet provides a collection of products within a category
$cat = Mage::getModel('catalog/category')->load(1);
$coll = Mage::getResourceModel('catalog/product_collection');
$coll->addCategoryFilter($cat);
Related cards:
Adding Attribute To Category List Product Collection
Only a core set of attributes are added to the product collection (for the list page) by default. This bit of XML will allow you to add additional attributes to that collection:
<config>
<frontend>
<product>
...
In Stock Product Collection
This snippet provides a collection of in-stock products, or products which do not have stock management enabled on them
$productCollection = Mage::getResourceModel('catalog/product_collection');
Mage::getSingleton('cataloginventory/stock'...
Getting A Products URL
Potentially confusing due to the 3 methods you could use, all of which are in Mage_Catalog_Model_Product
:
public function getUrlPath($category=null)
public function getUrlInStore($params = array())
public function getProductUrl($use...
Get Category Children
public function getCategories()
{
if (!$this->categories) {
$categoryId = $this->getData('parent_category_id');
$parentCategory = Mage::getModel('catalog/category')->load($categoryId);
$categor...
Product Price Index
The Display Out Of Stock Configuration Option
is implemented by this index. If you have chosen not to display out of stock products,
then the effect is that a prod...
Product Types
Type | Composite[^1] | Inventory[^2] | Description | Example |
---|---|---|---|---|
Simple | - | Yes | The most basic form of product | Example |
Grouped | Yes | No | Several simple products displ... |
Product Attribute Addition
This code shows all possible configuration options for an attribute that I know of, you need not include all of these when adding an attribute (although it won't hurt)
$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
...
Boilerplate Resource Model Collection Class (CE 1.6 / EE 1.11 And After)
/**
* Yourcompany.com
*
* PHP Version 5
*
* @category Namespace
* @package Namespace_Module
* @author Your Name <your.name@yourcompany.com>
* @copyright 2012 yourcompany.com
* @license http:...
Boilerplate Resource Model Collection Class (Before CE 1.6 / EE 1.11)
/**
* Yourcompany.com
*
* PHP Version 5
*
* @category Namespace
* @package Namespace_Module
* @author Your Name <your.name@yourcompany.com>
* @copyright 2012 yourcompany.com
* @license http:...
Removing Custom Attributes Across Multiple Products
If you have custom attributes named the same across multiple products, you
wish to remove said attributes, this might come in useful. The SQL below restricts
the removal of the attributes to a certain attribute set name, but you can remove
this is...