Here is a big array of all USA states and their magento Id.
[php]
$rionnarr = array("Alabama"=>1,"Alaska"=>2,"American Samoa"=>3,"Arizona"=>4,"Arkansas"=>5,"Armed Forces Africa"=>6,"Armed Forces Americas"=>7,"Armed Forces Canada"=>8,"Armed Forces Europe"=>9,"Armed Forces Middle East"=>10,"Armed Forces Pacific"=>11,"California"=>12,"Colorado"=>13,"Connecticut"=>14,"Delaware"=>15,"District of Columbia"=>16,"Federated States Of Micronesia"=>17,"Florida"=>18,"Georgia"=>19,"Guam"=>20,"Hawaii"=>21,"Idaho"=>22,"Illinois"=>23,"Indiana"=>24,"Iowa"=>25,"Kansas"=>26,"Kentucky"=>27,"Louisiana"=>28,"Maine"=>29,"Marshall Islands"=>30,"Maryland"=>31,"Massachusetts"=>32,"Michigan"=>33,"Minnesota"=>34,"Mississippi"=>35,"Missouri"=>36,"Montana"=>37,"Nebraska"=>38,"Nevada"=>39,"New Hampshire"=>40,"New Jersey"=>41,"New Mexico"=>42,"New York"=>43,"North Carolina"=>44,"North Dakota"=>45,"Northern Mariana Islands"=>46,"Ohio"=>47,"Oklahoma"=>48,"Oregon"=>49,"Palau"=>50,"Pennsylvania"=>51,"Puerto Rico"=>52,"Rhode Island"=>53,"South Carolin"=>54,"South Dakota"=>55,"Tennessee"=>56,"Texas"=>57,"Utah"=>58,"Vermont"=>59,"Virgin Islands"=>60,"Virginia"=>61,"Washington"=>62,"West Virginia"=>63,"Wisconsin"=>64,"Wyoming"=>65);
[/php]
Friday, March 29, 2013
Magento : Usefull Region/ID array
Wednesday, March 27, 2013
Magento: Difference between Mage::getSingleton() and Mage::getModel()
You may be in thinking sometime what is the difference between magento getSingleton and getModel method so here is a explanation of the difference
The Mage::getModel('module/model') create a instance of model object each time method is got called this approach is resource consuming require separate memory for each object instance.
[php] Mage::getModel('catalog/product'), it will create new instance of the object product each time. [/php]
[php]
e.g.
$obj1 = Mage::getModel('catalog/product');
$obj2 = Mage::getModel('catalog/product');
Then $obj1 is a one instance of product and $obj is another instance of product.
[/php]
While Mage::getSingleton('catalog/product') will create reference of an existing object if any reference is not exists then this method will create an instance using Mage::getModel() and returns reference to it.
So, if
$obj1 = Mage::getSingleton('catalog/product');
$obj2 = Mage::getSingleton('catalog/product');
Then $obj1 and $obj2 both refer to the same instance of product.
The Mage::getModel('module/model') create a instance of model object each time method is got called this approach is resource consuming require separate memory for each object instance.
[php] Mage::getModel('catalog/product'), it will create new instance of the object product each time. [/php]
[php]
e.g.
$obj1 = Mage::getModel('catalog/product');
$obj2 = Mage::getModel('catalog/product');
Then $obj1 is a one instance of product and $obj is another instance of product.
[/php]
While Mage::getSingleton('catalog/product') will create reference of an existing object if any reference is not exists then this method will create an instance using Mage::getModel() and returns reference to it.
So, if
$obj1 = Mage::getSingleton('catalog/product');
$obj2 = Mage::getSingleton('catalog/product');
Then $obj1 and $obj2 both refer to the same instance of product.
Magento : Solution for SQL Integrity constraint violation
I was working on client project with a special requirement which says product prices should update daily but after some time i have started getting this error in magento admin while trying to add new products
[php]
QLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`irciycom_magento/weee_discount`, CONSTRAINT `FK_CATALOG_PRODUCT_ENTITY_WEEE_DISCOUNT_PRODUCT_ENTITY` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASC).
[/php]
The solution to problem is open the file Url.php located at app/code/core/Mage/Catalog/Model/Resource and edit the function public function getProductModel() located at around line 113
[php]
public function getProductModel()
{
return Mage::getSingleton('catalog/product');
}
[/php]
to
[php]
public function getProductModel()
{
return Mage::getModel('catalog/product');
}
[/php]
And that's it, solved the error gone.
Alternatively if you don't want to edit the core files just follow this steps
1. Create these folders under the app/code/local , Mage/Catalog/Model/Resource
2. Copy the file Url.php from core to Resource folder and do the changes to Url.php and save it
3. You are done won battle with magento.
You could be in thinking what does getSingleton and getModel do. so you need to read this post.
Enjoy :-)
[php]
QLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`irciycom_magento/weee_discount`, CONSTRAINT `FK_CATALOG_PRODUCT_ENTITY_WEEE_DISCOUNT_PRODUCT_ENTITY` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASC).
[/php]
The solution to problem is open the file Url.php located at app/code/core/Mage/Catalog/Model/Resource and edit the function public function getProductModel() located at around line 113
[php]
public function getProductModel()
{
return Mage::getSingleton('catalog/product');
}
[/php]
to
[php]
public function getProductModel()
{
return Mage::getModel('catalog/product');
}
[/php]
And that's it, solved the error gone.
Alternatively if you don't want to edit the core files just follow this steps
1. Create these folders under the app/code/local , Mage/Catalog/Model/Resource
2. Copy the file Url.php from core to Resource folder and do the changes to Url.php and save it
3. You are done won battle with magento.
You could be in thinking what does getSingleton and getModel do. so you need to read this post.
Enjoy :-)
Saturday, March 23, 2013
Magento : Godady hosting installation error "No input file specified".
I was working on a project and i need to work on godady hosting after uploading all the magento files to godady folder i have access the site for installation but got this message No input file specified. which i have't heard before, it was completely new for me so i tried finding it on google and found some useful links here i am sharing my experience that helped me.
1. Edit the .htaccess file and add this
[php]
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^.+.php$ /bogusfile
[/php]
Access your site if this still doesn't work try out the second solution
2. If your have magento on root add this to your .htaccess
[php]RewriteBase /[/php]
Or have it other folder add this
[php]RewriteBase /youfolder/[/php]
3. Try accessing your site if still no luck with this try renaming the php.ini file to php5.ini , you will find this under your root directory.
4. If all the three steps did't worked try adding this line to your php5.ini you don't find your php.ini or php5.ini you can create and add this line
[php]cgi.fix_pathinfo = 1[/php]
5. And if you are getting the error try add the below line to very top your magento .htaccess
[php]Options -MultiViews[/php]
Keep your changes wait for about 30 min to 1 hrs
The above tricks worked for me but you if it did't worked for you then its your bad luck with hosting and you should contact the support immediately .
Thanks.
1. Edit the .htaccess file and add this
[php]
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^.+.php$ /bogusfile
[/php]
Access your site if this still doesn't work try out the second solution
2. If your have magento on root add this to your .htaccess
[php]RewriteBase /[/php]
Or have it other folder add this
[php]RewriteBase /youfolder/[/php]
3. Try accessing your site if still no luck with this try renaming the php.ini file to php5.ini , you will find this under your root directory.
4. If all the three steps did't worked try adding this line to your php5.ini you don't find your php.ini or php5.ini you can create and add this line
[php]cgi.fix_pathinfo = 1[/php]
5. And if you are getting the error try add the below line to very top your magento .htaccess
[php]Options -MultiViews[/php]
Keep your changes wait for about 30 min to 1 hrs
The above tricks worked for me but you if it did't worked for you then its your bad luck with hosting and you should contact the support immediately .
Thanks.
Wednesday, March 20, 2013
Magento : Error while adding a shopping cart price rule
While developing a project i have ran into a weird situation and this sucks me for complete two days, the problem was when i got to admin click shopping cart price rules under promotions and add new rule Or edit the previously created rule an error comes and the reports was saying ....
[php]
Wrong tab configuration
Mage_Adminhtml_Block_Widget_Tabs->addTab('coupons_section', 'promo_quote_edi...')
[/php]
and found this solution to the problem ,
1) create a file Coupons.php at this path
[php]app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab[/php]
2) Put all the code given below in Coupons.php
[php]
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to hide@address.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Mage
* @package Mage_Adminhtml
* @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
* "Manage Coupons Codes" Tab
*
* @category Mage
* @package Mage_Adminhtml
* @author Magento Core Team <hide@address.com>
*/
class Mage_Adminhtml_Block_Promo_Quote_Edit_Tab_Coupons
extends Mage_Adminhtml_Block_Text_List
implements Mage_Adminhtml_Block_Widget_Tab_Interface
{
/**
* Prepare content for tab
*
* @return string
*/
public function getTabLabel()
{
return Mage::helper('salesrule')->__('Manage Coupons Codes');
}
/**
* Prepare title for tab
*
* @return string
*/
public function getTabTitle()
{
return Mage::helper('salesrule')->__('Manage Coupons Codes');
}
/**
* Returns status flag about this tab can be shown or not
*
* @return bool
*/
public function canShowTab()
{
return $this->_isEditing();
}
/**
* Returns status flag about this tab hidden or not
*
* @return bool
*/
public function isHidden()
{
return !$this->_isEditing();
}
/**
* Check whether we edit existing rule or adding new one
*
* @return bool
*/
protected function _isEditing()
{
$priceRule = Mage::registry('current_promo_quote_rule');
return !is_null($priceRule->getRuleId());
}
}
[/php]
3) And refresh
This solved my error i was on magento version 1.6.2
Happy coding :-)
[php]
Wrong tab configuration
Mage_Adminhtml_Block_Widget_Tabs->addTab('coupons_section', 'promo_quote_edi...')
[/php]
and found this solution to the problem ,
1) create a file Coupons.php at this path
[php]app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab[/php]
2) Put all the code given below in Coupons.php
[php]
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to hide@address.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Mage
* @package Mage_Adminhtml
* @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
* "Manage Coupons Codes" Tab
*
* @category Mage
* @package Mage_Adminhtml
* @author Magento Core Team <hide@address.com>
*/
class Mage_Adminhtml_Block_Promo_Quote_Edit_Tab_Coupons
extends Mage_Adminhtml_Block_Text_List
implements Mage_Adminhtml_Block_Widget_Tab_Interface
{
/**
* Prepare content for tab
*
* @return string
*/
public function getTabLabel()
{
return Mage::helper('salesrule')->__('Manage Coupons Codes');
}
/**
* Prepare title for tab
*
* @return string
*/
public function getTabTitle()
{
return Mage::helper('salesrule')->__('Manage Coupons Codes');
}
/**
* Returns status flag about this tab can be shown or not
*
* @return bool
*/
public function canShowTab()
{
return $this->_isEditing();
}
/**
* Returns status flag about this tab hidden or not
*
* @return bool
*/
public function isHidden()
{
return !$this->_isEditing();
}
/**
* Check whether we edit existing rule or adding new one
*
* @return bool
*/
protected function _isEditing()
{
$priceRule = Mage::registry('current_promo_quote_rule');
return !is_null($priceRule->getRuleId());
}
}
[/php]
3) And refresh
This solved my error i was on magento version 1.6.2
Happy coding :-)
Sunday, March 17, 2013
10 Best WordPress Themes For Free Download
Demo | Download
A very elegant and any responsive wordpress theme best for creating online portfolio.
Key Features :
Genre : Portfolio
Responsive : Yes
Localization : Yes
Custom Elements : Custom page templates
USP : Hybrid Core framework
Demo | Download
Looking for a cool,funky and casual theme for your wordpress this theme is designed for you.
Key Features :
1. Suitable for both blog or website.
2. Supports all post formats
3. Optional responsive design for smaller screens (perfect for iPhone, iPad and other mobile devices)
4. Custom backgrounds, a custom pop-up menu and three widget-ready sidebars in the footer.
Demo | Download
Key Features :
1. Responsive.
2. Subscription Box.
3. Countdown Timer.
4. Twitter Integration.
5. Rocket Launching Effect.
6. Social Media Integration.
7. Options Panel.
Demo | Download
Bursting with bold, vibrant colors and clean styling, Prospect is the perfect choice for any business site. It's sure to make a lasting impression on your visitors, turning them into return customers over time.
Key Features :
1. DRAG & DROP FORMS.
2. CUSTOM LOGO UPLOAD.
3. SOCIAL MEDIA.
4. BEAUTIFUL DESIGN.
5. Extensive Admin Panel.
6. Home Content Boxes.
7. Custom Portfolio Templates.
Demo | Download
Free WordPress Theme for Creative People
Key Features :
1. Custom Post Types.
2. 4 Portfolio Layouts.
3. Responsive Design.
4. Localization Support.
5. Archive + 404 Pages.
6. Browser Support.
7. SEO & Valid HTML.
Demo | Download
Simple and responsive theme, suitable as a vCard website.
Key Features :
1. Multiple Color Styles.
2. Responsive Design.
3. HTML5 and CSS3.
4. Always Up to Date.
5. Detailed Documentation.
6. Localization Ready.
Demo | Download
Photo Free Responsive Gallery WordPress Theme
Key Features :
1. Featured homepage slider using “Soliloquy“.
2. Built-in theme options panel using Options Framework Plugin.
3. Responsive design.
4. Social options.
5. Google fonts added properly via wp_enqueue_script();.
6. Symple Shortcodes Plugin support – added responsive styles.
7. Free GPL theme!
Demo | Download
Shortnotes is a tumblogging theme with support for custom post formats.
Key Features :
1. Responsive Design.
2. Built-in Pagination.
3. Widget Ready.
4. Theme Options Panel.
5. Web Fonts Supported.
6. Localization Ready.
Demo | Download
Western is a premium WordPress theme for tutorial sites.
Demo | Download
SimpleCorp is a gorgeous theme meant for corporate and business websites. It features a plethora of tweak-worthy options to help you customize your site.
Key Features :
1. HTML5 and CSS3.
2. Responsive Design.
3. Multiple Color Styles.
4. Built-in Pagination.
5. Built-in Contact Form.
6. Theme Options Panel.
Tuesday, March 12, 2013
Magento : How to fetch all out of stock products and save them in a CSV file
Ever wanted to get all of the out is stock products from your magento store and save them in csv file, here is a ready made script for your help.
[php]
ini_set('memory_limit', '-1'); //in-case if we have large inventory
set_time_limit(0); //in-case if we have large inventory, it could take infinite time
require_once ('app/Mage.php'); //loading magento
Mage::app('default'); //loading default store view
//Create a test folder
$fp = fopen('test/Outofstockproducts.csv', 'w'); //this line will create Outofstockproducts.csv file under //test folder
//CSV head columns
$list = array (
array('SKU','NAME')
);
//Write the head
foreach($list as $fields){
fputcsv($fp, $fields);
}
$stockCollection = Mage::getModel('cataloginventory/stock_item')->getCollection()
->addFieldToFilter('is_in_stock', 0);
$productIds = array();
foreach ($stockCollection as $item) {
$productIds[] = $item->getOrigData('product_id');
}
$productCollection = Mage::getModel('catalog/product')->getCollection()
->addIdFilter($productIds)
->addAttributeToSelect('name');
$products = array();
foreach($productCollection as $product){
$list = array(
array($product->getData('sku'), $product->getData('name'))
);
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
}
[/php]
Paste this code on php file and save it as GetOutOfStock.php place it on magento root folder run the script from the browser http://yoursite.com/GetOutOfStock.php after completing the script you will find a
csv file under test folder containing all of the out of stock products of the default store.
Hope it helps,Thanks
Happy coding
[php]
ini_set('memory_limit', '-1'); //in-case if we have large inventory
set_time_limit(0); //in-case if we have large inventory, it could take infinite time
require_once ('app/Mage.php'); //loading magento
Mage::app('default'); //loading default store view
//Create a test folder
$fp = fopen('test/Outofstockproducts.csv', 'w'); //this line will create Outofstockproducts.csv file under //test folder
//CSV head columns
$list = array (
array('SKU','NAME')
);
//Write the head
foreach($list as $fields){
fputcsv($fp, $fields);
}
$stockCollection = Mage::getModel('cataloginventory/stock_item')->getCollection()
->addFieldToFilter('is_in_stock', 0);
$productIds = array();
foreach ($stockCollection as $item) {
$productIds[] = $item->getOrigData('product_id');
}
$productCollection = Mage::getModel('catalog/product')->getCollection()
->addIdFilter($productIds)
->addAttributeToSelect('name');
$products = array();
foreach($productCollection as $product){
$list = array(
array($product->getData('sku'), $product->getData('name'))
);
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
}
[/php]
Paste this code on php file and save it as GetOutOfStock.php place it on magento root folder run the script from the browser http://yoursite.com/GetOutOfStock.php after completing the script you will find a
csv file under test folder containing all of the out of stock products of the default store.
Hope it helps,Thanks
Happy coding
Monday, March 11, 2013
Magento : Weird url parameter on detail page
Hii.. here is another interesting issue which i have found today that i have added addthis share button on my product detail page and found that there were some weird url param like #AHb4gs1hwck was adding to the end of every product product url in the address bar, it was really weird and i want to remove this so i have google this and found a solution
It was in the add this configuration on the page, the data_track_addressbar was set to true
Before :
[js]<script type="text/javascript">var addthis_config = {"data_track_addressbar":true};</script>[/js]
After :
[js]<script type="text/javascript">var addthis_config = {"data_track_addressbar":false};</script>[/js]
And this completely remove the param from the url
Hope it helps
Happy coding
It was in the add this configuration on the page, the data_track_addressbar was set to true
Before :
[js]<script type="text/javascript">var addthis_config = {"data_track_addressbar":true};</script>[/js]
After :
[js]<script type="text/javascript">var addthis_config = {"data_track_addressbar":false};</script>[/js]
And this completely remove the param from the url
Hope it helps
Happy coding
Sunday, March 10, 2013
Magento : How to get product custom option value programmatically
Magento has the power to define product variations (custom options) with each product, which allow your online customers to select an specific product from wide range of option available with each product,
Custom options are a good solution if your inventory needs are simple and you have a limited number of available SKUs.

[php]
$product = Mage::getModel("catalog/product")->load(1); //product id 1
$i = 1;
echo "<pre>";
foreach ($product->getOptions() as $o) {
echo "<strong>Custom Option:" . $i . "</strong><br/>";
echo "Custom Option TITLE: " . $o->getTitle() . "<br/>"; //Colors
echo "Custom Option TYPE: " . $o->getType() . "<br/>"; //drop_down
echo "Custom Option Values: <br/>";
$values = $o->getValues();
foreach ($values as $v) {
print_r($v->getData());
}
$i++;
echo "<br/>";
}
[/php]
Hope It helps.
Happy coding
Custom options are a good solution if your inventory needs are simple and you have a limited number of available SKUs.
[php]
$product = Mage::getModel("catalog/product")->load(1); //product id 1
$i = 1;
echo "<pre>";
foreach ($product->getOptions() as $o) {
echo "<strong>Custom Option:" . $i . "</strong><br/>";
echo "Custom Option TITLE: " . $o->getTitle() . "<br/>"; //Colors
echo "Custom Option TYPE: " . $o->getType() . "<br/>"; //drop_down
echo "Custom Option Values: <br/>";
$values = $o->getValues();
foreach ($values as $v) {
print_r($v->getData());
}
$i++;
echo "<br/>";
}
[/php]
Hope It helps.
Happy coding
How to reset you magento password from phpmyadmin
If you ever ran into a situation where you can not reset your password using forgot password forms e.g. while working on localhost the reset password mail does not triggers, for this situation you can easily change your password from your phpmyadmin interface
Here is how to :
1. Open your phpmyadmin
2. Go to table admin_user

3. Go to this URL
4. Type your password and get hash text for that their
5. Edit the admin row under the admin_user table of phpmyadmin
6. Go to password column and paste the copied text (Password Hash) to column
7. Go to admin page and login with password for which you have generated your hash
Thanks.
Hope it helps
Here is how to :
1. Open your phpmyadmin
2. Go to table admin_user
3. Go to this URL
4. Type your password and get hash text for that their
5. Edit the admin row under the admin_user table of phpmyadmin
6. Go to password column and paste the copied text (Password Hash) to column
7. Go to admin page and login with password for which you have generated your hash
Thanks.
Hope it helps
Magento : Illegal scheme supplied, only alphanumeric characters are permitted
If you are using magento 1.6 version and ever found this error saying that Illegal scheme supplied, only alphanumeric characters are permitted This is probably a bug in Magento 1.6.1.0, see here, full discussion on magento fourm
here is quick patch by Dan
Download it from here
here is quick patch by Dan
Download it from here
Subscribe to:
Comments (Atom)