Magento 1.9 – Script to Update Product Prices for Certain Product Types

magento-1.9priceproduct-type

I have a magento store (1.9.1.1).

I have a range of different product types, one of which is "Booking/reservation".

I need to update all these products, so that they have a price increase of £0.70p.

I don't want to have to manually amend each price and I hoped that someone out there had a script that I might be able to tweak?

Help advise or help would be really appreciated.

Best Answer

You should be able to update this from Admin Catalog Grid.

Select the Product Type from the selector drop down for product type (if it was properly defined as a new product type). Select all the products you wish to update the price for (Select All possibly) Then go to the Actions drop down and choose Update Attributes. On the next screen simply select the price field Change check box and input the new price and save.


* EDIT *

<?php

// drop into Magento root directory updateprice.php and execute

require_once('app/Mage.php');
ob_implicit_flush(true);
umask(0);
set_time_limit(0);
ini_set('display_errors', 1);
ini_set('memory_limit', '2048M');
Mage::setIsDeveloperMode(true);
Mage::app();
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

function productCallback($args) {

    $product = Mage::getModel('catalog/product');

    // set product data from row iterator
    $product->setData($args['row']); 
    $product_data = array();

    // get current price 
    $price = $product->getPrice();

    // add additional value to existing price
    $product->setPrice($price + .70);

    echo "Updating Price for: ".$product->getName()."<br />\n\r";    
    $product->save();
    $product->clearInstance();  
    unset($price);
}

try {

    // get collection of products
    $collection = Mage::getResourceModel('catalog/product_collection')
            ->addAttributeToSelect('*')
            ->addAttributeToFilter('type_id','Booking/reservation'); // define product type 

    // output SQL query for collection
    echo $collection->getSelect();

    // use magento iterator callback to not consume memory for large catalogs
    Mage::getSingleton('core/resource_iterator')->walk($collection->getSelect(), array('productCallback'), array('arg1' => '===='));

} catch (Exception $e) {
    zend_debug::dump($e);
} 
Related Topic