Pages

Friday, 28 November 2014

Magento Category image resize

1-Copy category folder from base/default/template/catalog/category and paste it in your theme before modification.
2-copy and paste the following code in your-theme/default/template/catalog/category/view.phtml
$_file_name = $_category->getThumbnail();             
$_media_dir = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category' . DS;
$cache_dir = $_media_dir . 'resize' . DS;

if (file_exists($cache_dir . $_file_name)) {
$_categoryImg =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(500, 500); // change image height, width
$_image->save($cache_dir . $_file_name);
$_categoryImg = Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . 'resize' . DS . $_file_name;
}
//echo  $_categoryImg ; // display resize category thumbnail imagename

Thursday, 27 November 2014

Magento Remove all Customers with Reset Id

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;

Tuesday, 25 November 2014

Magento add custom field in 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 : 
 

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 ............ and reindex

Wednesday, 19 November 2014

Magento change the newsletter validation message

1- In your root folder\js\prototype\validation.js

2-Open the above file and find it (validate-email) in magento 1.9 near line 526 change it according to your requirement.

Wednesday, 12 November 2014

Magento To get the total product under the particular category(product count)

<?php
    $prodCollection = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($child);
    
    echo $prodCollection->count(); ?>