1

I have created a module inside admin, which is based on Gold rates, if admin update the gold rates for specific Carat then it will update the prices for that Carat products.

Now my problem is that, if there are less no. of products like 400, it is working fine, but when there are around 2000 products it updates the few products and then gives the 500 internal server error.

I have written the code as per the guidelines mentioned in the URL:http://www.atwix.com/magento/working-with-large-collections/

Please Please suggest, and help me.

1

Seems like this error might be due to keep-alive setting or also the php max execution time, check your apache/nginx error log and php error log as well. You can change the php max execution time within your observer, altough I would not recomend it, at least try it with:

ini_set('max_input_time', 3600);

Also check apache or nginx keep alive.

And if it's possible to optimize your update script try to begin with that.

| improve this answer | |
  • Thanks lloiacono, ini_set didn't work for me, the only solution which worked is to optimize the update script, I am adding the solution in the answer, hope it helps to others too. – Ankur Jain Jul 30 '15 at 11:18
  • @AnkurJain : i have also 500 server error, only i get when i export my product – Gem Jul 25 '16 at 4:45
  • @Jeeva Rthinam: Please check the error log, and also check the memory_limit & max execution time, hope this will resolve your problem. – Ankur Jain Jul 26 '16 at 9:31
0
    $write_connection = $this->_getConnection('core_write');            
                    $price_attribute_id = $this->_getAttributeId();
                    $attribute_table = $this->_getTableName('catalog_product_entity_decimal');

    $price_array = array("1002"=>12.00,"500"=>100.12); // price array corresponding to product id

$collection = Mage::getModel('product/catalog')->getCollection(); // Product collection object

// Below function is to iterate through collection faster than foreach
// passed some object like write connection, price attribute id so that we need not to create object everytime iterator will loop

Mage::getSingleton('core/resource_iterator')->walk(
                $collection->getSelect(),
                array(array($this, 'productCallback')),
                array('post' => $price_array,'write_connection'=>write_connection ,'price_attribute_id '=>$price_attribute_id ,'attribute_table'=>$attribute_table 
                      )
            );

function productCallback($args)
{
$product = Mage::getModel('catalog/product');
$product->setData($args['row']);
$data = $args['post'];
$product_id = $product->getId();


$write_connection = $args['write_connection'];

$price_attribute_id = $args['price_attribute_id'];
$attribute_table = $args['attribute_table '];

if($data[$product_id])
                        {
                            $sql = "UPDATE " .$attribute_table . " cped
                            SET  cped.value = '".$data[$product->getId()]."'
                            WHERE  cped.attribute_id = ".$price_attribute_id."
                            AND cped.entity_id = ".$product_id;

                         $write_connection->query($sql);


                        }                                                   
}
| improve this answer | |

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.