Friday 19 December 2014

Magento remove selected items from shopping cart

When you have too many products in you shopping cart and you want to remove particular products out of it, you only need to do it one-by-one. And its really frustrating especially for testers. Magento does not provide the feature to remove selected products by default.

I have developed a code that could allow users to select the products which they want to remove by simply checking the products and click the remove button. And they all will be removed at a time.


Please download the extension here. Extract it and move it inside appropriate folders.
Tested on Version 1.7.2 and 1.8.1 community edition.

Monday 8 December 2014

Magento update backorder programatically

To update a products backorder status i wrote a custom script. My script reads the SKU's from the csv file and checks if the product exists and updates its backorder status.

Below is the code.

$products = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
if($products)
{     
   // get product's stock data such quantity, in_stock etc
   $stockData = Mage::getModel('cataloginventory/stock_item')->loadByProduct($products);
           
   //to update backorder
   $stockData->setData('use_config_backorders', '0'); //not to use config settings           
   /*0 = No Backorders
   1 = Allow Qty Below 0
   2 = Allow Qty Below 0 and Notify Customer*/
   $stockData->setData('backorders', '1');
                       
   // then set product's stock data to update
   $stockData->save();
           
   // call save() method to save your product with updated data
   $products->save();                
}


You can download the complete code here.  It reads the csv file and checks for the products, If it is found the data are updated. Upon running this file. It will output all the products status (Found, Not found, How many not found) in the webpage. It also Writes the missing sku's in a new CSV file.