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.
-
Open the global.php file in the /storeadmin/ folder.
-
Find the following code, around line 88:
// Update sale prices else if ($mode == "saleprice") { -
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]); } ?> -
Find the following code, almost at the bottom of the page:
} include("includes/links2.php"); -
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)) { ?>(Note that this goes above the last closing bracket before the include.)
-
Save and upload the changed file.
-
Select 'Default Items' in the storeadmin area.
-
Select as a default product the item that has the options you want to copy from.
-
Select 'Global Updates' in the storeadmin area.
-
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.