Saturday, April 30, 2011

How to install or uninstall pear packages in xampp for windows


Recently I had some tough time installing pear packages in xampp so I am sharing procedure here so that it can help you.

First of all go to folder c:\xampp\php and find the file pear.bat. In my case I installed xampp in c drive. If its not in c drive go to the correct path and find pear.bat file.

Open that file in Notepad or Notepad++ to edit. Find the following line in in that file.


Add following line above this line.


Now include c:\xampp\php to PATH environment variable.

In windows vista you can find it here.

Start->Control Panel->System and Maintenance->System->Advanced System Settings->Environment Variable

That's it and now go to command prompt and type command pear. You will see all the possible options for that command.

Use following command to install pear package.

pear install -o 'path of package'

Use following command to uninstall pear package.

pear uninstall 'pearname'

Generally name of pear is directory name inside php/pears folder.

Hope this post saves your time.

Tuesday, April 26, 2011

Use JavaScript to built multilingual web application


Recently I was working on a project which requires multilingual support. Front end was built ExtJs so I decided to add multilingual support through JavaScript files. At a time of login user language is retrieved from database and respective language is downloaded on a client side then it can be used through out the app.

The approach is to store all language files in one common folder and from there it will be dynamically loaded using ScriptLoader.

For Example.


Each language file stores conversation in some common format. See the example below.


WebAppName.language = {
    PageTitle : "Welcome to The Site",
    HomePage : "This is HomePage",
    WelcomeMessage : "Welcome to the Web App"

Here Ext.ns is used to define namespace. Once namespace is defined it can be used any where in the app with that reference name.

Once any of above files are loaded it can be used as follow.

var title = WebAppName.language['PageTitle '];

Above code will assign "Welcome to The Site" string to title variable. Same way any other words can be loaded and used through out the app.

So this was the approach to built multilingual web app using JavaScript. This approach is useful when you are building front end using JavaScript frameworks like ExtJs, jQuery. Main advantage of this approach is it will be one time download a language file and all the values are available on client side so it does not require server request.

Please remember above code will work for ExtJs.

Saturday, April 9, 2011

Programmatically add configurable products to Magento Shopping Cart

Hello Guys, 

Here we have another Magento blog. Recently I was working on building a quick shop module for magento. Its like customer can quickly search products based on some attributes. All the products with matching criteria will be displayed with their options. Customer can select product options and enter quantity and those products get added to shopping cart manually. Here all the products will be configurable products. So I created a custom module for it. After relevant products are displayed all the data like product id, quantity, option id and option values will be sent to cart controller page. This is the page where we need to write code to add product in the cart.

There are two way to do this. Following are the two options.

Option 1 : Via query string

Following is the URL format to add product to shopping cart.

$route  = "[22]=30";

header("Location : ".$route);

Here 272 is the product entity id displayed in magento admin panel. 22 is the attribute associated with this product and 30 is the selected value of that attribute.  

This will add product to the cart and redirect to cart page. Using this approach you can add a a single product to cart. What if we have more than one product. Like in my case customer can select more than one products and options. Following is the another option to add product manually.

Option 2 :

Following is the code to add product to shopping cart.

$params = array(
    'product' => 272,
    'super_attribute' => array(
        22 =>30 ,
    'qty' => 2,

$cart = Mage::getSingleton('checkout/cart'); 
$product = new Mage_Catalog_Model_Product();
$cart->addProduct($product, $params);

Using above code you can add any number of products to the cart.
Above code will work for only configurable products having only one option. If configurable product has more option then all the option values should be specified.

Friday, April 8, 2011

Use Channel Advisor Order PHP API with Magento


In my previous blog I mentioned about Channel Advisor API. You can read that blog here. In this blog we will see how to use Channel Advisor Order service to get order details from Channel Advisor. This service is useful when you want to import orders from Channel Advisor to your own CMS or ERP. In my case I was working with Magento - Channel Advisor synchronization. So the requirement was to get order from Channel Advisor and add order to Magento.

Following is the code to create soap client for order service.

$client = new SoapClient("");

$headersData = array('DeveloperKey' => $developerKey, 'Password' => $password);

$head = new SoapHeader("","APICredentials",$headersData);


To get necessary order details, we need to set order criteria. Following is the example of order criteria.

$OrderCriteria = array(
               'OrderCreationFilterBeginTimeGMT'=> $date1,
               'OrderCreationFilterEndTimeGMT'=> $date2,
               'StatusUpdateFilterBeginTimeGMT' => $date1,
               'StatusUpdateFilterEndTimeGMT' => $date2,
               'DetailLevel' => 'Complete',
               'ExportState' => 'NotExported',
               'OrderStateFilter' => 'Active',
               'PaymentStatusFilter' => 'Cleared',
               'CheckoutStatusFilter'  => 'Completed',
               'ShippingStatusFilter'  =>'Shipped',

Here date1 and date2 variable specify date range for orders. After this call function of API to get order data.

$arrData = array(

You will get API response in $result. If there is only one order matching criteria then it will return order object else it will return order object array if more than one order is matching criteria.