Magento: Bulk Update Product Attribute (using sql file or from a controller)

Share
Posted on December 14th, 2012 | Posted by admin

After creating a New Magento Module to add special functionality to catalog products I needed to set the value for this product to all downloadable products that were already created because this is a required attribute and the site would not function correctly with out it. So here is how you can update an attribute(s) for a given set of products. Please note that this will update a text attribute. If you are trying to update a select or multiselect attribute you may need to format you values differently.

If you can not figure out the exact format you need you can test it by doing a bulk attribute update from the admin and edit the file for Mage_Catalog_Model_Product_Action class and in the updateAttributes method just print the value for $attrData. Then mimic this in you update script.

Empty the cart programatically in Magento

Share
Posted on December 11th, 2012 | Posted by admin

One of the last things I had to implement in Magento was a function to empty the customer cart. At first I found this great magento extension made by the Inchoo people, but it did much more than I needed. Having a controller to do this is fair enough, and the only code you need to put in that controller is the following:

1
2
3
$quote = Mage::getSingleton('checkout/session')->getQuote();
$quote->delete();

Page Speed Analyzer Helpful for Magento, Joomla & WordPress Websites

Share
Posted on December 8th, 2012 | Posted by admin

Here is a helpful website for checking the page speed optimizations already in place for your website as well as the potential page speed optimizations you could utilize to increase the speed of your website. This is an exceptional tool for learning how to increase the speed of a Magento, Joomla or WordPress website. As we all know, Google recently began using page speed as part of its algorithm for determining the placement of websites for highly competitive search phrases.

Google’s Page Speed Online analyzes a website, then generates suggestions to make the website load faster. Learn more at Google Page Speed Checker

Magento Performance Boost: Enable Log Cleaning

Share
Posted on December 7th, 2012 | Posted by admin

Magento stores a lot of logging information in the database tables prefixed with log_e.g. log_visitor_info, log_url_info, etc. As with Magento’s session files, if not handled properly, these tables will grow out of control and hinder performance.

Magento has automated log cleaning functionality built in, but it is not enabled by default. Here’s how to turn it on.

  1. Firstly you need make sure Magento’s cron system is running.
    If you are unsure about this, see this article on setting up cron (scheduled tasks).
  2. Once cron is enabled and running, simply enable log cleaning via the admin:
    System > Configuration > Advanced > System > Log Cleaning

As per the screenshot below, I like to save 1 days logs, and perform the cleaning at 4:00am each morning.

Some useful function retrieves values related to magento website and currency configuration

Share
Posted on December 5th, 2012 | Posted by admin

When we want to check Type of customer. Following function helps us to ge that

<?php      echo $customerEntityType = Mage::getModel(‘eav/entity’)->setType(‘customer’)->getTypeId(); ?>

CURRENT WEBSITE ID IN MAGENTO CAN BE RETRIEVED WITH THE FOLLOWING FUNCTION. IN CASE OF MULTIPLE WEBSITES IN MAGENTO WE CAN GET THE CURRENT WEBSITE ID WITH THE BELOW CODE.

1
<!--DVFMTSC--><?php  $currentWebSite = Mage::getModel('core/website')->load( 'base', 'code');
2
            echo $currentWebSiteID = $currentWebSite->getId();
3
?>

Getting Website Name from the configuration. Anywhere when you want to retrieve any configure related value, you can call Store configuration function as follows, we used here to get the website name.