Created
November 20, 2015 15:53
-
-
Save molotovbliss/dac4c4958e79e82b2fd9 to your computer and use it in GitHub Desktop.
Update Product Price Programmatically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Answer for: https://magento.stackexchange.com/questions/90946/script-to-update-product-prices-for-certain-product-types/90948