Wednesday, 3 December 2014

Non WWW to WWW in magento direct and Remove index.php and of the domain

#non www to www
RewriteCond %{HTTP_HOST} ^(?!www\.)(.+) [NC]
RewriteRule ^(.*) http://www.%1/$1 [R=301,NE,L]

#remove index.php after domain name
DirectoryIndex index.php\
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]

Thursday, 25 September 2014

Magento Custom Options – Change the Option to show total price.

Sol : You need to modify Abstact.PHP file.. It is located at app/code/core/Mage/Catalog/Block/Product/View/Options/Abstract.php
        $_priceInclTax = $this->getPrice($value['pricing_value'], true);
        $_priceExclTax = $this->getPrice($value['pricing_value']);

 Replace above code below code

        $_priceInclTax = $this->getPrice($value['pricing_value'], true)+$this->getProduct()->getFinalPrice();
        $_priceExclTax = $this->getPrice($value['pricing_value'])+$this->getProduct()->getFinalPrice();

Wednesday, 17 September 2014

Show third level catgories in Magento

<?php $_helper = Mage::helper('catalog/category') ?>
                <?php $_categories = $_helper->getStoreCategories() ?>
                <?php $currentCategory = Mage::registry('current_category') ?>
                <?php if (count($_categories) > 0): ?>
                 <?php foreach($_categories as $_category): ?>
              <li>
                <a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
                    <span class="guitar"><?php echo $_category->getName() ?></span>
                </a>
                <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
                <?php $_subcategories = $_category->getChildrenCategories() ?>
                <?php if (count($_subcategories) > 0): ?>
                  <ul>
                        <?php foreach($_subcategories as $_subcategory): ?>
                            <li>
                                <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
                                    <?php echo $_subcategory->getName() ?>
                                </a>
                                <?php // third level /// ?>
                                    <?php $_sub_subcategory = Mage::getModel('catalog/category')->load($_subcategory->getId()) ?>
                                    <?php $_sub_subcategories = $_sub_subcategory->getChildrenCategories() ?>
                                    <?php if (count($_sub_subcategories) > 0): ?>
                                        <ul>
                                            <?php foreach($_sub_subcategories as $_subsubcategory): ?>
                                                <li>
                                                    <a href="<?php echo $_helper->getCategoryUrl($_subsubcategory) ?>">
                                                        <?php echo $_subsubcategory->getName() ?>
                                                    </a>
                                                </li>
                                            <?php endforeach; ?>
                                        </ul>
                                    <?php endif; ?>
                                   
                                <?php /// third level //// ?>
                               
                            </li>
                        <?php endforeach; ?>
                    </ul>
                <?php endif; ?>
            </li>
        <?php endforeach; ?>
         <?php endif; ?>

Tuesday, 16 September 2014

Category image resize in Magento

<?php
$_file_name = $cat->getThumbnail();             
$_media_dir = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category' . DS;
$cache_dir = $_media_dir . 'resize' . DS;

if (file_exists($cache_dir . $_file_name)) {
$catImg =Mage::getBaseUrl('media') .  'catalog' . DS . 'category' . DS . 'resize' . DS . $_file_name;
 } elseif (file_exists($_media_dir . $_file_name)) {
if (!is_dir($cache_dir)) {
mkdir($cache_dir);
}

$_image = new Varien_Image($_media_dir . $_file_name);
$_image->constrainOnly(true);
$_image->keepAspectRatio(false);
$_image->keepFrame(false);
$_image->keepTransparency(true);
$_image->resize(224, 174); // change image height, width
$_image->save($cache_dir . $_file_name);
$catImg = Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . 'resize' . DS . $_file_name;
                         }
 echo  $catImg ; // display resize category thumbnail imagename
 ?>

<img src="<?php echo $catImg;  ?>"  />

Magento Add Payment Method to Admin invoice Grid

 protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel($this->_getCollectionClass());
      
        $collection->join(array('payment'=>'sales/order_payment'),'main_table.order_id=parent_id',array('method','po_number'));
      
        $collection->getSelect()->joinLeft('sales_flat_order_address', 'main_table.order_id = sales_flat_order_address.parent_id',array('full_name'=>'CONCAT(sales_flat_order_address.firstname, " " , sales_flat_order_address.lastname)','full_address'=>'CONCAT(sales_flat_order_address.street, " ", sales_flat_order_address.city, sales_flat_order_address.postcode)','telephone','city','firstname','postcode','company','street','email' ) )->where("sales_flat_order_address.address_type =  'billing'");
      
      
          $collection->getSelect()->joinLeft('sales_flat_order', 'main_table.order_id=sales_flat_order.entity_id', array("shipping_desc"=>"shipping_description","weight"=>"weight","subtotal_incl_tax"=>"subtotal_incl_tax","base_subtotal_invoiced"=>"base_subtotal_invoiced","base_shipping_invoiced"=>"base_shipping_invoiced","base_tax_amount"=>"base_tax_amount"));
        
     
         $this->setCollection($collection);
         return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
        
    }
$payments = Mage::getModel('payment/config')->getAllMethods();
        $methods = array();
            foreach ($payments as $paymentCode=>$paymentModel)
            {
                $paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title');
                $methods[$paymentCode] = $paymentTitle;
            }
            $this->addColumnAfter('method', array(
                'header' => Mage::helper('sales')->__('Payment Method'),
                'index' => 'method',
                'filter_index' => 'method',
                'type'  => 'options',
                'width' => '1050px',
                'options' => $methods,
            ));

Sunday, 6 April 2014

Remove all Customers with Reset Id in Magento.

Run Below Query in your database.please  make a backup your db 
SET FOREIGN_KEY_CHECKS=0;
-- reset customers
TRUNCATE customer_address_entity;
TRUNCATE customer_address_entity_datetime;
TRUNCATE customer_address_entity_decimal;
TRUNCATE customer_address_entity_int;
TRUNCATE customer_address_entity_text;
TRUNCATE customer_address_entity_varchar;
TRUNCATE customer_entity;
TRUNCATE customer_entity_datetime;
TRUNCATE customer_entity_decimal;
TRUNCATE customer_entity_int;
TRUNCATE customer_entity_text;
TRUNCATE customer_entity_varchar;
TRUNCATE log_customer;
TRUNCATE log_visitor;
TRUNCATE log_visitor_info;

ALTER TABLE customer_address_entity AUTO_INCREMENT=1;
ALTER TABLE customer_address_entity_datetime AUTO_INCREMENT=1;
ALTER TABLE customer_address_entity_decimal AUTO_INCREMENT=1;
ALTER TABLE customer_address_entity_int AUTO_INCREMENT=1;
ALTER TABLE customer_address_entity_text AUTO_INCREMENT=1;
ALTER TABLE customer_address_entity_varchar AUTO_INCREMENT=1;
ALTER TABLE customer_entity AUTO_INCREMENT=1;
ALTER TABLE customer_entity_datetime AUTO_INCREMENT=1;
ALTER TABLE customer_entity_decimal AUTO_INCREMENT=1;
ALTER TABLE customer_entity_int AUTO_INCREMENT=1;
ALTER TABLE customer_entity_text AUTO_INCREMENT=1;
ALTER TABLE customer_entity_varchar AUTO_INCREMENT=1;
ALTER TABLE log_customer AUTO_INCREMENT=1;
ALTER TABLE log_visitor AUTO_INCREMENT=1;
ALTER TABLE log_visitor_info AUTO_INCREMENT=1;
SET FOREIGN_KEY_CHECKS=1;

Wednesday, 26 March 2014

How to add custom field in Magento newsletter module.

Step 1 : Open file: root/app/design/frontend/your-package-name/your-theme/template/newsletter/subscribe.phtml

Add input field for ‘Name’ before ‘Email’ Field :
<input type="text" name="subscriber_name" id="subscriber_name" title="<?php echo $this->__('Name') ?>" />
 
Step 2 : Open file:  root/app/code/core/Mage/Newsletter/controllers/SubscriberController.php
A. Search:
$status = Mage::getModel('newsletter/subscriber')->subscribe($email);
Replace with:
if ($this->getRequest()->getPost('subscriber_name'))
{
$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
$subscriber_name     = (string) $this->getRequest()->getPost('subscriber_name');
$subscriber->setsubscriber_name($subscriber_name);
}
$status = Mage::getModel('newsletter/subscriber')->subscribe($email,$subscriber_name);
 
Step 3 : Open file : root/app/code/core/Mage/Newsletter/Model/Subscriber.php
A. Search:
public function subscribe($email)
Replace with:
public function subscribe($email,$subscriber_name=null)
B. Search:
$this->setSubscriberEmail($email);
Add after it:
$this->setsubscriber_name($subscriber_name);
C. Search:
public function setEmail($value)
{
return $this->setSubscriberEmail($value);
}
Add after it:
public function setsubscriber_name($value)
{
return $this->setSubscriberName($value);
}
Step 4 : Open file : root/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid.php
A. Search:
$this->addColumn('email', array(
'header'    => Mage::helper('newsletter')->__('Email'),
'index'     => 'subscriber_email'
));
Add before it:
$this->addColumn('subscriber_name', array(
'header'    => Mage::helper('newsletter')->__('Subscriber Name'),
'index'     => 'subscriber_name',
'default'   =>    '----'
));
Step 5 : Open your database.
Create a field ‘subscriber_name’ in table “Newsletter Subscriber”.
Step 6 : Clear the caches ................
 
  
 
 
 
 
 
  
 
  

Monday, 13 January 2014

After upgrade 1.7 to 1.8, ‘Place Order’ button does not work

Replace the base file the following path
app/design/frontend/default/your_theme/template/checkout/onepage/review/info.phtml
(or)
Replace the line number 81 in info.phtml
review = new Review(’<?php echo $this->getUrl('checkout/onepage/saveOrder', array('form_key' => Mage::getSingleton('core/session')->getFormKey())) ?>’, ‘<?php echo $this->getUrl('checkout/onepage/success') ?>’, $(’checkout-agreements’));