echo $qtyStock = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
Showing posts with label products. Show all posts
Showing posts with label products. Show all posts
Monday, October 17, 2011
How to get products available stock quantity in magento?
Here is the code to get produts stock quantity. Place this code in your view.phtml file.
Monday, September 19, 2011
How to get configurable products attributes / super attributes details in magento?
$productId = $_product->getId();
$product=Mage::getModel("catalog/product")->load($prodcutId);
/**
* Get Configurable Type Product Instace and get Configurable attributes collection
*/
$configurableAttributeCollection=$product->getTypeInstance()->getConfigurableAttributes();
/**
* Use the collection to get the desired values of attribute
*/
foreach($configurableAttributeCollection as $attribute){
echo "Attr-Code:".$attribute->getProductAttribute()->getAttributeCode()."
";
echo "Attr-Label:".$attribute->getProductAttribute()->getFrontend()->getLabel()."
";
echo "Attr-Id:".$attribute->getProductAttribute()->getId()."
";
}
Labels:
attributes,
configurable,
get,
Magento,
products,
super,
super attributes
Tuesday, September 13, 2011
How to get Most Viewed products in Magento?
Here is the code to get most viewed Products in Magento
/**
* Number of products to display
* You may change it to your desired value
*/
$productCount = 5;
/**
* Get Store ID
*/
$storeId = Mage::app()->getStore()->getId();
/**
* Get most viewed product collection
*/
$products = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->setStoreId($storeId)
->addStoreFilter($storeId)
->addViewsCount()
->setPageSize($productCount);
Mage::getSingleton('catalog/product_status')
->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')
->addVisibleInCatalogFilterToCollection($products);
print_r($products);
Monday, September 12, 2011
Configurable products options are empty after moving my cart side bar to header?
I have explained Moving Cart from Right Sidebar to Header in this tutorial. After moving my cart to header I have noticed configurable options are not shown up in header. To display configurable product options do the following.
Edit your "template/checkout/cart/sidebar/default.phtml" file.
Find the line if ($_options = $this->getOptionList()):
Replace with the following
Edit your "template/checkout/cart/sidebar/default.phtml" file.
Find the line if ($_options = $this->getOptionList()):
Replace with the following
$_product = Mage::getModel('catalog/product')->load($this->getProduct()->getId());
$config = new Mage_Catalog_Helper_Product_Configuration();
if ($_options = $config->getConfigurableOptions($_item)):
Thats it. You are done.
Subscribe to:
Posts (Atom)