2

The following piece of code provided by SuperDicq Remove products from all categories when price is zero) gives me a HTTP 500 error, anyone knows what's wrong?

I changed the name of htaccess, put memory limit on 1024mb. I have other scripts which are causing no problems. Also when I add this one below they start giving errors as well.

 require_once 'app/Mage.php';
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
Mage::app();
$products = Mage::getModel('catalog/product')->getCollection()
 ->addAttributeToFilter(
 array(
 array('attribute'=>'price', 'eq'=>'0'),
 array('attribute'=>'price', 'isnull'=>true),
 )
);
$category_id = 863; // "Old models" category ID.
foreach($products as $product) {
 $product->setCategoryIds($category_id);
 $product->save();
}
asked Mar 14, 2019 at 9:45
3
  • 1
    Is this script on your magento root ? Commented Mar 14, 2019 at 9:52
  • 1
    Isn't there anything in your log files? 500 server errors could also imply errors on your webserver (httpd/nginx), so it would make sense to check those as well besides your Magento log files. Commented Mar 14, 2019 at 10:02
  • Yes it's in the root. Can't find any error in the logs when I turn error reporting on Commented Mar 14, 2019 at 10:05

2 Answers 2

1

HTTP 500 Error can occur due to the file permission also..i have the same issue today..

check that the file have proper file permission..

php file need a 644 permission..

please try this..

answered Mar 14, 2019 at 10:57
1
  • Thanks for your reply, unfortunately it's already on 644 :( Commented Mar 14, 2019 at 12:10
0

I had the same issue and found out that, in my case it was due to large sets of data.

Ended up adding:

->setPageSize(X) ->setCurPage(1);

To the collection. I simply started by adding a small number to setPageSize() eg. X = 100 and then slowlyg worked my way up till I found a higher number, that didn't cause error 500.

It might be some settings that needs to be changed, but for now this can resolve the issue.

answered Oct 27, 2020 at 19:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.