code to get attribute option labels
public function getOptionsLabels($attribute_code) { $options = Mage::getModel('eav/entity_attribute') ->loadByCode('catalog_product', $attribute_code) ->getSource()->getAllOptions(true, true); $labels = array(); foreach($options as $option) { if (trim($option['label']) != '') { $labels[] = $option['label']; } } return $labels; }
get the entity attribute set collection
$attributeSetCollection = Mage::getResourceModel('eav/entity_attribute_set_collection') ->load();
Get categories products ordered by number of sales
$categoryId = 1; $category = Mage::getModel('catalog/category')->load($categoryId); $products = Mage::getResourceModel('reports/product_collection') ->addOrderedQty() ->addAttributeToSelect('*') ->setOrder('ordered_qty', 'desc') ->addCategoryFilter($category);
$defaultCategoryId = 2; $topLevelCats = Mage::getModel('catalog/category') ->getCollection() ->addAttributeToSelect('path','name','id') ->addAttributeToFilter('parent_id', $defaultCategoryId) ->setOrder('position', 'ASC');
Get product type from product SKU
$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$product_sku); $productType = $product->getTypeId();
Get all associated products
helper('catalog/output'); ?> getAllowProducts() ?>
= $_helper->productAttribute($_item, $_item->getName(), 'name'); ?> | = $_item->getName(); ?> | = $_item->getPrice(); ?>
Get / filter all products by attribute value
Get all products related to any particular brand. Let us suppose that we are fetching the products related to ‚Apple‘ brand. The manufacturer ID of Apple = 3.
$manufacturerId = 3; $attributeCode = 'manufacturer'; $products = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter($attributeCode, $manufacturerId); // print all products print_r($products->getItems());
Hersteller anzeigen
echo $_product->getAttributeText('manufacturer');