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

Magento blows up with sql updates
 
spencer321
Jr. Member
 
Total Posts:  8
Joined:  2008-02-13
Chico, CA
 

I have a ton of skus to import, but I couldn’t figure out how to set the attribute_set_id or the is_in_stock using the import file.  So I just imported the skus with as much data as I could figure out and figured I would just update the tables on my own afterward.  I updated the attribute_set_id for the skus I wanted, afterwich I was able to view the attribute fields just fine via the admin console.  But then I tried updating the cataloginventory_stock_item table, setting is_in_stock = 1 and everything blew up.  For a few minutes I wasn’t able to get back into the admin console, was getting page could not be displayed.  but now it looks like i can so i will try restoring to backup.

It would be helpful to have a table schema and some advise about what we should and should not try to do using sql queries.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mark_Kimsal
Sr. Member
 
Total Posts:  186
Joined:  2007-09-12
Michigan, USA
 

A.) to set the attribute, you just put the attribute_set name in a field, not the attribute_set_id

B.) I know, setting the quantity can’t be done yet through the import/export.

C.) it’s much easier to create a tiny little magento script that loads all the libraries properly than to do SQL (trust me)

Here’s a shell

<?php

require_once 'app/Mage.php';

umask(0);
$_SERVER['SERVER_PORT']='443';
Mage::app('base');

// do your library calls here

Notice that “Mage::run(’base’)” has been changed to “Mage::app(’base’)”.  Mage::app() simply loads all the libraries necessary and doesn’t execute a full request.  The server port line is necessary if you are running this from the command line and are trying to do admin type things.

Finally, this is the SQL I used to update the stock and it didn’t blow up for me.

$product Mage::getModel('catalog/product');
$read $product->getResource()->getWriteConnection();
$rs $read->query('select `entity_id` FROM `catalog_product_entity`"' );
 while  (
$row $rs->fetch() ) {
    $categoryIds[] 
$row['entity_id'];
  
}
  
foreach ($categoryIds as $entity_id{
   $read
->query'INSERT INTO cataloginventory_stock_item
    (`product_id`,`stock_id`,`qty`,`is_in_stock`) 
    VALUES ( '
.$entity_id.', 1, 99999, 1)' ); 
  
}

$read should probably be called “$write”.  Throw a try catch around the insert and put an update in the catch if you want to do consecutive updates of this.  Oh, and paste the top script onto the top of this one, save it in the same dir as index.php

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