Tuesday, April 24, 2012

can not login into magento admin Panel

I have installed magento 1.6.2.After installing fresh magento,I could not login in to admin panel of magento.It is even not throwing any exception message.Although Password and username are correct,I am not able to login in magento admin panel.After providing correct username and password,it only generates a new URL ,something like:


http://localhost/magento/index.php/admin/index/index/key/f1585bj4de664ab83db50940e058a/


Solution:
\magento\app\code\core\Mage\Core\Model\Session\Abstract\Varien.php


change line no 84 to 87


from:
 // session cookie params
        $cookieParams = array(
            'lifetime' => $cookie->getLifetime(),
            'path'     => $cookie->getPath(),
            'domain'   => $cookie->getConfigDomain(),
            'secure'   => $cookie->isSecure(),
            'httponly' => $cookie->getHttponly()
        );
to:
 // session cookie params
        $cookieParams = array(
            'lifetime' => $cookie->getLifetime(),
            'path'     => $cookie->getPath()
            // 'domain'   => $cookie->getConfigDomain(),
            // 'secure'   => $cookie->isSecure(),
            // 'httponly' => $cookie->getHttponly()
        );
Reason:
Magento do not store cookies.We run it on localhost which is actually not a true real domain But to store cookies we generally need a domain.Becasue of that we can not login  and even not getting any exception or error message.

Friday, April 20, 2012

Add Address fields in customer registration

To show all address fields in create account page for customer,you have to comment following lines in:


\magento\app\design\frontend\base\default\template\customer\form\register.phtml


replace line no:77
from:
  <?php if($this->getShowAddressFields()): ?>
to
  <?php / /if($this->getShowAddressFields()): ?>


replace line no:149
from:
  <?php endif; ?>
to
  <?php // endif; ?>


As well,to get the list of states,you need to comment same line in java script too.

\magento\app\design\frontend\base\default\template\customer\form\register.phtml


replace line no:178
from:
  <?php if($this->getShowAddressFields()): ?>
to
  <?php / /if($this->getShowAddressFields()): ?>

replace line no:180
from:
  <?php endif; ?>
to
  <?php // endif; ?>

Now,You can see address fields in,create account form.


If you are still not able to see the address fields in create account form,means you have activate persistent cart.In that case you need to comment the same lines in
\magento\app\design\frontend\base\default\template\persistent\customer\form\register.phtml

Template/Block Hints in Admin Panel

Magento’s admin panel uses the exact same design pattern as the front end ( blocks/layouts/templates).If you have done any modification at admin side and you need to turn on template/block hints for the admin panel,you need to do following steps as there is not built in support from magento.

step 1:
Go to Magento Database

step 2: Turn on

INSERT INTO core_config_data (scope, scope_id, path, value)
VALUES ('default', 0, 'dev/debug/template_hints', 1),
('default', 0, 'dev/debug/template_hints_blocks', 1);

Now,you can check at admin panel for template/block hints.

step 3: Turn off

To turn off hints,delete above record from the table or if you are thinking to turn on it again then simply update its value field from 1 to 0.

Logic behind this is:
 /app/code/core/Mage/Core/Block/Template.php

public function getShowTemplateHints()
{
    if (is_null(self::$_showTemplateHints)) {
        self::$_showTemplateHints = Mage::getStoreConfig('dev/debug/template_hints')
            && Mage::helper('core')->isDevAllowed();
        self::$_showTemplateHintsBlocks = Mage::getStoreConfig('dev/debug/template_hints_blocks')
            && Mage::helper('core')->isDevAllowed();
    }
    return self::$_showTemplateHints;
}


The “Mage::getStoreConfig” method checks for config values that are set in the current scope (ie, default, website, store, store view). In the admin panel, only values set in the “Default Scope” are loaded.

Magento only allows you to turn on hints when you’re in the configuration scope of a Website or Store View. This means that when the code above tries to load the configuration, it returns “null” because that config value isn’t set in the “Default Config” scope. Running the MySQL query above adds the hint config values to the “Default Config” scope. Here is a screenshot showing the settings for turning on the hints – notice that the “Main Website” configuration scope is selected.




Get child categories in Magento

to get all the child categories of the required category id



<?php    

    $category_model = Mage::getModel('catalog/category'); //get category model

    $_category = $category_model->load($categoryid); //$categoryid for which the child categories to be found        

   $all_child_categories = $category_model->getResource()->getAllChildren($_category); //array consisting of all child categories id

?>

Call Custom Model method/function

For example,I have created a custom module UserProfile .
i.e
magento\app\code\local\CustomerProfile\Userprofile

and my model in Userprofile is
magento\app\code\local\CustomerProfile\Userprofile\Model\Customersettings.php

Customersettings.php is as following:


class CustomerProfile_Userprofile_Model_Customersettings extends Mage_Core_Model_Abstract
{

protected function _construct()
{
$this->_init("userprofile/customersettings");
}

function getmessage()
       {
              echo "Hello From Custom model method:";
       }
}


I can call the method of custom model anywhere as following:

Mage::getModel('modulename/modelname')->modelmethod();

i.e.
Mage::getModel('userprofile/customersettings')->getmessage();

Thursday, April 19, 2012

Birth date issue while creating new customer account

when i try to create a new customer account and i enter birth date as 09/30/1987(mm/dd/yyyy) format.it shows me an error message as:"Please enter a valid full date".
To Resolve this error:



I changed line 437 in /js/varien/js.js


from: 
var error = false, day = parseInt(this.day.value) || 0, month = parseInt(this.month.value) || 0, year = parseInt(this.year.value) || 0;


to: 
var error = false, day = parseInt(this.day.value, 10) || 0, month = parseInt(this.month.value, 10) || 0, year = parseInt(this.year.value, 10) || 0;


Now,Customer account created successfully.

Fatal error: Class Zend\Stdlib\Parameters contains 1 abstract method... magento 2

Fatal error: Class Zend\Stdlib\Parameters contains 1 abstract method and must therefore be declared abstract or implement the remaining met...