Tuesday 23 April 2013

Add first/last name in newsletter module Magento

 >> First add two fields ( subscriber_firstname, subscriber_lastname) in newsletter_subscriber table and app\design\frontend\THEME\default\template\newsletter\subscribe.phtml.

    >> Now edit this page : app\code\core\Mage\Newsletter\controllers\SubscriberController.php

        Here you'll find "public function newAction()"
            Paste the below code after this following code:
            $status = Mage::getModel('newsletter/subscriber')->subscribe($email);    //line (63)

     ///////////////////////// First Name //////////////////////////////

            if ($this->getRequest()->getPost('subscriber_firstname'))
                {
                     $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
                     $name     = (string) $this->getRequest()->getPost('subscriber_firstname');
                     $subscriber->setSubscriberFirstname($name);
                     $subscriber->save();
                }

     //////////////////////  END  ///////////////////////////////////////

            Do same for field Last Name....

    >> The above code will effect your frontend. If you want to see the information from Admin too, you have to implement a little bit.

    Go to this link : app\code\core\Mage\Adminhtml\Block\Newsletter\Subscriber\grid.php
    Add this code :

    //It will show the information to the admin on News Letter Subscriber Section.
    $this->addColumn('subscriber_firstname', array(
            'header'    => Mage::helper('newsletter')->__('Subscriber First Name'),
            'index'     => 'subscriber_firstname',
            'default'   =>    '----'
        )); 

   

                                        ***********         Good Luck        **********

On click text remove

onclick="if(value=='Last name') value = ''" onblur="if(value=='') value = 'Last name'"

Generating a random password in php


   function rand_string( $length ) {
                   
                        $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                        return substr(str_shuffle($chars),0,$length);
                   
                    }
echo rand_string(7);

Thursday 4 April 2013

Magento get category level


<?php
// get category level, assuming that you have known category object, $_category
echo $categoryLevel = $_category->getLevel();

?>

Wednesday 3 April 2013

How to Change the Order Increment ID and Prefix in Magento

http://www.warpconduit.net/2012/04/18/how-to-change-the-order-increment-id-and-prefix-in-magento/



UPDATE eav_entity_store
INNER JOIN eav_entity_type ON eav_entity_type.entity_type_id = eav_entity_store.entity_type_id
SET eav_entity_store.increment_last_id='XXXXXXXXXX'
WHERE eav_entity_type.entity_type_code='order' AND eav_entity_store.store_id = 'Y';

Monday 1 April 2013

category thumbnail images


<?php  $imageUrl = Mage::getBaseUrl('media')
                . 'catalog/category/'
                . $_subcat->getData('thumbnail');?>