Globally update options (v. 2.83)

The following modification adds the ability to globally update options for items in a particular category to match the options of your default product. Please note that this modification will reset all options for items in that category, and will delete all inventory counts from the products that are getting updated. We strongly recommend backing up your database every time you use this update.

  1. Open the global.php file in the /storeadmin/ folder.

  2. Find the following code, around line 88:

    // Update sale prices
    else if ($mode == "saleprice")
    {
  3. Just above this code, add the following code:

    // DEFAULT ITEM WITH OPTIONS
    $glob_opt_err = (isset($optcatid) AND empty($optcatid)) ? "Please select a category" : "";
    list($default_id, $default_item, $default_options) = array(0, '', '');
    $defaultitem = mysql_query("SELECT i.ID, Item FROM " .SB_DB_PREFIX ."_vars v LEFT JOIN " .SB_DB_PREFIX ."_items i ON i.ID=v.DefaultProduct", $dblink) or die ("Unable to select. Try again later.");
    if (mysql_num_rows($defaultitem) == 1)
    {
    $defaultrow = mysql_fetch_array($defaultitem);
    // IF SO, GET OPTIONS
    $getoptions = mysql_query("SELECT GROUP_CONCAT(DISTINCT CONCAT(Name, ' (', Type, ') ', Attributes, '-Active=', LEFT(Active, 1)) ORDER BY ID SEPARATOR ';') AS group_options FROM " .SB_DB_PREFIX ."_options WHERE ItemID=" .(int)$defaultrow[ID], $dblink) or die ("Unable to select. Try again later.");
    $getoptrow = mysql_fetch_array($getoptions);
    // DEFAULT ITEM HAS OPTIONS
    if (!empty($getoptrow[group_options]))
    list($default_id, $default_item, $default_options) = array($defaultrow[ID], stripslashes($defaultrow[Item]), explode(';', $getoptrow[group_options]));
    }
    
    // UPDATE OPTIONS
    $default_id = (int)$default_id;
    if (($set_master_key == "yes" OR $show_uploads == "Yes") AND !empty($default_id) AND !empty($default_item) AND !empty($default_options) AND !empty($optcatid))
    {
    $optcatid = (int)$optcatid;
    // HOW MANY ITEMS?
    $oitems = mysql_query("SELECT ID, Item FROM " . SB_DB_PREFIX . "_items WHERE (Category" .implode("=$optcatid OR Category", range(1,15)) ."=$optcatid) AND id<>".$default_id);
    $oitemnum = mysql_num_rows($oitems);
    
    // UPDATE OPTIONS
    if ($upd == 'y')
    {
    // REMOVE ALL INVENTORY	
    $updiinv = mysql_query("UPDATE " . SB_DB_PREFIX . "_items SET Inventory=NULL WHERE (Category" .implode("=$optcatid OR Category", range(1,15)) ."=$optcatid) AND ID<>$default_id", $dblink);
    $deliinv = mysql_query("DELETE v FROM " . SB_DB_PREFIX . "_inventory v LEFT JOIN " . SB_DB_PREFIX . "_items i ON v.ProductID=i.ID WHERE (Category" .implode("=$optcatid OR Category", range(1,15)) ."=$optcatid) AND i.ID<>$default_id", $dblink);
    // REMOVE ALL OPTIONS
    $deliinv = mysql_query("DELETE o FROM " . SB_DB_PREFIX . "_options o LEFT JOIN " . SB_DB_PREFIX . "_items i ON o.ItemID=i.ID WHERE (Category" .implode("=$optcatid OR Category", range(1,15)) ."=$optcatid) AND i.ID<>$default_id", $dblink);
    // SELECT DEFAULT ITEM'S OPTIONS
    $getopts = mysql_query("SELECT * FROM " . SB_DB_PREFIX . "_options WHERE ItemID=$default_id", $dblink);
    while ($getorow=mysql_fetch_array($getopts))
    {
    $getonum = (int)$getorow[OptionNum];
    $getoname = addslash_mq($getorow[Name]);
    $getotype = addslash_mq($getorow[Type]);
    $getoatts = addslash_mq($getorow[Attributes]);
    $getoactive = addslash_mq($getorow[Active]);
    // UPDATE OPTIONS TO MATCH DEFAULT ITEM
    $updopt = mysql_query("INSERT INTO opc_options (ItemID, OptionNum, Name, Type, Attributes, Active) SELECT i.ID, $getonum, '$getoname', '$getotype', '$getoatts', '$getoactive' FROM opc_items i WHERE (Category" .implode("=$optcatid OR Category", range(1,15)) ."=$optcatid) AND i.ID<>$default_id", $dblink);
    }
    $glob_opt_err = "Options were updated in $oitemnum item(s).";
    }
    
    // OTHERWISE, SHOW FORM
    else
    {
    $mode = 'options';
    $showitemlists = array();
    while($oirow = mysql_fetch_array($oitems))
    {
    $showitemlists[] = stripslashes($oirow[Item]);
    }
    ?>
    
    Update Options
    0) { $ocrow = mysql_fetch_array($ocat); echo "

    You are going to change the following $oitemnum item(s) in the category " . stripslashes($ocrow[Category]) . ":

    ".implode(', ', $showitemlists)."

    to have the following options:

    "; foreach($default_options AS $optval) { $getactive = explode('-Active=', $optval); $optinfo = str_replace('~', ', ', stripslashes($getactive[0])); if ($getactive[1] == 'N') echo "$optinfo
    "; else echo $optinfo."
    "; } echo "

    Any inventory counts for these items will be permanently removed.

    Do you want to continue?

    Yes No

    "; } else echo "

    Your options could not be updated.

    "; ?>
  4. Find the following code, almost at the bottom of the page:

    }
    
    include("includes/links2.php");
  5. Just above this code, add the following code:

    if (($set_master_key == "yes" OR $show_uploads == "Yes") AND !empty($default_id) AND !empty($default_item) AND !empty($default_options))
    {
    ?>
    
    Update Options
    $glob_opt_err

    "; ?>

    Update all options in the following category:

    Select Category: "; echo ""; setcategories(0, 0, "", "  ", "- ", "", "catitem", 0, 0, "", "yes", "no", "no"); echo ""; ?>

    With the options from the default product:

    This process will completely modify the product options and remove all inventory counts in the selected category. Please make sure to back up first.

    (Note that this goes above the last closing bracket before the include.)

  6. Save and upload the changed file.

  7. Select 'Default Items' in the storeadmin area.

  8. Select as a default product the item that has the options you want to copy from.

  9. Select 'Global Updates' in the storeadmin area.

  10. At the bottom of the page, under 'Update Options', select the category that contains the items with options that you want to update, and click 'Update Options'. Note that options for all items in that category will be updated.