Skip to content

Instantly share code, notes, and snippets.

@BenRoe
Last active October 11, 2015 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenRoe/3902092 to your computer and use it in GitHub Desktop.
Save BenRoe/3902092 to your computer and use it in GitHub Desktop.
Magento Product Snippets (tested under 1.6)

Paths for Skin, Media, JS, Base & Store URL

//Not secure Skin URL
echo $this->getSkinUrl(‘images/sampleimage.jpg’)

//Secure Skin URL
echo $this->getSkinUrl(‘images/ sampleimage.gif’, array(‘_secure’=>true))

//Get  Current URL
$current_url = Mage::helper(‘core/url’)->getCurrentUrl();

//Get Home URL
$home_url = Mage::helper(‘core/url’)->getHomeUrl();

//Get Magento Media URL
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);

//Get Magento Skin URL
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);

//Get Magento Store URL
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

//Get Magento Js URL
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);

Stock

view.phtml

// show "only x left" if less than 5 items left

$qty = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();

if ( $qty < 5 && $qty > 0):?>
<p>Only <?php echo floor(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty())?> left</p>

<?php endif; ?>

Product Price

 
// assuming that you have known product object, $_product
 
//get product price snippet
echo $this->getPriceHtml($_product, true);
 
//get $_product price
echo $_product->getPrice();
echo number_format($_product->getPrice(), '2', '.', ',');
 
//get $_product special price
echo $_product->getSpecialPrice();
echo number_format($_product->getSpecialPrice(), '2', '.', ',');
 
//get $_product final price
echo $_prodcut->getFinalPrice();
echo number_format($_product->getFinalPrice(), '2', '.', ',');
 
//get $_product Msrp
echo $_product->getMsrp();
echo number_format($_product->getMsrp(), '2', '.', ',');
 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment