Esempio n. 1
0
 function get_product_price($product_id)
 {
     global $cart, $order;
     $products_id = smn_get_prid($product_id);
     // products price
     $qty = $cart->contents[$product_id]['qty'];
     $product_query = smn_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id='" . $product_id . "'");
     if ($product = smn_db_fetch_array($product_query)) {
         $prid = $product['products_id'];
         $products_tax = smn_get_tax_rate($product['products_tax_class_id']);
         $products_price = $product['products_price'];
         $specials_query = smn_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . $prid . "' and status = '1'");
         if (smn_db_num_rows($specials_query)) {
             $specials = smn_db_fetch_array($specials_query);
             $products_price = $specials['specials_new_products_price'];
         }
         if ($this->include_tax == 'true') {
             $total_price += ($products_price + smn_calculate_tax($products_price, $products_tax)) * $qty;
         } else {
             $total_price += $products_price * $qty;
         }
         // attributes price
         if (isset($cart->contents[$product_id]['attributes'])) {
             reset($cart->contents[$product_id]['attributes']);
             while (list($option, $value) = each($cart->contents[$product_id]['attributes'])) {
                 $attribute_price_query = smn_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 . "'");
                 $attribute_price = smn_db_fetch_array($attribute_price_query);
                 if ($attribute_price['price_prefix'] == '+') {
                     if ($this->include_tax == 'true') {
                         $total_price += $qty * ($attribute_price['options_values_price'] + smn_calculate_tax($attribute_price['options_values_price'], $products_tax));
                     } else {
                         $total_price += $qty * $attribute_price['options_values_price'];
                     }
                 } else {
                     if ($this->include_tax == 'true') {
                         $total_price -= $qty * ($attribute_price['options_values_price'] + smn_calculate_tax($attribute_price['options_values_price'], $products_tax));
                     } else {
                         $total_price -= $qty * $attribute_price['options_values_price'];
                     }
                 }
             }
         }
     }
     if ($this->include_shipping == 'true') {
         $total_price += $order->info['shipping_cost'];
     }
     return $total_price;
 }
 // Update products_ordered (for bestsellers list)
 smn_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . smn_get_prid($order->products[$i]['id']) . "'");
 if ($order->products[$i]['products_store_id'] == $store_list[$k]) {
     $sql_data_array = array('orders_id' => $insert_id, 'products_id' => smn_get_prid($order->products[$i]['id']), 'products_model' => $order->products[$i]['model'], 'products_name' => $order->products[$i]['name'], 'products_price' => $order->products[$i]['price'], 'final_price' => $order->products[$i]['final_price'], 'products_tax' => $order->products[$i]['tax'], 'products_quantity' => $order->products[$i]['qty']);
     smn_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array);
 }
 $order_products_id = smn_db_insert_id();
 $order_total_modules->update_credit_account($i);
 $member_product = explode('_', $order->products[$i]['model']);
 if ($member_product[0] == 'mem' && $store_id == 1) {
     $start_day = getdate();
     $day = $start_day['mday'];
     $month = $start_day['mon'];
     $year = $start_day['year'];
     $product_end_date = strftime('%Y', mktime(0, 0, 0, $month + (int) $member_product[1], $day, $year)) . '-' . strftime('%m', mktime(0, 0, 0, $month + (int) $member_product[1], $day, $year)) . '-' . strftime('%d', mktime(0, 0, 0, $month + (int) $member_product[1], $day, $year));
     $sql_data_array = array('orders_id' => $insert_id, 'store_id' => $insert_id, 'products_id' => smn_get_prid($order->products[$i]['id']), 'customer_id' => $customer_id, 'products_end_date' => $product_end_date);
     $update_query = smn_db_query("select store_id from " . TABLE_MEMBER_ORDERS . " where customer_id = '" . (int) $customer_id . "'");
     if (smn_db_num_rows($update_query)) {
         smn_db_perform(TABLE_MEMBER_ORDERS, $sql_data_array, 'update', "customer_id = '" . (int) $customer_id . "'");
     } else {
         smn_db_perform(TABLE_MEMBER_ORDERS, $sql_data_array);
     }
     smn_db_query("update " . TABLE_STORE_MAIN . " set store_status = 1 where customer_id = '" . (int) $customer_id . "'");
     $set_member_product = 'true';
 }
 //------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++) {
Esempio n. 3
0
function smn_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 = smn_get_prid($prid);
        if (is_numeric($uprid)) {
            if (strpos($prid, '{') !== false) {
                $attributes_check = true;
                $attributes_ids = '';
                // strpos()+1 to remove up to and including the first { which would create an empty array element in explode()
                $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;
}
 function update_quantity($products_id, $quantity = '', $attributes = '', $use_store_id = 1)
 {
     global $customer_id;
     $products_id_string = smn_get_uprid($products_id, $attributes);
     $products_id = smn_get_prid($products_id_string);
     if (defined('MAX_QTY_IN_CART') && MAX_QTY_IN_CART > 0 && (int) $quantity > MAX_QTY_IN_CART) {
         $quantity = MAX_QTY_IN_CART;
     }
     if (is_numeric($products_id) && isset($this->contents[$products_id_string]) && is_numeric($quantity)) {
         $this->contents[$products_id_string] = array('qty' => (int) $quantity, 'store_id' => (int) $use_store_id);
         // update database
         if (smn_session_is_registered('customer_id')) {
             smn_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . (int) $quantity . "' where customers_id = '" . (int) $customer_id . "' and products_id = '" . smn_db_input($products_id_string) . "'");
         }
         if (is_array($attributes)) {
             reset($attributes);
             while (list($option, $value) = each($attributes)) {
                 $this->contents[$products_id_string]['attributes'][$option] = $value;
                 // update database
                 if (smn_session_is_registered('customer_id')) {
                     smn_db_query("update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int) $value . "' where customers_id = '" . (int) $customer_id . "' and products_id = '" . smn_db_input($products_id_string) . "' and products_options_id = '" . (int) $option . "'");
                 }
             }
         }
     }
 }
 case 'update_product':
     for ($i = 0, $n = sizeof($_POST['products_id']); $i < $n; $i++) {
         if ($store_registered && in_array($_POST['products_id'][$i], is_array($_POST['cart_delete']) ? $_POST['cart_delete'] : array())) {
             $cart->remove($_POST['products_id'][$i]);
         } else {
             $attributes = $_POST['id'][$_POST['products_id'][$i]] ? $_POST['id'][$_POST['products_id'][$i]] : '';
             $cart->add_cart($_POST['products_id'][$i], $_POST['cart_quantity'][$i], $attributes, false);
         }
     }
     smn_redirect(smn_href_link($goto, smn_get_all_get_params($parameters)));
     break;
     // customer adds a product from the products page
 // customer adds a product from the products page
 case 'add_product':
     if ($store_registered && isset($_POST['products_id'])) {
         $cart->add_cart($_POST['products_id'], $cart->get_quantity(smn_get_prid(smn_get_uprid($_POST['products_id'], $_POST['id']))) + 1, $_POST['id']);
     }
     smn_redirect(smn_href_link($goto, smn_get_all_get_params($parameters)));
     break;
     // performed by the 'buy now' button in product listings and review page
 // performed by the 'buy now' button in product listings and review page
 case 'buy_now':
     if ($store_registered && isset($_GET['products_id'])) {
         if (smn_has_product_attributes($_GET['products_id'])) {
             smn_redirect(smn_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $_GET['products_id']));
         } else {
             $cart->add_cart($_GET['products_id'], $cart->get_quantity($_GET['products_id']) + 1);
         }
     }
     smn_redirect(smn_href_link($goto, smn_get_all_get_params($parameters)));
     break;
Esempio n. 6
0
     if (smn_db_num_rows($stock_query) > 0) {
         $stock_values = smn_db_fetch_array($stock_query);
         // do not decrement quantities if products_attributes_filename exists
         if (DOWNLOAD_ENABLED != 'true' || !$stock_values['products_attributes_filename']) {
             $stock_left = $stock_values['products_quantity'] - $order->products[$i]['qty'];
         } else {
             $stock_left = $stock_values['products_quantity'];
         }
         smn_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . smn_get_prid($order->products[$i]['id']) . "'");
         if ($stock_left < 1 && STOCK_ALLOW_CHECKOUT == 'false') {
             smn_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . smn_get_prid($order->products[$i]['id']) . "'");
         }
     }
 }
 // Update products_ordered (for bestsellers list)
 smn_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . smn_get_prid($order->products[$i]['id']) . "'");
 // Let's get all the info together for the email
 $total_weight += $order->products[$i]['qty'] * $order->products[$i]['weight'];
 $total_tax += smn_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty'];
 $total_cost += $total_products_price;
 // Let's get the attributes
 $products_ordered_attributes = '';
 if (isset($order->products[$i]['attributes']) && sizeof($order->products[$i]['attributes']) > 0) {
     for ($j = 0, $n2 = sizeof($order->products[$i]['attributes']); $j < $n2; $j++) {
         $products_ordered_attributes .= "\n\t" . $order->products[$i]['attributes'][$j]['option'] . ' ' . $order->products[$i]['attributes'][$j]['value'];
     }
 }
 // Let's format the products model
 $products_model = '';
 if (!empty($order->products[$i]['model'])) {
     $products_model = ' (' . $order->products[$i]['model'] . ')';
Esempio n. 7
0
 function before_process()
 {
     global $cart, $customer_id, $invoice, $order;
     if (ALLOW_STORE_PAYMENT == 'true') {
         $invoice_query = smn_db_query("select o.store_id from " . TABLE_ORDERS . " o where o.orders_id='" . $invoice . "'");
         while ($invoice = smn_db_fetch_array($invoice_query)) {
             $store_id = $invoice[store_id];
             for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
                 // PRODUCT LOOP STARTS HERE
                 unset($cart->contents[smn_get_prid($order->products[$i]['id'])]);
                 smn_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int) $customer_id . "' and products_id = '" . smn_get_prid($order->products[$i]['id']) . "' and store_id='" . $store_id . "'");
                 smn_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int) $customer_id . "' and products_id = '" . smn_get_prid($order->products[$i]['id']) . "' and store_id='" . $store_id . "'");
             }
         }
     } else {
         $cart->reset(true);
     }
     // unregister session variables used during checkout
     smn_session_unregister('sendto');
     smn_session_unregister('billto');
     smn_session_unregister('shipping');
     smn_session_unregister('payment');
     smn_session_unregister('comments');
     smn_session_unregister('cart_PayPal_IPN_ID');
     smn_redirect(smn_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'NONSSL'));
 }