Snippets with the tag: items

Check items in cart or not

Description

Check if there are any items in cart or not.

Code

$totalItemsInCart = Mage::helper('checkout/cart')->getItemsCount();

Get products data in cart

Description

Display products data in cart

Code

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

foreach($items as $item) {
        echo 'ID: '.$item->getProductId().'
'; echo 'Name: '.$item->getName().'
'; echo 'Sku: '.$item->getSku().'
'; echo 'Quantity: '.$item->getQty().'
'; echo 'Price: '.$item->getPrice().'
'; echo "
"; }

Get / filter all products by attribute value

Description

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.

Code

$manufacturerId = 3;
$attributeCode = 'manufacturer';

$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter($attributeCode, $manufacturerId);

// print all products
print_r($products->getItems());