Friday, April 4, 2014

Make Magento “Continue Shopping” button redirect to the last-added-to-cart product's category

Copy following file 
 /app/code/core/core/Mage/Checkout/Block/Cart.php  
and place under local codepool 
app/code/core/local/Mage/Checkout/Block/Cart.php 
 
Update the following code into function getContinueShoppingUrl() 

public function getContinueShoppingUrl()
    {

      /*
        $url = $this->getData('continue_shopping_url');
        if (is_null($url)) {
            $url = Mage::getSingleton('checkout/session')->getContinueShoppingUrl(true);
            if (!$url) {
                $url = Mage::getUrl();
            }
            $this->setData('continue_shopping_url', $url);
        }
        return $url;

      */
       
            $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();
            }
  
            return $continueShoppingCategoryUrl;
    }


Enjoy the work!!


How to get the customer login, logout, register and checkout url?

Mage::getUrl(‘customer/account/login’); //login url

Mage::getUrl(‘customer/account/logout’); //logout url

Mage::getUrl(‘customer/account’); //My Account url

Mage::getUrl(‘customer/account/create’); // Register url

Mage::getUrl(‘checkout/cart’); //Checkout url

Magento: Check if Customer Logged in

//LOAD MAGENTO
 

require_once 'YOUR_PATH_TO_MAGENTO/app/Mage.php';
umask(0);
Mage::app('YOUR_WEBSITE_CODE', 'website');


//GET SESSION DATA
Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('customer/session', array('name'=>'frontend'));

$customer_data = Mage::getModel('customer/customer')->$session->id);

//CHECK IF LOGGED IN
if($session->isLoggedIn()){
echo 'Welcome ' . $customer_data->firstname . " " . $customer_data->lastname;
}
else {
echo "Access Denied: Sorry, but this page is for registered members only.";
exit;
}

Magento -- 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"}}