Get The Current Product
Mage::registry('current_product');
Related cards:
Get Methods of Class
Yes, very dirty, but it works a treat! Save this file in your Magento root directory, then fire up a command line and run whatever.php Mage_Core_Model_App
(or some other class) and you should see the output.
Output looks like below:
$ ./cl...
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...
Getting the Theme In Use
How to get the theme for each component, works on the active store:
Mage::getSingleton('core/design_package')->getTheme('locale');
Mage::getSingleton('core/design_package')->getTheme('template');
Mage::getSingleton('core/design_packag...
Getting The Amount Of Items in the Cart
To get the amount of line items (i.e. 10 of 1 product is 1):
Mage::helper('checkout/cart')->getItemsCount();
To get the total number of items (i.e. 10 of 1 product is 10):
Mage::helper('checkout/cart')->getSummaryCount();
![](http://mi...
Get A Products Stock Quantity
$product->getStockItem()->getQty();
Yes, there is no method for it - it's set using setStockItem()
from Mage_CatalogInventory_Model_Stock_Item::assignProduct()
via the catalog_product_load_after
event.
![](http://mikewhitby.co.uk/makan...
Add A Tab To The Admin Product Screen
Declare an admin layout XML file for your module in your config.xml
:
<config>
<adminhtml>
<layout>
<updates>
<your_module>
<file>your-module.xml</file>
...
Getting The Last Order ID From The Session
Mage::getSingleton('checkout/session')->getLastOrderId();
Get and Resize Category Images
public function getCategoryImage(Mage_Catalog_Model_Category $category, $width = 250, $height = 250)
{
// return when no image exists
if (!$category->getImage()) {
return false;
}
// return when...
Get Value of Product Attribute
This resolves the value of the attribute, so rather than supplying you with a value ID, it will supply you with the associated value, via the source model:
$_product->getAttributeText('brand');