4

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.

2 Answers 2

2

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);
} 
5
  • 1
    Thanks, however this sets the price for all products to what I enter, I want to increment the already entered price by 70p
    – rosey85uk
    Commented Nov 20, 2015 at 15:19
  • Updated answer with script that should do what you need (not tested)
    – B00MER
    Commented Nov 20, 2015 at 15:50
  • 1
    Thanks! got some errors at first, but tweaked it and worked perfectly.
    – rosey85uk
    Commented Nov 20, 2015 at 16:43
  • What were the errors, to help others looking for the same?
    – B00MER
    Commented Nov 20, 2015 at 16:45
  • 1
    I was getting an exception and then an error dump, I removed: Mage::setIsDeveloperMode(true); and all worked.
    – rosey85uk
    Commented Nov 20, 2015 at 16:48
1

Run the following script in the root to achieve the desired results:

<?php

// For all product:-
require_once 'app/Mage.php';
Mage::app('default');
$products = Mage::getModel('catalog/product')
            ->getCollection()
            ->addAttributeToSelect('*');

    foreach ($products as $product) {   
        $product->setPrice($product->getPrice() + 0.70);
        $product->save();
    }
// For some product:- 
require_once 'app/Mage.php';
Mage::app('default');
$product_id =  1, 2,3 ...;
$products = Mage::getModel('catalog/product')
            ->getCollection()
            ->addAttributeToSelect('*')
            ->addFieldToFilter('entity_id',array($product_id)); // pass the product id's in array   
    foreach ($products as $product) {   
        $product->setPrice($product->getPrice() + 0.70);
        $product->save();
    }

?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.