Example #1
0
function olc_get_products_stock($products_id)
{
    $products_id = olc_get_prid($products_id);
    $stock_query = olc_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . $products_id . APOS);
    $stock_values = olc_db_fetch_array($stock_query);
    return $stock_values['products_quantity'];
}
 function get_order_total()
 {
     global $order, $cart;
     $order_total = $order->info['total'];
     // Check if gift voucher is in cart and adjust total
     $products = $cart->get_products();
     for ($i = 0; $i < sizeof($products); $i++) {
         $t_prid = olc_get_prid($products[$i]['id']);
         $gv_query = olc_db_query("select products_price, products_tax_class_id, products_model from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . APOS);
         $gv_result = olc_db_fetch_array($gv_query);
         if (ereg('^GIFT', addslashes($gv_result['products_model']))) {
             $qty = $cart->get_quantity($t_prid);
             $products_tax = olc_get_tax_rate($gv_result['products_tax_class_id']);
             if ($this->include_tax == FALSE_STRING_S) {
                 $gv_amount = $gv_result['products_price'] * $qty;
             } else {
                 $gv_amount = ($gv_result['products_price'] + olc_calculate_tax($gv_result['products_price'], $products_tax)) * $qty;
             }
             $order_total = $order_total - $gv_amount;
         }
     }
     if ($this->include_tax == FALSE_STRING_S) {
         $order_total = $order_total - $order->info['tax'];
     }
     if ($this->include_shipping == FALSE_STRING_S) {
         $order_total = $order_total - $order->info['shipping_cost'];
     }
     return $order_total;
 }
function olc_get_uprid($prid, $params)
{
    if (is_numeric($prid)) {
        $uprid = $prid;
        if (is_array($params) && sizeof($params) > 0) {
            $attributes_check = true;
            $attributes_ids = '';
            reset($params);
            while (list($option, $value) = each($params)) {
                if (is_numeric($option) && is_numeric($value)) {
                    $attributes_ids .= '{' . (int) $option . '}' . (int) $value;
                } else {
                    $attributes_check = false;
                    break;
                }
            }
            if ($attributes_check == true) {
                $uprid .= $attributes_ids;
            }
        }
    } else {
        $uprid = olc_get_prid($prid);
        if (is_numeric($uprid)) {
            if (strpos($prid, '{') !== false) {
                $attributes_check = true;
                $attributes_ids = '';
                $attributes = explode('{', substr($prid, strpos($prid, '{') + 1));
                for ($i = 0, $n = sizeof($attributes); $i < $n; $i++) {
                    $pair = explode('}', $attributes[$i]);
                    if (is_numeric($pair[0]) && is_numeric($pair[1])) {
                        $attributes_ids .= '{' . (int) $pair[0] . '}' . (int) $pair[1];
                    } else {
                        $attributes_check = false;
                        break;
                    }
                }
                if ($attributes_check == true) {
                    $uprid .= $attributes_ids;
                }
            }
        } else {
            return false;
        }
    }
    return $uprid;
}
         p.products_discount_allowed,
         p.products_weight,
         p.products_tax_class_id
         from " .
         TABLE_PRODUCTS . " p, " .
         TABLE_PRODUCTS_DESCRIPTION . " pd
         where
         p.products_id='#' and
         pd.products_id = p.products_id and
         pd.language_id = '" . SESSION_LANGUAGE_ID . APOS;
         */
         $products = array();
         $price_raw = 0;
         while ($products_basket = olc_db_fetch_array($products_basket_query)) {
             $products_id = $products_basket['products_id'];
             $prid = olc_get_prid($products_id);
             $products_query_sql = str_replace(HASH, $prid, $products_query_sql0);
             $products_query = olc_db_query($products_query_sql);
             if ($current_product = olc_db_fetch_array($products_query)) {
                 $products_price = abs(olc_get_products_price($prid, $price_special = 0, $quantity = 1));
                 $price_raw += $products_price;
                 $products[] = array('id' => $products_id, 'name' => $current_product['products_name'], 'model' => $current_product['products_model'], 'image' => $current_product['products_image'], 'price' => $current_product_price, 'discount_allowed' => $current_product['products_discount_allowed'], 'quantity' => $products_basket['customers_basket_quantity'], 'weight' => $current_product['products_weight'], 'final_price' => $products_price, 'tax_class_id' => $current_product['products_tax_class_id']);
             }
         }
         $show_saved_cart = true;
         $module_content_save = $module_content;
         include_once DIR_WS_MODULES . 'order_details_cart.php';
         $module_content = $module_content_save;
         $show_saved_cart = false;
     }
 } else {
 function count_contents_virtual()
 {
     // get total number of items in cart disregard gift vouchers
     $total_items = 0;
     if (is_array($this->contents)) {
         reset($this->contents);
         while (list($products_id, ) = each($this->contents)) {
             $no_count = false;
             $gv_query = olc_db_query("select products_model from " . TABLE_PRODUCTS . " where products_id = '" . $products_id . APOS);
             $gv_result = olc_db_fetch_array($gv_query);
             if (ereg('^GIFT', $gv_result['products_model'])) {
                 $no_count = true;
             }
             if (NO_COUNT_ZERO_WEIGHT == 1) {
                 $gv_query = olc_db_query("select products_weight from " . TABLE_PRODUCTS . " where products_id = '" . olc_get_prid($products_id) . APOS);
                 $gv_result = olc_db_fetch_array($gv_query);
                 if ($gv_result['products_weight'] <= MINIMUM_WEIGHT) {
                     $no_count = true;
                 }
             }
             if (!$no_count) {
                 $total_items += $this->get_quantity($products_id);
             }
         }
         return $total_items;
     }
 }
    olc_db_query(DELETE_FROM . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . $where_orders_id);
} else {
    $sql_data_array['orders_id'] = $orders_id;
    olc_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
}
// initialized for the email confirmation
$products_ordered = EMPTY_STRING;
$products_ordered_html = EMPTY_STRING;
$subtotal = 0;
$total_tax = 0;
$download_enabled = DOWNLOAD_ENABLED == TRUE_STRING_S;
$stock_limited = STOCK_LIMITED == TRUE_STRING_S;
for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
    // Stock Update - Joao Correia
    $current_product = $order->products[$i];
    $current_product_id = olc_get_prid($current_product['id']);
    $current_product_qty = $current_product['qty'];
    $current_product_id_where = " where products_id = '" . $current_product_id . APOS;
    $update_table_products = SQL_UPDATE . TABLE_PRODUCTS . " set ";
    if ($stock_limited) {
        if ($download_enabled) {
            $stock_query_raw = SELECT . "\n\t\t\t\tproducts_quantity, pad.products_attributes_filename\n\t\t\t\tFROM " . TABLE_PRODUCTS . " p\n\t\t\t\tLEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa\n\t\t\t\tON p.products_id=pa.products_id\n\t\t\t\tLEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad\n\t\t\t\tON pa.products_attributes_id=pad.products_attributes_id\n\t\t\t\tWHERE p.products_id = '" . $current_product_id . APOS;
            // Will work with only one option for downloadable products
            // otherwise, we have to build the query dynamically with a loop
            $products_attributes = $current_product['attributes'];
            if (is_array($products_attributes)) {
                for ($i = 0; $i < sizeof($products_attributes); $i++) {
                    $current_products_attribute = $products_attributes[$i];
                    $stock_query_raw .= " AND pa.options_id = '" . $current_products_attribute['option_id'] . "' AND pa.options_values_id = '" . $current_products_attribute['value_id'] . APOS;
                }
            }
 function get_product_price($product_id)
 {
     global $order, $olPrice;
     $products_id = olc_get_prid($product_id);
     // products price
     $qty = $_SESSION['cart']->contents[$product_id]['qty'];
     $product_query = olc_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id='" . $product_id . APOS);
     if ($product = olc_db_fetch_array($product_query)) {
         $products_tax = $olPrice->TAX[$product['products_tax_class_id']];
         $prid = $product['products_id'];
         if ($this->include_tax == TRUE_STRING_S) {
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
                 $total_price += olc_get_products_price($product['products_id'], $price_special = 0, $qty) + olc_calculate_tax(olc_get_products_price($product['products_id'], $price_special = 0, $qty), $products_tax);
             } else {
                 $total_price += olc_get_products_price($product['products_id'], $price_special = 0, $qty);
             }
         } else {
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 1) {
                 $total_price += olc_get_products_price($product['products_id'], $price_special = 0, $qty) - olc_calculate_tax(olc_get_products_price($product['products_id'], $price_special = 0, $qty) / (100 + $products_tax) * 100, $products_tax);
             } else {
                 $total_price += olc_get_products_price($product['products_id'], $price_special = 0, $qty);
             }
         }
         // attributes price
         if (isset($_SESSION['cart']->contents[$product_id]['attributes'])) {
             reset($_SESSION['cart']->contents[$product_id]['attributes']);
             while (list($option, $value) = each($_SESSION['cart']->contents[$product_id]['attributes'])) {
                 $attribute_price_query = olc_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . $prid . "' and options_id = '" . $option . "' and options_values_id = '" . $value . APOS);
                 $attribute_price = olc_db_fetch_array($attribute_price_query);
                 if ($attribute_price['price_prefix'] == '+') {
                     if ($this->include_tax == TRUE_STRING_S) {
                         if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
                             $total_price += olc_get_products_attribute_price($attribute_price['options_values_price'], $product['products_tax_class_id'], 0, $qty, $attribute_price['price_prefix']) + olc_calculate_tax(olc_get_products_attribute_price($attribute_price['options_values_price'], $product['products_tax_class_id'], 0, $qty, $attribute_price['price_prefix']), $products_tax);
                         } else {
                             $total_price += olc_get_products_attribute_price($attribute_price['options_values_price'], $product['products_tax_class_id'], 0, $qty, $attribute_price['price_prefix']);
                         }
                     } else {
                         $total_price += olc_get_products_attribute_price($attribute_price['options_values_price'], '', 0, $qty, $attribute_price['price_prefix']);
                     }
                 } else {
                     if ($this->include_tax == TRUE_STRING_S) {
                         if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
                             $total_price -= olc_get_products_attribute_price($attribute_price['options_values_price'], $product['products_tax_class_id'], 0, $qty, $attribute_price['price_prefix']) + olc_calculate_tax(olc_get_products_attribute_price($attribute_price['options_values_price'], $product['products_tax_class_id'], 0, $qty, $attribute_price['price_prefix']), $products_tax);
                         } else {
                             $total_price -= olc_get_products_attribute_price($attribute_price['options_values_price'], $product['products_tax_class_id'], 0, $qty, $attribute_price['price_prefix']);
                         }
                     } else {
                         $total_price -= olc_get_products_attribute_price($attribute_price['options_values_price'], '', 0, $qty, $attribute_price['price_prefix']);
                     }
                 }
             }
         }
     }
     return $total_price;
 }
 function get_products()
 {
     if (!is_array($this->contents)) {
         return 0;
     }
     $products_array = array();
     reset($this->contents);
     while (list($products_id, ) = each($this->contents)) {
         $products_query = olc_db_query("\n\t\t\tselect p.products_id, pd.products_name, p.products_model, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd\n\t\t\twhere p.products_id='" . olc_get_prid($products_id) . "'\n\t\t\tand pd.products_id = p.products_id\n\t\t\tand pd.language_id = '" . SESSION_LANGUAGE_ID . APOS);
         if ($products = olc_db_fetch_array($products_query)) {
             $prid = $products['products_id'];
             $products_price = $products['products_price'];
             $specials_query = olc_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . $prid . "' and status = '1'");
             if (olc_db_num_rows($specials_query)) {
                 $specials = olc_db_fetch_array($specials_query);
                 $products_price = $specials['specials_new_products_price'];
             }
             $products_array[] = array('id' => $products_id, 'name' => $products['products_name'], 'model' => $products['products_model'], 'price' => $products_price, 'quantity' => $this->contents[$products_id]['qty'], 'weight' => $products['products_weight'], 'final_price' => $products_price + $this->attributes_price($products_id), 'tax_class_id' => $products['products_tax_class_id'], 'attributes' => $this->contents[$products_id]['attributes']);
         }
     }
     return $products_array;
 }
 function updateProducts(&$order)
 {
     // initialized for the email confirmation
     $this->products_ordered = '';
     $subtotal = 0;
     $total_tax = 0;
     for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
         // Stock Update - Joao Correia
         if (STOCK_LIMITED == TRUE_STRING_S) {
             if (DOWNLOAD_ENABLED == TRUE_STRING_S) {
                 $stock_query_raw = "SELECT products_quantity, pad.products_attributes_filename\n                              FROM " . TABLE_PRODUCTS . " p\n                              LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa\n                               ON p.products_id=pa.products_id\n                              LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad\n                               ON pa.products_attributes_id=pad.products_attributes_id\n                              WHERE p.products_id = '" . olc_get_prid($order->products[$i]['id']) . APOS;
                 // Will work with only one option for downloadable products
                 // otherwise, we have to build the query dynamically with a loop
                 $products_attributes = $order->products[$i]['attributes'];
                 if (is_array($products_attributes)) {
                     $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . APOS;
                 }
                 $stock_query = olc_db_query($stock_query_raw);
             } else {
                 $stock_query = olc_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . olc_get_prid($order->products[$i]['id']) . APOS);
             }
             if (olc_db_num_rows($stock_query) > 0) {
                 $stock_values = olc_db_fetch_array($stock_query);
                 // do not decrement quantities if products_attributes_filename exists
                 if (DOWNLOAD_ENABLED != TRUE_STRING_S || !$stock_values['products_attributes_filename']) {
                     $stock_left = $stock_values['products_quantity'] - $order->products[$i]['qty'];
                 } else {
                     $stock_left = $stock_values['products_quantity'];
                 }
                 olc_db_query(SQL_UPDATE . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . olc_get_prid($order->products[$i]['id']) . APOS);
                 if ($stock_left < 1 && STOCK_ALLOW_CHECKOUT == FALSE_STRING_S) {
                     olc_db_query(SQL_UPDATE . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . olc_get_prid($order->products[$i]['id']) . APOS);
                 }
             }
         }
         // Update products_ordered (for bestsellers list)
         olc_db_query(SQL_UPDATE . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . olc_get_prid($order->products[$i]['id']) . APOS);
         //------insert customer choosen option to order--------
         $attributes_exist = '0';
         $products_ordered_attributes = '';
         if (isset($order->products[$i]['attributes'])) {
             $attributes_exist = '1';
             for ($j = 0, $n2 = sizeof($order->products[$i]['attributes']); $j < $n2; $j++) {
                 if (DOWNLOAD_ENABLED == TRUE_STRING_S) {
                     $attributes_query = "select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount , pad.products_attributes_filename\n                                 from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa\n                                 left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad\n                                  on pa.products_attributes_id=pad.products_attributes_id\n                                 where pa.products_id = '" . $order->products[$i]['id'] . "'\n                                  and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "'\n                                  and pa.options_id = popt.products_options_id\n                                  and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "'\n                                  and pa.options_values_id = poval.products_options_values_id\n                                  and popt.language_id = '" . $this->languageID . "'\n                                  and poval.language_id = '" . $this->languageID . APOS;
                     $attributes = olc_db_query($attributes_query);
                 } else {
                     $attributes = olc_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . $order->products[$i]['id'] . "' and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $this->languageID . "' and poval.language_id = '" . $this->languageID . APOS);
                 }
                 $attributes_values = olc_db_fetch_array($attributes);
                 if (DOWNLOAD_ENABLED == TRUE_STRING_S && isset($attributes_values['products_attributes_filename']) && olc_not_null($attributes_values['products_attributes_filename'])) {
                     $sql_data_array = array('orders_id' => $this->orderID, 'orders_products_id' => $order->products[$i]['orders_products_id'], 'orders_products_filename' => $attributes_values['products_attributes_filename'], 'download_maxdays' => $attributes_values['products_attributes_maxdays'], 'download_count' => $attributes_values['products_attributes_maxcount']);
                     olc_db_perform(TABLE_ORDERS_PRODUCTS_DOWNLOAD, $sql_data_array);
                 }
                 $products_ordered_attributes .= "\n\t" . $attributes_values['products_options_name'] . ' ' . $attributes_values['products_options_values_name'];
             }
         }
         //------insert customer choosen option eof ----
         $total_weight += $order->products[$i]['qty'] * $order->products[$i]['weight'];
         $total_tax += olc_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty'];
         $total_cost += $total_products_price;
         //$currency_price = $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']);
         $products_ordered_price = $this->displayPrice($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']);
         $this->products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . LPAREN . $order->products[$i]['model'] . ') = ' . $products_ordered_price . $products_ordered_attributes . NEW_LINE;
     }
 }