3 replies [Last post]
Mariano's picture
Offline
Joined: 09/04/2007
Juice: 110
Was this information Helpful?

Hi =)

I want to reorganize the current inventory, including a change for every product's sku. I want a new sequence to keep better track of the products (ca. 80), and new sku's for new attributes which will represent the desired carrier/provider. Does changing the sku's would bring any problems? Would it cause errors to the past orders (fulfilled) or the ones that are currently in process? How would it be better to do it? Directly from the database, or one by one from the product's edit mode?

Thanks for any help!

Regards.

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: SKU Updates

Changing the SKUs won't affect the orders created before the change. The only thing that might affect is reports over both time periods. Without knowing exactly how uc_reports work, it may or may not consider two SKUs two different products if the nids are the same. Probably since uc_attribute would cause the same kind of situation.

Products that are still in someone's cart will still use the SKU defined by uc_attribute's adjustments when they were added to the cart.

I have no idea how any of this would affect any stock tracking modules you might have.

cfab's picture
Offline
Joined: 06/30/2009
Juice: 70
Hi, I'm experiencing this

Hi,

I'm experiencing this problem, with remanent old SKUs in stock report.
I've installed Product Power Tools and put the auto-sku generation on, which overrided my old manually set SKUs, but now I've the new and the old entry in the report.

Except from doing this directly in the DB, Is there a way to remove old entries from this report?

Regards,
cfab

cfab's picture
Offline
Joined: 06/30/2009
Juice: 70
a solution

Well, if someone needs the same cleaning, I've written this function which could be integrated in uc_stock.admin.inc :

<?php
/**
* Table cleaner, this function detects non existent SKUs still present in stock management
*
*/
function uc_stock_clean() {

   

$sku=array();
   
$removed=array();

   

drupal_set_title(t("Stock Clean"));

   

// we get sku which are present in products table
   
$sql="
    SELECT s.sku FROM {uc_product_stock} s
    INNER JOIN {uc_products} p
    ON s.sku=p.model AND s.nid=p.nid
    ORDER BY p.model;
    "
;
   
   
$result=db_query($sql);
   
// we parse the result to fill the correct sku array
   
while ($tab=db_fetch_array($result)){
       
$sku[]=(string)$tab["sku"];
    }
       
   
// we get sku which are present in products variations table
   
$sql="SELECT s.sku FROM {uc_product_stock} AS s INNER JOIN {uc_product_adjustments} AS p ON (s.sku=p.model AND s.nid=p.nid) ORDER BY p.model;";
   
$result=db_query($sql);
   
// we parse the result to fill the correct sku array
   
while ($tab=db_fetch_array($result)){
       
$sku[]=(string)$tab["sku"];
    }
       
   
// now we have a complete existent sku array, we will delete others
   
$sql="SELECT sku FROM {uc_product_stock};";
   
$result=db_query($sql);
   
// we parse the result to fill the correct sku array
   
while ($tab=db_fetch_array($result)){
        if (!
in_array($tab["sku"],$sku,TRUE)){
           
db_query("DELETE FROM {uc_product_stock} WHERE sku='".$tab["sku"]."'");
           
$removed[]=$tab["sku"];
        }
       
    }
 
     
// we inform of what was done
   
if (count($removed)>0) {
       
$removed = implode(", ", $removed);
       
drupal_set_message(t('The following SKUs were updated: %removed .', array('%removed' => $removed)));
        }
    else {
       
drupal_set_message(t('No SKUs were updated.'));
    }
   
}
?>

and for the menu part, in admin.module, just add to uc_stock_menu this item :

<?php
  $items
['admin/store/settings/stock/clean'] = array(
   
'title' => 'Stock clean',
   
'description' => 'Clean the stock table.',
   
'page callback' => 'drupal_get_form',
   
'page arguments' => array('uc_stock_clean'),
   
'access arguments' => array('administer product stock'),
   
'type' => MENU_NORMAL_ITEM,
   
'file' => 'uc_stock.admin.inc',
  );
?>