Archive for the ‘Version 1.3.*’ Category

Hello Everyone,

 

After a long search i found solution to validate php tags using javascript from input values in magento.

 

I have modified magento/js/prototype/validation.js file and added new class to validate php tags:

You can review below code inside ‘Validation.addAllThese’ array  to add new class to validate php tags.


['validate-no-php-tags', 'PHP tags are not allowed', function(v) {

return  !/<\?[=|?php]?[\s\S]*?\?>/.test(v) && !/<\?[=|php]?[\s\S]*?/.test(v) && !/\?[\s\S]*?/.test(v) ;

}],

you can use ‘validate-no-php-tags’  css class in input tag in magento.

Above validation will validate tags like ‘<?php’, ‘<?’, ‘?>’, ‘<?php ?>’, ‘<? ?>’.

I hope above solution works like  charm.

 

Thanks,

Bijal Bhavsar

Hello Guys,

Today i’ll show you how to add affiliate code in checkout success page.

Below is the code for Product Specific Campaign setup for magento.

Open success.phtml from PATH:  Yourproject/app/design/frontend/package/theme/template/checkout/success.phtml.

Add Below code at the end of file.

We need to display below image code at checkout success page.

<img src="http://yourdomain.directtrack.com/i_prod/yourdomainname/PRODUCT_STRING/TRANSACTION_ID/OPTIONAL_INFO">  
<?php /****** START::  Affiliate  *******/?>
<?php  if($_orderID = $this->getOrderId()) {
$url = 'https://yourdomain.directtrack.com/i_prod/yourdomainname/';
$_order =  Mage::getModel('sales/order')->loadByIncrementId($_orderID);?>
<?php  $_items = $_order->getItemsCollection(); ?>
<?php $querystring='';
foreach ($_items as $_item):  ?>
<?php $querystring .='prod:'.$_item->getSku().':qty:'.$_item->getQtyOrdered();?>
<?php endforeach; ?>
<?php $querystring.= '/'.$_orderID;?>
<?php $url = $url.$querystring;?>
<img src="<?php echo $url?>" />
<?php }?>
<?php /****** END *********/?>

Thanks,
Bijal Bhavsar 🙂

Hello,

Today i’ll show you how to resolve issue of custom module frontend url is forced to https. instead of http. If you have used module creator to create module. Than you will definetly find below code in config.xml


<admin>
       <routers>
         <[ModuleName]>
            <use>admin</use>
            <args>
                <module>[NameSpace_ModuleName]</module>
                <frontName>[frontName]</frontName>
            </args>
        </[ModuleName]>
    </routers>
</admin>

To resolve issue of redirection to https instead of http, you need to comment above code from module config.xml file Path: app/code/(codepool)/(NameSpace)/(ModuleName)/etc/config.xml OR you can add different “frontName” for <admin> and <frontend> routers. Eg.:


<admin>
       <routers>
         <[ModuleName]>
            <use>admin</use>
            <args>
                <module>[NameSpace_ModuleName]</module>
                <frontName>[frontName]</frontName>
            </args>
        </[ModuleName]>
    </routers>
</admin>

<frontend>
       <routers>
         <[ModuleName]>
            <use>standard</use>
            <args>
                <module>[NameSpace_ModuleName]</module>
                <frontName>[frontName1]</frontName>
            </args>
        </[ModuleName]>
    </routers>
</frontend>

As per above code admin url will be http://yourdomain.com/index.php/frontName/adminhtml_moduleName/ and  frontend url will be like: http://yourdomain.com/index.php/frontName1

I hope above content is useful to you. Thanks for visiting my blog. Feel free to ask questions, if you have doubt.

Thanks,
Bijal Bhavsar 🙂

Hello,

Magento maintains several tables for logging. These tables log things such as customer accesses and which products have been compared. Magento has a mechanism for cleaning these logs regularly, but unfortunately this feature is disabled by default and most customers do not turn it on.

The following tables are managed by Magento’s Log Cleaning function:


TRUNCATE `dataflow_batch_export`;
TRUNCATE `dataflow_batch_import`;
TRUNCATE `log_customer`;
TRUNCATE `log_quote`;
TRUNCATE `log_summary`;
TRUNCATE `log_summary_type`;
TRUNCATE `log_url`;
TRUNCATE `log_url_info`;
TRUNCATE `log_visitor`;
TRUNCATE `log_visitor_info`;
TRUNCATE `log_visitor_online`;
TRUNCATE `report_viewed_product_index`;
TRUNCATE `report_compared_product_index`;
TRUNCATE `report_event`;
TRUNCATE `index_event`;

You can use below script file and use it by scheduling cronjob. Filename will be cleanup.php


<?php
$xml = simplexml_load_file('./app/etc/local.xml', NULL, LIBXML_NOCDATA);

$db['host'] = $xml->global->resources->default_setup->connection->host;
$db['name'] = $xml->global->resources->default_setup->connection->dbname;
$db['user'] = $xml->global->resources->default_setup->connection->username;
$db['pass'] = $xml->global->resources->default_setup->connection->password;
$db['pref'] = $xml->global->resources->db->table_prefix;

if($_GET['clean'] == 'log') clean_log_tables();
if($_GET['clean'] == 'var') clean_var_directory();

function clean_log_tables() {
	global $db;

	$tables = array(
		'dataflow_batch_export',
		'dataflow_batch_import',
		'log_customer',
		'log_quote',
		'log_summary',
		'log_summary_type',
		'log_url',
		'log_url_info',
		'log_visitor',
		'log_visitor_info',
		'log_visitor_online',
		'index_event',
		'report_event',
		'report_compared_product_index',
		'report_viewed_product_index',
		'catalog_compare_item',
		'catalogindex_aggregation',
		'catalogindex_aggregation_tag',
		'catalogindex_aggregation_to_tag'
	);

	mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
	mysql_select_db($db['name']) or die(mysql_error());

	foreach($tables as $v => $k) {
		@mysql_query('TRUNCATE `'.$db['pref'].$k.'`');
	}
}

function clean_var_directory() {
	$dirs = array(
		'downloader/.cache/*',
		'downloader/pearlib/cache/*',
		'downloader/pearlib/download/*',
		'var/cache/',
		'var/locks/',
		'var/log/',
		'var/report/',
		'var/session/',
		'var/tmp/'
	);

	foreach($dirs as $v => $k) {
		exec('rm -rf '.$k);
	}
}
?>

Save the file to the root directory of Magento code.

Next, open cPanel and click on the Cron Manager link.

In the Add Cron Job section, select Once a day from the Common Settings dropdown list. In the Command field, enter the following line of code, making sure to replace the yourdomain name with your own:


curl -s -o /dev/null http://www.yourdomain.com/cleanup.php?clean=log

Once you have this set at your preferred interval, click the Add Cron Job button.

Repeat the same steps as you did before, but change the Common Settings dropdown selection to 1st and 15th, and add the following line of code to the Command field:


curl -s -o /dev/null http://www.yourdomain.com/cleanup.php?clean=var

Now click the Add Cron Job button.

I hope above content is useful to you. Thanks for reading my blog.

Thanks,
Bijal Bhavsar 🙂

Hello,

Sometimes when we do re-index in magento, it shows error like “Can’t initialize indexer process”. And this error occurs while re-indexing “Product Prices”, than you can’t able to save product from admin too.

To resolve the above error you need to run below query. Probably it removes only 1 record.
This solution was taken from Magento forum. Here is the direct link:
http://www.magentocommerce.com/boards/viewthread/176845/



DELETE cpop.* FROM catalog_product_option_price AS cpop
INNER JOIN catalog_product_option AS cpo
ON cpo.option_id = cpop.option_id
WHERE
cpo.type = ‘checkbox’ OR
cpo.type = ‘radio’ OR
cpo.type = ‘drop_down’;DELETE cpotp.* FROM catalog_product_option_type_price AS cpotp
INNER JOIN catalog_product_option_type_value AS cpotv
ON cpotv.option_type_id = cpotp.option_type_id
INNER JOIN catalog_product_option AS cpo
ON cpotv.option_id = cpo.option_id
WHERE
cpo.type  ‘checkbox’ AND
cpo.type  ‘radio’ AND
cpo.type  ‘drop_down’; 


I hope above content is useful to you. Thanks for reading my blog.

Thanks,
Bijal Bhavsar

The upgrade error is probably corrected by updating most tables to use the InnoDB engine (instead of MyISAM). The syntax to update tables to the InnoDB engine is as follows:

ALTER TABLE table_name ENGINE = InnoDB;

I noticed that a fresh install had no problem reindexing everything, but there were odd errors creating tables after an upgrade. The errors are found by turning on the exceptions log: Admin -> System -> Configuration -> Developer -> Log Settings -> Enabled = Yes.

This outputs to: /var/log/exception.log

Most errors had something to do with cryptic foreign key constraints. Changing most tables to InnoDB seems to solve this problem.

I’m including the code that I ran on sql.


ALTER TABLE admin_assert ENGINE = InnoDB;
ALTER TABLE admin_role ENGINE = InnoDB;
ALTER TABLE admin_rule ENGINE = InnoDB;
ALTER TABLE admin_user ENGINE = InnoDB;
ALTER TABLE api_assert ENGINE = InnoDB;
ALTER TABLE api_role ENGINE = InnoDB;
ALTER TABLE api_rule ENGINE = InnoDB;
ALTER TABLE api_user ENGINE = InnoDB;
ALTER TABLE catalogindex_eav ENGINE = InnoDB;
ALTER TABLE catalogindex_minimal_price ENGINE = InnoDB;
ALTER TABLE catalogindex_price ENGINE = InnoDB;
ALTER TABLE cataloginventory_stock_item ENGINE = InnoDB;
ALTER TABLE catalogrule ENGINE = InnoDB;
ALTER TABLE catalogrule_product ENGINE = InnoDB;
ALTER TABLE catalogrule_product_price ENGINE = InnoDB;
ALTER TABLE catalogsearch_query ENGINE = InnoDB;
ALTER TABLE catalog_category_entity ENGINE = InnoDB;
ALTER TABLE catalog_category_entity_datetime ENGINE = InnoDB;
ALTER TABLE catalog_category_entity_decimal ENGINE = InnoDB;
ALTER TABLE catalog_category_entity_int ENGINE = InnoDB;
ALTER TABLE catalog_category_entity_text ENGINE = InnoDB;
ALTER TABLE catalog_category_entity_varchar ENGINE = InnoDB;
ALTER TABLE catalog_category_product ENGINE = InnoDB;
ALTER TABLE catalog_category_product_index ENGINE = InnoDB;
ALTER TABLE catalog_compare_item ENGINE = InnoDB;
ALTER TABLE catalog_product_bundle_option ENGINE = InnoDB;
ALTER TABLE catalog_product_bundle_option_value ENGINE = InnoDB;
ALTER TABLE catalog_product_bundle_selection ENGINE = InnoDB;
ALTER TABLE catalog_product_enabled_index ENGINE = InnoDB;
ALTER TABLE catalog_product_entity_datetime ENGINE = InnoDB;
ALTER TABLE catalog_product_entity_decimal ENGINE = InnoDB;
ALTER TABLE catalog_product_entity_gallery ENGINE = InnoDB;
ALTER TABLE catalog_product_entity_int ENGINE = InnoDB;
ALTER TABLE catalog_product_entity_media_gallery ENGINE = InnoDB;
ALTER TABLE catalog_product_entity_media_gallery_value ENGINE = InnoDB;
ALTER TABLE catalog_product_entity_text ENGINE = InnoDB;
ALTER TABLE catalog_product_entity_tier_price ENGINE = InnoDB;
ALTER TABLE catalog_product_entity_varchar ENGINE = InnoDB;
ALTER TABLE catalog_product_link ENGINE = InnoDB;
ALTER TABLE catalog_product_link_attribute ENGINE = InnoDB;
ALTER TABLE catalog_product_link_attribute_decimal ENGINE = InnoDB;
ALTER TABLE catalog_product_link_attribute_int ENGINE = InnoDB;
ALTER TABLE catalog_product_link_attribute_varchar ENGINE = InnoDB;
ALTER TABLE catalog_product_link_type ENGINE = InnoDB;
ALTER TABLE catalog_product_option ENGINE = InnoDB;
ALTER TABLE catalog_product_option_price ENGINE = InnoDB;
ALTER TABLE catalog_product_option_title ENGINE = InnoDB;
ALTER TABLE catalog_product_option_type_price ENGINE = InnoDB;
ALTER TABLE catalog_product_option_type_title ENGINE = InnoDB;
ALTER TABLE catalog_product_option_type_value ENGINE = InnoDB;
ALTER TABLE catalog_product_super_attribute ENGINE = InnoDB;
ALTER TABLE catalog_product_super_attribute_label ENGINE = InnoDB;
ALTER TABLE catalog_product_super_attribute_pricing ENGINE = InnoDB;
ALTER TABLE catalog_product_super_link ENGINE = InnoDB;
ALTER TABLE catalog_product_website ENGINE = InnoDB;
ALTER TABLE checkout_agreement ENGINE = InnoDB;
ALTER TABLE checkout_agreement_store ENGINE = InnoDB;
ALTER TABLE cms_block ENGINE = InnoDB;
ALTER TABLE cms_block_store ENGINE = InnoDB;
ALTER TABLE cms_page ENGINE = InnoDB;
ALTER TABLE cms_page_store ENGINE = InnoDB;
ALTER TABLE core_config_data ENGINE = InnoDB;
ALTER TABLE core_email_template ENGINE = InnoDB;
ALTER TABLE core_flag ENGINE = InnoDB;
ALTER TABLE core_layout_link ENGINE = InnoDB;
ALTER TABLE core_layout_update ENGINE = InnoDB;
ALTER TABLE core_resource ENGINE = InnoDB;
ALTER TABLE core_session ENGINE = InnoDB;
ALTER TABLE core_store ENGINE = InnoDB;
ALTER TABLE core_store_group ENGINE = InnoDB;
ALTER TABLE core_translate ENGINE = InnoDB;
ALTER TABLE core_url_rewrite ENGINE = InnoDB;
ALTER TABLE cron_schedule ENGINE = InnoDB;
ALTER TABLE customer_address_entity ENGINE = InnoDB;
ALTER TABLE customer_address_entity_datetime ENGINE = InnoDB;
ALTER TABLE customer_address_entity_decimal ENGINE = InnoDB;
ALTER TABLE customer_address_entity_int ENGINE = InnoDB;
ALTER TABLE customer_address_entity_text ENGINE = InnoDB;
ALTER TABLE customer_address_entity_varchar ENGINE = InnoDB;
ALTER TABLE customer_entity ENGINE = InnoDB;
ALTER TABLE customer_entity_datetime ENGINE = InnoDB;
ALTER TABLE customer_entity_decimal ENGINE = InnoDB;
ALTER TABLE customer_entity_int ENGINE = InnoDB;
ALTER TABLE customer_entity_text ENGINE = InnoDB;
ALTER TABLE customer_entity_varchar ENGINE = InnoDB;
ALTER TABLE customer_group ENGINE = InnoDB;
ALTER TABLE dataflow_batch ENGINE = InnoDB;
ALTER TABLE dataflow_batch_export ENGINE = InnoDB;
ALTER TABLE dataflow_batch_import ENGINE = InnoDB;
ALTER TABLE dataflow_import_data ENGINE = InnoDB;
ALTER TABLE dataflow_profile ENGINE = InnoDB;
ALTER TABLE dataflow_profile_history ENGINE = InnoDB;
ALTER TABLE dataflow_session ENGINE = InnoDB;
ALTER TABLE design_change ENGINE = InnoDB;
ALTER TABLE directory_country ENGINE = InnoDB;
ALTER TABLE directory_country_region ENGINE = InnoDB;
ALTER TABLE directory_country_region_name ENGINE = InnoDB;
ALTER TABLE directory_currency_rate ENGINE = InnoDB;
ALTER TABLE eav_attribute_group ENGINE = InnoDB;
ALTER TABLE eav_attribute_option ENGINE = InnoDB;
ALTER TABLE eav_attribute_option_value ENGINE = InnoDB;
ALTER TABLE eav_attribute_set ENGINE = InnoDB;
ALTER TABLE eav_entity ENGINE = InnoDB;
ALTER TABLE eav_entity_attribute ENGINE = InnoDB;
ALTER TABLE eav_entity_datetime ENGINE = InnoDB;
ALTER TABLE eav_entity_decimal ENGINE = InnoDB;
ALTER TABLE eav_entity_int ENGINE = InnoDB;
ALTER TABLE eav_entity_text ENGINE = InnoDB;
ALTER TABLE eav_entity_type ENGINE = InnoDB;
ALTER TABLE eav_entity_varchar ENGINE = InnoDB;
ALTER TABLE gift_message ENGINE = InnoDB;
ALTER TABLE googlebase_attributes ENGINE = InnoDB;
ALTER TABLE googlebase_items ENGINE = InnoDB;
ALTER TABLE googlebase_types ENGINE = InnoDB;
ALTER TABLE googlecheckout_api_debug ENGINE = InnoDB;
ALTER TABLE googleoptimizer_code ENGINE = InnoDB;
ALTER TABLE newsletter_problem ENGINE = InnoDB;
ALTER TABLE newsletter_queue ENGINE = InnoDB;
ALTER TABLE newsletter_queue_link ENGINE = InnoDB;
ALTER TABLE newsletter_queue_store_link ENGINE = InnoDB;
ALTER TABLE newsletter_subscriber ENGINE = InnoDB;
ALTER TABLE newsletter_template ENGINE = InnoDB;
ALTER TABLE paygate_authorizenet_debug ENGINE = InnoDB;
ALTER TABLE paypaluk_api_debug ENGINE = InnoDB;
ALTER TABLE paypal_api_debug ENGINE = InnoDB;
ALTER TABLE poll ENGINE = InnoDB;
ALTER TABLE poll_answer ENGINE = InnoDB;
ALTER TABLE poll_store ENGINE = InnoDB;
ALTER TABLE poll_vote ENGINE = InnoDB;
ALTER TABLE product_alert_price ENGINE = InnoDB;
ALTER TABLE rating ENGINE = InnoDB;
ALTER TABLE rating_entity ENGINE = InnoDB;
ALTER TABLE rating_option ENGINE = InnoDB;
ALTER TABLE rating_option_vote ENGINE = InnoDB;
ALTER TABLE rating_option_vote_aggregated ENGINE = InnoDB;
ALTER TABLE rating_store ENGINE = InnoDB;
ALTER TABLE rating_title ENGINE = InnoDB;
ALTER TABLE report_event ENGINE = InnoDB;
ALTER TABLE report_event_types ENGINE = InnoDB;
ALTER TABLE review ENGINE = InnoDB;
ALTER TABLE review_detail ENGINE = InnoDB;
ALTER TABLE review_entity ENGINE = InnoDB;
ALTER TABLE review_entity_summary ENGINE = InnoDB;
ALTER TABLE review_status ENGINE = InnoDB;
ALTER TABLE review_store ENGINE = InnoDB;
ALTER TABLE salesrule ENGINE = InnoDB;
ALTER TABLE salesrule_customer ENGINE = InnoDB;
ALTER TABLE sales_flat_order_item ENGINE = InnoDB;
ALTER TABLE sales_flat_quote ENGINE = InnoDB;
ALTER TABLE sales_flat_quote_address ENGINE = InnoDB;
ALTER TABLE sales_flat_quote_address_item ENGINE = InnoDB;
ALTER TABLE sales_flat_quote_item ENGINE = InnoDB;
ALTER TABLE sales_flat_quote_item_option ENGINE = InnoDB;
ALTER TABLE sales_flat_quote_payment ENGINE = InnoDB;
ALTER TABLE sales_flat_quote_shipping_rate ENGINE = InnoDB;
ALTER TABLE sales_order ENGINE = InnoDB;
ALTER TABLE sales_order_datetime ENGINE = InnoDB;
ALTER TABLE sales_order_decimal ENGINE = InnoDB;
ALTER TABLE sales_order_entity ENGINE = InnoDB;
ALTER TABLE sales_order_entity_datetime ENGINE = InnoDB;
ALTER TABLE sales_order_entity_decimal ENGINE = InnoDB;
ALTER TABLE sales_order_entity_int ENGINE = InnoDB;
ALTER TABLE sales_order_entity_text ENGINE = InnoDB;
ALTER TABLE sales_order_entity_varchar ENGINE = InnoDB;
ALTER TABLE sales_order_int ENGINE = InnoDB;
ALTER TABLE sales_order_tax ENGINE = InnoDB;
ALTER TABLE sales_order_text ENGINE = InnoDB;
ALTER TABLE sales_order_varchar ENGINE = InnoDB;

In the end, the only tables that are using the MyISAM engine are as follows:

ALTER TABLE catalogsearch_fulltext ENGINE = MyISAM;
ALTER TABLE catalog_product_index_price_bndl_opt ENGINE = MyISAM;
ALTER TABLE catalog_product_index_price_bndl_sel ENGINE = MyISAM;
ALTER TABLE catalog_product_index_price_bundle ENGINE = MyISAM;
ALTER TABLE catalog_product_index_price_downloadable_idx ENGINE = MyISAM;
ALTER TABLE catalog_product_index_price_final_idx ENGINE = MyISAM;
ALTER TABLE catalog_product_index_price_idx_cfg_option ENGINE = MyISAM;
ALTER TABLE catalog_product_index_price_idx_cfg_opt_aggregate ENGINE = MyISAM;
ALTER TABLE catalog_product_index_price_idx_option ENGINE = MyISAM;
ALTER TABLE catalog_product_index_price_idx_option_aggregate ENGINE = MyISAM;
ALTER TABLE sendfriend_log ENGINE = MyISAM;

After updating to InnoDB I can able to reindex everything successfully and the store seems to be back up and running as it should. All products are back.

I hope this post will help to solve problem of reindexing.

If this post is helpful to you, don’t forget to comment.

Thanks,
Bijal Bhavsar 🙂

Hello,

Below code will delete particular category in magento.


 require_once realpath(dirname(__FILE__).'/app/Mage.php';
 Mage::app('default'); // Default or your store view name.
 Mage::register('isSecureArea', 1);// This will set secure area as admin
 $category = Mage::getModel('catalog/category')->load(15);//Here 15 is category id & it create category object
 $category->delete(); // This code will delete category whose id is 15

I hope above content is useful to you. Thanks for reading my blog.

Thanks,
Bijal Bhavsar:)

Hello All,

Today i found how to set default filter in product grid by product type (e.g.  ‘simple’) in admin product grid. For that you need to rewrite grid.php class of product in path  yourproject/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php

You need to add below code in _construct() method of grid.php


  $this->setDefaultFilter( array(
                'type' => constant(get_class(Mage::getSingleton('catalog/product_type')) . '::TYPE_SIMPLE'),
            )); 

In above code ‘type’ is field and “constant(get_class(Mage::getSingleton(‘catalog/product_type’)) . ‘::TYPE_SIMPLE’)” is value, you can change its value as per your requirement.

I hope this code will help you, Thanks for reading my blog.

Thanks,

Bijal Bhavsar 🙂

Some question and answer of magento

How do I get the Magento Home URL?
Mage::getBaseUrl();
How do I get the Magento Home Directory?
Mage::getBaseDir();
How do I get the URL of a file in the skin directory?
$this->getSkinUrl(‘images/myfile.png’); // in a template or Block
Mage::getDesign()->getSkinUrl(‘images/myfile.png’); // from anywhere
How do I format a price value?
Mage::helper(‘core’)->formatPrice($amount);
How do I get the display value of a (multi-)select product attribute?
echo $product->getAttributeText(‘manufacturer’);
How do I create an object instance in magento?
Mage::getModel(‘module/class’); // for models
Mage::helper(‘module/class’); // for helpers
Mage::app()->getLayout()->createBlock(‘module/class’, ‘name_in_layout’); // for blocks
How do I get at GET/POST parameters?
Mage::app()->getRequest()->getParam(‘param_name’); // single parameter
Mage::app()->getRequest()->getParams(); // all parameters
How do I get the Id of the curent store view?
Mage::app()->getStore()->getId();
How do I get all Store Views?
Mage::app()->getStores(); // pass true to include the admin store view, too
How do I get the configurable/grouped/bundled product a simple product belongs to?
$simpleProduct->loadParentProductIds();
$parentProductIds = $simpleProduct->getParentProductIds();
How do I get the simple products assigned to a configurable product?
$configProduct->getTypeInstance()->getUsedProductCollection($configProduct);
How do I get an instance of an attribute?
Mage::getSingleton(‘eav/config’)->getAttribute($entityType, $attributeCode)

How to check query of collection?
echo $colleciton->getSelect();// note: this will not work when you use load() to get object of any product/category etc id

How to see which class is used?
echo get_class(Mage::getModel('catalog/product')); // Default it will return Mage_Catalog_Model_Product
echo get_class(Mage::helper('product')); // Default it will return Mage_Catalog_Helper_Product

Here: get_class is php function

I hope this code will help you, Thanks for reading my blog.

Thanks,
Bijal Bhavsar :)

Hello Guys,

I want to share you how to change product attribute input type from dropdown to multiselect in magento.

Below code will change input type of attribute ‘grade’ & remove value of attribute already exist in products. You can create file and add below code, Don’t forget to replace ‘grade’ with your attribute code.


<?php
define('MAGENTO_ROOT', getcwd());

$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
umask(0);
Mage::app('default');

$installer = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();

$entityTypeId = $installer->getEntityTypeId('catalog_product');

$idAttributeOldSelect = $installer->getAttribute($entityTypeId, 'grade', 'attribute_id');
$installer->updateAttribute($entityTypeId,$idAttributeOldSelect, 'frontend_input','multiselect');
$installer->updateAttribute($entityTypeId,$idAttributeOldSelect, 'backend_type','varchar');
$installer->updateAttribute($entityTypeId,$idAttributeOldSelect, 'backend_model','eav/entity_attribute_backend_array');
$installer->updateAttribute($entityTypeId,$idAttributeOldSelect, 'source_model','');
$installer->run("DELETE FROM `catalog_product_entity_int` where `attribute_id` = {$idAttributeOldSelect}");
$installer->endSetup();
?>

 

I hope above code will help you.

Thank You,
Bijal Bhavsar 🙂