VD : debug
require_once('../logger/include.php');
// <- VD
require('includes/application_top.php');
// include the appropriate functions & classes
include('order_editor/functions.php');
include('order_editor/cart.php');
include('order_editor/order.php');
include(DIR_WS_LANGUAGES . $language. '/' . FILENAME_ORDERS_EDIT);
// Include currencies class
require(DIR_WS_CLASSES . 'currencies.php');
$currencies = new currencies();
$oID = tep_db_prepare_input((int)$_GET['oID']);
$order = new manualOrder($oID);
// -> QPBPP135
require(DIR_WS_CLASSES . 'PriceFormatter.php');
$pf = new PriceFormatter;
// <- QPBPP135
// Setup variables
$step = ((isset($_POST['step'])) ? (int)$_POST['step'] : 1);
$add_product_categories_id = ((isset($_POST['add_product_categories_id'])) ? (int)$_POST['add_product_categories_id'] : '');
$add_product_products_id = ((isset($_POST['add_product_products_id'])) ? (int)$_POST['add_product_products_id'] : 0);
// $firephp->info($action, 'edit_orders_add_product.php : action');
// $firephp->log($step, 'edit_orders_add_product.php : step');
// $_GET['action'] switch
if (isset($_GET['action'])) {
switch ($_GET['action']) {
////
// Add a product to the virtual cart
case 'add_product':
if ($step != 5) break;
$AddedOptionsPrice = 0;
// Get Product Attribute Info
if (isset($_POST['add_product_options'])) {
foreach($_POST['add_product_options'] as $option_id => $option_value_id) {
$result = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_ATTRIBUTES . " pa INNER JOIN " . TABLE_PRODUCTS_OPTIONS . " po ON (po.products_options_id = pa.options_id and po.language_id = '" . $languages_id . "') INNER JOIN " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov on (pov.products_options_values_id = pa.options_values_id and pov.language_id = '" . $languages_id . "') WHERE products_id = '" . $add_product_products_id . "' and options_id = '" . $option_id . "' and options_values_id = '" . $option_value_id . "'");
$row = tep_db_fetch_array($result);
if (is_array($row)) extract($row, EXTR_PREFIX_ALL, "opt");
if ($opt_price_prefix == '-')
{$AddedOptionsPrice -= $opt_options_values_price;}
else //default to positive
{$AddedOptionsPrice += $opt_options_values_price;}
$option_value_details[$option_id][$option_value_id] = array (
"options_values_price" => $opt_options_values_price,
"price_prefix" => $opt_price_prefix);
$option_names[$option_id] = $opt_products_options_name;
$option_values_names[$option_value_id] = $opt_products_options_values_name;
//add on for downloads
if (DOWNLOAD_ENABLED == 'true') {
$download_query_raw ="SELECT products_attributes_filename, products_attributes_maxdays, products_attributes_maxcount
FROM " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . "
WHERE products_attributes_id='" . $opt_products_attributes_id . "'";
$download_query = tep_db_query($download_query_raw);
if (tep_db_num_rows($download_query) > 0) {
$download = tep_db_fetch_array($download_query);
$filename[$option_id] = $download['products_attributes_filename'];
$maxdays[$option_id] = $download['products_attributes_maxdays'];
$maxcount[$option_id] = $download['products_attributes_maxcount'];
} //end if (tep_db_num_rows($download_query) > 0) {
} //end if (DOWNLOAD_ENABLED == 'true') {
//end downloads
} //end foreach($_POST['add_product_options'] as $option_id => $option_value_id) {
} //end if (isset($_POST['add_product_options'])) {
// Get Product Info
//BOF Added languageid (otherwise products_name is empty)
//$product_query = tep_db_query("select p.products_model, p.products_price, pd.products_name, p.products_tax_class_id from " . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on pd.products_id = p.products_id where p.products_id = '" . (int)$add_product_products_id . "'");
// -> MARP256 + QPBPP135
$product_query = tep_db_query("select p.products_model, p.products_price, p.products_cost, pd.products_name, p.products_tax_class_id, p.products_qty_blocks from " . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on pd.products_id = p.products_id where p.products_id = '" . (int)$add_product_products_id . "' and pd.language_id = '" . $languages_id . "'");
// <- MARP256 + QPBPP135
//EOF Added languageid
$product = tep_db_fetch_array($product_query);
$country_id = oe_get_country_id($order->delivery["country"]);
$zone_id = oe_get_zone_id($country_id, $order->delivery['state']);
$products_tax = tep_get_tax_rate($product['products_tax_class_id'], $country_id, $zone_id);
// -> OSC-94 - Prix par palier reservé aux professionnels
$c_id_result = tep_db_query('SELECT customers_id FROM orders WHERE orders_id="' . (int)$oID . '"');
$cid = tep_db_fetch_array($c_id_result);
if ($cid){
$cust_id = $cid['customers_id'];
$pf->setCustomerId($cust_id);
}
// <- OSC-94 - Prix par palier reservé aux professionnels
// -> QPBPP135 : ajustement du prix selon la quantité / ajustement du prix pour les partenaires
$account_query = tep_db_query("select is_partner,coeff_partner from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$cust_id . "'");
$account = tep_db_fetch_array($account_query);
$coeff_partner = $account['coeff_partner'];
$is_partner = $account['is_partner'];
$pf->loadProduct((int)$add_product_products_id, $product['products_price'], $products_tax, (int)$product['products_qty_blocks']);
if ($is_partner==true) {
//qty mis à 9999 pour récuperer le prix derniere colonne ( le partenaire à le prix le plus avantageux)
$product['products_price'] = min($pf->computePrice(9999, 0, false),$product['products_cost']*$coeff_partner);
}else {
$product['products_price'] = $pf->computePrice($_POST['add_product_quantity'], 0, false);
}
// <- QPBPP135
// 2.1.3 Pull specials price from db if there is an active offer
$special_price = tep_db_query("
SELECT specials_new_products_price
FROM " . TABLE_SPECIALS . "
WHERE products_id =". $add_product_products_id . "
AND status");
$new_price = tep_db_fetch_array($special_price);
if ($new_price)
{
if ($is_partner==true) { $product['products_price'] = min($new_price['specials_new_products_price'],$product['products_cost']*$coeff_partner);}
else{
$product['products_price'] = $new_price['specials_new_products_price'];
}
}
//sppc patch
//Set to false by default, configurable in the Order Editor section of the admin panel
//thanks to whistlerxj for the original version of this patch
if (ORDER_EDITOR_USE_SPPC == 'true') {
// first find out the customer associated with this order ID..
$c_id_result = tep_db_query('SELECT customers_id
FROM orders
WHERE orders_id="' . (int)$oID . '"');
$cid = tep_db_fetch_array($c_id_result);
if ($cid){
$cust_id = $cid['customers_id'];
// now find the customer's group.
$c_g_id_result = tep_db_query('SELECT customers_group_id
FROM customers
WHERE customers_id="' . $cust_id . '"');
$c_g_id = tep_db_fetch_array($c_g_id_result);
if ($c_g_id){
$cust_group_id = $c_g_id['customers_group_id'];
// get the price of the product from the products_groups table.
$price_result = tep_db_query('SELECT customers_group_price
FROM products_groups
WHERE products_id="' . $add_product_products_id . '"
AND customers_group_id="' . $cust_group_id . '"');
$price_array = tep_db_fetch_array($price_result);
if ($price_array){
// set the price of the new product to the group specific price.
$product['products_price'] = $price_array['customers_group_price'];
}
}
}
}
//end sppc patch
$sql_data_array = array('orders_id' => tep_db_prepare_input($oID),
'products_id' => tep_db_prepare_input($add_product_products_id),
'products_model' => tep_db_prepare_input($product['products_model']),
'products_name' => tep_db_prepare_input($product['products_name']),
'products_price' => tep_db_prepare_input($product['products_price']),
// -> MARP256
'products_cost' => tep_db_prepare_input($product['products_cost']),
// <- MARP256
'final_price' => tep_db_prepare_input(($product['products_price'] + $AddedOptionsPrice)),
'products_tax' => tep_db_prepare_input($products_tax),
'products_quantity' => tep_db_prepare_input($_POST['add_product_quantity']));
tep_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array);
$new_product_id = tep_db_insert_id();
if (isset($_POST['add_product_options'])) {
foreach($_POST['add_product_options'] as $option_id => $option_value_id) {
$sql_data_array = array('orders_id' => tep_db_prepare_input($oID),
'orders_products_id' => tep_db_prepare_input($new_product_id),
'products_options' => tep_db_prepare_input($option_names[$option_id]),
'products_options_values' => tep_db_prepare_input($option_values_names[$option_value_id]),
'options_values_price' => tep_db_prepare_input($option_value_details[$option_id][$option_value_id]['options_values_price']),
'price_prefix' => tep_db_prepare_input($option_value_details[$option_id][$option_value_id]['price_prefix']));
tep_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES, $sql_data_array);
//add on for downloads
if (DOWNLOAD_ENABLED == 'true' && isset($filename[$option_id])) {
$Query = "INSERT INTO " . TABLE_ORDERS_PRODUCTS_DOWNLOAD . " SET
orders_id = '" . tep_db_prepare_input($oID) . "',
orders_products_id = '" . tep_db_prepare_input($new_product_id) . "',
orders_products_filename = '" . tep_db_prepare_input($filename[$option_id]) . "',
download_maxdays = '" . tep_db_prepare_input($maxdays[$option_id]) . "',
download_count = '" . tep_db_prepare_input($maxcount[$option_id]) . "'";
tep_db_query($Query);
} //end if (DOWNLOAD_ENABLED == 'true') {
//end downloads
}
}
// -> VDOFS : gestion des articles épuisés
// Update inventory Quantity
// This is only done if store is set up to use stock
if (STOCK_LIMITED == 'true'){
tep_db_query("UPDATE " . TABLE_PRODUCTS . " SET
products_quantity = products_quantity - " . $_POST['add_product_quantity'] . "
WHERE products_id = '" . $_POST['add_product_products_id'] . "'");
}
// Update products_ordered info
tep_db_query ("UPDATE " . TABLE_PRODUCTS . " SET
products_ordered = products_ordered + " . $_POST['add_product_quantity'] . "
WHERE products_id = '" . $_POST['add_product_products_id'] . "'");
// <- VDOFS
// Unset selected product & category
$add_product_categories_id = 0;
$add_product_products_id = 0;
tep_redirect(tep_href_link(FILENAME_ORDERS_EDIT_ADD_PRODUCT, 'oID=' . $oID . '&step=1&submitForm=yes'));
break;
}
}
////
// Generate product list based on chosen category or search keywords
$not_found = true;
if (isset($_POST['search'])) {
$search_array = explode(" ", $_POST['product_search']);
$search_array = oe_clean_SQL_keywords($search_array);
if (sizeof($search_array) <= 1) {
$search_fields = array('p.products_id', 'p.products_price', 'p.products_model', 'pd.products_name');
$product_search = oe_generate_search_SQL($search_array, $search_fields);
} else {
$search_fields = array('pd.products_name');
$product_search = oe_generate_search_SQL($search_array, $search_fields, 'AND');
}
$products_query = tep_db_query("select p.products_id, p.products_price, p.products_model, pd.products_name from " . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on (p.products_id = pd.products_id) where pd.language_id = '" . $languages_id . "' and (" . $product_search . ") order by pd.products_name");
$not_found = ((tep_db_num_rows($products_query)) ? false : true);
}
if (!isset($_POST['search'])) {
$product_search = " where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id ";
$_GET['inc_subcat'] = '1';
if ($_GET['inc_subcat'] == '1') {
$subcategories_array = array();
oe_get_subcategories($subcategories_array, $add_product_categories_id);
$product_search .= " and p2c.products_id = p.products_id and p2c.products_id = pd.products_id and (p2c.categories_id = '" . (int)$add_product_categories_id . "'";
for ($i=0, $n=sizeof($subcategories_array); $i<$n; $i++ ) {
$product_search .= " or p2c.categories_id = '" . $subcategories_array[$i] . "'";
}
$product_search .= ")";
} else {
$product_search .= " and p2c.products_id = p.products_id and p2c.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p2c.categories_id = '" . (int)$add_product_categories_id . "'";
}
$products_query = tep_db_query("select distinct p.products_id, p.products_price, p.products_model, pd.products_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c " . $product_search . " order by pd.products_name");
$not_found = ((tep_db_num_rows($products_query)) ? false : true);
}
$category_array = array(array('id' => '', 'text' => TEXT_SELECT_CATEGORY),
array('id' => '0', 'text' => TEXT_ALL_CATEGORIES));
if (($step > 1) && (!$not_found)) {
$product_array = array(array('id' => 0, 'text' => TEXT_SELECT_PRODUCT));
while($products = tep_db_fetch_array($products_query)) {
$product_array[] = array('id' => $products['products_id'],
'text' => $products['products_name'] . ' (' . $products['products_model'] . ')' . ': ' . $currencies->format($products['products_price'], true, $order->info['currency'], $order->info['currency_value']));
}
}
$has_attributes = false;
$products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$add_product_products_id . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . $languages_id . "'");
$products_attributes = tep_db_fetch_array($products_attributes_query);
if ($products_attributes['total'] > 0) $has_attributes = true;
?>
>
';
}
?>
|
|
|
1) && (!$not_found)) {
echo ' ' . "\n" .
' | ' . tep_draw_separator('pixel_trans.gif', '1', '1') . ' | ' . "\n" .
' ' . "\n" .
' ' . "\n" .
' | ' . tep_draw_separator('pixel_trans.gif', '1', '10') . ' | ' . "\n" .
' ' . "\n";
?>
|
2) && ($add_product_products_id > 0)) {
echo ' ' . "\n" .
' | ' . tep_draw_separator('pixel_trans.gif', '1', '1') . ' | ' . "\n" .
' ' . "\n" .
' ' . "\n";
if ($has_attributes) echo ' ' . "\n" .
' ' . "\n";
$i++;
}
echo ' | | ' . "\n" .
' ' . ((isset($_POST['search'])) ? '' : '') . ' | ' . "\n" .
' ' . "\n" .
' ' . "\n";
} else {
$step = 4;
echo ' ' . TEXT_SKIP_NO_OPTIONS . ' | ' . "\n" .
' ' . "\n";
}
}
if ($step > 3) {
// -> QPBPP135
$product_query = tep_db_query("select products_qty_blocks from " . TABLE_PRODUCTS . " where products_id = '" . (int)$add_product_products_id . "'");
$product = tep_db_fetch_array($product_query);
$extra = "";
if ( (int)$product['products_qty_blocks'] > 1 )
{
$extra = " (par lot de " . $product['products_qty_blocks'] . ")";
}
// <- QPBPP135
echo ' ' . "\n" .
' | ' . tep_draw_separator('pixel_trans.gif', '1', '1') . ' | ' . "\n" .
' ' . "\n" .
' ' . "\n" .
' | ' . tep_draw_separator('pixel_trans.gif', '1', '10') . ' | ' . "\n" .
' ' . "\n" .
' ' . "\n" .
' | ' . tep_draw_separator('pixel_trans.gif', '1', '1') . ' | ' . "\n" .
' ' . "\n" .
' ' . "\n";
}
?>
|