Exemplo n.º 1
0
     $smarty->assign("admin_sub_dpt", "error_forbidden.tpl");
 } else {
     if (isset($_GET["save_successful"])) {
         //update was successful
         $smarty->assign("save_successful", ADMIN_UPDATE_SUCCESSFUL);
     }
     if (isset($_POST["save_values"])) {
         if (CONF_BACKEND_SAFEMODE) {
             Redirect(ADMIN_FILE . "?dpt=catalog&sub=extra&optionID=" . $_POST["optionID"] . "&safemode=yes");
         }
         // update existing values
         $updateOptions = ScanPostVariableWithId(array("sort_order", "option_value"));
         optUpdateOptionValues($updateOptions);
         // add new value
         if (isset($_POST["add_value"]) && trim($_POST["add_value"]) != "") {
             optAddOptionValue($_POST["optionID"], $_POST["add_value"], (int) $_POST["add_sort"]);
         }
         Redirect(ADMIN_FILE . "?dpt=catalog&sub=extra&optionID=" . $_POST["optionID"]);
     }
     if (isset($_POST["save_options"])) {
         if (CONF_BACKEND_SAFEMODE) {
             Redirect(ADMIN_FILE . "?dpt=catalog&sub=extra&safemode=yes");
         }
         //save existing
         $updateOptions = ScanPostVariableWithId(array("extra_option", "extra_sort"));
         //now update database
         optUpdateOptions($updateOptions);
         //add a new option
         if (isset($_POST["add_option"])) {
             optAddOption($_POST["add_option"], $_POST["add_sort"]);
         }
Exemplo n.º 2
0
function _importExtraOptionValues($row, $productID, $updated_extra_option)
{
    /* var_dump($updated_extra_option);
    
          var_dump($row); */
    //now setup all product's extra options
    for ($j = 0; $j < count($updated_extra_option); $j++) {
        if (isset($updated_extra_option[$j]) && $updated_extra_option[$j]) {
            //a column which is an extra option
            $optionID = $updated_extra_option[$j];
            $curr_value = trim($row[$j]);
            $default_variantID = 0;
            if (strpos($curr_value, "{") === 0 && strpos($curr_value, "}") == strlen($curr_value) - 1) {
                //is it a selectable value?
                $curr_value = substr($curr_value, 1, strlen($curr_value) - 2);
                $values_options = explode(",", $curr_value);
                //delete all current product option configuration
                db_query("delete from " . PRODUCT_OPTIONS_VALUES_TABLE . " where optionID=" . (int) $optionID . " and productID=" . (int) $productID);
                db_query("delete from " . PRODUCTS_OPTIONS_SET_TABLE . " where optionID=" . (int) $optionID . " and productID=" . (int) $productID);
                foreach ($values_options as $key => $val) {
                    if (strstr($val, "=")) {
                        // current value is "OPTION_NAME=SURCHARGE", e.g. red=3, xl=1, s=-1, m=0
                        $a = explode("=", $val);
                        $val_name = $a[0];
                        $val_surcharge = (double) $a[1];
                    } else {
                        // current value is a option value name, e.g. red, xl, s, m
                        $val_name = $val;
                        $val_surcharge = 0;
                    }
                    //search for a specified option value in the database
                    $variantID = optOptionValueExists($optionID, $val_name);
                    if (!$variantID) {
                        //does not exist => add new variant value
                        $variantID = optAddOptionValue($optionID, $val_name, 0);
                    }
                    if (!$default_variantID) {
                        $default_variantID = $variantID;
                    }
                    //now append this variant value to the product
                    db_query("insert into " . PRODUCTS_OPTIONS_SET_TABLE . " (productID, optionID, variantID, price_surplus) " . " values (" . (int) $productID . ", " . (int) $optionID . ", " . (int) $variantID . ", " . xEscSQL($val_surcharge) . ");");
                }
                //assign default variant ID - first option in the variants list is default
                if ($default_variantID) {
                    db_query("insert into " . PRODUCT_OPTIONS_VALUES_TABLE . " (optionID, productID, option_type, option_show_times, variantID) " . " values (" . (int) $optionID . ", " . (int) $productID . ", 1, 1, " . (int) $default_variantID . ")");
                }
            } else {
                // a custom fixed value
                db_query("delete from " . PRODUCT_OPTIONS_VALUES_TABLE . " where optionID=" . (int) $optionID . " and productID=" . (int) $productID);
                db_query("insert into " . PRODUCT_OPTIONS_VALUES_TABLE . " (optionID, productID, option_value) " . " values (" . (int) $optionID . ", " . (int) $productID . ", '" . xEscSQL($curr_value) . "')");
            }
        }
    }
}