Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Integrity constraint violation: 1062 for key ‘PRIMARY
 
ppareek
Jr. Member
 
Total Posts:  6
Joined:  2009-10-26
jaipur
 

Hello

I am trying to update product quantity via cron below is the function :

public function manageStockByCron() {
        
        $_productsCollection 
Mage::getResourceModel(\\\\\\\'catalog/product_collection\\\\\\\')->load();
        
$i 0;
        foreach(
$_productsCollection as $_product)
            $productObj 
Mage::getModel(\\\\\\\'catalog/product\\\\\\\')->load($_product->getId());
            
            
            
$this->_productInstance $productObj;
            
$supplierQuantity $this->getSupplierStockQuantity();
            
            if((
is_array($supplierQuantity) && $supplierQuantity[\\\\\\\'have_error\\\\\\\'!= true) || $productObj->getTypeId() == \\\\\\\'simple\\\\\\\'{
            
                
// get product\\\\\\\'s stock data such quantity, in_stock etc
                
$stockData $productObj->getStockData();
                
                
// update stock data using new data
                
if(isset($supplierQuantity[\\\\\\\'qty\\\\\\\']) && $supplierQuantity[\\\\\\\'qty\\\\\\\'0):            
                    
$stockData[\\\\\\\'qty\\\\\\\'$supplierQuantity[\\\\\\\'qty\\\\\\\'];
                    
$stockData[\\\\\\\'is_in_stock\\\\\\\'1;
                else:
                    
$stockData[\\\\\\\'qty\\\\\\\'0;
                    
$stockData[\\\\\\\'is_in_stock\\\\\\\'0;
                endif;    

                
// then set product\\\\\\\'s stock data to update
                
$productObj->setStockData($stockData);

                
// call save() method to save your product with updated data
                
$productObj->save();
            
}
        }
        
        
for ($j 1$j <= 9$j++) {
            $process 
Mage::getModel(\\\\\\\'index/process\\\\\\\')->load($j);
            
$process->reindexAll();
        
}
        
    }

But i am getting this error

exception \\\\\\\’PDOException\\\\\\\’ with message \\\\\\\’SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry \\\\\\\’44-70-1-109\\\\\\\’ for key \\\\\\\’PRIMARY\\\\\\\’\\\\\\\’ in lib/Zend/Db/Statement/Pdo.php:228

I tried a lot to resolve the issue but not getting suceess ...

Pls .... Pls Help !!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top