Wednesday, July 22, 2015

How to get cart items total on header file in Magento



Source : frontend\default\your_theme\template\page\html\header.phtml


Put This Code:

<?php
      $count = $this->helper('checkout/cart')->getSummaryCount();  //get total items in cart
      $total = $this->helper('checkout/cart')->getQuote()->getGrandTotal(); //get total price
      if($count==0)
      {
        echo $this->__('<a href="/checkout/cart" class="cartgo">(0 ITEMS)</a>',$count);
      }
      if($count==1)
      {
        echo $this->__('<a href="/checkout/cart" class="cartgo">(1 ITEM)</a>',$count);
      }
      if($count>1)
      {
        echo $this->__('<a href="/checkout/cart" class="cartgo">(%s ITMES)</a>',$count);
      }
      echo $this->__('', $this->helper('core')->formatPrice($total, false));
    ?>

Sending custom emails in Magento

Step 1: Create html file in app/locale/en_us/template/email/sales/sample_order.html

-> sample_order.html file in put your html (Mail sending) content.


Step 2: Adding your template to etc/config.xml to register the email template. 
-> app/code/[codePool]/[Namespace]/[Module]/etc/config.xml

   <config>
<global>
<template>
             <email>
                 <sample_order translate="label" module="[Module Name]">
     <label>Sample Order</label>
     <file>sales/sample_order.html</file>
     <type>html</type>
                 </sample_order>
             </email>
         </template>

</global>    
   </config>

Step 3: Sending the email  !

-> app/code/[codePool]/[Namespace]/[Module]/controllers/IndexController.php


//Send Custom Email Start
 $emailTemplate = Mage::getModel('core/email_template')->loadDefault('sample_order');

 $senderName = Mage::getStoreConfig('trans_email/ident_general/name');
 $senderEmail = Mage::getStoreConfig('trans_email/ident_general/email');

 $name = $data['name'];
 $email = $data['email'];
 $pro_name = $data['product_name'];
 $pro_img  = $data['product_img'];
 $pro_sku  = $data['product_sku'];
 $pro_color  = $data['color'];  
//Variables for Confirmation Mail.
$emailTemplateVariables = array(
    'customer_name' => $name,
    'product_name'  => $pro_name,
    'product_img'   => $pro_img,
    'product_sku'   => $pro_sku,
    'product_color' => $pro_color
    
);

$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
   //Sending E-Mail to Customers.

$mail = Mage::getModel('core/email')
 ->setToName($name)
 ->setToEmail($email)
 ->setBody($processedTemplate)
 ->setSubject('Sample Order')
 ->setFromEmail($senderEmail)
 ->setFromName($senderName)
 ->setType('html');
 try{
  //Confimation E-Mail Send
  $mail->send();
 }
 catch(Exception $error)
 {
  Mage::getSingleton('core/session')->addError($error->getMessage());
  return false;
 }

//Send Custom Email End
Setp 4: Your Mail Send Sucessfully.