| 1 | <?php
|
|---|
| 2 | if ($cart_object->type == 'cart' && $action == 'add_product') {
|
|---|
| 3 |
|
|---|
| 4 | // include needed functions
|
|---|
| 5 | require_once (DIR_FS_INC.'xtc_check_stock.inc.php');
|
|---|
| 6 | require_once (DIR_FS_INC.'xtc_get_products_stock.inc.php');
|
|---|
| 7 | require_once (DIR_FS_INC.'check_stock_specials.inc.php');
|
|---|
| 8 | require_once (DIR_FS_INC.'xtc_remove_non_numeric.inc.php');
|
|---|
| 9 |
|
|---|
| 10 | $_POST['products_id'] = (int)$_POST['products_id'];
|
|---|
| 11 | $attributes_array = ((isset($_POST['id'])) ? $_POST['id'] : '');
|
|---|
| 12 | $cart_quantity = $cart_object->get_quantity(xtc_get_uprid($_POST['products_id'], $attributes_array));
|
|---|
| 13 |
|
|---|
| 14 | if (STOCK_CHECK == 'true') {
|
|---|
| 15 | $check_stock = xtc_check_stock($_POST['products_id'], $cart_quantity);
|
|---|
| 16 | if ($check_stock) {
|
|---|
| 17 | $products_stock = xtc_get_products_stock($_POST['products_id']);
|
|---|
| 18 | if ($products_stock <= 0 && STOCK_ALLOW_CHECKOUT == 'false') {
|
|---|
| 19 | $cart_object->remove(xtc_get_uprid($_POST['products_id'], $attributes_array));
|
|---|
| 20 | } else {
|
|---|
| 21 | $cart_object->add_cart($_POST['products_id'], $products_stock, $attributes_array, false);
|
|---|
| 22 | $_SESSION['cart_qty_adjust'] = true;
|
|---|
| 23 | }
|
|---|
| 24 | }
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | if (STOCK_CHECK_SPECIALS == 'true' && $xtPrice->xtcCheckSpecial($_POST['products_id'])) {
|
|---|
| 28 | $check_stock = check_stock_specials($_POST['products_id'], $cart_quantity);
|
|---|
| 29 | if ($check_stock) {
|
|---|
| 30 | $stock_check_query = xtc_db_query("SELECT specials_quantity
|
|---|
| 31 | FROM ".TABLE_SPECIALS."
|
|---|
| 32 | WHERE products_id = '".$_POST['products_id']."'");
|
|---|
| 33 | $stock_check = xtc_db_fetch_array($stock_check_query);
|
|---|
| 34 | $cart_object->add_cart($_POST['products_id'], $stock_check['specials_quantity'], $attributes_array, false);
|
|---|
| 35 |
|
|---|
| 36 | $_SESSION['cart_qty_adjust'] = true;
|
|---|
| 37 | }
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | if (ATTRIBUTE_STOCK_CHECK == 'true' && STOCK_CHECK == 'true' && is_array($attributes_array)) {
|
|---|
| 41 | $products_stock = xtc_get_products_stock($_POST['products_id']);
|
|---|
| 42 | while (list ($option, $value) = each($_POST['id'])) {
|
|---|
| 43 | $attributes = $main->getAttributes($_POST['products_id'], $option, $value);
|
|---|
| 44 | if ($attributes['attributes_stock'] - $cart_quantity < 0) {
|
|---|
| 45 | if ($attributes['attributes_stock'] <= 0 && STOCK_ALLOW_CHECKOUT == 'false') {
|
|---|
| 46 | $cart_object->remove(xtc_get_uprid($_POST['products_id'], $attributes_array));
|
|---|
| 47 | } else {
|
|---|
| 48 | $cart_object->add_cart($_POST['products_id'], $attributes['attributes_stock'], $attributes_array, false);
|
|---|
| 49 | $_SESSION['cart_qty_adjust'] = true;
|
|---|
| 50 | }
|
|---|
| 51 | }
|
|---|
| 52 | }
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | }
|
|---|
| 56 | ?>
|
|---|