Ejemplo n.º 1
0
/**
 * Add to cart product with options
 *
 * @param int $productID
 * @param array $variants  - row is variantID
 * @param int $qty
 */
function cartAddToCart($productID, $variants, $qty = 1, $sample = 0)
{
    if ($qty === '') {
        $qty = 1;
    }
    $qty = max(0, intval($qty));
    $productID = intval($productID);
    $product_data = GetProduct($productID);
    if (!$product_data['ordering_available']) {
        return false;
    }
    if (!$product_data['enabled']) {
        return false;
    }
    $is = intval($product_data['in_stock']);
    $min_order_amount = $product_data['min_order_amount'];
    //$min_order_amount = db_phquery_fetch(DBRFETCH_FIRST, "SELECT min_order_amount FROM ?#PRODUCTS_TABLE WHERE productID=?", $productID );
    if (!isset($_SESSION["log"])) {
        //save shopping cart in the session variables
        //$_SESSION["gids"] contains product IDs
        //$_SESSION["counts"] contains product quantities
        //($_SESSION["counts"][$i] corresponds to $_SESSION["gids"][$i])
        //$_SESSION["configurations"] contains variants
        //$_SESSION[gids][$i] == 0 means $i-element is 'empty'
        if (!isset($_SESSION["gids"])) {
            $_SESSION["gids"] = array();
            $_SESSION["counts"] = array();
            $_SESSION["configurations"] = array();
            $_SESSION["sample"] = array();
        }
        //check for current item in the current shopping cart content
        $item_index = SearchConfigurationInSessionVariable($variants, $productID);
        if ($item_index != -1) {
            //increase current product's quantity
            /*if($_SESSION["counts"][$item_index]+$qty<$min_order_amount){
            	 $qty=$min_order_amount-$_SESSION["counts"][$item_index];
            	 }*/
            //$qty = max($qty,$min_order_amount - $_SESSION["counts"][$item_index],0);
            if (CONF_CHECKSTOCK != 0) {
                $qty = min($qty, $is - $_SESSION["counts"][$item_index]);
            }
            $qty = max($qty, 0);
            $_SESSION["sample"][$item_index] = $sample;
            if (CONF_CHECKSTOCK == 0 || $_SESSION["counts"][$item_index] + $qty <= $is && $is && $qty) {
                if ($sample) {
                    $_SESSION["counts"][$item_index] = 1;
                } else {
                    $_SESSION["counts"][$item_index] += $qty;
                }
            } else {
                return $_SESSION["counts"][$item_index];
            }
        } else {
            //no item - add it to $gids array
            $qty = max($qty, $min_order_amount, 0);
            if (CONF_CHECKSTOCK != 0) {
                $qty = min($qty, $is);
            }
            $qty = max($qty, 0);
            if ($sample) {
                $qty = 1;
            }
            $_SESSION["sample"][] = $sample;
            if (CONF_CHECKSTOCK == 0 || $is >= $qty && $qty) {
                $_SESSION["gids"][] = $productID;
                $_SESSION["counts"][] = $qty;
                $_SESSION["configurations"][] = $variants;
                cartUpdateAddCounter($productID);
            } else {
                return 0;
            }
        }
    } else {
        //authorized customer - get cart from database
        $itemID = SearchConfigurationInDataBase($variants, $productID);
        $customerEntry = Customer::getAuthedInstance();
        if (is_null($customerEntry)) {
            return false;
        }
        if ($itemID != -1) {
            // if this configuration exists in database
            $quantity = db_phquery_fetch(DBRFETCH_FIRST, "SELECT Quantity FROM ?#SHOPPING_CARTS_TABLE WHERE customerID=? AND itemID=?", $customerEntry->customerID, $itemID);
            /*if($quantity+$qty<$min_order_amount){
            	 $qty=$min_order_amount-$quantity;
            	 }*/
            //$qty = max($qty,$min_order_amount - $quantity);
            if (CONF_CHECKSTOCK != 0) {
                $qty = min($qty, $is - $quantity);
            }
            $qty = max($qty, 0);
            if (CONF_CHECKSTOCK == 0 || $quantity + $qty <= $is && $is) {
                if ($sample) {
                    db_phquery("UPDATE ?#SHOPPING_CARTS_TABLE SET Quantity=?, sample=? WHERE customerID=? AND itemID=?", 1, $sample, $customerEntry->customerID, $itemID);
                } else {
                    db_phquery("UPDATE ?#SHOPPING_CARTS_TABLE SET Quantity=?, sample=? WHERE customerID=? AND itemID=?", $quantity + $qty, $sample, $customerEntry->customerID, $itemID);
                }
            } else {
                return $quantity;
            }
        } else {
            //insert new item
            $qty = max($qty, $min_order_amount);
            if (CONF_CHECKSTOCK != 0 && $qty > $is) {
                $qty = min($qty, $is);
            }
            if ($sample) {
                $qty = 1;
            }
            if ((CONF_CHECKSTOCK == 0 || $is >= $qty) && $qty > 0) {
                $itemID = InsertNewItem($variants, $productID);
                InsertItemIntoCart($itemID);
                if ($sample) {
                    db_phquery("UPDATE ?#SHOPPING_CARTS_TABLE SET Quantity=?, sample=? WHERE customerID=? AND itemID=?", 1, $sample, $customerEntry->customerID, $itemID);
                } else {
                    db_phquery("UPDATE ?#SHOPPING_CARTS_TABLE SET Quantity=?, sample=? WHERE customerID=? AND itemID=?", $qty, $sample, $customerEntry->customerID, $itemID);
                }
                cartUpdateAddCounter($productID);
            } else {
                return 0;
            }
        }
    }
    //db_phquery("UPDATE ?#PRODUCTS_TABLE SET add2cart_counter=(add2cart_counter+1) WHERE productID=?",$productID);
    return true;
}
 /**
  * Emulate cartGetCartContent function not fully: doesnt fill feight_cost
  *
  * @return array: (cart_content, total_price, freight_cost)
  */
 function emulate_cartGetCartContent()
 {
     $cart_content = array();
     $freight_cost = 0;
     $r_aItem = $this->Items->getChildNodes('item');
     foreach ($r_aItem as $aItem) {
         /* @var $aItem xmlNodeX */
         $aProduct =& $aItem->getFirstChildByName('product');
         $aPrice =& $aItem->getFirstChildByName('price');
         $product = GetProduct($aProduct->attribute('id'));
         $strOptions = GetStrOptions($this->emulate_GetConfigurationByItemId($aItem));
         if (trim($strOptions) != '') {
             $product['name'] .= '  (' . $strOptions . ')';
         }
         $sample = $aItem->getChildData('sample');
         if ($sample == 1) {
             $product['name'] .= " [SAMPLE]";
             $q_sample_price = db_phquery('SELECT sample_price FROM SC_categories WHERE categoryID=(SELECT categoryID FROM SC_products WHERE productID=?)', $aProduct->attribute('id'));
             $sample_price = db_fetch_assoc($q_sample_price);
             $costUC = $sample_price["sample_price"];
             $quantity = 1;
             $cost = show_price($quantity * PaymentModule::_convertCurrency($costUC, $aPrice->attribute('currency'), 0), 0);
             $free_shipping = 1;
         } else {
             $costUC = $aPrice->getData();
             $cost = show_price($aItem->getChildData('quantity') * PaymentModule::_convertCurrency($aPrice->getData(), $aPrice->attribute('currency'), 0), 0);
             $quantity = $aItem->getChildData('quantity');
             $free_shipping = $aProduct->attribute('free-shipping');
         }
         $cart_content[] = array('productID' => $aProduct->attribute('id'), 'id' => $aItem->attribute('id') ? $aItem->attribute('id') : 0, 'name' => $product['name'], 'quantity' => $quantity, 'free_shipping' => $free_shipping, 'costUC' => $costUC, 'cost' => $cost, 'product_code' => $product['product_code']);
         $aFreight = $aProduct->getFirstChildByName('freight');
         if (!is_null($aFreight)) {
             $freight_cost += $aItem->getChildData('quantity') * virtualModule::_convertCurrency($aFreight->getData(), $aFreight->attribute('currency'), 0);
         }
     }
     $cart = array('cart_content' => $cart_content, 'total_price' => $this->calculateTotalPrice(), 'freight_cost' => $freight_cost);
     return $cart;
 }
        }
        $k += $price;
        $cnt += $quantity;
    }
} elseif (isset($_SESSION["gids"])) {
    //...session vars
    for ($i = 0; $i < count($_SESSION["gids"]); $i++) {
        if (!$_SESSION["gids"][$i]) {
            continue;
        }
        $sum = db_phquery_fetch(DBRFETCH_FIRST, "SELECT Price FROM ?#PRODUCTS_TABLE WHERE productID=?", $_SESSION["gids"][$i]);
        foreach ($_SESSION["configurations"][$i] as $var) {
            $sum += db_phquery_fetch(DBRFETCH_FIRST, "SELECT price_surplus FROM ?#PRODUCTS_OPTIONS_SET_TABLE WHERE variantID=? AND productID=?", $var, $_SESSION["gids"][$i]);
        }
        if ($_SESSION["sample"][$i]) {
            $quantity = 1;
            $q_sample_price = db_phquery('SELECT sample_price FROM SC_categories WHERE categoryID=(SELECT categoryID FROM SC_products WHERE productID=?)', $_SESSION["gids"][$i]);
            $sample_price = db_fetch_assoc($q_sample_price);
            $sum = $sample_price["sample_price"];
        } else {
            $quantity = $_SESSION["counts"][$i];
        }
        $k += $quantity * $sum;
        $cnt += $quantity;
    }
}
$d = oaGetDiscountValue(cartGetCartContent(), is_null($customerEntry) ? null : $customerEntry->Login);
$k = $k - $d;
$smarty->assign("shopping_cart_value", $k);
$smarty->assign("shopping_cart_value_shown", show_price($k));
$smarty->assign("shopping_cart_items", $cnt);
 if (!$a['picture'] && !$a['thumbnail']) {
     $a['picture'] = '';
     $a['thumbnail'] = '';
     $a['big_picture'] = '';
 }
 $a[12] = show_price($a["Price"]);
 $a[13] = show_price($a["list_price"]);
 $a[14] = show_price($a["list_price"] - $a["Price"]);
 //you save (value)
 $a["PriceWithOutUnit"] = show_priceWithOutUnit($a["Price"]);
 if ($a["list_price"]) {
     $a[15] = ceil(($a["list_price"] - $a["Price"]) / $a["list_price"] * 100);
     //you save (%)
 }
 $all_product_pictures = array();
 $dbres = db_phquery("SELECT * FROM ?#PRODUCT_PICTURES WHERE productID=? ORDER BY priority", $productID);
 while ($row = db_fetch_assoc($dbres)) {
     if (!$row['thumbnail'] || !file_exists(DIR_PRODUCTS_PICTURES . '/' . $row['thumbnail'])) {
         continue;
     }
     if (!$row['filename'] || !file_exists(DIR_PRODUCTS_PICTURES . '/' . $row['filename'])) {
         continue;
     }
     if ($row['enlarged'] && file_exists(DIR_PRODUCTS_PICTURES . '/' . $row['enlarged'])) {
         list($row['width'], $row['height']) = getimagesize(DIR_PRODUCTS_PICTURES . '/' . $row['enlarged']);
         $row['width'] += 40;
         $row['height'] += 30;
     } else {
         list($row['width'], $row['height']) = getimagesize(DIR_PRODUCTS_PICTURES . '/' . $row['filename']);
         $row['width'] += 40;
         $row['height'] += 30;
Ejemplo n.º 5
0
function psGetExtra($productID)
{
    if (!is_array($productID)) {
        $ProductIDs = array($productID);
        $IsProducts = false;
    } elseif (count($productID)) {
        $ProductIDs =& $productID;
        $IsProducts = true;
    } else {
        return array();
    }
    $extra = array();
    $sql = '
        SELECT
        v.productID,
        v.option_value,
        v.option_type,
        v.option_show_times,
        v.variantID,
        v.optionID,
        t.optionID,
        t.name
        FROM ?#PRODUCT_OPTIONS_VALUES_TABLE AS v
        LEFT JOIN  ?#PRODUCT_OPTIONS_TABLE AS t ON (t.optionID = v.optionID)
        WHERE v.productID IN (?@) ORDER BY  t.sort_order, t.name
        ';
    $q = db_phquery($sql, $ProductIDs);
    while ($row = db_fetch_assoc($q)) {
        if (($row['option_type'] == 0 || $row['option_type'] == NULL) && strlen(trim($row['option_value'])) > 0) {
            $extra[$row['productID']][$row['optionID']] = array('option_type' => $row['option_type'], 'name' => $row['name'], 'option_value' => $row['option_value'], 'optionID' => $row['optionID']);
            //if set Ресурс (стр)
            if ($row['optionID'] == 6) {
                $extra[$row['productID']][37] = array('option_type' => $row['option_type'], 'name' => 'Себестоимость печати', 'option_value' => $row['option_value'], 'optionID' => 37);
            }
        } else {
            if ($row['option_type'] == 1) {
                $sql = '
                SELECT
                v.option_value,
                v.variantID,
                o.price_surplus
                FROM ' . PRODUCTS_OPTIONS_SET_TABLE . ' AS o
                LEFT JOIN ' . PRODUCTS_OPTIONS_VALUES_VARIANTS_TABLE . ' AS v ON (v.variantID = o.variantID)
                WHERE v.optionID=' . $row['optionID'] . ' AND o.productID=' . $row['productID'] . ' AND v.optionID=' . $row['optionID'] . '
                ORDER BY v.sort_order, v.option_value';
                $q2 = db_query($sql);
                $row['values_to_select'] = array();
                $i = 0;
                while ($r = db_fetch_assoc($q2)) {
                    if ($r['variantID'] === $row['variantID']) {
                        $row['variant_name'] = $r['option_value'];
                    }
                    $row['values_to_select'][$i] = array();
                    $row['values_to_select'][$i]['variantID'] = $r['variantID'];
                    $row['values_to_select'][$i]['option_value'] = $r['option_value'];
                    // if ( $r['price_surplus'] > 0 )$row['values_to_select'][$i]['option_value'] .= ' (+ '.show_price($r['price_surplus']).')';
                    // elseif($r['price_surplus'] < 0 )$row['values_to_select'][$i]['option_value'] .= ' (- '.show_price(-$r['price_surplus']).')';
                    $row['values_to_select'][$i]['option_valueWithOutPrice'] = $r['option_value'];
                    $row['values_to_select'][$i]['price_surplus'] = show_priceWithOutUnit($r['price_surplus']);
                    $i++;
                }
                $row['values_to_select_count'] = count($row['values_to_select']);
                $extra[$row['productID']][$row['optionID']] = $row;
            }
        }
    }
    if (!$IsProducts) {
        if (!count($extra)) {
            return array();
        } else {
            return $extra[$productID];
        }
    }
    return $extra;
}
Ejemplo n.º 6
0
function &schOptionsAreSetToSearch($categoryID, &$options)
{
    $TC = count($options);
    $r_OptionID2Option = array();
    $r_OptionID = array();
    $r_OptionRes = array();
    for ($j = 0; $j < $TC; $j++) {
        $r_OptionID2Option[$options[$j]['optionID']] =& $options[$j];
        $r_OptionID[] = $options[$j]['optionID'];
        if (count($r_OptionID) > 299 || $j + 1 == $TC) {
            $SQL = 'select optionID,set_arbitrarily FROM ?#CATEGORY_PRODUCT_OPTIONS_TABLE
                                        WHERE categoryID=? AND optionID IN(?@)';
            $Result = db_phquery($SQL, (int) $categoryID, $r_OptionID);
            while ($Row = db_fetch_assoc($Result)) {
                $r_OptionRes[$Row['optionID']] = $Row['set_arbitrarily'];
            }
            $r_OptionID = array();
        }
    }
    return $r_OptionRes;
}
 function uninstall($_ConfigID = 0)
 {
     $_ConfigID = (int) $_ConfigID ? (int) $_ConfigID : $this->ModuleConfigID;
     parent::uninstall($_ConfigID);
     db_phquery('UPDATE ?#ORDERS_TABLE SET shipping_module_id=0 WHERE shipping_module_id=?', $_ConfigID);
 }
Ejemplo n.º 8
0
function _testExtraParametrsTemplate($productID, &$template)
{
    // get category ID
    $categoryID = $template["categoryID"];
    foreach ($template as $key => $item) {
        if (!isset($item["optionID"])) {
            continue;
        }
        if ((string) $key == "categoryID") {
            continue;
        }
        // get value to search
        if ($item['set_arbitrarily'] == 1) {
            $valueFromForm = $item["value"];
        } else {
            if ((int) $item["value"] == 0) {
                continue;
            }
            if (!isset($template[$key]['__option_value_from_db'])) {
                $SQL = 'select option_value FROM ?#PRODUCTS_OPTIONS_VALUES_VARIANTS_TABLE WHERE variantID=?
                                ';
                $option_value = db_fetch_assoc(db_phquery($SQL, (int) $item['value']));
                $template[$key]['__option_value_from_db'] = $option_value['option_value'];
            }
            $valueFromForm = $template[$key]['__option_value_from_db'];
        }
        // get option value
        $SQL = 'select option_value, option_type FROM ?#PRODUCT_OPTIONS_VALUES_TABLE WHERE optionID=? AND productID=?
                ';
        $q = db_phquery($SQL, (int) $item['optionID'], (int) $productID);
        if (!($row = db_fetch_row($q))) {
            if (trim($valueFromForm) == '') {
                continue;
            } else {
                return false;
            }
        }
        $option_value = $row['option_value'];
        $option_type = $row['option_type'];
        $valueFromDataBase = array();
        if ($option_type == 0) {
            $valueFromDataBase[] = $option_value;
        } else {
            $SQL = '
                select povv.option_value
                FROM ?#PRODUCTS_OPTIONS_SET_TABLE as pos
                LEFT JOIN ?#PRODUCTS_OPTIONS_VALUES_VARIANTS_TABLE as povv ON pos.variantID=povv.variantID
                WHERE pos.optionID=? AND pos.productID=?';
            $Result = db_phquery($SQL, (int) $item["optionID"], (int) $productID);
            while ($Row = db_fetch_assoc($Result)) {
                $valueFromDataBase[] = $Row['option_value'];
            }
        }
        if (trim($valueFromForm) != '') {
            $existFlag = false;
            $vcount = count($valueFromDataBase);
            for ($v = 0; $v < $vcount; $v++) {
                if (strstr(strtolower((string) trim($valueFromDataBase[$v])), strtolower((string) trim($valueFromForm)))) {
                    $existFlag = true;
                    break;
                }
            }
            if (!$existFlag) {
                return false;
            }
        }
    }
    return true;
}