Skip to content

Instantly share code, notes, and snippets.

@molotovbliss
Created November 20, 2015 15:53
Show Gist options
  • Save molotovbliss/dac4c4958e79e82b2fd9 to your computer and use it in GitHub Desktop.
Save molotovbliss/dac4c4958e79e82b2fd9 to your computer and use it in GitHub Desktop.
Update Product Price Programmatically
<?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 {
$productModel = Mage::getModel('catalog/product');
// 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->addAttributeToSelect('*')->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);
}
@molotovbliss
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment