function add_product() { global $VM_LANG, $vmLogger, $mosConfig_offset; require_once CLASSPATH . 'ps_product_attribute.php'; require_once CLASSPATH . 'ps_product.php'; $ps_product_attribute = new ps_product_attribute(); $ps_product = new ps_product(); $product_id = vmGet($_REQUEST, 'product_id'); $order_item_id = vmGet($_REQUEST, 'order_item_id'); $add_product_validate = vmGet($_REQUEST, 'add_product_validate'); $d = $_REQUEST; // On peux ins�rer le produit � la commande if ($add_product_validate == 1) { $quantity = trim(vmGet($_REQUEST, 'product_quantity')); if (!is_numeric($quantity) || $quantity < 1) { $vmLogger->err($VM_LANG->_('VM_ORDER_EDIT_ERROR_QUANTITY_MUST_BE_HIGHER_THAN_0', false)); $add_product_validate = 0; } } if (!isset($d['order_subtotal_withtax'])) { $d['order_subtotal_withtax'] = 0; } if ($add_product_validate == 1) { $result_attributes = $ps_product_attribute->cartGetAttributes($d); $dbp = new ps_DB(); $q = "SELECT vendor_id, product_in_stock,product_sales,product_parent_id, product_sku, product_name FROM #__{vm}_product WHERE product_id='{$product_id}'"; $dbp->query($q); $dbp->next_record(); $vendor_id = $dbp->f("vendor_id"); $product_sku = $dbp->f("product_sku"); $product_name = $dbp->f("product_name"); $product_parent_id = $dbp->f("product_parent_id"); // On r�cup�re le prix exact du produit $product_price_arr = $this->get_adjusted_attribute_price($product_id, $quantity, $d["description"], $result_attributes); $product_price = $product_price_arr["product_price"]; $my_taxrate = $ps_product->get_product_taxrate($product_id); $description = $d["description"]; $product_final_price = round($product_price * ($my_taxrate + 1), 2); $product_currency = $product_price_arr["product_currency"]; $db = new ps_DB(); $q = "SELECT * FROM #__{vm}_order_item "; $q .= " WHERE order_id=" . $this->order_id; $db->query($q); $db->next_record(); $user_info_id = $db->f("user_info_id"); $order_status = $db->f("order_status"); $timestamp = time() + $mosConfig_offset * 60 * 60; $q = "INSERT INTO #__{vm}_order_item "; $q .= "(order_id, user_info_id, vendor_id, product_id, order_item_sku, order_item_name, "; $q .= "product_quantity, product_item_price, product_final_price, "; $q .= "order_item_currency, order_status, product_attribute, cdate, mdate) "; $q .= "VALUES ('"; $q .= $this->order_id . "', '"; $q .= $user_info_id . "', '"; $q .= $vendor_id . "', '"; $q .= $product_id . "', '"; $q .= $product_sku . "', '"; $q .= $product_name . "', '"; $q .= $quantity . "', '"; $q .= $product_price . "', '"; $q .= $product_final_price . "', '"; $q .= $product_currency . "', '"; $q .= $order_status . "', '"; // added for advanced attribute storage $q .= addslashes($description) . "', '"; // END advanced attribute modifications $q .= $timestamp . "','"; $q .= $timestamp . "'"; $q .= ")"; $db->query($q); $db->next_record(); $q = "SELECT product_id, product_quantity, product_final_price, product_item_price, product_final_price - product_item_price AS item_tax "; $q .= "FROM #__{vm}_order_item WHERE order_id = '" . $this->order_id . "' "; $q .= "AND order_item_id = '" . addslashes($order_item_id) . "'"; $db->query($q); $db->next_record(); $net_price_change = $quantity * $product_price; $tax_change = $quantity * ($product_final_price - $product_price); $price_change = $quantity * $product_final_price; $order_subtotal = 0; if ($_SESSION["auth"]["show_price_including_tax"] == 1) { $product_price = round($product_price * ($my_taxrate + 1), 2); $product_price *= $quantity; $d['order_subtotal_withtax'] += $product_price; $product_price = $product_price / ($my_taxrate + 1); $order_subtotal += $product_price; } else { $order_subtotal += $product_price * $quantity; $product_price = round($product_price * ($my_taxrate + 1), 2); $product_price *= $quantity; $d['order_subtotal_withtax'] += $product_price; $product_price = $product_price / ($my_taxrate + 1); } // Update order $q = "UPDATE #__{vm}_orders "; $q .= "SET order_tax = (order_tax + " . $tax_change . " ), "; $q .= "order_total = (order_total + " . $price_change . " ), "; $q .= "order_subtotal = (order_subtotal + " . $net_price_change . ") "; $q .= "WHERE order_id = '" . $this->order_id . "'"; $db->query($q); $db->next_record(); $this->reload_from_db = 1; // Update Stock Level and Product Sales $q = "UPDATE #__{vm}_product "; $q .= "SET product_in_stock = product_in_stock - " . $quantity; $q .= " WHERE product_id = '" . $product_id . "'"; $db->query($q); $db->next_record(); $q = "UPDATE #__{vm}_product "; $q .= "SET product_sales= product_sales + " . $quantity; $q .= " WHERE product_id='" . $product_id . "'"; $db->query($q); $db->next_record(); $this->product_added = true; $vmLogger->info($VM_LANG->_('VM_ORDER_EDIT_PRODUCT_ADDED', false)); } }
/** * adds an item to the shopping cart * @author pablo * @param array $d */ function add(&$d) { global $sess, $VM_LANG, $cart, $vmLogger, $func; $d = $GLOBALS['vmInputFilter']->process($d); include_class("product"); $db = new ps_DB(); $ci = 0; $request_stock = ""; $total_quantity = 0; $total_updated = 0; $total_deleted = 0; $_SESSION['last_page'] = "shop.product_details"; if (!empty($d['product_id']) && !isset($d["prod_id"])) { if (empty($d['prod_id'])) { $d['prod_id'] = array(); } if (is_array($d['product_id'])) { $d['prod_id'] = array_merge($d['prod_id'], $d['product_id']); } else { $d['prod_id'] = array_merge($d['prod_id'], array($d['product_id'])); } } //Check to see if a prod_id has been set if (!isset($d["prod_id"])) { return true; } $multiple_products = sizeof($d["prod_id"]); //Iterate through the prod_id's and perform an add to cart for each one for ($ikey = 0; $ikey < $multiple_products; $ikey++) { // Create single array from multi array $key_fields = array_keys($d); foreach ($key_fields as $key) { if (is_array($d[$key])) { $e[$key] = @$d[$key][$ikey]; } else { $e[$key] = $d[$key]; } } if ($multiple_products > 1) { $func = "cartUpdate"; } $e['product_id'] = $d['product_id']; $e['Itemid'] = $d['Itemid']; if (is_array($d["prod_id"])) { $product_id = $d["prod_id"][$ikey]; } else { $product_id = $e["prod_id"]; } if (is_array($d["quantity"])) { $quantity = @$d['quantity'][$ikey]; } else { $quantity = @$e['quantity']; } // Check for negative quantity if ($quantity < 0) { vmRequest::setVar('product_id', $product_id); $vmLogger->warning($VM_LANG->_('PHPSHOP_CART_ERROR_NO_NEGATIVE', false)); return False; } if (!is_numeric($quantity)) { vmRequest::setVar('product_id', $product_id); $vmLogger->warning($VM_LANG->_('PHPSHOP_CART_ERROR_NO_VALID_QUANTITY', false)); return False; } $quantity = intval($quantity); // Check to see if checking stock quantity if (CHECK_STOCK) { $product_in_stock = ps_product::get_field($product_id, 'product_in_stock'); if (empty($product_in_stock)) { $product_in_stock = 0; } if ($quantity > $product_in_stock) { //Create an array for out of stock items and continue to next item $request_stock[$ci]['product_id'] = $product_id; $request_stock[$ci]['quantity'] = $quantity; $ci++; continue; } } // Check if product exists and is published if (!ps_product::product_exists($product_id)) { $vmLogger->tip($VM_LANG->_('VM_CART_PRODUCT_NOTEXIST', false)); return false; } // Quick add of item $q = "SELECT product_id FROM #__{vm}_product WHERE "; $q .= "product_parent_id = " . (int) $product_id; $db->query($q); if ($db->num_rows()) { vmRequest::setVar('product_id', $e["product_id"]); $vmLogger->tip($VM_LANG->_('PHPSHOP_CART_SELECT_ITEM', false)); $_REQUEST['flypage'] = ps_product::get_flypage($e["product_id"]); $GLOBALS['page'] = 'shop.product_details'; return true; } // Check to see if we already have it $updated = 0; $result = ps_product_attribute::cartGetAttributes($e); if ($result["attribute_given"] == false && !empty($result["advanced_attribute_list"]) || $multiple_products == 1 && ($result["custom_attribute_given"] == false && !empty($result["custom_attribute_list"]))) { $_REQUEST['flypage'] = ps_product::get_flypage($product_id); $GLOBALS['page'] = 'shop.product_details'; $vmLogger->tip($VM_LANG->_('PHPSHOP_CART_SELECT_ITEM', false)); return true; } //Check for empty custom field and quantity>0 for multiple addto //Normally means no info added to a custom field, but once added to a cart the quantity is automatically placed //If another item is added and the custom field is left blank for another product already added this will just ignore that item if ($multiple_products != 1 && $quantity != 0 && ($result["custom_attribute_given"] == false && !empty($result["custom_attribute_list"]))) { $vmLogger->tip($VM_LANG->_('PHPSHOP_CART_SELECT_ITEM', false)); continue; } // Check for duplicate and do not add to current quantity for ($i = 0; $i < $_SESSION["cart"]["idx"]; $i++) { // modified for advanced attributes if ($_SESSION['cart'][$i]["product_id"] == $product_id && $_SESSION['cart'][$i]["description"] == $e["description"]) { $updated = 1; } } list($min, $max) = ps_product::product_order_levels($product_id); if ($min != 0 && $quantity != 0 && $quantity < $min) { eval("\$msg = \"" . $VM_LANG->_('VM_CART_MIN_ORDER', false) . "\";"); $vmLogger->warning($msg); continue; } if ($max != 0 && $quantity != 0 && $quantity > $max) { eval("\$msg = \"" . $VM_LANG->_('VM_CART_MAX_ORDER', false) . "\";"); $vmLogger->warning($msg); continue; } // If we did not update then add the item if (!$updated && $quantity) { $k = $_SESSION['cart']["idx"]; $_SESSION['cart'][$k]["quantity"] = $quantity; $_SESSION['cart'][$k]["product_id"] = $product_id; $_SESSION['cart'][$k]["parent_id"] = $e["product_id"]; $_SESSION['cart'][$k]["category_id"] = vmGet($e, 'category_id', 0); // added for the advanced attribute modification $_SESSION['cart'][$k]["description"] = $e["description"]; $_SESSION['cart']["idx"]++; $total_quantity += $quantity; } else { list($updated_prod, $deleted_prod) = $this->update($e); $total_updated += $updated_prod; $total_deleted += $deleted_prod; } /* next 3 lines added by Erich for coupon code */ /* if the cart was updated we gotta update any coupon discounts to avoid ppl getting free stuff */ if (!empty($_SESSION['coupon_discount'])) { // Update the Coupon Discount !! require_once CLASSPATH . 'ps_coupon.php'; ps_coupon::process_coupon_code($d); } } // End Iteration through Prod id's $cart = $_SESSION['cart']; ps_cart::saveCart(); // Ouput info message with cart update details /* if ($total_quantity != 0 || $total_updated != 0 || $total_deleted != 0) { if ($total_quantity > 0 && $total_updated == 0) { $msg = $VM_LANG->_('VM_CART_PRODUCT_ADDED', false); } else { $msg = $VM_LANG->_('VM_CART_PRODUCT_UPDATED', false); } // Comment out the following line to turn off msg i.e. //$vmLogger->tip( $msg ); $vmLogger->info($msg); } else { if (@$request_stock) { $vmLogger->tip($VM_LANG->_('PHPSHOP_CART_GOTO_WAITING_LIST', false)); } elseif ($total_quantity == 0) { vmRequest::setVar('product_id', $product_id); $GLOBALS['last_page'] = 'shop.product_details'; $vmLogger->warning($VM_LANG->_('PHPSHOP_CART_ERROR_NO_VALID_QUANTITY', false)); return false; } else { $vmLogger->tip($VM_LANG->_('PHPSHOP_CART_QUANTITY_EXCEEDED', false)); } } // end cart update message */ // Perform notification of out of stock items if (@$request_stock) { global $notify; $_SESSION['notify'] = array(); $_SESSION['notify']['idx'] = 0; $k = 0; $notify = $_SESSION['notify']; foreach ($request_stock as $request) { $_SESSION['notify'][$k]["prod_id"] = $request['product_id']; $_SESSION['notify'][$k]["quantity"] = $request['quantity']; $_SESSION['notify']['idx']++; $k++; } if (vmIsXHR()) { $GLOBALS['vm_mainframe']->scriptRedirect($sess->url('index.php?page=shop.waiting_list&product_id=' . $product_id, true, false)); } else { vmRedirect($sess->url('index.php?page=shop.waiting_list&product_id=' . $product_id, true, false)); } } return True; }
function add_product() { global $VM_LANG, $vmLogger, $mosConfig_offset; require_once CLASSPATH . 'ps_product_attribute.php'; require_once CLASSPATH . 'ps_product.php'; $ps_product_attribute = new ps_product_attribute(); $ps_product = new vm_ps_product(); $product_id = vmGet($_REQUEST, 'product_id'); $order_item_id = vmGet($_REQUEST, 'order_item_id'); $add_product_validate = vmGet($_REQUEST, 'add_product_validate'); $d = $_REQUEST; // Check if quantity is a numeric value if ($add_product_validate == 1) { $quantity = trim(vmGet($_REQUEST, 'product_quantity')); if (!is_numeric($quantity) || $quantity < 1) { $vmLogger->err($VM_LANG->_('PHPSHOP_ORDER_EDIT_ERROR_QUANTITY_MUST_BE_HIGHER_THAN_0')); $add_product_validate = 0; } } if ($add_product_validate == 1) { $result_attributes = $ps_product_attribute->cartGetAttributes($d); $dbp = new ps_DB(); $q = "SELECT vendor_id, product_in_stock,product_sales,product_parent_id, product_sku, product_name FROM #__{vm}_product WHERE product_id='{$product_id}'"; $dbp->query($q); $dbp->next_record(); $vendor_id = $dbp->f("vendor_id"); $product_sku = $dbp->f("product_sku"); $product_name = $dbp->f("product_name"); $product_parent_id = $dbp->f("product_parent_id"); // Read user_info_id from db $prod_weight = $ps_product->get_weight($product_id); $dbu = new ps_DB(); $q = "SELECT user_info_id FROM #__{vm}_orders WHERE order_id = '" . $this->order_id . "' "; $dbu->query($q); $dbu->next_record(); $user_info_id = $dbu->f("user_info_id"); // On r�cup�re le prix exact du produit $my_taxrate = $ps_product->get_product_taxrate($product_id, $prod_weight, $user_info_id); $product_price_arr = $this->get_adjusted_attribute_price($product_id, $quantity, $d["description"], $result_attributes); //Inf Получение стоимости товара с дочернего сайта откуда заказ $odb = new ps_DB(); $oq = "SELECT shop_id FROM #__{vm}_orders WHERE order_id = '" . $this->order_id . "'"; $odb->query($oq); $shop_id = $odb->f("shop_id"); //Inf Информация о магазине require_once CLASSPATH . 'ps_multishop.php'; $ps_multishop = new ps_multishop($this->order_id); if ($shop_id > 1) { $_product_price_arr = file_get_contents($ps_multishop->getShop_url() . "/api/productinfo.php?sku=" . $product_sku . "&order_id=" . $this->order_id); if ($_product_price_arr != -1) { $product_price_arr = unserialize($_product_price_arr); } } $product_price_arr["product_price"] = $GLOBALS['CURRENCY']->convert($product_price_arr["product_price"], $product_price_arr["product_currency"]); $product_price = $product_price_arr["product_price"]; $description = $d["description"]; $description = $this->getDescriptionWithTax($description, $product_id); // Don´t show attribute prices in descripton $product_final_price = round($product_price * ($my_taxrate + 1), 2); $product_currency = $product_price_arr["product_currency"]; $db = new ps_DB(); if ($product_parent_id > 0) { $q = "SELECT attribute_name, attribute_value, product_id "; $q .= "FROM #__{vm}_product_attribute WHERE "; $q .= "product_id='" . $product_id . "'"; $db->setQuery($q); $db->query(); while ($db->next_record()) { $description .= $db->f("attribute_name") . ": " . $db->f("attribute_value") . "; "; } } $q = "SELECT * FROM #__{vm}_order_item "; $q .= " WHERE order_id=" . $this->order_id; $db->query($q); $db->next_record(); $user_info_id = $db->f("user_info_id"); $order_status = $db->f("order_status"); $timestamp = time() + $mosConfig_offset * 60 * 60; $q = "SELECT order_item_id, product_quantity "; $q .= "FROM #__{vm}_order_item WHERE order_id = '" . $this->order_id . "' "; $q .= "AND product_id = '" . $product_id . "' "; $q .= "AND product_attribute = '" . addslashes($description) . "'"; $db->query($q); if ($db->next_record()) { $this->change_item_quantity($this->order_id, $db->f('order_item_id'), $quantity + (int) $db->f('product_quantity')); } else { $q = "INSERT INTO #__{vm}_order_item "; $q .= "(order_id, user_info_id, vendor_id, product_id, order_item_sku, order_item_name, "; $q .= "product_quantity, product_item_price, product_final_price, "; $q .= "order_item_currency, order_status, product_attribute, cdate, mdate) "; $q .= "VALUES ('"; $q .= $this->order_id . "', '"; $q .= $user_info_id . "', '"; $q .= $vendor_id . "', '"; $q .= $product_id . "', '"; $q .= $product_sku . "', '"; $q .= $db->getEscaped($product_name) . "', '"; $q .= $quantity . "', '"; $q .= $product_price . "', '"; $q .= $product_final_price . "', '"; $q .= $product_currency . "', '"; $q .= $order_status . "', '"; // added for advanced attribute storage $q .= $db->getEscaped($description) . "', '"; // END advanced attribute modifications $q .= $timestamp . "','"; $q .= $timestamp . "'"; $q .= ")"; $db->query($q); $db->next_record(); // Update Stock Level and Product Sales $q = "UPDATE #__{vm}_product "; $q .= "SET product_in_stock = product_in_stock - " . $quantity . ",\n\t\t\t\t\t\t\t\tproduct_sales= product_sales + " . $quantity; $q .= " WHERE product_id='" . $product_id . "'"; $db->query($q); } $this->recalc_order($this->order_id); $this->reload_from_db = 1; $vmLogger->info($VM_LANG->_('PHPSHOP_ORDER_EDIT_PRODUCT_ADDED')); $this->orderlog->saveLog($this->order_id, 'Добавление позиции', $product_name, 0, $quantity); } }
function add_product() { global $VM_LANG, $vmLogger; require_once CLASSPATH . 'ps_product_attribute.php'; require_once CLASSPATH . 'ps_product.php'; $ps_product_attribute = new ps_product_attribute(); $ps_product = new ps_product(); $product_id = vmGet($_REQUEST, 'product_id'); $order_item_id = vmGet($_REQUEST, 'order_item_id'); $add_product_validate = vmGet($_REQUEST, 'add_product_validate'); $d = $_REQUEST; // Check if quantity is a numeric value if ($add_product_validate == 1) { $quantity = trim(vmGet($_REQUEST, 'product_quantity')); if (!is_numeric($quantity) || $quantity < 1) { $vmLogger->err($VM_LANG->_('PHPSHOP_ORDER_EDIT_ERROR_QUANTITY_MUST_BE_HIGHER_THAN_0')); $add_product_validate = 0; } } if ($add_product_validate == 1) { $result_attributes = $ps_product_attribute->cartGetAttributes($d); $dbp = new ps_DB(); $q = "SELECT vendor_id, product_in_stock,product_sales,product_parent_id, product_sku, product_name FROM #__{vm}_product WHERE product_id='{$product_id}'"; $dbp->query($q); $dbp->next_record(); $vendor_id = $dbp->f("vendor_id"); $product_sku = $dbp->f("product_sku"); $product_name = $dbp->f("product_name"); $product_parent_id = $dbp->f("product_parent_id"); // On r�cup�re le prix exact du produit $product_price_arr = $this->get_adjusted_attribute_price($product_id, $quantity, $d["description"], $result_attributes); $product_price = $product_price_arr["product_price"]; $my_taxrate = $ps_product->get_product_taxrate($product_id); $description = $d["description"]; $product_final_price = round($product_price * ($my_taxrate + 1), 2); $product_currency = $product_price_arr["product_currency"]; $db = new ps_DB(); if ($product_parent_id > 0) { $q = "SELECT attribute_name, attribute_value, product_id "; $q .= "FROM #__{vm}_product_attribute WHERE "; $q .= "product_id='" . $product_id . "'"; $db->setQuery($q); $db->query(); while ($db->next_record()) { $description .= $db->f("attribute_name") . ": " . $db->f("attribute_value") . "; "; } } $q = "SELECT * FROM #__{vm}_order_item "; $q .= " WHERE order_id=" . $this->order_id; $db->query($q); $db->next_record(); $user_info_id = $db->f("user_info_id"); $order_status = $db->f("order_status"); $timestamp = time() + $mosConfig_offset * 60 * 60; $q = "SELECT order_item_id, product_quantity "; $q .= "FROM #__{vm}_order_item WHERE order_id = '" . $this->order_id . "' "; $q .= "AND product_id = '" . $product_id . "' "; $q .= "AND product_attribute = '" . addslashes($description) . "'"; $db->query($q); if ($db->next_record()) { $this->change_item_quantity($this->order_id, $db->f('order_item_id'), $quantity + (int) $db->f('product_quantity')); } else { $q = "INSERT INTO #__{vm}_order_item "; $q .= "(order_id, user_info_id, vendor_id, product_id, order_item_sku, order_item_name, "; $q .= "product_quantity, product_item_price, product_final_price, "; $q .= "order_item_currency, order_status, product_attribute, cdate, mdate) "; $q .= "VALUES ('"; $q .= $this->order_id . "', '"; $q .= $user_info_id . "', '"; $q .= $vendor_id . "', '"; $q .= $product_id . "', '"; $q .= $product_sku . "', '"; $q .= $product_name . "', '"; $q .= $quantity . "', '"; $q .= $product_price . "', '"; $q .= $product_final_price . "', '"; $q .= $product_currency . "', '"; $q .= $order_status . "', '"; // added for advanced attribute storage $q .= addslashes($description) . "', '"; // END advanced attribute modifications $q .= $timestamp . "','"; $q .= $timestamp . "'"; $q .= ")"; $db->query($q); $db->next_record(); } // Update Stock Level and Product Sales $q = "UPDATE #__{vm}_product "; $q .= "SET product_in_stock = product_in_stock - " . $quantity . ",\r\n\t\t\t\t\t\t\tproduct_sales= product_sales + " . $quantity; $q .= " WHERE product_id='" . $product_id . "'"; $db->query($q); $this->recalc_order($this->order_id); $this->reload_from_db = 1; $vmLogger->info($VM_LANG->_('PHPSHOP_ORDER_EDIT_PRODUCT_ADDED')); } }