0

i want to increase my products price in magento

foreach ($prodCollection as $product) {
    echo $product->getName() .'<br>';
    echo "old: " . $product->getPrice() .'<br>';
    $newPrice = ($product->getPrice() * 1.3);
    $product->setPrice("price",$newPrice);
    $product->save();
    echo "new: " . $product->getPrice();
    echo '<br><br><br><br>';
}

and this is my code but icant update price and get this error

Fatal error: Uncaught TypeError: Argument 3 passed to Mage_Catalog_Model_Resource_Abstract::_canUpdateAttribute() must be of the type array, null given

0
0

Just Create priceupdate.php file on root directory of your website and paste below code in your file and run this file in browser. all prices should be increased 5%. you can also change 1.05 according to your needs, how much to want increase prices for your products. and below code for some products, you can update that var with category_id.

// For all product:-
require 'app/Mage.php'; Mage::app();

$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$write->query("
UPDATE catalog_product_entity_decimal val
SET  val.value = (val.value * 1.05)
WHERE  val.attribute_id = (
SELECT attribute_id FROM eav_attribute eav
WHERE eav.entity_type_id = 4
AND eav.attribute_code = 'price'
")


// 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();
    }
2
  • how can i do this for specific category products - e.g category id =4 – majid Mar 6 '18 at 14:18
  • i add code for specific products. you can modify according to your needs. – Wajahat Bashir Mar 7 '18 at 4:56
2

You should replace $product->setPrice("price",$newPrice); to $product->setPrice($newPrice);. Then check is your issue solved or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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