Friday 25 December 2015

How to display latest added products first in Magento

If you want to display latest added product first. Then, use below code:  


<?php 


 $_productCollection=$category->getProductCollection()
                         ->addAttributeToSort('entity_id', 'desc');

                     

 // Use this code for sort product as "Ascending" and "Descending" (Red Color Code)


?>




How to display Featured Product on Home Page according to Category Id in Magento?

If you want to display "Featured Products" on home page. You can use below code in product listing code.


    <?php

 
 $categoryid = 8;   // Here you can replace from your category id
                   $category_cb = new Mage_Catalog_Model_Category();     $category_cb->load($categoryid);

$this->getProducts();

$_productCollection=$category_cb->getProductCollection()
->addAttributeToSort('entity_id', 'desc')
->addAttributeToSelect('*') ->addAttributeToFilter(array(
array('attribute' => 'featured', 'eq' => true),
));
 

?> 





How to display Featured Product on Home Page By Category Id in Magento?

Hello Friends,


If you want to display Featured Product on Home Page according to Category Id, So Please see below code. Which Display Featured Product By Category Id.

For Display Featured Product.

First Create attribute in Magento Admin Panel.

For add attribute, 

1. You go to admin Panel

2. Mouse over on "Catalog" Menu (third menu)

3. Mouse over "Attribute" and Click on Manage Attribute (See Screenshot)





4. Open listing of all Attribute.

5. Now Click on "Add New Attribute" on right side.



6. After click "Add New Attribute" , open new page. Here, you can add your attribute. Please see below screenshot for example.



7. After Fill form, click on "Save Attribute". Now, Your "Featured" Attribute is added.

8. Now, make Products as "Featured(option 'Yes')" which, You want to assign as a Featured Product.

Now, You can paste below code, where you want to display Featured Products.

         <?php
 $categoryid = 11;   // Here you can replace from your category id
                   $category_cb = new Mage_Catalog_Model_Category();     $category_cb->load($categoryid);

$this->getProducts();

$_productCollection=$category_cb->getProductCollection()
->addAttributeToSort('entity_id', 'desc')
->addAttributeToSelect('*') ->addAttributeToFilter(array(
array('attribute' => 'featured', 'eq' => true),
));
?> 


Thanks and Enjoy 





Thursday 24 December 2015

After Patched SUPEE-6788, product not displaying on home page in Magento


This error is error of permissions, which display products on home page. So follow below steps.


After patched,  add some section in your admin.


Open
System -> permission -> blocks

Here, You must add the home page blocks for allowed permissions. Like, if you want to display new products, so add New Block "catalog/product_new" in Block Name and "Is Allowed" is Yes.

After Add New Block,  flush cache and reload home page. Now, New Products are displaying on HomePage



Tuesday 22 December 2015

How to replace text in a particular column in a table in phpmyadmin?

Use the REPLACE function with a UPDATE statement:


UPDATE table_name
SET column_name= REPLACE(
column_name, 'search_text', 'replacement_text')



How to get category name by product id in magento?

You can get category name by product id by following code. Where You want display category name, put the code.


<?php $product = Mage::getModel('catalog/product')->load($_product->getId());
$cats = $product->getCategoryIds();
foreach($cats as $categoryId) {
    $category = Mage::getModel('catalog/category')->load($categoryId);
    echo $category->getName();
}
?>



How to display image in magento?

You can display image in magento by following code:



<img src="<?php echo $this->getSkinUrl('images/dummy.jpg');?>" />




Monday 14 December 2015

Magento: Fatal error call to undefined function curl_setopt() in curl.php

If your magento page display this error so please check CURL is enable or not in php.ini file.

If not then enable
curl in php.ini file.



Please find "extension=php_curl.dll" in php.ini file. And remove ";" from starting. Like below: 


;extension=php_curl.dll
to
extension=php_curl.dll 





How to Display the recently added products first in Magento?

 Display the recently added products first in Magento


Please copy the file Toolbar.php from 


app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php

And  Create a Directory structure in local and paste the Toolbar.php as shown below 

app/code/local/Mage/Catalog/Block/Product/List/Toolbar.php

and Find the below code at around line 232


if ($this->getCurrentOrder()) {
  $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
}


Now Replace the above code with below code:

if ($this->getCurrentOrder()) {
  if(($this->getCurrentOrder())=='position'){
      $this->_collection->setOrder('entity_id','desc');
  }
  else {
   $this->_collection->setOrder($this->getCurrentOrder(),$this->getCurrentDirection());
  }
}








How to create admin user by database?

Paste Following code into your database and then Login to your Magento admin panel by using new credentials.


INSERT INTO `admin_user` (
`user_id` ,
`firstname` ,
`lastname` ,
`email` ,
`username` ,
`password` ,
`created` ,
`modified` ,
`logdate` ,
`lognum` ,
`reload_acl_flag` ,
`is_active` ,
`extra` ,
`rp_token` ,
`rp_token_created_at`
)
VALUES (
NULL , 'CHANDRA', 'BHUSHAN', 'cb8022@gmail.com', 'cb8022', MD5( 'cb#8022' ) ,
CURRENT_TIMESTAMP , NULL , NULL , '0', '0', '1', NULL , NULL , NULL
)



INSERT INTO admin_role SELECT
 NULL `role_id`,
 0 `parent_id`,
 2 `tree_level`,
 0 `sort_order`,
 'U' `role_type`,
 (SELECT `user_id` FROM admin_user WHERE `username` = 'cb8022') `user_id`,
 'Administrators' `role_name`;

How to clean log via Magento Admin Panel?

Log cleaning via magento admin panel, method is easier for non technical store owners who don’t know to familiar with the Magento store’s database. So, user can activate log cleaning option in Magento admin panel by following steps:


1. Log on to your Magento Admin Panel.
2. Go to System => Configuration
3. On the left side,  under Advanced click on System (Advanced = > System)
4. Under system you will see “Log Cleaning” option
5. Fill the desired “Log Cleaning” option values and click Save.




How to clean logs through database in Magento?

If you want to delete Magento logs through database. So truncate the some table which have logs data. So execute following sql query in database:




SET foreign_key_checks = 0;
TRUNCATE dataflow_batch_export;
TRUNCATE dataflow_batch_import;
TRUNCATE log_customer;
TRUNCATE log_quote;
TRUNCATE log_summary;
TRUNCATE log_summary_type;
TRUNCATE log_url;
TRUNCATE log_url_info;
TRUNCATE log_visitor;
TRUNCATE log_visitor_info;
TRUNCATE log_visitor_online;
TRUNCATE report_viewed_product_index;
TRUNCATE report_compared_product_index;
TRUNCATE report_event;
TRUNCATE index_event;
TRUNCATE catalog_compare_item;
SET foreign_key_checks = 1;




Friday 11 December 2015

What is difference between shopping cart price rules and catalog price rules Magento?

Magento : Difference between  shopping cart price rules and catalog price rules



Shopping Cart Price Rules



Shopping cart price rules can be use for Attribute wise discount, product discount/sale discount, Customer group wise discount, Country wise discount under the certain conditions. Shopping cart price rules use coupon code but not necessary, you can create rule without coupon code also. Shopping cart price rules always apply on shopping cart when conditions are meet. Discount appears on the shopping cart page under the subtotal.





Catalog Price Rules


Catalog price rules use for products discounts or products sales discount under certain conditions. Catalog price rules do not use coupon codes, because they are applied before the product add to cart. Discount appears on products listing.





Thursday 10 December 2015

How to get subcategories of current category in magento?

Display all the subcategories of any category in Magento.


If you have a category ID (current category OR any category) then you can easily display all the subcategories of that particular category.


Below code will load all the subcategories of the current category. 


If you want to get all the subcategories of any specific category, so assign category id in $categoryID. 



<?php 
         
       $catID = $current_category->getId(); //or any specific category id, e.g. 5

       $children = Mage::getModel('catalog/category')->getCategories($catID);

       foreach ($children as $category) 

         {
          
           echo $category->getId();
      
           echo $category->getName();
    
           echo $category->getRequestPath();
     
          print_r($category->getData());

}

?>

How to get sub categories by parent category id in Magento?

You can try below code for display all sub category of one particular category by category id.



<?php 

$category_id = 13;   // you can change category id according to you


$parentCat = Mage::getModel('catalog/category')->load($category_id); 


$subCat = explode(',',$parentCat ->getChildren()); 


$collection  = $parentCat
             ->getCollection()
             ->addAttributeToSelect("*")
             ->addFieldToFilter("entity_id", array("in", $subCat) );


foreach($collection as $catname)

{

     echo $catname->getName();


}


?> 

How to get custom option values in Magento?

If you want custom options value in magento. Then

You can try following code.




<?php
             
          $customoptions = $item->getProductOptions();
                 
           foreach($customoptions ['options'] as $key=>$valuecb)
             {

               echo $valuecb['label'];

              echo $valuecb['option_value'];

  }
}


?> 

How to get Custom Options Programmatically any where in Magento?

How to get Custom Options Programmatically any where in Magento?

You can get custom options by following code. 


$product = Mage::getModel("catalog/product")->load($_product->getId());


$custom = $product->getOptions();


foreach($
custom as $customoptionKey => $customoptionVal){


    foreach($
customoptionVal->getValues() as $valuesKey => $valuesVal){


        echo $
customoptionVal->getId();


    }

}

Friday 4 December 2015

How to Create a custom Database connection in Magento?

Create a connectdb.php file in your root folder. And paste the following code. Now 

you are able to access Data base on your file.




1. require_once ("app/Mage.php");

2. $app = Mage::app('default');

3. $config  = Mage::getConfig()->getResourceConnectionConfig("default_setup"); 

4. $dbinfo = array("host" => $config->host, "user" => $config->username,"pass" => $config->password, "dbname" => $config->dbname); 

5. $hostname = $dbinfo["host"];

6. $user = $dbinfo["user"];

7. $password = $dbinfo["pass"];

8. $dbname = $dbinfo["dbname"];

9. $con = mysql_select_db($dbname,mysql_connect($hostname,$user,$password));





What is Difference between Mage::getSingleton() and Mage::getModel() in Magento

What is difference between getSingleton and getModel in magento. It's very important question for interview in Magento. Every Interviewer asked this question.



Mage::getSingleton()

Mage::getSingleton() is first check the object are created or not. If the object is created then return existing object. If the object is not created then it will create. So Mage::getSingleton() faster than Mage::getModel().

1. $getproduct1  =  Mage::getSingleton('catalog/product');

2. $getproduct2  =  Mage::getSingleton('catalog/product');


$getproduct1 and $getproduct2  both are have same memory and return only one object each time.



Mage::getModel()

Mage::getModel() is always create new object.

1. $getproduct1  =  Mage::getModel('catalog/product');

2. $getproduct2  =  Mage::getModel('catalog/product');


$getproduct1 and $getproduct2  both have different object and also have different memory .

Monday 12 October 2015

Please enter a valid URL. Protocol is required (http://, https:// or ftp://) when Magento installing?

We need to disable URL validation here.



1. Open \app\design\install\default\default\template\install\config.phtml


2. Open file in your text editor and find the textbox where the base url is entered.

         It will be around line no 50. 



3. Remove "validate-url" from its class and save the file.

<input type="text" name="config[unsecure_base_url]" id="base_url" value="<?php echo $this->getFormData()->getUnsecureBaseUrl() ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Base URL')) ?>" class="required-entry  validate-url  input-text" />



4. After remove "validate-url" from its class. Now looks like:

<input type="text" name="config[unsecure_base_url]id="base_url" value="<?php echo $this->getFormData()->getUnsecureBaseUrl() ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Base URL')) ?>class="required-entry input-text" />


5. Now you can continue the installation




Thursday 24 September 2015

Magento: How to delete ‘Url Rewrite Management’ URLs?


You can delete some ‘Url Rewrite Management’ URLs form follow the following steps:


1. Open your magneto database.


2. Open  ‘core_url_rewrite’ table.


If you want delete all URLs, then empty the table.


                                  or


want delete some particular URLs, then search and delete URLs. Like- You want delete "Mens" category URLs, then search "mens" with like operator and delete all URLs. 


3. Now open magneto backend and Reindex Data.


Above steps will delete all manually and system created rewrites URLs. Now you can recreate only needed URLs and your category and products URLs will recreate automatically.



Wednesday 16 September 2015

Magento: Product Review Form is not submitting.

While I submit the Product Review form in magneto but it is not submitting and not showing any error message.

Then I checked the Review form. I found some error in code. 


<?php echo $this->getBlockHtml('formkey'); ?>


was not writting.  So I added this code in "form.phml" of Review after form tag.


Now code looks like :


 <?php if ($this->getAllowWriteReviewFlag()): ?>

    <form action="<?php echo $this->getAction() ?>" method="post" id="review-form">

<?php echo $this->getBlockHtml('formkey'); ?>


        <fieldset>

Saturday 27 June 2015

How can add custom option title in dropdown option in magento

Open file:  app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Select.php


Find following code (Maybe line number - 59):


         $select->setName('options['.$_option->getid().']')
                              ->addOption('', $this->__('-- Please Select --'));


add this line at above of code:


                      $getOptionTitle= ucwords($_option->getTitle());


Now code looks like as:


         $getOptionTitle = ucwords($_option->getTitle());

                                ->setName('options['.$_option->getid().']')

                                      ->addOption('', $this->__('-- Please Select'.$getOptionTitle. '--'));


Now go to frontend. And check now, Title of Custom Option is displaying in drop down.

Monday 13 April 2015

How To Change Admin Password in Magento

Go To phpmyadmin. 

Open 'admin_user' table in database.

And execute following mysql query:



UPDATE `admin_user` SET `password` = MD5('NEWPASSWORD') WHERE `username` = 'ADMINUSERNAME';









Tuesday 31 March 2015

Magento - Display Full Breadcrumb Path on product page

Copy core file to local: 


app\code\local\Mage\Catalog\Block\Breadcrumbs.php


Change "protected function _prepareLayout()" function from following code:



/** * Preparing layout * * @return Mage_Catalog_Block_Breadcrumbs */


protected function _prepareLayout()

{ 

if ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs')) { $breadcrumbsBlock->addCrumb('home', array( 'label'=>Mage::helper('catalog')->__('Home'),
'title'=>Mage::helper('catalog')->__('Go to Home Page'),
'link'=>Mage::getBaseUrl()
));


// sometimes magento can't get category associated with a product 

// so the full breadcrumb is not shown // this is a hack to fix the issue. 

$current_category   = Mage::registry('current_category');
$current_product    = Mage::registry('current_product');


// let's check if magento knows what current category is 

// if it doesn't know, let's feed this info to it's brain :) 

if(!$current_category && $current_product){
$categories = $current_product->getCategoryCollection()->addAttributeToSelect('name')->setPageSize(1);
foreach($categories as $category) { Mage::unregister('current_category');
Mage::register('current_category', $category);
}
}
$title = array(); $path  = Mage::helper('catalog')->getBreadcrumbPath();
foreach ($path as $name => $breadcrumb) { $breadcrumbsBlock->addCrumb($name, $breadcrumb);
$title[] = $breadcrumb['label'];
}
if ($headBlock = $this->getLayout()->getBlock('head')) { $headBlock->setTitle(join($this->getTitleSeparator(), array_reverse($title))); }
}
return parent::_prepareLayout();

}

Monday 30 March 2015

How to delete all orders from Magento?

Go to Phpmyadmin and run following sql code:

SET FOREIGN_KEY_CHECKS=0;

TRUNCATE `sales_flat_creditmemo`;

TRUNCATE `sales_flat_creditmemo_comment`;

TRUNCATE `sales_flat_creditmemo_grid`;

TRUNCATE `sales_flat_creditmemo_item`;

TRUNCATE `sales_flat_invoice`;

TRUNCATE `sales_flat_invoice_comment`;

TRUNCATE `sales_flat_invoice_grid`;

TRUNCATE `sales_flat_invoice_item`;

TRUNCATE `sales_flat_order`;

TRUNCATE `sales_flat_order_address`;

TRUNCATE `sales_flat_order_grid`;

TRUNCATE `sales_flat_order_item`;

TRUNCATE `sales_flat_order_payment`;

TRUNCATE `sales_flat_order_status_history`;

TRUNCATE `sales_flat_quote`;

TRUNCATE `sales_flat_quote_address`;

TRUNCATE `sales_flat_quote_address_item`;

TRUNCATE `sales_flat_quote_item`;

TRUNCATE `sales_flat_quote_item_option`;

TRUNCATE `sales_flat_quote_payment`;

TRUNCATE `sales_flat_quote_shipping_rate`;

TRUNCATE `sales_flat_shipment`;

TRUNCATE `sales_flat_shipment_comment`;

TRUNCATE `sales_flat_shipment_grid`;

TRUNCATE `sales_flat_shipment_item`;

TRUNCATE `sales_flat_shipment_track`;

TRUNCATE `sales_invoiced_aggregated`;

TRUNCATE `sales_invoiced_aggregated_order`;

TRUNCATE `sales_order_aggregated_created`;

TRUNCATE `sendfriend_log`;

TRUNCATE `tag`;

TRUNCATE `tag_relation`;

TRUNCATE `tag_summary`;

TRUNCATE `wishlist`;

TRUNCATE `log_quote`;

TRUNCATE `report_event`;

ALTER TABLE `sales_flat_creditmemo` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_creditmemo_comment` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_creditmemo_grid` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_creditmemo_item` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_invoice` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_invoice_comment` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_invoice_grid` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_invoice_item` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_order` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_order_address` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_order_grid` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_order_payment` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_order_status_history` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_quote_payment` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_quote_shipping_rate` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_shipment` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_shipment_comment` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_shipment_grid` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_shipment_item` AUTO_INCREMENT=1;

ALTER TABLE `sales_flat_shipment_track` AUTO_INCREMENT=1;

ALTER TABLE `sales_invoiced_aggregated` AUTO_INCREMENT=1;

ALTER TABLE `sales_invoiced_aggregated_order` AUTO_INCREMENT=1;

ALTER TABLE `sales_order_aggregated_created` AUTO_INCREMENT=1;

ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;

ALTER TABLE `tag` AUTO_INCREMENT=1;

ALTER TABLE `tag_relation` AUTO_INCREMENT=1;

ALTER TABLE `tag_summary` AUTO_INCREMENT=1;

ALTER TABLE `wishlist` AUTO_INCREMENT=1;

ALTER TABLE `log_quote` AUTO_INCREMENT=1;

ALTER TABLE `report_event` AUTO_INCREMENT=1;


SET FOREIGN_KEY_CHECKS=1; 

Tuesday 17 March 2015

Magento Currency Symbol page not found, display 404 error when i go to admin

Change line 68 in:  app\code\core\Mage\CurrencySymbol\etc\config.xml



And change to

<currencysymbol>Mage_CurrencySymbol_Adminhtml</currencysymbol> 


from


<currencysymbol before="Mage_Adminhtml">Mage_CurrencySymbol_Adminhtml</currencysymbol>

How to add custom filters on the category page in Magento

Directory file path:   app/code/core/Mage/Catalog/Model/Category.php




public function getProductCollection()
    {
        $collection = Mage::getResourceModel('catalog/product_collection')
            ->setStoreId($this->getStoreId())
            ->addCategoryFilter($this)
->addAttributeToFilter('featured', array('value'=>'1'));
        return $collection;
    }

How to filters products by attribute value in Magento

Directory file path : app/design/frontend/base/default/template/catalog/product/list.phtml



$_productCollection=$this->getLoadedProductCollection();

$_productCollection = clone $this->getLoadedProductCollection();

$_productCollection->clear()

->addAttributeToFilter('featured', array('value'=>'1'))

->load();




Wednesday 11 March 2015

How to add Indian States in Magento?

In this tutorial, we will see how to add states of any country in Magento.


All states value are stored in two main table: directory_country_region and 
directory_country_region_name.

So Please Follow the following steps:


1. open phpmyadmin
2. select your database
3. open 'directory_country_region' table
4. click on sql and paste following code:



INSERT INTO `directory_country_region` (`region_id`, `country_id`, `code`, `default_name`) VALUES
(485, 'IN', 'ANDRA', 'Andra Pradesh'),
(486, 'IN', 'ARUNA', 'Arunachal Pradesh'),
(487, 'IN', 'ASSAM', 'Assam'),
(488, 'IN', 'BIHAR', 'Bihar'),
(489, 'IN', 'CHAND', 'Chandigarh'),
(490, 'IN', 'CHHAT', 'Chhattisgarh'),
(491, 'IN', 'DADAR', 'Dadar and Nagar Haveli'),
(492, 'IN', 'DAMAN', 'Daman and Diu'),
(493, 'IN', 'DELHI', 'Delhi'),
(494, 'IN', 'GOA', 'Goa'),
(495, 'IN', 'GUJAR', 'Gujarat'),
(496, 'IN', 'HARYA', 'Haryana'),
(497, 'IN', 'HP', 'Himachal Pradesh'),
(498, 'IN', 'JK', 'Jammu and Kashmir'),
(499, 'IN', 'JHARK', 'Jharkhand'),
(500, 'IN', 'KARNA', 'Karnataka'),
(501, 'IN', 'KERAL', 'Kerala'),
(502, 'IN', 'LAKSH', 'Lakshadeep'),
(503, 'IN', 'MP', 'Madya Pradesh'),
(504, 'IN', 'MAHAR', 'Maharashtra'),
(505, 'IN', 'MANIP', 'Manipur'),
(506, 'IN', 'MEGHA', 'Meghalaya'),
(507, 'IN', 'MIZOR', 'Mizoram'),
(508, 'IN', 'NAGAL', 'Nagaland'),
(510, 'IN', 'ORISS', 'Orissa'),
(511, 'IN', 'PONDI', 'Pondicherry'),
(512, 'IN', 'PUNJA', 'Punjab'),
(513, 'IN', 'RAJAS', 'Rajasthan'),
(514, 'IN', 'SIKKI', 'Sikkim'),
(515, 'IN', 'TAMIL', 'Tamil Nadu'),
(516, 'IN', 'TELANGANA', 'Telangana'),
(517, 'IN', 'TAMIL', 'Tripura'),
(518, 'IN', 'UP', 'Uttar Pradesh'),
(519, 'IN', 'UTTAR', 'Uttaranchal'),
(520, 'IN', 'WB', 'West Bengal');


And press 'Go' Button in right bottom.

Now check dropdown list, all states of India are displaying.

You can add any states of any Country. Follow the above steps.




Thursday 8 January 2015

Magento: Back Button On Product Detail Page

"/app/design/frontend/default/default/template/catalog/product/view.phtml"
path for view.phtml can be diffrent for diffrent magento themes.

and put this code


<?php if ($_category = $_product->getCategory()): ?>

<div class="back-button">
    <button onclick="history.back();" class="button" title="<?php echo $this->__('Back') ?>" type="button">
        <span>
            <span>
<?php echo $this->__('Back') ?></span>
        </span>
    </button>
</div>
<?php endif; ?>

Magento: “Continue Shopping” button redirect to the last product's category page

It is working fine.

<?php
    $lastProductAddedToCartId = Mage::getSingleton('checkout/session')->getLastAddedProductId();
    if($lastProductAddedToCartId) {
        $productCategoryIdsArray = Mage::getModel('catalog/product')->load($lastProductAddedToCartId)->getCategoryIds();
        $continueShoppingCategoryUrl = Mage::getModel('catalog/category')->load($productCategoryIdsArray[0])->getUrl();
    }
?>
<button type="button" title="Continue Shopping" class="button" onclick="setLocation('<?php echo (isset($continueShoppingCategoryUrl)) ? $continueShoppingCategoryUrl : $this->getContinueShoppingUrl(); ?>')"><span><span>Continue Shopping</span></span></button>

Wednesday 7 January 2015

Magento: Home Page condition

<?  $action = Mage::app()->getFrontController()->getAction()->getFullActionName();

if($action=='cms_index_index'){

    echo "Here Your custom code";

?>

 

<!-- or here you can write your custom code -->

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

<?php  }  ?>