I feel close with my solution (but I may be way off knowing my luck) I am attempting to write a simple php script to update all prices in a specific category within Magento. Below is my code please help me out. The problem is it won't return any results. If I take out the sections that refer specifically to category it runs fine against every product.
<?php
require 'app/Mage.php'; Mage::app();
$products = Mage::getModel('catalog/product')->getCollection()
->addStoreFilter()
->addAttributeToSelect('name')
->addAttributeToSelect('price')
;
$_products = Mage::getModel('catalog/product')->load($productId);
$_category = $_products->getCategoryId();
if($_category == 5){
foreach ($products as $product) {
echo $product->getName() .'<br>';
echo "old: " . $product->getPrice() .'<br>';
$newPrice = ($product->getPrice() * 1.3);
$product->setPrice($newPrice);
$product->save();
echo "new: " . $product->getPrice();
echo '<br><br><br><br>';
}
} else { echo "No Results";
}
?>
Latest modifications. Cleaned out the garbage from the above code and it is still missing something. I have searched all over for an answer to this. Again works if the if statement is removed. Thank you
<?php
require 'app/Mage.php'; Mage::app();
$products = Mage::getModel('catalog/category')
->load($category_id)
->getProductCollection()
->addAttributeToSelect('*');
if($category_id == 5){
foreach($products as $product) {
echo $product->getName() .'<br>';
echo "old: " . $product->getPrice() .'<br>';
$newPrice = ($product->getPrice() * 1.3);
$product->setPrice($newPrice);
$product->save();
echo "new: " . $product->getPrice();
echo '<br><br><br><br>';
}
} else { echo "No Results";
}
?>