Follow by Email

Wednesday, January 29, 2014

Display tier prices at category listing page

$_product->setData('tier_price',null);
$_tierPrices = $this->getTierPrices($_product);

how to get product minimum qty product list page

The following code will help to bring product minimum Qty
<?php echo Mage::getModel("cataloginventory/stock_item")->loadByProduct($_product)->getMinSaleQty();
 ?>

How to run magento store only for USA

Go to System > Configuration > Genera
and change the States Options, Countries Options into your preferable state
it will work..

Thursday, January 23, 2014

Add new field in registration page magento 1.8.1

I have done this with the following steps.
Suppose if you want to add "occupation" after email 
Open template/customer/form/register.phtml and template/customer/form/edit.phtml
 <li>
        <div class="input-box">
            <label for="email_address"><?php echo $this->__('Email Address') ?> <span class="required">*</span></label><br/>
            <input type="text" name="email" id="email_address" value="<?php echo $this->htmlEscape($this->getFormData()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="validate-email required-entry input-text" />
        </div>
        <div class="input-box">
            <label for="occupation"><?php echo $this->__('Occupation/Title') ?></label><br/>
            <input type="text" name="occupation" id="occupation" value="<?php echo $this->htmlEscape($this->getFormData()->getOccupation()) ?>" title="<?php echo $this->__('Occupation') ?>" class="input-text" />
        </div>

    </li>


Now open app\code\core\Mage\Customer\etc\config.xml
and add <occupation><create>1</create><update>1</update></occupation>
after <fieldsets><customer_dataflow> 

Now open app\code\core\Mage\Customer\Model\Resource\Setup.php
 find $entities = array(  and add the following code 
'occupation'               => array(
                        'type'               => 'varchar',
                        'label'              => 'Fax',
                        'input'              => 'text',
                        'required'           => false,
                        'sort_order'         => 130,
                        'validate_rules'     => 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}',
                        'position'           => 130,
                    ), 

 
Now i insert some value in db

INSERT INTO  `eav_attribute` (
`attribute_id` ,
`entity_type_id` ,
`attribute_code` ,
`attribute_model` ,
`backend_model` ,
`backend_type` ,
`backend_table` ,
`frontend_model` ,
`frontend_input` ,
`frontend_label` ,
`frontend_class` ,
`source_model` ,
`is_required` ,
`is_user_defined` ,
`default_value` ,
`is_unique` ,
`note`
)
VALUES (
NULL '1''school', NULL , NULL 'int', NULL , NULL 'select''School', NULL 'profile/entity_school''1''0''0''0'''
);
- See more at: http://www.excellencemagentoblog.com/customer-registration-fields-magento1-6#sthash.ubBrtvuS.dpuf
INSERT INTO  `eav_attribute` (
`attribute_id` ,
`entity_type_id` ,
`attribute_code` ,
`attribute_model` ,
`backend_model` ,
`backend_type` ,
`backend_table` ,
`frontend_model` ,
`frontend_input` ,
`frontend_label` ,
`frontend_class` ,
`source_model` ,
`is_required` ,
`is_user_defined` ,
`default_value` ,
`is_unique` ,
`note`
)
VALUES (
NULL '1''school', NULL , NULL 'int', NULL , NULL 'select''School', NULL 'profile/entity_school''1''0''0''0'''
);
- See more at: http://www.excellencemagentoblog.com/customer-registration-fields-magento1-6#sthash.ubBrtvuS.dpuf
 INSERT INTO  `eav_attribute` (
`attribute_id` ,
`entity_type_id` ,
`attribute_code` ,
`attribute_model` ,
`backend_model` ,
`backend_type` ,
`backend_table` ,
`frontend_model` ,
`frontend_input` ,
`frontend_label` ,
`frontend_class` ,
`source_model` ,
`is_required` ,
`is_user_defined` ,
`default_value` ,
`is_unique` ,
`note`
)
VALUES (
NULL ,  '1',  'occupation', NULL , NULL ,  'int', NULL , NULL ,  'select',  'School', NULL ,  'profile/entity_school',  '1',  '0',  '0',  '0',  ''
);

INSERT INTO  `eav_entity_attribute` (
`entity_attribute_id` ,
`entity_type_id` ,
`attribute_set_id` ,
`attribute_group_id` ,
`attribute_id` ,
`sort_order`
)
VALUES (
NULL ,  '1',  '1',  '1',  '121',  '0'
);

INSERT INTO  `customer_eav_attribute` (
`attribute_id` ,
`is_visible` ,
`input_filter` ,
`multiline_count` ,
`validate_rules` ,
`is_system` ,
`sort_order` ,
`data_model`
)
VALUES (
'121',  '1', NULL ,  '1', NULL ,  '0',  '0', NULL
);

INSERT INTO `customer_eav_attribute_website` (
`attribute_id` ,
`website_id` ,
`is_visible` ,
`is_required` ,
`default_value` ,
`multiline_count`
)
VALUES (
'121',  '0',  '1',  '0', NULL , NULL
);

INSERT INTO  `customer_form_attribute` (
`form_code` ,
`attribute_id`
)
VALUES (
'adminhtml_customer',  '121'
), (
'checkout_register',  '121'
), (
'customer_account_create',  '121'
), (
'customer_account_edit',  '121'
)
;


Also go to the 
System→Configurations→Customers→Customer Configurations→Address Templates
and Add this code in the “Text” textarea:-
 
{{depend occupation}}{{var occupation}}{{/depend}}

Add this code in the “Html” textarea      
{{depend occupation}}{{var occupation}}<br />{{/depend}}
Add the below code in the “PDF” text area. 
{{depend occupation}}{{var occupation}}|{{/depend}}
 
 

Tuesday, January 21, 2014

Create Left menu in category page

Please open your template\catalog\navigation\left.phtml
 And wright the following code there.

<?php
$current_category = Mage::registry('current_category');
global $current_category_id;
$current_category_id = $current_category->getId();
if($current_category->getLevel()==2){
?>
<div class="block block-layered-nav">
    <div class="block-content">
    <dl id="narrow-by-list2">
            <dt><?php echo $this->__('Category') ?></dt>
            <dd>
               
                    <?php
                    $rootcatId= Mage::app()->getStore()->getRootCategoryId();
                    $categories = Mage::getModel('catalog/category')->getCategories($rootcatId);
                    function  get_categories($categories,$lvl,$c_cat) {   
                        global $current_category_id;
                        $array= '<ul class="level_'.$lvl;
                        if($lvl>1){                           
                            if($current_category_id!=$c_cat){
                                $array .=' cate" style="display:none">';
                            }else{
                                $array .= ' cate open">';
                            }
                        }else{
                            $array .='">';
                        }
                        foreach($categories as $category) {
                            $cat = Mage::getModel('catalog/category')->load($category->getId());
                            $count = $cat->getProductCount();
                            $array .= '<li>';
                           
                            if($cat->getLevel()==2){
                                if($current_category_id!=$category->getId())
                                    $array .='<span class="slide active2"></span>';
                                else
                                    $array .='<span class="slide active1"></span>';
                            }
                           
                            $array .= '<a href="' . Mage::getUrl($cat->getUrlPath()). '">' .
                                      $category->getName() . "(".$count.")</a>\n";
                            if($category->hasChildren()) {
                                $children = Mage::getModel('catalog/category')->getCategories($category->getId());
                                $levl = $category->getLevel();
                                 $array .=  get_categories($children,$levl,$category->getId());
                                }
                             $array .= '</li>';
                        }
                        return  $array . '</ul>';
                    }
                    echo  get_categories($categories,1,$rootcatId);                    
                    ?>
          </dd>         
    </div>               
</div>
<?php } ?>

<script>
var $js = jQuery.noConflict();
$js(document).ready(function() {
    $js('.slide').click(function(){
        $js('.cate').slideUp(300);
        $js('.slide').removeClass('active1');
        $js('.slide').addClass('active2');
       
        $js(this).next().next().slideDown(300);
        $js(this).removeClass('active2');
        $js(this).addClass('active1');
    });
   
});
</script>

Thursday, January 16, 2014

Add Customer group in registration page

If you want to customer can select customer group during registration, then add <group_id><create>1</create></group_id> code into the customer account fieldset.(app\code\core\Mage\Customer\etc\config.xml)

<fieldsets>
<customer_account>
<prefix><create>1</create><update>1</update><name>1</name></prefix>
<firstname><create>1</create><update>1</update><name>1</name></firstname>
<middlename><create>1</create><update>1</update><name>1</name></middlename>
<lastname><create>1</create><update>1</update><name>1</name></lastname>
<suffix><create>1</create><update>1</update><name>1</name></suffix>
<email><create>1</create><update>1</update></email>
<password><create>1</create></password>
<confirmation><create>1</create></confirmation>
<dob><create>1</create><update>1</update></dob>
<taxvat><create>1</create><update>1</update></taxvat>
<group_id><create>1</create></group_id>
</customer_account>
</fieldsets>

Open template/customer/form/register.phtml and add the following code anywhere in the form

<div class="input-box">
<label for="group_id"><?php echo $this->__('Group') ?><span class="required">*</span></label><br/>
<select name="group_id" id="group_id" title="<?php echo $this->__('Group') ?>" class="validate-group required-entry input-text" />
<?php $groups = Mage::helper('customer')->getGroups()->toOptionArray(); ?>
<?php foreach($groups as $group){ ?>
<option value="<?php print $group['value'] ?>"><?php print $group['label'] ?></option>
<?php } ?>
</select>
</div>

Active address field in registration page

It's very easy to active address field in registration page.
Just add an action tag in customer.xml:

<customer_account_create translate="label">
        <
reference name="content">
            <
block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml">
                <
action method="setShowAddressFields"><value>true</value></action>
                <
block type="page/html_wrapper" name="customer.form.register.fields.before" as="form_fields_before" translate="label">
                    <
label>Form Fields Before</label>
                </
block>
            </
block>
        </
reference>
    </
customer_account_create>