Magento insert PHTML in PHTML
Here is how to insert a template into another template: echo $this->getLayout()->createBlock(‘core/template’)->setTemplate(‘path/to/template.phtml’)->toHtml();
Read MoreArchives
Date July 3, 2014 Author By Razvan Mocanu Category Magento how to
Here is how to insert a template into another template: echo $this->getLayout()->createBlock(‘core/template’)->setTemplate(‘path/to/template.phtml’)->toHtml();
Read MoreDate June 29, 2014 Author By Razvan Mocanu Category Magento how to
Here is how to get the images for a specified product. The image path will point to a resized image of the specified size. $_images = Mage::getModel(‘catalog/product’)->load($_product->getId())->getMediaGalleryImages(); if($_images) { foreach($_images as $_image){ $pathToImage = $this->helper(‘catalog/image’)->init($_product, ‘thumbnail’, $_image->getFile())->resize(200); //200 is the size of $imageLabel = $_image->getLabel(); // construct array to collect data or […]
Read MoreDate June 29, 2014 Author By Razvan Mocanu Category Magento how to
I couldn’t find a easier solution yet. This is what I use to find out if a product is on sale in order to add a corresponding tag: <?php $specialPrice = Mage::getModel(‘catalog/product’)->load($_product->getId())->getSpecialPrice(); $specialPriceFromDate = Mage::getModel(‘catalog/product’)->load($_product->getId())->getSpecialFromDate(); $specialPriceToDate = Mage::getModel(‘catalog/product’)->load($_product->getId())->getSpecialToDate(); $rightNow = time(); if($specialPrice && ($rightNow >= strtotime( $specialPriceFromDate) && $rightNow <= strtotime($specialPriceToDate) || $rightNow >= strtotime( […]
Read MoreDate June 29, 2014 Author By Razvan Mocanu Category Magento how to
If you need to add a new tag to a product you need to find out whatever the product is set as new or not. Here is the method I use: <?php if (date(“Y-m-d”) >= substr($_product->getNewsFromDate(), 0, 10) && date(“Y-m-d”) <= substr($_product->getNewsToDate(), 0, 10)) : ?> <!– replace the line below with the […]
Read MoreDate June 28, 2014 Author By Razvan Mocanu Category Magento how to
If you need to get the value of a system setting, here is how to do it: Mage::getStoreConfig(‘full_path/to_the/setting’) For example: Mage::getStoreConfig(‘customer/create_account/email_domain’) These settings are stored in core_config_data table and the full path is in the path column.
Read MoreDate June 28, 2014 Author By Razvan Mocanu Category Magento how to
After a fresh install of Magento the notice “This is a demo store. Any orders placed through this store will not be honored or fulfilled.” is displayed right at the top of the page. To remove this notice, go in the admin and open System -> Configuration then open General -> Design -> HTML Head […]
Read MoreDate June 24, 2014 Author By Razvan Mocanu Category Magento how to
One of the easiest ways to get access to the current product is to use the Magento registry: $currentproduct = Mage::registry(‘current_product’); Once you have the product you can access the data like this: echo $currentproduct->getName(); echo $currentproduct->getId();
Read MoreDate June 24, 2014 Author By Razvan Mocanu Category Magento how to
Even if the block is inserted via XML or via code, parameters can be passed with the call. If the block is defined in XML, this is how you pass data for processing in the phtml file: <block type=”core/template” name=”block_name” as=”block_name” before=”-” template=”page/html/custom/blocktemplate.phtml”> <action method=”setData”> <name>currentStep</name><value>2</value> </action></block> If the block is inserted via code, here […]
Read MoreDate June 19, 2014 Author By Razvan Mocanu Category Magento how to
By activating the block hints, Magento will display the class name and template of a block while messing up the front end appearence. Now, we have the class names. How do we get the actual block name? How do we find the parent/children block names? Here is a small extension I made exactly for this: […]
Read MoreDate June 16, 2014 Author By Razvan Mocanu Category Magento how to
Even if in PHP using session variables is pretty easy, believe it or not in Magento is even simpler: To set data Mage::getSingleton(‘core/session’)->setData(‘var_name’,$somevalue) To get data Mage::getSingleton(‘core/session’)->getData(‘var_name’) Session variables persist between different page loads so you can use this to pass data between pages.
Read More