Monthly Archives: March 2012

Magento Mass deletion of Coupon and Mass activation of Date

For deleting or changing the “from” and “to” date of the coupon each time we have to go into each coupon and then we have to delete it or change the date Below functionality will help to do the mass deletion of the coupon and changes t he date also For that we have to copy the app/code/core/Mage/Adminhtml/Block/Promo/Quote/Grid.php into app/code/local/Mage/Adminhtml/Block/Promo/Quote/grid.php and following functions

protected function _prepareMassaction()
{
$dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
$this->setMassactionIdField(‘rule_id’);
$this->getMassactionBlock()->setFormFieldName(‘rule’);
$this->getMassactionBlock()->addItem(‘delete’, array(
‘label’ => Mage::helper(‘rule’)->__(‘Delete’),
‘url’ => $this->getUrl(‘*/*/massDelete’),
‘confirm’ => Mage::helper(‘rule’)->__(‘Are you sure?’)
));
array_unshift($da, array(‘label’=>”, ‘value’=>”));

$this->getMassactionBlock()->addItem(‘date’, array(
‘label’=> Mage::helper(‘salesrule’)->__(‘Change Date’),
‘url’ => $this->getUrl(‘*/*/massDate’, array(‘_current’=>true)),
‘additional’ => array(
‘visibility’ => array(
‘name’ => ‘from_date’,
‘type’ => ‘date’,
‘class’ => ‘required-entry date’,
‘image’ => $this->getSkinUrl(‘images/grid-cal.gif’),
‘format’ => $dateFormatIso,
‘index’ => ‘from_date’,
‘label’ => Mage::helper(‘rule’)->__(‘From Date’)
),
array(
‘name’ => ‘to_date’,
‘type’ => ‘date’,
‘class’ => ‘required-entry date’,
‘format’ => $dateFormatIso,
‘index’ => ‘to_date’,
‘image’ => $this->getSkinUrl(‘images/grid-cal.gif’),
‘label’ => Mage::helper(‘rule’)->__(‘To Date’),
//’values’ => $date
)
)
));
return $this;
}

Clear the Cache from admin Hope this will help

Magento show subcategory instead of Products in grid/list Page

Magneto Have default functionality of showing the Products in list view or Grid view
But some time we require to show the Sub catgeory in list page and if that sub categroy have another subcategory
For showing that we need to work on following
1) Copy the Category.php file from Mage/Catalog/Model/Resource core to local.Create directories required under app/code/local/age/Catalog/Model/Resource.
2) Add –
addAttrbuteToSelect(‘image’) to getChildrenCategories

public function getChildrenCategories($category)
{
    $collection = $category->getCollection();
/* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
$collection->addAttributeToSelect('url_key')->addAttributeToSelect('name')->addAttributeToSelect('image')
    ->addAttributeToSelect('all_children')->addAttributeToSelect('is_anchor')->addAttributeToFilter('is_active', 1)->addIdFilter($category->getChildren())->setOrder('position', 'ASC')->joinUrlRewrite()->load();
         return $collection;
           }

3) Add or modify the category view template app/design/frontend/yourdiractory_path/default/template/catalog/category/view.phtml:

getCurrentCategory();
$collection = Mage::getModel('catalog/category')->getCategories($_category->entity_id);
$rootcat = $_category->entity_id;
$cat = Mage::getModel('catalog/category')->load($rootcat);
$child = $cat->getChildren();

    $helper = Mage::helper('catalog/category');
    $_helper = $this->helper('catalog/output');
    
categoryAttribute($_category, $_category->getName(), 'name') ?>
getIsActive()):?> load($cat->getId());?>
getProductListHtml() ?>

that’s it refresh the cache Sub Categroy will show instead of Products

Magento Config.xml

However all the files are merged together during the parsing process.It will help to understand the XML structure. It is the reason that the module name is repeated as an XML element name (represented below as <(modulename)>) several times through every file – this is necessary to segregate configuration for each module. Without these elements, the configuration in these sections would be overwritten by the configuration files in other modules.so let us understand the XMl and its ELements ans tructure

Every Config.xml has following elements

modules global admin adminhtml install frontend default stores websites

The XML sub-structure of each element is described separately below.
1)Modules

<(NameSpace_ModuleName)>
[true|false]
[core|community|local]

<(AnotherNameSpace_ModuleName) />

(version_number)

active codePool depends version

2) Global

<global>

<models>

<(modulename)>

<class>(ClassName_Prefix)</class>

<resourceModel>(modulename)_(resource_model_type)</resourceModel>

<(modulename)_(resource_model_type)>

<!– definition –>

</(modulename)_(resource_model_type)>

<rewrite><!– definition –></rewrite>

</(modulename)>

</models>

<resources>

<(modulename)_setup><!– definition –></(modulename)_setup>

<(modulename)_read><!– definition –></(modulename)_read>

<(modulename)_write><!– definition –></(modulename)_write>

</resources>

<blocks>

<(modulename)>

<class>(ClassName_Prefix)</class>

</(modulename)>

</blocks>

<helpers>

<(modulename)>

<class>(ClassName_Prefix)</class>

</(modulename)>

</helpers>

<fieldsets>

<(page_handle?)>

<(field_name)>?</(field_name)>

</(page_handle?)>

</fieldsets>

<template>

<email>

<(email_template_name)

module=”(modulename)”

translate=”[label][,description]”

>

<!– definition –>

<(/email_template_name)>

</email>

</template>

<events>

<(event_name)>

<observers><!– observers –></observers>

</(event_name)>

</events>

<eav_attributes><!– definition –></eav_attributes>

<(modulename)><!– custom config variables –></(modulename)>

</global>

 

models resources blocks helpers fieldsets template events eav_attributes

 

3)admin

<admin>

        <attributes>

            <(attribute_name) />

        <attributes>

        <fieldsets><!– definition –></fieldsets>

        <routers>

            <(modulename)>

                <use>[standard|admin|default]</use>

                <args>

                    <module>(NameSpace_ModuleName)</module>

                    <frontName>(frontname)</frontName>

                </args>

            </(modulename)>

            <!– or –>

            <(modulename)>

                <args>

                    <modules>

                        <(NameSpace_ModuleName)

                            before=”(AnotherNameSpace_ModuleName)”

                            >

                            (New_ClassName)

                        <(NameSpace_ModuleName)

                </args>

            </(modulename)>

        </routers>

    </admin>

 

attributes fieldsets routers

 

4)adminhtml

 <adminhtml>

        <events>

            <(event_name)>

                <observers><!– observers –></observers>

            </(event_name)>

        </events>

        <global_search>

            <products>

                <class>(modulename)/search_catalog</class>

                <acl>catalog</acl>

            </products>

            <customers>

                <class>adminhtml/search_customer</class>

                <acl>customer</acl>

            </customers>

            <sales>

                <class>adminhtml/search_order</class>

                <acl>sales</acl>

            </sales>

        </global_search>

        <translate>

            <modules>

                <(NameSpace_ModuleName)>

                    <files>

                        <default>(name_of_translation_file.csv)</default>

                    </files>

                </(NameSpace_ModuleName)>

            </modules>

        </translate>

        <layout>

            <updates>

                <(modulename)>

                    <file>(name_of_layout_file.xml)</file>

                </(modulename)>

            </updates>

        </layout>

        <(modulename)><!– custom config variables –></(modulename)>

    </adminhtml>

 

events global_search translate layout

 

5)Frontend

<frontend>

        <secure_url>

            <(page_handle)>/relative/url</page_handle>

        </secure_url>

        <events>

            <(event_name)>

                <observers><!– observers –></observers>

            </(event_name)>

        </events>

        <routers>

            <(modulename)>

                <use>[standard|admin|default]</use>

                <args>

                    <module>(NameSpace_ModuleName)</module>

                    <frontName>(frontname)</frontName>

                </args>

            </(modulename)>

        </routers>

        <translate>

            <modules>

                <(NameSpace_ModuleName)>

                    <files>

                        <default>(name_of_translation_file.csv)</default>

                    </files>

                </(NameSpace_ModuleName)>

            </modules>

        </translate>

        <layout>

            <updates>

                <(modulename)>

                    <file>(name_of_layout_file.xml)</

                </(modulename)>

            </updates>

        </layout>

    </frontend>

 

secure_url events routers translate layout

 

 

 

Magento Add New field in Customer Admin

Adding an Attribute in Product quite simple we can add through admin but adding a field(attribute) in customer cannot be achieved through admin so here is the simple solution for adding the attribute in Category through Database.Open the phpmyadmin.Here we need to work on three tables.

First query for the eav_attribute table
Insert into eav_attribute
`attribute_id` = ”,
`entity_type_id` = 1,
`attribute_code` = ‘new_attribute_code’,
`attribute_model` = NULL,
`backend_model` = ”,
`backend_type` = ‘text’,
`backend_table` = ”,
`frontend_model` = ”,
`frontend_input` = ‘text’,
`frontend_label` = ‘New Attribute Name’,
`frontend_class` = NULL,
`source_model` = ”,
`is_required` = 0,
`is_user_defined` = 0,
`default_value` = ”,
`is_unique` = 0,
`note` = ”

After insert this query it will generate attribute id that attribute id we will be using for our next query
for Us it had generated 963 so we are using that in our query

We need to run the Query in the following table “customer_form_attribute” as my attribute id = 963

Second Query for customer_form_attribute
INSERT INTO `customer_form_attribute` (`form_code`, `attribute_id`) VALUES (‘adminhtml_customer’, ‘963’);
INSERT INTO `customer_form_attribute` (`form_code`, `attribute_id`) VALUES (‘customer_account_create’, ‘963’);
INSERT INTO `customer_form_attribute` (`form_code`, `attribute_id`) VALUES (‘customer_account_edit’, ‘963’);
INSERT INTO `customer_form_attribute` (`form_code`, `attribute_id`) VALUES (‘adminhtml_customer_address’, ‘963’);

and thus clear the cache manually and from admin your new feild be added in the admin for customer 

Magento How to call a phtml file in magento cms page

You can’t call a phtml file by writing php code in Magento admin panel as Magento admin panel doesn’t support this.To call a PHTML write the folllowing code in the page which you have created under CMS

{{block type="core/template" name="a-name" template="yourfoldernmae/yourfilename.phtml"}}

Code explaination 

template=”” you can write your file path.

name=””  you can give proper and unique name

type=””  you can write your module directory also  or {{block type=”core/template” ….}}

 

(e.g:- catalog/product if you are calling list.phtml file) OR

 

One more way to call a phtml file. You can use your layout or xml file to do.

 

For example we are going to attached yourfilename.phtml file which reside in yourfoldernmae folder

app->design->frontend->yourtheme->youfolder->yourfile

<reference name="content">
<block type="core/template" name="a-name" template="yourfoldernmae/yourfilename.phtml"/>
</reference>

Hope this will help you!

Magento install step by step

Easy way to install magento on local machine with XAMPP or WAMP server

1) Go to Magento and download a latest copy of this software here.
Extract the folder to C:Xampphtdocs or C:wampwww (if you install them in default mode).
Download a sample data and extract them to your folder from magento site

2) Go to http://localhost/phpmyadmin
Create a new database
Import a sql file that you just extracted from the sample file into this database from magento

3) Some setting need in php.ini and find the line
max_execution_time = 30
Change it to:
max_execution_time = 180

extension=php_mcrypt.dll
extension=php_curl.dll
extension=php_pdo_mysql.dll
extension=php_pdo.dll

Following extension sholud be active  Meaning, that you just need to remove the “;” (semi-colon) character out from in front of it
and also  Enable URL rewrites:

You can do this by remove the “#” hash character in front of the following line:
LoadModule rewrite_module modules/mod_rewrite.so

4) Now Magento Installation Wizard will start if you have set up all the things cprrectly in your broser. Open up the lcalhost url with folder in which you have addded the magento in your browser, and if you did all the above setup correctly, you’ll see the first part of the Magento installation screen:

5)Go next as per the following as per the screen shots

6) Make sure enter the Db name 
Enter the base url if we have valid url if we don’t have and as we are installing on localhost so need to do some more step go, While installation it may ask that url is not valid so you need to open the js folder under root folder of magento i.e  js\prototype\validation.js search for the validate-url and comment that line and then refresh the Browser where magento had asked for valid url and then proceed after completion of the installation un comment the line  
7)This part will take more time to exceute as it will loaded all the remaning table and setting up the enviornment 
 Feel free to login to the backend to start setting things up.

Magento Template Hints

While Working on Magento Some time we can’t able to find the template files of particular module so by default magento had provide the feature to Debug  that and that can be seen in Front EndWhen you work with Magento, you will sooner or later as a developer can not avoid the Template Hints. The template hints can be found under the Admin

System> Configuration> Developer> Debug> Template Path Hints

Make it yes for all three or you make for Template links so screen will look like this and you can easily figure out the module name with template file

Template links shown in frontend

Magento Add “is in stock” column in Products Grid

Adding the “Availability” in the column Catalog product gird
Here how to add new column to manage “in stock” and “out of stock” products
Edit this file:
app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php
and add in local folder 
app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php

For Magento 1.3
Search the following code

$collection = Mage::getModel('catalog/product')->getCollection()

            ->addAttributeToSelect('sku')

            ->addAttributeToSelect('name')

            ->addAttributeToSelect('attribute_set_id')

            ->addAttributeToSelect('type_id')

            ->joinField('qty',

                'cataloginventory/stock_item',

                'qty',

                'product_id=entity_id',

                '{{table}}.stock_id=1',

                'left');

Replace with

$collection = Mage::getModel('catalog/product')->getCollection()

            ->addAttributeToSelect('sku')

            ->addAttributeToSelect('name')

            ->addAttributeToSelect('attribute_set_id')

            ->addAttributeToSelect('type_id')

            ->joinField('qty',

                'cataloginventory/stock_item',

                'qty',

                'product_id=entity_id',

                '{{table}}.stock_id=1',

                'left')->joinTable( 'cataloginventory/stock_item', 'product_id=entity_id', array("stock_status" => "is_in_stock") )

            ->addAttributeToSelect('stock_status');

For Magento 1.5 and above
Search the following code

$collection->joinField( 'qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left' );

Replace with

$collection->joinField( 'qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left' )

   ->joinTable( 'cataloginventory/stock_item', 'product_id=entity_id', array("stock_status" => "is_in_stock") )->addAttributeToSelect('stock_status');

Here we have used the join with the cataloginventory/stock_item table to show the availibality in grid with status
For any versions
Find “protected function _prepareColumns()”
here we have our columns….just add the following one where you like between other two columns:

$this->addColumn('stock_status',

            array(

                'header'=> 'Availability',

                'width' => '60px',             //this is the column width

                'index' => 'stock_status',

                'type'  => 'options',

                'options' => array('0'=>'In stock','1'=>'Out of stock'),

        ));

and you will get the Availability in grid……..Hope this will help!