Posts

Showing posts from June, 2014

How to check if Magento is on 404 page?

$action = Mage :: app ()-> getRequest ()-> getActionName () if ( $action == 'noRoute' ){ //do some stuff }

To Call a Navigation in Footer (to call any block through xml files)

To call the navigation in footer go to page.xml file,copy the topMenu block and place in the footer block <block type="core/text_list" name="top.menu" as="topMenu" translate="label">                     <label>Navigation Bar</label>                     <block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml"/>  </block>  now goto footer and call the block    <?php echo $this->getChildHtml('topMenu') ?>    or u can call cms page or static block too      <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('footer_links')->toHtml() ?>

To add condition based on the Current URL"s

<?php $baseUrl=Mage::getBaseUrl(); $currentUrl = Mage::helper('core/url')->getCurrentUrl(); $a=$baseUrl."checkout/onepage/success/"; if ($currentUrl == $a) { ?> <?php } ?>

Magento Load Product By Name / SKU / ID

// Load by name $_category = Mage::getModel('catalog/category')->loadByAttribute('name', 'Ruby Ring'); $_product = Mage::getModel('catalog/product')->loadByAttribute('name', 'emerald earring');   // Load by SKU $_product = Mage::getModel('catalog/product')->loadByAttribute('sku', 'Eram18j4');   //Load by ID (just load): $_product = Mage::getModel('catalog/product')->load($productID); example: <?php $productID = $this->getProduct()->getId(); $_product = Mage::getModel('catalog/product')->load($productID); //echo '<pre>'; //print_r($_product); ?> <img src="http://54.219.137.93/magento/media/catalog/product<?php echo $_product->getSmallImage(); ?>" width=100 height=100 /> <?php echo '<br/>'; echo "List Price"; echo $_product->getPrice(); echo '<br/>'; echo "Sale Price"; echo...

To get the current product id

$product_id = $this -> getProduct ()-> getId (); When you don’t have access to $this, you can use Magento registry:   $product_id = Mage :: registry ( 'current_product' )-> getId ();

Magento: How to tell if you're on a category page, or product page in .phtml

<?php $controller_name=Mage::app()->getFrontController()->getRequest()->getControllerName(); echo controller_name

To get the id of product and load the product base on the product id

$product_id = $this->getProduct()->getId();  $collection = Mage::getModel('catalog/product')->load($product_id);

How to call static block in magento

How to call image in static block {{skin url='images/media/about_us_img.jpg'}} How to creating a link to another page within your site {{store direct_url='mypage.html'}} How to call staic block any XML file <reference name="left">      <block type="cms/block" name="sample_block" before="-">          <action method="setBlockId"><block_id>sample_block</block_id></action>      </block>    </reference> How to call staick block in your template or .phtml files <?php echo $this ->getLayout()->createBlock( 'cms/block' )->setBlockId( 'my_static_block_name' )->toHtml() ?> How to call static block in CMS->Pages   {{block type="cms/block" block_id="your_block_id"}}

Update Product Status (ENABLED/DISABLED) In Magento Programmatically

$productid =10; // product id which you want to change status;   $storeid =1 // your store id 0 is for default store id Mage::getModel( 'catalog/product_status' )->updateProductStatus( $productid , $storeid , Mage_Catalog_Model_Product_Status::STATUS_ENABLED);

How to Use PHTML File in CMS or Static Block

In Magento CMS or Static block, if you want to add PHP code then you can just call any custom .phtml file by using following code. Like here I am including my_custom.phtml . { { block type = "core/template" name = "myCustom" template = "cms/my_custom.phtml" } }   This is equivalent to following layout tag: < block type = "core/template" name = "myCustom" template = "cms/my_custom.phtml" >

To call the model anywhere in magento

<?php $a = Mage::getModel('brand/brand')->getCollection(); Mage::getModel('module name/model name')->getCollection() folder structure: Communuity/Redstage/"Brand"/ here brand is a module name (Brand) and to get model name Or <config> <modules> <Redstage_Brand>(NameSpace_moduleName) <version>0.2.3</version> </Redstage_Brand> </modules> <frontend> .. .. <brand> (in tag is model name) Note: The module and model name must be in small caps if name of module is WebForm then we must use the module name as webform  foreach ($a as $b) {   //echo '<pre>'; //print_r($b); //echo $b->getUrlKey(); ?> <img src="http://54.219.137.93/magento/media/brand/<?php echo $b->getImage(); ?>" /> <br/> <br/> <br/> <?php }  ?>

to avoid the conflict between Prototype and Jquery.

After all the Jquery script tag's add <script> jQuery . noConflict (); </script>

Cart items preview on mouseover

yes, its realy a nice addon. It works with 1.5.1 ! The installation instructions aren't the best so want to tell how I managed it. 1. Activate the cart-sidebar in the backend 2. open the checkout.xml in YOUR template folder 3. copy the code between the [...] from the "overview" and paste into your checkout.xml between <default></default> - let the rest of the code stay there 4. paste <?php echo $this->getChildHtml('cartview_link') ?> it into the header.phtml between the quick-access <div> or use this code <?php echo $this->getChildHtml('topLinks')  ?> 5. copy the new css from the default folder into your css folder 6. you can style the most in your style.css 7. if you dislike the left cart now you can paste .col-left .block-cart {display:none;} into your style.css, best @the /* Block: Cart */ chapter here it works: www.menxclusive.de (as long as my customer wants it) magento connect: http://www.magent...

toplinks short code

<?php echo $this->getChildHtml('topLinks') ?>

short code for search

<?php echo $this->getChildHtml('topSearch') ?>

Rating problem shows ratings for the first product, and nothing for the rest

I am having the same problem - it only shows ratings for the first product, and nothing for the rest. I have tried the PHP-solution in #5, but the page just stops working. This is a reported bug. open file: app/code/core/Mage/Catalog/Block/Product/Abstract.php change: protected function  _initReviewsHelperBlock ()      {          if (! $this -> _reviewsHelperBlock )  {              if ( Mage :: helper ( 'catalog' )-> isModuleEnabled ( 'Mage_Review' ))  {                 $this -> _reviewsHelperBlock  =  $this -> getLayout ()-> createBlock ( 'review/helper' );                 return  true ;        ...

to add any type of social button

http://www.sharethis.com/