Search This Blog

Monday 25 February 2013

Loading large collections using walk / callBack

Tuesday 12 February 2013

Magento States list for other countries - Australia, China, Japan, Mexico and United Kingdom

Here are the SQL Queries for states list different countries:

Australia:
INSERT INTO `directory_country_region` VALUES (NULL , "AU", "ACT","Australian Capital Territory"),(NULL , "AU", "NSW","New South Wales"),(NULL , "AU", "NT","Northern Territory"),(NULL , "AU", "QLD","Queensland"),(NULL , "AU", "SA","South Australia"),(NULL , "AU", "TAS","Tasmania"),(NULL , "AU", "VIC","Victoria"),(NULL , "AU", "WA","Western Australia");

INSERT INTO `directory_country_region_name` (`locale` ,`region_id` ,`name` ) SELECT 'en_US', tmp.region_id, tmp.default_name FROM `directory_country_region` AS tmp WHERE tmp.country_id='AU';

China:
INSERT INTO `directory_country_region` VALUES (NULL , "CN", "Heilongjiang Province","Heilongjiang Province"),(NULL , "CN", "Jilin Province","Jilin Province"),(NULL , "CN", "Liaoning Province","Liaoning Province"),(NULL , "CN", "Neimenggu A. R.","Neimenggu A. R."),(NULL , "CN", "Gansu Province","Gansu Province"),(NULL , "CN", "Ningxia A. R.","Ningxia A. R."),(NULL , "CN", "Xinjiang A. R.","Xinjiang A. R."),(NULL , "CN", "Qinghai Province","Qinghai Province"),(NULL , "CN", "Hebei Province","Hebei Province"),(NULL , "CN", "Henan Province","Henan Province"),(NULL , "CN", "Shandong Province","Shandong Province"),(NULL , "CN", "Shanxi Province","Shanxi Province"),(NULL , "CN", "Shaanxi Province","Shaanxi Province"),(NULL , "CN", "Jiangsu Province","Jiangsu Province"),(NULL , "CN", "Zhejiang Province","Zhejiang Province"),(NULL , "CN", "Anhui Province","Anhui Province"),(NULL , "CN", "Hubei  Province","Hubei  Province"),(NULL , "CN", "Hunan Province","Hunan Province"),(NULL , "CN", "Sichuan Province","Sichuan Province"),(NULL , "CN", "Guizhou Province","Guizhou Province"),(NULL , "CN", "Jiangxi  Province","Jiangxi  Province"),(NULL , "CN", "Guangdong Province","Guangdong Province"),(NULL , "CN", "Guangxi A. R.","Guangxi A. R."),(NULL , "CN", "Yunnan Province","Yunnan Province"),(NULL , "CN", "Hainan Province","Hainan Province"),(NULL , "CN", "Xizang A. R.","Xizang A. R."),(NULL , "CN", "Beijing","Beijing"),(NULL , "CN", "Shanghai","Shanghai"),(NULL , "CN", "Tianjin","Tianjin"),(NULL , "CN", "Chongqing","Chongqing"),(NULL , "CN", "Fujian Province","Fujian Province");

INSERT INTO `directory_country_region_name` (`locale` ,`region_id` ,`name` ) SELECT 'en_US', tmp.region_id, tmp.default_name FROM `directory_country_region` AS tmp WHERE tmp.country_id='CN';

Japan:
INSERT INTO `directory_country_region` VALUES (NULL , "JP", "Hokkaido","Hokkaido"),(NULL , "JP", "Aomori","Aomori"),(NULL , "JP", "Iwate","Iwate"),(NULL , "JP", "Miyagi","Miyagi"),(NULL , "JP", "Akita","Akita"),(NULL , "JP", "Yamagata","Yamagata"),(NULL , "JP", "Fukushima","Fukushima"),(NULL , "JP", "Ibaraki","Ibaraki"),(NULL , "JP", "Tochigi","Tochigi"),(NULL , "JP", "Gunma","Gunma"),(NULL , "JP", "Saitama","Saitama"),(NULL , "JP", "Chiba","Chiba"),(NULL , "JP", "Tokyo","Tokyo"),(NULL , "JP", "Kanagawa","Kanagawa"),(NULL , "JP", "Niigata","Niigata"),(NULL , "JP", "Toyama","Toyama"),(NULL , "JP", "Ishikawa","Ishikawa"),(NULL , "JP", "Fukui","Fukui"),(NULL , "JP", "Yamanashi","Yamanashi"),(NULL , "JP", "Nagano","Nagano"),(NULL , "JP", "Gifu","Gifu"),(NULL , "JP", "Shizuoka","Shizuoka"),(NULL , "JP", "Aichi","Aichi"),(NULL , "JP", "Mie","Mie"),(NULL , "JP", "Shiga","Shiga"),(NULL , "JP", "Kyoto","Kyoto"),(NULL , "JP", "Osaka","Osaka"),(NULL , "JP", "Hyogo","Hyogo"),(NULL , "JP", "Nara","Nara"),(NULL , "JP", "Wakayama","Wakayama"),(NULL , "JP", "Tottori","Tottori"),(NULL , "JP", "Shimane","Shimane"),(NULL , "JP", "Okayama","Okayama"),(NULL , "JP", "Hiroshima","Hiroshima"),(NULL , "JP", "Yamaguchi","Yamaguchi"),(NULL , "JP", "Tokushima","Tokushima"),(NULL , "JP", "Kagawa","Kagawa"),(NULL , "JP", "Ehime","Ehime"),(NULL , "JP", "Kochi","Kochi"),(NULL , "JP", "Fukuoka","Fukuoka"),(NULL , "JP", "Saga","Saga"),(NULL , "JP", "Nagasaki","Nagasaki"),(NULL , "JP", "Kumamoto","Kumamoto"),(NULL , "JP", "Oita","Oita"),(NULL , "JP", "Miyazaki","Miyazaki"),(NULL , "JP", "Kagoshima","Kagoshima"),(NULL , "JP", "Okinawa","Okinawa");

INSERT INTO `directory_country_region_name` (`locale` ,`region_id` ,`name` ) SELECT 'en_US', tmp.region_id, tmp.default_name FROM `directory_country_region` AS tmp WHERE tmp.country_id='JP';

Mexico:
INSERT INTO `directory_country_region` VALUES (NULL , "MX", "AGS","Aguascalientes"),(NULL , "MX", "BCN","Baja California Norte"),(NULL , "MX", "BCS","Baja California Sur"),(NULL , "MX", "CAM","Campeche"),(NULL , "MX", "CHIS","Chiapas"),(NULL , "MX", "CHIH","Chihuahua"),(NULL , "MX", "COAH","Coahuila"),(NULL , "MX", "COL","Colima"),(NULL , "MX", "DF","Distrito Federal"),(NULL , "MX", "DGO","Durango"),(NULL , "MX", "GTO","Guanajuato"),(NULL , "MX", "GRO","Guerrero"),(NULL , "MX", "HGO","Hidalgo"),(NULL , "MX", "JAL","Jalisco"),(NULL , "MX", "MICH","Michoacan"),(NULL , "MX", "MOR","Morelos"),(NULL , "MX", "MEX","Mexico (Estado de)"),(NULL , "MX", "NAY","Nayarit"),(NULL , "MX", "NL","Nuevo Leon"),(NULL , "MX", "OAX","Oaxaca"),(NULL , "MX", "PUE","Puebla"),(NULL , "MX", "QRO","Queretaro"),(NULL , "MX", "QROO","Quintana Roo"),(NULL , "MX", "SLP","San Luis Potosi"),(NULL , "MX", "SIN","Sinaloa"),(NULL , "MX", "SON","Sonora"),(NULL , "MX", "TAB","Tabasco"),(NULL , "MX", "TAMPS","Tamaulipas"),(NULL , "MX", "TLAX","Tlaxcala"),(NULL , "MX", "VER","Veracruz"),(NULL , "MX", "YUC","Yucatan"),(NULL , "MX", "ZAC","Zacatecas");

INSERT INTO `directory_country_region_name` (`locale` ,`region_id` ,`name` ) SELECT 'en_US', tmp.region_id, tmp.default_name FROM `directory_country_region` AS tmp WHERE tmp.country_id='MX';

United Kingdom:
INSERT INTO `directory_country_region` VALUES (NULL , "GB", "Aberdeenshire","Aberdeenshire"),(NULL , "GB", "Angus","Angus"),(NULL , "GB", "Argyll","Argyll"),(NULL , "GB", "Avon","Avon"),(NULL , "GB", "Ayrshire","Ayrshire"),(NULL , "GB", "Banffshire","Banffshire"),(NULL , "GB", "Beds.","Bedfordshire"),(NULL , "GB", "Berks.","Berkshire"),(NULL , "GB", "Berwickshire","Berwickshire"),(NULL , "GB", "Bucks.","Buckinghamshire"),(NULL , "GB", "Caithness","Caithness"),(NULL , "GB", "Cambs.","Cambridgeshire"),(NULL , "GB", "Ches.","Cheshire"),(NULL , "GB", "Clackmannanshire","Clackmannanshire"),(NULL , "GB", "Cleveland","Cleveland"),(NULL , "GB", "Clwyd","Clwyd"),(NULL , "GB", "Cornwall","Cornwall"),(NULL , "GB", "Co Antrim","Country Antrim"),(NULL , "GB", "Co Armagh","Country Armagh"),(NULL , "GB", "Co Down","County Down"),(NULL , "GB", "Durham","Country Durham"),(NULL , "GB", "Co Fermanagh","County Fermanagh"),(NULL , "GB", "Co Londonderry","County Londonderry"),(NULL , "GB", "Co Tyrone","County Tyrone"),(NULL , "GB", "Cumbria","Cumbria"),(NULL , "GB", "Derbys.","Derbyshire"),(NULL , "GB", "Devon","Devon"),(NULL , "GB", "Dorset","Dorset"),(NULL , "GB", "Dumfriesshire","Dumfriesshire"),(NULL , "GB", "Dunbartonshire","Dunbartonshire"),(NULL , "GB", "Dyfed","Dyfed"),(NULL , "GB", "E Lothian","East Lothian"),(NULL , "GB", "E Sussex","East Sussex"),(NULL , "GB", "Essex","Essex"),(NULL , "GB", "Fife","Fife"),(NULL , "GB", "Gloucs.","Gloucestershire"),(NULL , "GB", "London","Greater London"),(NULL , "GB", "Gwent","Gwent"),(NULL , "GB", "Gwynedd","Gwynedd"),(NULL , "GB", "Hants.","Hampshire"),(NULL , "GB", "Hereford","Herefordshire"),(NULL , "GB", "Herts.","Hertfordshire"),(NULL , "GB", "Inverness-shire","Inverness-shire"),(NULL , "GB", "Isle of Arran","Isle of Arran"),(NULL , "GB", "Isle of Barra","Isle of Barra"),(NULL , "GB", "Isle of Benbecula","Isle of Benbecula"),(NULL , "GB", "Isle of Bute","Isle of Bute"),(NULL , "GB", "Isle of Canna","Isle of Canna"),(NULL , "GB", "Isle of Coll","Isle of Coll"),(NULL , "GB", "Isle of Colonsay","Isle of Colonsay"),(NULL , "GB", "Isle of Cumbrae","Isle of Cumbrae"),(NULL , "GB", "Isle of Eigg","Isle of Eigg"),(NULL , "GB", "Isle of Gigha","Isle of Gigha"),(NULL , "GB", "Isle of Harris","Isle of Harris"),(NULL , "GB", "Isle of Iona","Isle of Iona"),(NULL , "GB", "Isle of Islay","Isle of Islay"),(NULL , "GB", "Isle of Jura","Isle of Jura"),(NULL , "GB", "Isle of Lewis","Isle of Lewis"),(NULL , "GB", "Isle of Mull","Isle of Mull"),(NULL , "GB", "Isle of North Uist","Isle of North Uist"),(NULL , "GB", "Isle of Rum","Isle of Rum"),(NULL , "GB", "Isle of Scalpay","Isle of Scalpay"),(NULL , "GB", "Isle of Skye","Isle of Skye"),(NULL , "GB", "Isle of South Uist","Isle of South Uist"),(NULL , "GB", "Isle of Tiree","Isle of Tiree"),(NULL , "GB", "Isle of Wight","Isle of Wight"),(NULL , "GB", "Kent","Kent"),(NULL , "GB", "Kincardineshire","Kincardineshire"),(NULL , "GB", "Kinross-shire","Kinross-shire"),(NULL , "GB", "Kirkcudbrightshire","Kirkcudbrightshire"),(NULL , "GB", "Lancarkshire","Lancarkshire"),(NULL , "GB", "Lancs.","Lancashire"),(NULL , "GB", "Leics.","Leicestershire"),(NULL , "GB", "Lincs.","Lincolnshire"),(NULL , "GB", "Merseyside","Merseyside"),(NULL , "GB", "M Glam","Mid Glamorgan"),(NULL , "GB", "Mid Lothian","Mid Lothian"),(NULL , "GB", "Middx.","Middlesex"),(NULL , "GB", "Morayshire","Morayshire"),(NULL , "GB", "Nairnshire","Nairnshire"),(NULL , "GB", "Norfolk","Norfolk"),(NULL , "GB", "N Humberside","North Humberside"),(NULL , "GB", "N Yorkshire","North Yorkshire"),(NULL , "GB", "Northants.","Northamptonshire"),(NULL , "GB", "Northumberland","Northumberland"),(NULL , "GB", "Notts.","Nottinghamshire"),(NULL , "GB", "Oxon.","Oxfordshire"),(NULL , "GB", "Peeblesshire","Peeblesshire"),(NULL , "GB", "Perthshire","Perthshire"),(NULL , "GB", "Powys","Powys"),(NULL , "GB", "Renfrewshire","Renfrewshire"),(NULL , "GB", "Ross-shire","Ross-shire"),(NULL , "GB", "Roxburghshire","Roxburghshire"),(NULL , "GB", "Selkirkshire","Selkirkshire"),(NULL , "GB", "Shrops","Shropshire"),(NULL , "GB", "Somt.","Somerset"),(NULL , "GB", "S Glam","South Glamorgan"),(NULL , "GB", "S Humberside","South Humberside"),(NULL , "GB", "S Yorkshire","South Yorkshire"),(NULL , "GB", "Staffs.","Staffordshire"),(NULL , "GB", "Stirlingshire","Stirlingshire"),(NULL , "GB", "Suffolk","Suffolk"),(NULL , "GB", "Surrey","Surrey"),(NULL , "GB", "Sutherland","Sutherland"),(NULL , "GB", "Tyne & Wear","Tyne and Wear"),(NULL , "GB", "Warks","Warwickshire"),(NULL , "GB", "W Glam","West Glamorgan"),(NULL , "GB", "W Lothian","West Lothian"),(NULL , "GB", "W Midlands","West Midlands"),(NULL , "GB", "W Sussex","West Sussex"),(NULL , "GB", "W Yorkshire","West Yorkshire"),(NULL , "GB", "Wigtownshire","Wigtownshire"),(NULL , "GB", "Wilts","Wiltshire"),(NULL , "GB", "Worcs","Worcestershire");

INSERT INTO `directory_country_region_name` (`locale` ,`region_id` ,`name` ) SELECT 'en_US', tmp.region_id, tmp.default_name FROM `directory_country_region` AS tmp WHERE tmp.country_id='GB';

Note: You might need to change the table name if you have any table prefix in your Magento installation.

Wednesday 6 February 2013

Tuesday 5 February 2013

Ultimate Module Creator


Because I was always stuck on doing the same thing over and over again, each time I needed to create a module, I've decided to create a module that does the work for me. 
I know that there are some module creators out there, but an other one doesn't hurt.
You can find the "Ultimate ModuleCreator" on github. https://github.com/tzyganu/moduleCreator

It is also available on the Magento connect:
http://www.magentocommerce.com/magento-connect/catalog/product/view/id/15449/s/ultimate-modulecreator-8949/
The module creator was built on Magento CE 1.7. It works on Magento CE 1.6+.
The extensions you create with it work on Magento CE 1.6+. They will probably work on equivalent PE and EE, but I didn't test.
After you install the module creator you will find it under the System menu.


http://marius-strajeru.blogspot.in/p/ultimate-module-creator.html

Magento Configurable Products - Setting Default Value for Options

Add the javascript hack at the bottom into template\catalog\product\view\type\options\configurable.phtml and automatically load the first option. copy below code under the var spConfig line:

function fireEvent(element,event)
{
if (document.createEventObject)
{
// dispatch for IE
var evt = document.createEventObject();
return element.fireEvent('on'+event,evt);
}
else
{
// dispatch for firefox + others
var evt = document.createEvent("HTMLEvents");
evt.initEvent(event, true, true );
return !element.dispatchEvent(evt);
}
}

function setDefaultConfigOptions()
{
if (spConfigIndex >= spConfig.settings.length)
{
return; // stop
}

spConfig.settings[spConfigIndex].selectedIndex = 1;
var obj = spConfig.settings[spConfigIndex];

++spConfigIndex;

Event.observe(obj,'change',function(){});
fireEvent(obj,'change');

window.setTimeout("setDefaultConfigOptions()", 1); // Add a small delay before moving onto the next option
}

var spConfigIndex = 0;
Event.observe(window, 'load', function() {
setDefaultConfigOptions();
}); 

Source: http://icebergcommerce.com/software/blog/iss/article/magento-configurable-products-setting-default-value-for-options

Monday 4 February 2013

Configurable product modification in Magento

In this article, I’ll give you extension that will change drop down selection (select field) to radio buttons on configurable products in Magento Community edition.

Well, what I had to do is rewrite Mage_Catalog_Block_Product_View_Type_Configurable block, and create a custom phtml file (configurable.phtml) with some custom validation on it.
Everything I just told you equals to this config.xml:
<?xml version="1.0"?>
<config>
    <modules>
        <Inchoo_Configurable>
            <version>0.1.1</version>
        </Inchoo_Configurable>
    </modules>
    <global>
        <models>
            <configurable>
                <class>Inchoo_Configurable_Model</class>
            </configurable>
        </models>
        <blocks>
            <configurable>
                <class>Inchoo_Configurable_Block</class>
            </configurable>
            <catalog>
                <rewrite>
                    <product_view_type_configurable>Inchoo_Configurable_Block_Frontend_Configurable</product_view_type_configurable>
                </rewrite>
            </catalog>
        </blocks>
    </global>
    <frontend>
        <layout>
            <updates>
                <configurable module="Inchoo_Configurable">
                    <file>configurable.xml</file>
                </configurable>
            </updates>
        </layout>
    </frontend>
</config>
And block rewrite consisted of addition of new method “getRegularConfig” that corresponds to “getJsonConfig”, except it doesn’t return Json encoded data.
And custom template packed in attached zip file is located under “test” theme folder. For installation you need to extract both layout (configurable.xml) and phtml (configurable.phtml) files.
Notice: keep folder structure for phtml file in your theme

And finally, you can download it here.

 Source: http://inchoo.net/ecommerce/magento/configurable-product-modification-in-magento/

Adding magento attribute with custom input renderer


This is example which will explain you, how to add new attribute with custom input render. You will be able to modify existing functionality, add javascript, some other option or change default input renderer by your wishes.

You probably will ask yourself, what is magento input renderer and I will explain. This is Magento php class which is in charge for “rendering” html form elements. In magento there are different classes for rendering, you can find them in next folder: /lib/Varien/Data/Form/Element. In this folder you will notice next classes for rendering: price, date, image and so on.
Let’s go with our example.
First of all, you should create magento setup file which will add new product attribute with custom frontend input render, example is below:
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'example_field', array(
    'group'             => 'General',
    'type'              => 'text',
    'backend'           => '',
    'input_renderer'    => 'test/catalog_product_helper_form_example',//definition of renderer
    'label'             => 'Example field',
    'class'             => '',
    'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE,
    'visible'           => true,
    'required'          => false,
    'user_defined'      => true,
    'searchable'        => false,
    'filterable'        => false,
    'comparable'        => false,
    'visible_on_front'  => false,
    'unique'            => false,
    'apply_to'          => 'simple,configurable,bundle,grouped',
    'is_configurable'   => false,
));
$installer->endSetup();
You can see that we are adding attribute with method “addAttribute”, variable “$installer” is instance of “Mage_Catalog_Model_Resource_Setup”, and frontend input rendere is defined in array ‘input_renderer’ => ‘test/catalog_product_helper_form_example’
Next step, you have to create your own input renderer. My example of renderer class (Inchoo_Test_Block_Catalog_Product_Helper_Form_Price) is below, this is very simple class, only for demonstration purpose.
<?php
class Inchoo_Test_Block_Catalog_Product_Helper_Form_Example extends Varien_Data_Form_Element_Text
{
    public function getAfterElementHtml()
    {
        $html = parent::getAfterElementHtml();
        return $html."  <script>
                        $('".$this->getHtmlId()."').disable();
                        </script>";
    }
}
In my example you can see that I added javascript code which disable input element, admin user can’t edit this field.
http://inchoo.net/ecommerce/magento/adding-magento-attribute-with-custom-input-renderer/