function process()
 {
     global $order, $currencies;
     if (MODULE_ORDER_TOTAL_LOWORDERFEE_LOW_ORDER_FEE == 'true') {
         switch (MODULE_ORDER_TOTAL_LOWORDERFEE_DESTINATION) {
             case 'national':
                 if ($order->delivery['country_id'] == STORE_COUNTRY) {
                     $pass = true;
                 }
                 break;
             case 'international':
                 if ($order->delivery['country_id'] != STORE_COUNTRY) {
                     $pass = true;
                 }
                 break;
             case 'both':
                 $pass = true;
                 break;
             default:
                 $pass = false;
                 break;
         }
         if ($pass == true && $order->info['total'] - $order->info['shipping_cost'] < MODULE_ORDER_TOTAL_LOWORDERFEE_ORDER_UNDER) {
             $tax = tep_get_tax_rate(MODULE_ORDER_TOTAL_LOWORDERFEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $tax_description = tep_get_tax_description(MODULE_ORDER_TOTAL_LOWORDERFEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $order->info['tax'] += tep_calculate_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax);
             $order->info['tax_groups']["{$tax_description}"] += tep_calculate_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax);
             $order->info['total'] += MODULE_ORDER_TOTAL_LOWORDERFEE_FEE + tep_calculate_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax);
             $this->output[] = array('title' => $this->title . ':', 'text' => $currencies->format(tep_add_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax), true, $order->info['currency'], $order->info['currency_value']), 'value' => tep_add_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax));
         }
     }
 }
Beispiel #2
0
 function process()
 {
     global $order, $currencies;
     if (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') {
         $pass = false;
         switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) {
             case 'national':
                 if ($order->delivery['country_id'] == STORE_COUNTRY) {
                     $pass = true;
                 }
                 break;
             case 'international':
                 if ($order->delivery['country_id'] != STORE_COUNTRY) {
                     $pass = true;
                 }
                 break;
             case 'both':
                 $pass = true;
                 break;
             default:
                 $pass = false;
                 break;
         }
         if ($pass == true && $order->info['total'] - $order->info['shipping_cost'] >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) {
             $order->info['shipping_method'] = OSCOM::getDef('free_shipping_title');
             $order->info['total'] -= $order->info['shipping_cost'];
             $order->info['shipping_cost'] = 0;
         }
     }
     if (strpos($_SESSION['shipping']['id'], '\\') !== false) {
         list($vendor, $app, $module) = explode('\\', $_SESSION['shipping']['id']);
         list($module, $method) = explode('_', $module);
         $module = $vendor . '\\' . $app . '\\' . $module;
         $code = 'Shipping_' . str_replace('\\', '_', $module);
         if (Registry::exists($code)) {
             $OSCOM_SM = Registry::get($code);
         }
     } else {
         list($module, $method) = explode('_', $_SESSION['shipping']['id']);
         if (is_object($GLOBALS[$module])) {
             $OSCOM_SM = $GLOBALS[$module];
         }
     }
     if (tep_not_null($order->info['shipping_method'])) {
         if ($OSCOM_SM->tax_class > 0) {
             $shipping_tax = tep_get_tax_rate($OSCOM_SM->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $shipping_tax_description = tep_get_tax_description($OSCOM_SM->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $order->info['tax'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['tax_groups']["{$shipping_tax_description}"] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['total'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             if (DISPLAY_PRICE_WITH_TAX == 'true') {
                 $order->info['shipping_cost'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             }
         }
         $this->output[] = array('title' => $order->info['shipping_method'] . ':', 'text' => $currencies->format($order->info['shipping_cost'], true, $order->info['currency'], $order->info['currency_value']), 'value' => $order->info['shipping_cost']);
     }
 }
Beispiel #3
0
 function process()
 {
     global $order, $currencies;
     if (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') {
         switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) {
             case 'national':
                 if ($order->delivery['country_id'] == STORE_COUNTRY) {
                     $pass = true;
                 }
                 break;
             case 'international':
                 if ($order->delivery['country_id'] != STORE_COUNTRY) {
                     $pass = true;
                 }
                 break;
             case 'both':
                 $pass = true;
                 break;
             default:
                 $pass = false;
                 break;
         }
         /* One Page Checkout - BEGIN */
         /*        if ( ($pass == true) && ( ($order->info['subtotal'] - $order->info['shipping_cost']) >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) ) {
                   $order->info['shipping_method'] = FREE_SHIPPING_TITLE;
                   $order->info['total'] -= $order->info['shipping_cost'];
                   $order->info['shipping_cost'] = 0;
                 }
         */
         if (ONEPAGE_CHECKOUT_ENABLED != 'True') {
             if ($pass == true && $order->info['subtotal'] - $order->info['shipping_cost'] >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) {
                 $order->info['shipping_method'] = FREE_SHIPPING_TITLE;
                 $order->info['total'] -= $order->info['shipping_cost'];
                 $order->info['shipping_cost'] = 0;
             }
         }
         /* One Page Checkout - END */
     }
     $module = substr($GLOBALS['shipping']['id'], 0, strpos($GLOBALS['shipping']['id'], '_'));
     if (tep_not_null($order->info['shipping_method'])) {
         if ($GLOBALS[$module]->tax_class > 0) {
             $shipping_tax = tep_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $shipping_tax_description = tep_get_tax_description($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $order->info['tax'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['tax_groups']["{$shipping_tax_description}"] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['total'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             if (DISPLAY_PRICE_WITH_TAX == 'true') {
                 $order->info['shipping_cost'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             }
         }
         $this->output[] = array('title' => $order->info['shipping_method'] . ':', 'text' => $currencies->format($order->info['shipping_cost'], true, $order->info['currency'], $order->info['currency_value']), 'value' => $order->info['shipping_cost']);
     }
 }
Beispiel #4
0
 function process()
 {
     global $order, $currencies;
     if (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') {
         switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) {
             case 'national':
                 if ($order->delivery['country_id'] == STORE_COUNTRY) {
                     $pass = true;
                 }
                 break;
             case 'international':
                 if ($order->delivery['country_id'] != STORE_COUNTRY) {
                     $pass = true;
                 }
                 break;
             case 'both':
                 $pass = true;
                 break;
             default:
                 $pass = false;
                 break;
         }
         if ($pass == true && $order->info['total'] - $order->info['shipping_cost'] >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) {
             $order->info['shipping_method'] = FREE_SHIPPING_TITLE;
             $order->info['total'] -= $order->info['shipping_cost'];
             $order->info['shipping_cost'] = 0;
         }
     }
     $module = substr($GLOBALS['shipping']['id'], 0, strpos($GLOBALS['shipping']['id'], '_'));
     if (tep_not_null($order->info['shipping_method'])) {
         if ($GLOBALS[$module]->tax_class > 0) {
             $shipping_tax = tep_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $shipping_tax_description = tep_get_tax_description($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $order->info['tax'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['tax_groups']["{$shipping_tax_description}"] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['total'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             if (DISPLAY_PRICE_WITH_TAX == 'true') {
                 $order->info['shipping_cost'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             }
         }
         $search = array(' regimark', ' tradmrk');
         $replace = array('<sup>&reg;</sup>', '<sup>&trade;</sup>');
         $this->output[] = array('title' => str_replace($search, $replace, $order->info['shipping_method']) . ':', 'text' => $currencies->format($order->info['shipping_cost'], true, $order->info['currency'], $order->info['currency_value']), 'value' => $order->info['shipping_cost']);
     }
 }
 function process()
 {
     global $osC_Session, $osC_Tax, $order, $osC_Currencies;
     if (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') {
         switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) {
             case 'national':
                 if ($order->delivery['country_id'] == STORE_COUNTRY) {
                     $pass = true;
                 }
                 break;
             case 'international':
                 if ($order->delivery['country_id'] != STORE_COUNTRY) {
                     $pass = true;
                 }
                 break;
             case 'both':
                 $pass = true;
                 break;
             default:
                 $pass = false;
                 break;
         }
         if ($pass == true && $order->info['total'] - $order->info['shipping_cost'] >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) {
             $order->info['shipping_method'] = $this->title;
             $order->info['total'] -= $order->info['shipping_cost'];
             $order->info['shipping_cost'] = 0;
         }
     }
     $shipping =& $osC_Session->value('shipping');
     $module = substr($shipping['id'], 0, strpos($shipping['id'], '_'));
     if (tep_not_null($order->info['shipping_method'])) {
         if ($GLOBALS[$module]->tax_class > 0) {
             $shipping_tax = $osC_Tax->getTaxRate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $shipping_tax_description = $osC_Tax->getTaxRateDescription($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $order->info['tax'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['tax_groups']["{$shipping_tax_description}"] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['total'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             if (DISPLAY_PRICE_WITH_TAX == 'true') {
                 $order->info['shipping_cost'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
             }
         }
         $this->output[] = array('title' => $order->info['shipping_method'] . ':', 'text' => $osC_Currencies->format($order->info['shipping_cost'], $order->info['currency'], $order->info['currency_value']), 'value' => $order->info['shipping_cost']);
     }
 }
Beispiel #6
0
/**
 * Process a <new-order-notification>.
 *
 * If the email user does not exist, create the user and log in.
 *
 * If the user does not exist as a Google Checkout user, add them
 * to the google_checkout table to match the buyer_id and customer_id.
 *
 * Add the order to the logged-in user.
 *
 * TODO(eddavisson): This function is way too long. Split into pieces.
 */
function process_new_order_notification($google_response, $google_checkout)
{
    global $order, $currencies, $languages_id;
    list($root, $gc_data) = $google_response->GetParsedXML();
    // Check if the order was already processed.
    $google_order = tep_db_fetch_array(tep_db_query("select orders_id " . " from " . $google_checkout->table_order . " " . " where google_order_number = " . $gc_data[$root]['google-order-number']['VALUE']));
    // Check if order was alread processed.
    if ($google_order['orders_id'] != '') {
        //Send ACK http 200 to avoid notification resend.
        $google_response->log->logError(sprintf(GOOGLECHECKOUT_ERR_DUPLICATED_ORDER, $gc_data[$root]['google-order-number']['VALUE'], $google_order['orders_id']));
        $google_response->SendAck();
    }
    // Check if the email exists.
    $customer_exists = tep_db_fetch_array(tep_db_query("select customers_id from " . TABLE_CUSTOMERS . " where customers_email_address = '" . gc_make_sql_string($gc_data[$root]['buyer-billing-address']['email']['VALUE']) . "'"));
    // Check if the GC buyer id exists
    $customer_info = tep_db_fetch_array(tep_db_query("select gct.customers_id from " . $google_checkout->table_name . " gct " . " inner join " . TABLE_CUSTOMERS . " tc on gct.customers_id = tc.customers_id " . " where gct.buyer_id = " . gc_make_sql_string($gc_data[$root]['buyer-id']['VALUE'])));
    $new_user = false;
    // Ignore session to avoid mix of Cart-GC sessions/emails
    // GC email is the most important one
    if ($customer_exists['customers_id'] != '') {
        $customer_id = $customer_exists['customers_id'];
        tep_session_register('customer_id');
    } else {
        if ($customer_info['customers_id'] != '') {
            $customer_id = $customer_info['customers_id'];
            tep_session_register('customer_id');
        } else {
            list($firstname, $lastname) = explode(' ', gc_make_sql_string($gc_data[$root]['buyer-billing-address']['contact-name']['VALUE']), 2);
            $sql_data_array = array('customers_firstname' => $firstname, 'customers_lastname' => $lastname, 'customers_email_address' => $gc_data[$root]['buyer-billing-address']['email']['VALUE'], 'customers_telephone' => $gc_data[$root]['buyer-billing-address']['phone']['VALUE'], 'customers_fax' => $gc_data[$root]['buyer-billing-address']['fax']['VALUE'], 'customers_default_address_id' => 0, 'customers_password' => tep_encrypt_password(gc_make_sql_string($gc_data[$root]['buyer-id']['VALUE'])), 'customers_newsletter' => $gc_data[$root]['buyer-marketing-preferences']['email-allowed']['VALUE'] == 'true' ? 1 : 0);
            if (ACCOUNT_DOB == 'true') {
                $sql_data_array['customers_dob'] = 'now()';
            }
            tep_db_perform(TABLE_CUSTOMERS, $sql_data_array);
            $customer_id = tep_db_insert_id();
            tep_session_register('customer_id');
            tep_db_query("insert into " . TABLE_CUSTOMERS_INFO . "\n        (customers_info_id, customers_info_number_of_logons,\n        customers_info_date_account_created)\n        values ('" . (int) $customer_id . "', '0', now())");
            tep_db_query("insert into " . $google_checkout->table_name . " " . " values ( " . $customer_id . ", " . $gc_data[$root]['buyer-id']['VALUE'] . ")");
            $new_user = true;
        }
    }
    // The user exists and is logged in.
    // Check database to see if the address exist.
    $address_book = tep_db_query("select address_book_id, entry_country_id, entry_zone_id from " . TABLE_ADDRESS_BOOK . "\n          where  customers_id = '" . $customer_id . "'\n              and entry_street_address = '" . gc_make_sql_string($gc_data[$root]['buyer-shipping-address']['address1']['VALUE']) . "'\n              and entry_suburb = '" . gc_make_sql_string($gc_data[$root]['buyer-shipping-address']['address2']['VALUE']) . "'\n              and entry_postcode = '" . gc_make_sql_string($gc_data[$root]['buyer-shipping-address']['postal-code']['VALUE']) . "'\n              and entry_city = '" . gc_make_sql_string($gc_data[$root]['buyer-shipping-address']['city']['VALUE']) . "'");
    // If not, add the address as the default.
    if (!tep_db_num_rows($address_book)) {
        $buyer_state = $gc_data[$root]['buyer-shipping-address']['region']['VALUE'];
        $zone_answer = tep_db_fetch_array(tep_db_query("select zone_id, zone_country_id from " . TABLE_ZONES . " where zone_code = '" . $buyer_state . "'"));
        list($firstname, $lastname) = explode(' ', gc_make_sql_string($gc_data[$root]['buyer-shipping-address']['contact-name']['VALUE']), 2);
        $sql_data_array = array('customers_id' => $customer_id, 'entry_gender' => '', 'entry_company' => $gc_data[$root]['buyer-shipping-address']['company-name']['VALUE'], 'entry_firstname' => $firstname, 'entry_lastname' => $lastname, 'entry_street_address' => $gc_data[$root]['buyer-shipping-address']['address1']['VALUE'], 'entry_suburb' => $gc_data[$root]['buyer-shipping-address']['address2']['VALUE'], 'entry_postcode' => $gc_data[$root]['buyer-shipping-address']['postal-code']['VALUE'], 'entry_city' => $gc_data[$root]['buyer-shipping-address']['city']['VALUE'], 'entry_state' => $buyer_state, 'entry_country_id' => $zone_answer['zone_country_id'], 'entry_zone_id' => $zone_answer['zone_id']);
        tep_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array);
        $address_id = tep_db_insert_id();
        tep_db_query("update " . TABLE_CUSTOMERS . "\n        set customers_default_address_id = '" . (int) $address_id . "'\n        where customers_id = '" . (int) $customer_id . "'");
        $customer_default_address_id = $address_id;
        $customer_country_id = $zone_answer['zone_country_id'];
        $customer_zone_id = $zone_answer['zone_id'];
    } else {
        $customer_default_address_id = $address_book['address_book_id'];
        $customer_country_id = $address_book['entry_country_id'];
        $customer_zone_id = $address_book['entry_zone_id'];
    }
    $customer_first_name = $gc_data[$root]['buyer-billing-address']['contact-name']['VALUE'];
    tep_session_register('customer_default_address_id');
    tep_session_register('customer_country_id');
    tep_session_register('customer_zone_id');
    tep_session_register('customer_first_name');
    // Customer exists, is logged and address book is up to date.
    list($shipping, $shipping_cost, $shipping_method_name, $shipping_method_code) = get_shipping_info($google_checkout, $gc_data[$root]);
    $tax_amt = $gc_data[$root]['order-adjustment']['total-tax']['VALUE'];
    //$order_total = $gc_data[$root]['order-total']['VALUE'];
    require DIR_WS_CLASSES . 'order.php';
    $order = new order();
    // Load the selected shipping module.
    $payment_method = $google_checkout->title;
    if (MODULE_PAYMENT_GOOGLECHECKOUT_MODE == 'https://sandbox.google.com/checkout/') {
        $payment_method .= " - SANDBOX";
    }
    //$method_name = '';
    //if (!empty($shipping)) {
    //  require (DIR_WS_CLASSES . 'shipping.php');
    //  $shipping_modules = new shipping($shipping);
    //  list ($a, $method_name) = explode(': ', $shipping, 2);
    //}
    // Set up order info.
    list($order->customer['firstname'], $order->customer['lastname']) = explode(' ', $gc_data[$root]['buyer-billing-address']['contact-name']['VALUE'], 2);
    $order->customer['company'] = $gc_data[$root]['buyer-billing-address']['company-name']['VALUE'];
    $order->customer['street_address'] = $gc_data[$root]['buyer-billing-address']['address1']['VALUE'];
    $order->customer['suburb'] = $gc_data[$root]['buyer-billing-address']['address2']['VALUE'];
    $order->customer['city'] = $gc_data[$root]['buyer-billing-address']['city']['VALUE'];
    $order->customer['postcode'] = $gc_data[$root]['buyer-billing-address']['postal-code']['VALUE'];
    $order->customer['state'] = $gc_data[$root]['buyer-billing-address']['region']['VALUE'];
    $order->customer['country']['title'] = $gc_data[$root]['buyer-billing-address']['country-code']['VALUE'];
    $order->customer['telephone'] = $gc_data[$root]['buyer-billing-address']['phone']['VALUE'];
    $order->customer['email_address'] = $gc_data[$root]['buyer-billing-address']['email']['VALUE'];
    $order->customer['format_id'] = 2;
    list($order->delivery['firstname'], $order->delivery['lastname']) = explode(' ', $gc_data[$root]['buyer-shipping-address']['contact-name']['VALUE'], 2);
    $order->delivery['company'] = $gc_data[$root]['buyer-shipping-address']['company-name']['VALUE'];
    $order->delivery['street_address'] = $gc_data[$root]['buyer-shipping-address']['address1']['VALUE'];
    $order->delivery['suburb'] = $gc_data[$root]['buyer-shipping-address']['address2']['VALUE'];
    $order->delivery['city'] = $gc_data[$root]['buyer-shipping-address']['city']['VALUE'];
    $order->delivery['postcode'] = $gc_data[$root]['buyer-shipping-address']['postal-code']['VALUE'];
    $order->delivery['state'] = $gc_data[$root]['buyer-shipping-address']['region']['VALUE'];
    $order->delivery['country']['title'] = $gc_data[$root]['buyer-shipping-address']['country-code']['VALUE'];
    $order->delivery['format_id'] = 2;
    list($order->billing['firstname'], $order->billing['lastname']) = explode(' ', $gc_data[$root]['buyer-billing-address']['contact-name']['VALUE'], 2);
    $order->billing['company'] = $gc_data[$root]['buyer-billing-address']['company-name']['VALUE'];
    $order->billing['street_address'] = $gc_data[$root]['buyer-billing-address']['address1']['VALUE'];
    $order->billing['suburb'] = $gc_data[$root]['buyer-billing-address']['address2']['VALUE'];
    $order->billing['city'] = $gc_data[$root]['buyer-billing-address']['city']['VALUE'];
    $order->billing['postcode'] = $gc_data[$root]['buyer-billing-address']['postal-code']['VALUE'];
    $order->billing['state'] = $gc_data[$root]['buyer-billing-address']['region']['VALUE'];
    $order->billing['country']['title'] = $gc_data[$root]['buyer-billing-address']['country-code']['VALUE'];
    $order->billing['format_id'] = 2;
    $order->info['payment_method'] = $payment_method;
    $order->info['payment_module_code'] = $google_checkout->code;
    $order->info['shipping_method'] = $shipping_method_name;
    $order->info['shipping_module_code'] = $shipping_method_code;
    $order->info['cc_type'] = '';
    $order->info['cc_owner'] = '';
    $order->info['cc_number'] = '';
    $order->info['cc_expires'] = '';
    $order->info['order_status'] = GC_STATE_NEW;
    $order->info['tax'] = $tax_amt;
    $order->info['currency'] = $gc_data[$root]['order-total']['currency'];
    $order->info['currency_value'] = 1;
    //$customers_ip_address'] = $gc_data[$root]['shopping-cart']['merchant-private-data']['ip-address']['VALUE'];
    $order->info['comments'] = GOOGLECHECKOUT_STATE_NEW_ORDER_NUM . $gc_data[$root]['google-order-number']['VALUE'] . "\n" . GOOGLECHECKOUT_STATE_NEW_ORDER_MC_USED . (@$gc_data[$root]['order-adjustment']['merchant-calculation-successful']['VALUE'] == 'true' ? 'True' : 'False') . ($new_user ? "\n" . GOOGLECHECKOUT_STATE_NEW_ORDER_BUYER_USER . $gc_data[$root]['buyer-billing-address']['email']['VALUE'] . "\n" . GOOGLECHECKOUT_STATE_NEW_ORDER_BUYER_PASS . $gc_data[$root]['buyer-id']['VALUE'] : '');
    $coupons = gc_get_arr_result(@$gc_data[$root]['order-adjustment']['merchant-codes']['coupon-adjustment']);
    //$gift_cert = get_arr_result(@$gc_data[$root]['order-adjustment']['merchant-codes']['gift-certificate-adjustment']);
    $items = gc_get_arr_result($gc_data[$root]['shopping-cart']['items']['item']);
    // Get Coustoms OT
    $custom_order_totals_total = 0;
    $custom_order_totals = array();
    $order->products = array();
    foreach ($items as $item) {
        if (isset($item['merchant-private-item-data']['item']['VALUE'])) {
            $order->products[] = unserialize(base64_decode($item['merchant-private-item-data']['item']['VALUE']));
        } else {
            if ($item['merchant-private-item-data']['order_total']['VALUE']) {
                $order_total = unserialize(base64_decode($item['merchant-private-item-data']['order_total']['VALUE']));
                $custom_order_totals[] = $order_total;
                $order_total_value = $order_total['value'] * (strrpos($order_total['text'], '-') === false ? 1 : -1);
                $custom_order_totals_total += $currencies->get_value($gc_data[$root]['order-total']['currency']) * $order_total_value;
            } else {
                // For invoices.
                $order->products[] = array('qty' => $item['quantity']['VALUE'], 'name' => $item['item-name']['VALUE'], 'model' => $item['item-description']['VALUE'], 'tax' => 0, 'tax_description' => @$item['tax-table-selector']['VALUE'], 'price' => $item['unit-price']['VALUE'], 'final_price' => $item['unit-price']['VALUE'], 'onetime_charges' => 0, 'weight' => 0, 'products_priced_by_attribute' => 0, 'product_is_free' => 0, 'products_discount_type' => 0, 'products_discount_type_from' => 0, 'id' => @$item['merchant-item-id']['VALUE']);
            }
        }
    }
    $cart = new shoppingCart();
    $prod_attr = gc_get_prattr($order->products);
    foreach ($prod_attr as $product_id => $item_data) {
        //$products_id, $qty = '1', $attributes = '
        $cart->add_cart($product_id, $item_data['qty'], $item_data['attr']);
    }
    // Update values so that order_total modules get the correct values.
    $order->info['total'] = $gc_data[$root]['order-total']['VALUE'];
    $order->info['subtotal'] = $gc_data[$root]['order-total']['VALUE'] - ($shipping_cost + $tax_amt) + @$coupons[0]['applied-amount']['VALUE'] - $custom_order_totals_total;
    $order->info['coupon_code'] = @$coupons[0]['code']['VALUE'];
    $order->info['shipping_method'] = $shipping;
    $order->info['shipping_cost'] = $shipping_cost;
    $order->info['tax_groups']['tax'] = $tax_amt;
    $order->info['currency'] = $gc_data[$root]['order-total']['currency'];
    $order->info['currency_value'] = 1;
    require DIR_WS_CLASSES . 'order_total.php';
    $order_total_modules = new order_total();
    // Disable OT sent as items in the GC cart
    foreach ($order_total_modules->modules as $order_total_code => $order_total) {
        if (!in_array(substr($order_total, 0, strrpos($order_total, '.')), $google_checkout->ignore_order_total)) {
            unset($order_total_modules->modules[$order_total_code]);
        }
    }
    $order_totals = $order_total_modules->process();
    // Not necessary, since order totals are already disabled.
    //foreach($order_totals as $order_total_code => $order_total){
    //  if(!in_array($order_total['code'], $google_checkout->ignore_order_total)){
    //    unset($order_totals[$order_total_code]);
    //  }
    //}
    // Merge all order totals.
    $order_totals = array_merge($order_totals, $custom_order_totals);
    if (isset($gc_data[$root]['order-adjustment']['merchant-codes']['coupon-adjustment'])) {
        $order_totals[] = array('code' => 'ot_coupon', 'title' => "<b>" . MODULE_ORDER_TOTAL_COUPON_TITLE . " " . @$coupons[0]['code']['VALUE'] . ":</b>", 'text' => $currencies->format(@$coupons[0]['applied-amount']['VALUE'] * -1, false, @$coupons[0]['applied-amount']['currency']), 'value' => @$coupons[0]['applied-amount']['VALUE'], 'sort_order' => 280);
    }
    function order_total_compare($a, $b)
    {
        if ($a['sort_order'] == $b['sort_order']) {
            return 0;
        } else {
            return $a['sort_order'] < $b['sort_order'] ? -1 : 1;
        }
    }
    usort($order_totals, "order_total_compare");
    $sql_data_array = array('customers_id' => $customer_id, 'customers_name' => $order->customer['firstname'] . ' ' . $order->customer['lastname'], 'customers_company' => $order->customer['company'], 'customers_street_address' => $order->customer['street_address'], 'customers_suburb' => $order->customer['suburb'], 'customers_city' => $order->customer['city'], 'customers_postcode' => $order->customer['postcode'], 'customers_state' => $order->customer['state'], 'customers_country' => $order->customer['country']['title'], 'customers_telephone' => $order->customer['telephone'], 'customers_email_address' => $order->customer['email_address'], 'customers_address_format_id' => $order->customer['format_id'], 'delivery_name' => $order->delivery['firstname'] . ' ' . $order->delivery['lastname'], 'delivery_company' => $order->delivery['company'], 'delivery_street_address' => $order->delivery['street_address'], 'delivery_suburb' => $order->delivery['suburb'], 'delivery_city' => $order->delivery['city'], 'delivery_postcode' => $order->delivery['postcode'], 'delivery_state' => $order->delivery['state'], 'delivery_country' => $order->delivery['country']['title'], 'delivery_address_format_id' => $order->delivery['format_id'], 'billing_name' => $order->billing['firstname'] . ' ' . $order->billing['lastname'], 'billing_company' => $order->billing['company'], 'billing_street_address' => $order->billing['street_address'], 'billing_suburb' => $order->billing['suburb'], 'billing_city' => $order->billing['city'], 'billing_postcode' => $order->billing['postcode'], 'billing_state' => $order->billing['state'], 'billing_country' => $order->billing['country']['title'], 'billing_address_format_id' => $order->billing['format_id'], 'payment_method' => $order->info['payment_method'], 'cc_type' => $order->info['cc_type'], 'cc_owner' => $order->info['cc_owner'], 'cc_number' => $order->info['cc_number'], 'cc_expires' => $order->info['cc_expires'], 'date_purchased' => 'now()', 'orders_status' => $order->info['order_status'], 'currency' => $order->info['currency'], 'currency_value' => $order->info['currency_value']);
    tep_db_perform(TABLE_ORDERS, $sql_data_array);
    $insert_id = tep_db_insert_id();
    for ($i = 0, $n = sizeof($order_totals); $i < $n; $i++) {
        $sql_data_array = array('orders_id' => $insert_id, 'title' => $order_totals[$i]['title'], 'text' => $order_totals[$i]['text'], 'value' => $order_totals[$i]['value'], 'class' => $order_totals[$i]['code'], 'sort_order' => $order_totals[$i]['sort_order']);
        tep_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array);
    }
    $customer_notification = SEND_EMAILS == 'true' ? '1' : '0';
    $sql_data_array = array('orders_id' => $insert_id, 'orders_status_id' => $order->info['order_status'], 'date_added' => 'now()', 'customer_notified' => $customer_notification, 'comments' => $order->info['comments']);
    tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
    // Initialized for the email confirmation.
    $products_ordered = '';
    $subtotal = 0;
    $total_tax = 0;
    $total_weight = 0;
    $total_products_price = 0;
    $products_tax = 0;
    $total_cost = 0;
    for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
        // Stock Update - Joao Correia.
        if (STOCK_LIMITED == 'true') {
            if (DOWNLOAD_ENABLED == 'true') {
                $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 = '" . tep_get_prid($order->products[$i]['id']) . "'";
                // 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'] . "'";
                }
                $stock_query = tep_db_query($stock_query_raw);
            } else {
                $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
            }
            if (tep_db_num_rows($stock_query) > 0) {
                $stock_values = tep_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'];
                }
                tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                if ($stock_left < 1 && STOCK_ALLOW_CHECKOUT == 'false') {
                    tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                }
            }
        }
        // Update products_ordered (for bestsellers list)
        tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
        $sql_data_array = array('orders_id' => $insert_id, 'products_id' => tep_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']);
        tep_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array);
        $order_products_id = tep_db_insert_id();
        // Insert customer-chosen options into 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') {
                    $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 = '" . $languages_id . "'\n                                and poval.language_id = '" . $languages_id . "'";
                    $attributes = tep_db_query($attributes_query);
                } else {
                    $attributes = tep_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 = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");
                }
                $attributes_values = tep_db_fetch_array($attributes);
                $sql_data_array = array('orders_id' => $insert_id, 'orders_products_id' => $order_products_id, 'products_options' => $attributes_values['products_options_name'], 'products_options_values' => $attributes_values['products_options_values_name'], 'options_values_price' => $attributes_values['options_values_price'], 'price_prefix' => $attributes_values['price_prefix']);
                tep_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES, $sql_data_array);
                if (DOWNLOAD_ENABLED == 'true' && isset($attributes_values['products_attributes_filename']) && tep_not_null($attributes_values['products_attributes_filename'])) {
                    $sql_data_array = array('orders_id' => $insert_id, 'orders_products_id' => $order_products_id, 'orders_products_filename' => $attributes_values['products_attributes_filename'], 'download_maxdays' => $attributes_values['products_attributes_maxdays'], 'download_count' => $attributes_values['products_attributes_maxcount']);
                    tep_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'];
            }
        }
        $total_weight += $order->products[$i]['qty'] * $order->products[$i]['weight'];
        $total_tax += tep_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty'];
        $total_cost += $total_products_price;
        $products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . $products_ordered_attributes . "\n";
    }
    // FOR COUPON SUPPORT
    /*
    $insert_id = $order->create($order_totals, 2);
    //$order_total_modules = new order_total();
    // Store the product info to the order.
    $order->create_add_products($insert_id);
    //$order_number_created'] = $insert_id;
    // Add coupon to redeem track.
    if (isset ($gc_data[$root]['order-adjustment']['merchant-codes']['coupon-adjustment'])) {
      $sql = "select coupon_id
                              from " . TABLE_COUPONS . "
                              where coupon_code= :couponCodeEntered
                              and coupon_active='Y'";
      $sql = $db->bindVars($sql, ':couponCodeEntered', $coupons[0]['code']['VALUE'], 'string');
    
      $coupon_result = tep_db_query($sql);
      $cc_id = $coupon_result['coupon_id'];
    
      tep_db_query("insert into " . TABLE_COUPON_REDEEM_TRACK . "
                                  (coupon_id, redeem_date, redeem_ip, customer_id, order_id)
                                  values ('" . (int) $cc_id . "', now(), '" .
      $gc_data[$root]['shopping-cart']['merchant-private-data']['ip-address']['VALUE'] .
      "', '" . (int) $customer_id . "', '" . (int) $insert_id . "')");
      $cc_id = "";
    }
    */
    // Add the order details to the table.
    // This table could be modified to hold the merchant id and key if required
    // so that different mids and mkeys can be used for different orders.
    tep_db_query("insert into " . $google_checkout->table_order . " values (" . $insert_id . ", " . gc_make_sql_string($gc_data[$root]['google-order-number']['VALUE']) . ", " . gc_make_sql_float($gc_data[$root]['order-total']['VALUE']) . ")");
    $cart->reset(TRUE);
    tep_session_unregister('sendto');
    tep_session_unregister('billto');
    tep_session_unregister('shipping');
    tep_session_unregister('payment');
    tep_session_unregister('comments');
    $google_response->SendAck();
}
Beispiel #7
0
  function tep_add_tax($price, $tax) {
    global $currencies;

    if ( (DISPLAY_PRICE_WITH_TAX == 'true') && ($tax > 0) ) {
      return tep_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']) + tep_calculate_tax($price, $tax);
    } else {
      return tep_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
    }
  }
 function before_process()
 {
     global $cart_PayPal_Pro_HS_ID, $customer_id, $pphs_result, $order, $order_totals, $sendto, $billto, $languages_id, $payment, $currencies, $cart, ${$payment};
     $result = false;
     if (isset($_GET['tx']) && !empty($_GET['tx'])) {
         // direct payment (eg, credit card)
         $result = $this->_app->getApiResult('APP', 'GetTransactionDetails', array('TRANSACTIONID' => $_GET['tx']), OSCOM_APP_PAYPAL_HS_STATUS == '1' ? 'live' : 'sandbox');
     } elseif (isset($_POST['txn_id']) && !empty($_POST['txn_id'])) {
         // paypal payment
         $result = $this->_app->getApiResult('APP', 'GetTransactionDetails', array('TRANSACTIONID' => $_POST['txn_id']), OSCOM_APP_PAYPAL_HS_STATUS == '1' ? 'live' : 'sandbox');
     }
     if (!in_array($result['ACK'], array('Success', 'SuccessWithWarning'))) {
         tep_redirect(tep_href_link('shopping_cart.php', 'error_message=' . stripslashes($result['L_LONGMESSAGE0'])));
     }
     $order_id = substr($cart_PayPal_Pro_HS_ID, strpos($cart_PayPal_Pro_HS_ID, '-') + 1);
     $seller_accounts = array($this->_app->getCredentials('HS', 'email'));
     if (tep_not_null($this->_app->getCredentials('HS', 'email_primary'))) {
         $seller_accounts[] = $this->_app->getCredentials('HS', 'email_primary');
     }
     if (!isset($result['RECEIVERBUSINESS']) || !in_array($result['RECEIVERBUSINESS'], $seller_accounts) || $result['INVNUM'] != $order_id || $result['CUSTOM'] != $customer_id) {
         tep_redirect(tep_href_link('shopping_cart.php'));
     }
     $pphs_result = $result;
     $check_query = tep_db_query("select orders_status from orders where orders_id = '" . (int) $order_id . "' and customers_id = '" . (int) $customer_id . "'");
     $tx_order_id = $pphs_result['INVNUM'];
     $tx_customer_id = $pphs_result['CUSTOM'];
     if (!tep_db_num_rows($check_query) || $order_id != $tx_order_id || $customer_id != $tx_customer_id) {
         tep_redirect(tep_href_link('shopping_cart.php'));
     }
     $check = tep_db_fetch_array($check_query);
     $this->verifyTransaction();
     $new_order_status = DEFAULT_ORDERS_STATUS_ID;
     if ($check['orders_status'] != OSCOM_APP_PAYPAL_HS_PREPARE_ORDER_STATUS_ID) {
         $new_order_status = $check['orders_status'];
     }
     if (OSCOM_APP_PAYPAL_HS_ORDER_STATUS_ID > 0 && $check['orders_status'] == OSCOM_APP_PAYPAL_HS_ORDER_STATUS_ID) {
         $new_order_status = OSCOM_APP_PAYPAL_HS_ORDER_STATUS_ID;
     }
     tep_db_query("update orders set orders_status = '" . (int) $new_order_status . "', last_modified = now() where orders_id = '" . (int) $order_id . "'");
     $sql_data_array = array('orders_id' => $order_id, 'orders_status_id' => (int) $new_order_status, 'date_added' => 'now()', 'customer_notified' => SEND_EMAILS == 'true' ? '1' : '0', 'comments' => $order->info['comments']);
     tep_db_perform('orders_status_history', $sql_data_array);
     // initialized for the email confirmation
     $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') {
             if (DOWNLOAD_ENABLED == 'true') {
                 $stock_query_raw = "SELECT products_quantity, pad.products_attributes_filename\n                                FROM products p\n                                LEFT JOIN products_attributes pa\n                                ON p.products_id=pa.products_id\n                                LEFT JOIN products_attributes_download pad\n                                ON pa.products_attributes_id=pad.products_attributes_id\n                                WHERE p.products_id = '" . tep_get_prid($order->products[$i]['id']) . "'";
                 // 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'] . "'";
                 }
                 $stock_query = tep_db_query($stock_query_raw);
             } else {
                 $stock_query = tep_db_query("select products_quantity from products where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
             }
             if (tep_db_num_rows($stock_query) > 0) {
                 $stock_values = tep_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'];
                 }
                 tep_db_query("update products set products_quantity = '" . $stock_left . "' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                 if ($stock_left < 1 && STOCK_ALLOW_CHECKOUT == 'false') {
                     tep_db_query("update products set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                 }
             }
         }
         // Update products_ordered (for bestsellers list)
         tep_db_query("update products set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
         //------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') {
                     $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 products_options popt, products_options_values poval, products_attributes pa\n                                   left join 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 = '" . $languages_id . "'\n                                   and poval.language_id = '" . $languages_id . "'";
                     $attributes = tep_db_query($attributes_query);
                 } else {
                     $attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from products_options popt, products_options_values poval, 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 = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");
                 }
                 $attributes_values = tep_db_fetch_array($attributes);
                 $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 += tep_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty'];
         $total_cost += $total_products_price;
         $products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . $products_ordered_attributes . "\n";
     }
     // lets start with the email confirmation
     $email_order = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . $order_id . "\n" . EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link('account_history_info.php', 'order_id=' . $order_id, 'SSL', false) . "\n" . EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";
     if ($order->info['comments']) {
         $email_order .= tep_db_output($order->info['comments']) . "\n\n";
     }
     $email_order .= EMAIL_TEXT_PRODUCTS . "\n" . EMAIL_SEPARATOR . "\n" . $products_ordered . EMAIL_SEPARATOR . "\n";
     for ($i = 0, $n = sizeof($order_totals); $i < $n; $i++) {
         $email_order .= strip_tags($order_totals[$i]['title']) . ' ' . strip_tags($order_totals[$i]['text']) . "\n";
     }
     if ($order->content_type != 'virtual') {
         $email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" . EMAIL_SEPARATOR . "\n" . tep_address_label($customer_id, $sendto, 0, '', "\n") . "\n";
     }
     $email_order .= "\n" . EMAIL_TEXT_BILLING_ADDRESS . "\n" . EMAIL_SEPARATOR . "\n" . tep_address_label($customer_id, $billto, 0, '', "\n") . "\n\n";
     if (is_object(${$payment})) {
         $email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" . EMAIL_SEPARATOR . "\n";
         $payment_class = ${$payment};
         $email_order .= $payment_class->title . "\n\n";
         if ($payment_class->email_footer) {
             $email_order .= $payment_class->email_footer . "\n\n";
         }
     }
     tep_mail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
     // send emails to other people
     if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
         tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
     }
     // load the after_process function from the payment modules
     $this->after_process();
     $cart->reset(true);
     // unregister session variables used during checkout
     tep_session_unregister('sendto');
     tep_session_unregister('billto');
     tep_session_unregister('shipping');
     tep_session_unregister('payment');
     tep_session_unregister('comments');
     tep_session_unregister('cart_PayPal_Pro_HS_ID');
     tep_session_unregister('pphs_result');
     tep_session_unregister('pphs_key');
     tep_redirect(tep_href_link('checkout_process.php', '', 'SSL'));
 }
Beispiel #9
0
function tep_add_tax($price, $tax)
{
    // BOF: MOD - Separate Pricing Per Customer, show_tax modification
    // next line was original code
    //    if ( (DISPLAY_PRICE_WITH_TAX == 'true') && ($tax > 0) ) {
    global $sppc_customer_group_show_tax;
    global $sppc_customer_group_tax_exempt;
    if (!isset($_SESSION['sppc_customer_group_show_tax'])) {
        $customer_group_show_tax = '1';
    } else {
        $customer_group_show_tax = $_SESSION['sppc_customer_group_show_tax'];
    }
    //    echo '<br>cg_tax_exempt: ';
    //    echo $sppc_customer_group_tax_exempt;
    if (DISPLAY_PRICE_WITH_TAX == 'true' && $tax > 0 && $customer_group_show_tax == '1') {
        // EOF: MOD - Separate Pricing Per Customer, show_tax modification
        return $price + tep_calculate_tax($price, $tax);
    } else {
        return $price;
    }
}
            } else {
                $attributes = tep_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 = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");
            }
            $attributes_values = tep_db_fetch_array($attributes);
            $sql_data_array = array('orders_id' => $insert_id, 'orders_products_id' => $order_products_id, 'products_options' => $attributes_values['products_options_name'], 'products_options_values' => $attributes_values['products_options_values_name'], 'options_values_price' => $attributes_values['options_values_price'], 'price_prefix' => $attributes_values['price_prefix']);
            tep_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES, $sql_data_array);
            if (DOWNLOAD_ENABLED == 'true' && isset($attributes_values['products_attributes_filename']) && tep_not_null($attributes_values['products_attributes_filename'])) {
                $sql_data_array = array('orders_id' => $insert_id, 'orders_products_id' => $order_products_id, 'orders_products_filename' => $attributes_values['products_attributes_filename'], 'download_maxdays' => $attributes_values['products_attributes_maxdays'], 'download_count' => $attributes_values['products_attributes_maxcount']);
                tep_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 += tep_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty'];
    $total_cost += $total_products_price;
    $products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . $products_ordered_attributes . "\n";
}
// lets start with the email confirmation
$email_order = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . $insert_id . "\n" . EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $insert_id, 'SSL', false) . "\n" . EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";
if ($order->info['comments']) {
    $email_order .= tep_db_output($order->info['comments']) . "\n\n";
}
$email_order .= EMAIL_TEXT_PRODUCTS . "\n" . EMAIL_SEPARATOR . "\n" . $products_ordered . EMAIL_SEPARATOR . "\n";
for ($i = 0, $n = sizeof($order_totals); $i < $n; $i++) {
    $email_order .= strip_tags($order_totals[$i]['title']) . ' ' . strip_tags($order_totals[$i]['text']) . "\n";
}
if ($order->content_type != 'virtual') {
    $email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" . EMAIL_SEPARATOR . "\n" . tep_address_label($customer_id, $sendto, 0, '', "\n") . "\n";
}
 function before_process()
 {
     global $customer_id, $order, $order_totals, $sendto, $billto, $languages_id, $payment, $currencies, $cart, $cart_PostFinance_ID;
     global ${$payment};
     $order_id = substr($cart_PostFinance_ID, strpos($cart_PostFinance_ID, '-') + 1);
     $order_status = $_GET['STATUS'];
     $check_query = tep_db_query("select orders_status from " . TABLE_ORDERS . " where orders_id = '" . (int) $order_id . "'");
     if (tep_db_num_rows($check_query)) {
         $check = tep_db_fetch_array($check_query);
         if ($check['orders_status'] == MODULE_PAYMENT_POSTFINANCE_PREPARE_ORDER_STATUS_ID) {
             $sql_data_array = array('orders_id' => $order_id, 'orders_status_id' => MODULE_PAYMENT_POSTFINANCE_PREPARE_ORDER_STATUS_ID, 'date_added' => 'now()', 'customer_notified' => '0', 'comments' => '');
             tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
         }
     }
     if ($order_status == '5' || $order_status == '9' || $order_status == '91' || $order_status == '51') {
         tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . (MODULE_PAYMENT_POSTFINANCE_ORDER_STATUS_ID > 0 ? (int) MODULE_PAYMENT_POSTFINANCE_ORDER_STATUS_ID : (int) DEFAULT_ORDERS_STATUS_ID) . "', last_modified = now() where orders_id = '" . (int) $order_id . "'");
     }
     if ($order_status == '5') {
         $comment_status = 'PostFinance IPN Verified [Payment has been authorized]';
     } elseif ($order_status == '9') {
         $comment_status = 'PostFinance IPN Verified [Payment has been accepted]';
     } elseif ($order_status == '51' || $order_status == '91') {
         $comment_status = 'PostFinance IPN Verified [Payment is pending]';
     }
     if ($order_status == "2") {
         $comment_status = 'PostFinance IPN Invalid [Declined]';
     } elseif ($order_status == "52" || $order_status == "92") {
         $comment_status = 'PostFinance IPN Invalid [Exception occured]';
     } elseif ($order_status == "1") {
         $comment_status = 'PostFinance IPN Invalid [Cancelled]';
     }
     $sql_data_array = array('orders_id' => $order_id, 'orders_status_id' => MODULE_PAYMENT_POSTFINANCE_ORDER_STATUS_ID > 0 ? (int) MODULE_PAYMENT_POSTFINANCE_ORDER_STATUS_ID : (int) DEFAULT_ORDERS_STATUS_ID, 'date_added' => 'now()', 'customer_notified' => SEND_EMAILS == 'true' ? '1' : '0', 'comments' => $comment_status);
     tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
     // initialized for the email confirmation
     $products_ordered = '';
     $subtotal = 0;
     $total_tax = 0;
     for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
         if (STOCK_LIMITED == 'true') {
             if (DOWNLOAD_ENABLED == 'true') {
                 $stock_query_raw = "SELECT products_quantity, pad.products_attributes_filename\r\n                                FROM " . TABLE_PRODUCTS . " p\r\n                                LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa\r\n                                ON p.products_id=pa.products_id\r\n                                LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad\r\n                                ON pa.products_attributes_id=pad.products_attributes_id\r\n                                WHERE p.products_id = '" . tep_get_prid($order->products[$i]['id']) . "'";
                 $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'] . "'";
                 }
                 $stock_query = tep_db_query($stock_query_raw);
             } else {
                 $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
             }
             if (tep_db_num_rows($stock_query) > 0) {
                 $stock_values = tep_db_fetch_array($stock_query);
                 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'];
                 }
                 if ($order_status == '5' || $order_status == '9' || $order_status == '91' || $order_status == '51') {
                     tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                     if ($stock_left < 1 && STOCK_ALLOW_CHECKOUT == 'false') {
                         tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                     }
                 }
             }
         }
         if ($order_status == '5' || $order_status == '9' || $order_status == '91' || $order_status == '51') {
             tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
         }
         //------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') {
                     $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\r\n                                   from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa\r\n                                   left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad\r\n                                   on pa.products_attributes_id=pad.products_attributes_id\r\n                                   where pa.products_id = '" . $order->products[$i]['id'] . "'\r\n                                   and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "'\r\n                                   and pa.options_id = popt.products_options_id\r\n                                   and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "'\r\n                                   and pa.options_values_id = poval.products_options_values_id\r\n                                   and popt.language_id = '" . $languages_id . "'\r\n                                   and poval.language_id = '" . $languages_id . "'";
                     $attributes = tep_db_query($attributes_query);
                 } else {
                     $attributes = tep_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 = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");
                 }
                 $attributes_values = tep_db_fetch_array($attributes);
                 $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 += tep_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty'];
         $total_cost += $total_products_price;
         $products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . $products_ordered_attributes . "\n";
     }
     // lets start with the email confirmation
     $email_order = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . $order_id . "\n" . EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $order_id, 'SSL', false) . "\n" . EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";
     if ($order->info['comments']) {
         $email_order .= tep_db_output($order->info['comments']) . "\n\n";
     }
     $email_order .= EMAIL_TEXT_PRODUCTS . "\n" . EMAIL_SEPARATOR . "\n" . $products_ordered . EMAIL_SEPARATOR . "\n";
     for ($i = 0, $n = sizeof($order_totals); $i < $n; $i++) {
         $email_order .= strip_tags($order_totals[$i]['title']) . ' ' . strip_tags($order_totals[$i]['text']) . "\n";
     }
     if ($order->content_type != 'virtual') {
         $email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" . EMAIL_SEPARATOR . "\n" . tep_address_label($customer_id, $sendto, 0, '', "\n") . "\n";
     }
     $email_order .= "\n" . EMAIL_TEXT_BILLING_ADDRESS . "\n" . EMAIL_SEPARATOR . "\n" . tep_address_label($customer_id, $billto, 0, '', "\n") . "\n\n";
     if (is_object(${$payment})) {
         $email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" . EMAIL_SEPARATOR . "\n";
         $payment_class = ${$payment};
         $email_order .= $payment_class->title . "\n\n";
         if ($payment_class->email_footer) {
             $email_order .= $payment_class->email_footer . "\n\n";
         }
     }
     if ($order_status == '5' || $order_status == '9' || $order_status == '91' || $order_status == '51') {
         tep_mail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
         // send emails to other people
         if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
             tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
         }
     }
     if ($order_status == '1' || $order_status == '2' || $order_status == '92' || $order_status == '52') {
         if (tep_not_null(MODULE_PAYMENT_POSTFINANCE_DEBUG_EMAIL)) {
             $email_body = '$HTTP_POST_VARS:' . "\n\n";
             reset($HTTP_POST_VARS);
             while (list($key, $value) = each($HTTP_POST_VARS)) {
                 $email_body .= $key . '=' . $value . "\n";
             }
             $email_body .= "\n" . '$HTTP_GET_VARS:' . "\n\n";
             reset($HTTP_GET_VARS);
             while (list($key, $value) = each($HTTP_GET_VARS)) {
                 $email_body .= $key . '=' . $value . "\n";
             }
             tep_mail('', MODULE_PAYMENT_POSTFINANCE_DEBUG_EMAIL, 'Post Finance IPN Invalid Process', $email_body, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
         }
         tep_db_query('delete from ' . TABLE_ORDERS . ' where orders_id = "' . $order_id . '"');
         tep_redirect(tep_href_link('checkout_payment.php'));
     }
     // load the after_process function from the payment modules
     $this->after_process();
     $cart->reset(true);
     // unregister session variables used during checkout
     tep_session_unregister('sendto');
     tep_session_unregister('billto');
     tep_session_unregister('shipping');
     tep_session_unregister('payment');
     tep_session_unregister('comments');
     tep_session_unregister('cart_PostFinance_ID');
     tep_redirect(tep_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'SSL'));
 }
Beispiel #12
0
 function get_product_price($product_id)
 {
     global $cart, $order;
     $products_id = tep_get_prid($product_id);
     // products price
     $qty = $cart->contents[$product_id]['qty'];
     $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id='" . $product_id . "'");
     if ($product = tep_db_fetch_array($product_query)) {
         $prid = $product['products_id'];
         $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
         $products_price = $product['products_price'];
         $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . $prid . "' and status = '1'");
         if (tep_db_num_rows($specials_query)) {
             $specials = tep_db_fetch_array($specials_query);
             $products_price = $specials['specials_new_products_price'];
         }
         if ($this->include_tax == 'true') {
             $total_price += ($products_price + tep_calculate_tax($products_price, $products_tax)) * $qty;
             //                        echo("total price = " . $total_price . " products_price = " . $products_price . " products_tax = " . $products_tax . "<br>");
         } 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 = tep_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 = tep_db_fetch_array($attribute_price_query);
                 if ($attribute_price['price_prefix'] == '+') {
                     if ($this->include_tax == 'true') {
                         $total_price += $qty * ($attribute_price['options_values_price'] + tep_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'] + tep_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;
 }
 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 = tep_get_prid($products[$i]['id']);
         $gv_query = tep_db_query("select products_price, products_tax_class_id, products_model from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'");
         $gv_result = tep_db_fetch_array($gv_query);
         if (ereg('^GIFT', addslashes($gv_result['products_model']))) {
             $qty = $cart->get_quantity($t_prid);
             $products_tax = tep_get_tax_rate($gv_result['products_tax_class_id']);
             if ($this->include_tax == false) {
                 $gv_amount = $gv_result['products_price'] * $qty;
             } else {
                 $gv_amount = ($gv_result['products_price'] + tep_calculate_tax($gv_result['products_price'], $products_tax)) * $qty;
             }
             $order_total = $order_total - $gv_amount;
         }
     }
     if ($this->include_tax == false) {
         $order_total = $order_total - $order->info['tax'];
     }
     if ($this->include_shipping == false) {
         $order_total = $order_total - $order->info['shipping_cost'];
     }
     return $order_total;
 }
Beispiel #14
0
                 if (!isset($quote['error'])) {
                     foreach ($quote['methods'] as $rate) {
                         $quotes_array[] = array('id' => $quote['id'] . '_' . $rate['id'], 'name' => $quote['module'], 'label' => $rate['title'], 'cost' => $rate['cost'], 'tax' => $quote['tax']);
                     }
                 }
             }
         }
     }
 }
 $counter = 0;
 $cheapest_rate = null;
 $expensive_rate = 0;
 $cheapest_counter = $counter;
 $default_shipping = null;
 foreach ($quotes_array as $quote) {
     $shipping_rate = $paypal_express->format_raw($quote['cost'] + tep_calculate_tax($quote['cost'], $quote['tax']));
     $params['L_SHIPPINGOPTIONNAME' . $counter] = $quote['name'] . ' (' . $quote['label'] . ')';
     $params['L_SHIPINGPOPTIONLABEL' . $counter] = $quote['name'] . ' (' . $quote['label'] . ')';
     $params['L_SHIPPINGOPTIONAMOUNT' . $counter] = $shipping_rate;
     $params['L_SHIPPINGOPTIONISDEFAULT' . $counter] = 'false';
     if (is_null($cheapest_rate) || $shipping_rate < $cheapest_rate) {
         $cheapest_rate = $shipping_rate;
         $cheapest_counter = $counter;
     }
     if ($shipping_rate > $expensive_rate) {
         $expensive_rate = $shipping_rate;
     }
     if (tep_not_null($shipping) && $shipping['id'] == $quote['id']) {
         $default_shipping = $counter;
     }
     $counter++;
function tep_add_tax($price, $tax)
{
    if (DISPLAY_PRICE_WITH_TAX == 'true' && $tax > 0) {
        return $price + tep_calculate_tax($price, $tax);
    } else {
        return $price;
    }
}
 function get_products_special_price($product_id)
 {
     global $order;
     $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id='" . $product_id . "'");
     if ($product = tep_db_fetch_array($product_query)) {
         $prid = $product['products_id'];
         $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
         $products_price = $product['products_price'];
         $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . $prid . "' and status = '1'");
         if (tep_db_num_rows($specials_query)) {
             $specials = tep_db_fetch_array($specials_query);
             $products_price = $specials['specials_new_products_price'];
             $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id='" . $product_id . "'");
             if ($product = tep_db_fetch_array($product_query)) {
                 $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
             }
             $qty = $order->products[$io]['qty'];
             if ($this->include_tax == true) {
                 $products_price += ($products_price + tep_calculate_tax($products_price, $products_tax)) * $qty;
             } else {
                 $products_price += $products_price * $qty;
             }
         }
     }
     return $products_price;
 }
     // Live server requires SSL to be enabled
     $item_params['CALLBACK'] = tep_href_link('ext/modules/payment/paypal/express.php', 'osC_Action=callbackSet', 'SSL', false, false);
     $item_params['CALLBACKTIMEOUT'] = '6';
     $item_params['CALLBACKVERSION'] = $paypal_express->api_version;
 }
 include DIR_WS_CLASSES . 'order_total.php';
 $order_total_modules = new order_total();
 $order_totals = $order_total_modules->process();
 // Remove shipping tax from total that was added again in ot_shipping
 if (DISPLAY_PRICE_WITH_TAX == 'true') {
     $order->info['shipping_cost'] = $order->info['shipping_cost'] / (1.0 + $quotes_array[$default_shipping]['tax'] / 100);
 }
 $module = substr($shipping['id'], 0, strpos($shipping['id'], '_'));
 $order->info['tax'] -= tep_calculate_tax($order->info['shipping_cost'], $quotes_array[$default_shipping]['tax']);
 $order->info['tax_groups'][tep_get_tax_description($module->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id'])] -= tep_calculate_tax($order->info['shipping_cost'], $quotes_array[$default_shipping]['tax']);
 $order->info['total'] -= tep_calculate_tax($order->info['shipping_cost'], $quotes_array[$default_shipping]['tax']);
 $items_total = $paypal_express->format_raw($order->info['subtotal']);
 foreach ($order_totals as $ot) {
     if (!in_array($ot['code'], array('ot_subtotal', 'ot_shipping', 'ot_tax', 'ot_total'))) {
         $item_params['L_PAYMENTREQUEST_0_NAME' . $line_item_no] = $ot['title'];
         $item_params['L_PAYMENTREQUEST_0_AMT' . $line_item_no] = $paypal_express->format_raw($ot['value']);
         $items_total += $paypal_express->format_raw($ot['value']);
         $line_item_no++;
     }
 }
 $params['PAYMENTREQUEST_0_AMT'] = $paypal_express->format_raw($order->info['total']);
 $item_params['MAXAMT'] = $paypal_express->format_raw($params['PAYMENTREQUEST_0_AMT'] + $expensive_rate + 100, '', 1);
 // safely pad higher for dynamic shipping rates (eg, USPS express)
 $item_params['PAYMENTREQUEST_0_ITEMAMT'] = $items_total;
 $item_params['PAYMENTREQUEST_0_SHIPPINGAMT'] = $paypal_express->format_raw($order->info['shipping_cost']);
 $paypal_item_total = $item_params['PAYMENTREQUEST_0_ITEMAMT'] + $item_params['PAYMENTREQUEST_0_SHIPPINGAMT'];
 function adwords_tag()
 {
     $this->installer = new adwords_tag_install();
     $scriptname = ltrim(basename($_SERVER['SCRIPT_NAME']));
     $return = array();
     switch ($scriptname) {
         case FILENAME_DEFAULT:
             global $category_depth;
             if ($category_depth == 'top') {
                 $this->page_type = 'home';
             } else {
                 $this->page_type = 'category';
             }
             $this->page_products_id = "''";
             break;
         case FILENAME_PRODUCT_INFO:
             global $_GET, $currency, $currencies;
             if (tep_not_null($_GET['products_id'])) {
                 $this->page_products_id = "'" . $_GET['products_id'] . "'";
                 global $product_info;
                 $rate = $currencies->currencies[$currency]['value'];
                 $decimal_places = $currencies->currencies[$currency]['decimal_places'];
                 $this->page_totalvalue = number_format(tep_add_tax($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) * $rate, $decimal_places);
                 if ($new_price = tep_get_products_special_price($product_info['products_id'])) {
                     $this->page_totalvalue = number_format(tep_add_tax($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])), $decimal_places);
                 }
             } else {
                 $this->page_products_id = "''";
             }
             $this->page_type = 'product';
             break;
         case FILENAME_SHOPPING_CART:
             global $cart, $currency, $currencies;
             if ($cart && is_object($cart)) {
                 $products_id_list = array();
                 foreach ($cart->contents as $products_id => $products_content) {
                     $products_id_list[] = "'" . (int) $products_id . "'";
                 }
                 if (count($products_id_list) <= 0) {
                     $this->page_products_id = "''";
                 } elseif (count($products_id_list) == 1) {
                     $this->page_products_id = $products_id_list[0];
                 } else {
                     $this->page_products_id = '[' . implode(',', $products_id_list) . ']';
                 }
                 $rate = $currencies->currencies[$currency]['value'];
                 $decimal_places = $currencies->currencies[$currency]['decimal_places'];
                 $this->page_totalvalue = number_format($cart->show_total() * $rate, $decimal_places);
             } else {
                 $this->page_products_id = "''";
             }
             $this->page_type = 'cart';
             break;
         case FILENAME_CHECKOUT_SHIPPING:
         case FILENAME_CHECKOUT_PAYMENT:
         case FILENAME_CHECKOUT_CONFIRMATION:
         case FILENAME_CHECKOUT_SUCCESS:
             global $order, $currency, $currencies;
             if ($order && is_object($order)) {
                 $products_id_list = array();
                 foreach ($order->products as $product) {
                     $products_id_list[] = "'" . (int) $product['id'] . "'";
                 }
                 if (count($products_id_list) <= 0) {
                     $this->page_products_id = "''";
                 } elseif (count($products_id_list) == 1) {
                     $this->page_products_id = $products_id_list[0];
                 } else {
                     $this->page_products_id = '[' . implode(',', $products_id_list) . ']';
                 }
                 $rate = $currencies->currencies[$currency]['value'];
                 $decimal_places = $currencies->currencies[$currency]['decimal_places'];
                 if ($scriptname == FILENAME_CHECKOUT_SHIPPING || $scriptname == FILENAME_CHECKOUT_PAYMENT) {
                     // calculate the shipping tax
                     if ($scriptname == FILENAME_CHECKOUT_PAYMENT) {
                         require DIR_WS_CLASSES . 'shipping.php';
                         $shipping_modules = new shipping();
                     }
                     $module = substr($GLOBALS['shipping']['id'], 0, strpos($GLOBALS['shipping']['id'], '_'));
                     $shipping_tax = tep_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                     $order->info['total'] += tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
                 }
                 $this->page_totalvalue = number_format($order->info['total'] * $rate, $decimal_places);
             } else {
                 $this->page_products_id = "''";
             }
             $this->page_type = 'purchase';
             break;
         case FILENAME_ADVANCED_SEARCH_RESULT:
             $this->page_products_id = "''";
             $this->page_type = 'searchresults';
             break;
         default:
             $this->page_products_id = "''";
             $this->page_type = 'other';
     }
 }
Beispiel #19
0
 **/
 $sproduct = new product($product_info['products_id']);
 //Sonderpreis beruecksichtigen
 if ($new_price = tep_get_products_special_price($product_info['products_id'])) {
     $product_info_price = $new_price;
     $specialPrice = 'yes';
 } else {
     $product_info_price = $product_info['products_price'];
     $specialPrice = 'no';
 }
 if (NUR_POSITIVER_PREIS && $product_info_price <= 0) {
     continue;
 }
 ++$item_counter;
 $tax_rate = tep_get_tax_rate($product_info['products_tax_class_id']);
 $tax = tep_calculate_tax($product_info_price, $tax_rate) * $currency_rate;
 $product_info_price = tep_add_tax($product_info_price, $tax_rate) * $currency_rate;
 /**
  * Beschreibung
  */
 $description = sk_strip_tags_and_entities($product_info[ELMAR_PRODUCTS_DESCRIPTION_FIELD]);
 if (ELMAR_PRODUCT_DESCRIPTION_MAX_LENGTH > 0) {
     $description = substr($description, 0, ELMAR_PRODUCT_DESCRIPTION_MAX_LENGTH - 3) . '...';
 }
 $longDescription = $description;
 // Modell
 $model = $product_info['products_model'];
 $shortDescription = (!empty($model) ? $model . ': ' : '') . $description;
 if (strlen($shortDescription) > 255) {
     $decr = 251;
     while ($decr >= 0 && $shortDescription[$decr] != ' ') {
Beispiel #20
0
 function before_process()
 {
     global $customer_id, $order, $order_totals, $sendto, $billto, $languages_id, $payment, $currencies, $cart, $cart_PayPal_Standard_ID, $order_total_modules;
     global ${$payment}, $onePageCheckout;
     $order_id = substr($cart_PayPal_Standard_ID, strpos($cart_PayPal_Standard_ID, '-') + 1);
     $check_query = tep_db_query("select orders_status from " . TABLE_ORDERS . " where orders_id = '" . (int) $order_id . "'");
     if (tep_db_num_rows($check_query)) {
         $check = tep_db_fetch_array($check_query);
         if ($check['orders_status'] == MODULE_PAYMENT_PAYPAL_STANDARD_PREPARE_ORDER_STATUS_ID) {
             $sql_data_array = array('orders_id' => $order_id, 'orders_status_id' => MODULE_PAYMENT_PAYPAL_STANDARD_PREPARE_ORDER_STATUS_ID, 'date_added' => 'now()', 'customer_notified' => '0', 'comments' => '');
             tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
         }
     }
     tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . (MODULE_PAYMENT_PAYPAL_STANDARD_ORDER_STATUS_ID > 0 ? (int) MODULE_PAYMENT_PAYPAL_STANDARD_ORDER_STATUS_ID : (int) DEFAULT_ORDERS_STATUS_ID) . "', last_modified = now() where orders_id = '" . (int) $order_id . "'");
     $sql_data_array = array('orders_id' => $order_id, 'orders_status_id' => MODULE_PAYMENT_PAYPAL_STANDARD_ORDER_STATUS_ID > 0 ? (int) MODULE_PAYMENT_PAYPAL_STANDARD_ORDER_STATUS_ID : (int) DEFAULT_ORDERS_STATUS_ID, 'date_added' => 'now()', 'customer_notified' => SEND_EMAILS == 'true' ? '1' : '0', 'comments' => $order->info['comments']);
     tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
     // initialized for the email confirmation
     $products_ordered = '';
     $subtotal = 0;
     $total_tax = 0;
     for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
         // Stock Update - Joao Correia
         //++++ QT Pro: Begin Changed code
         $products_stock_attributes = null;
         if (STOCK_LIMITED == 'true') {
             $products_attributes = $order->products[$i]['attributes'];
             //      if (DOWNLOAD_ENABLED == 'true')
             //++++ QT Pro: End Changed Code
             $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 = '" . tep_get_prid($order->products[$i]['id']) . "'";
             // Will work with only one option for downloadable products
             // otherwise, we have to build the query dynamically with a loop
             //++++ QT Pro: Begin Changed code
             //      $products_attributes = $order->products[$i]['attributes'];
             //++++ QT Pro: End Changed Code
             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'] . "'";
             }
             $stock_query = tep_db_query($stock_query_raw);
         } else {
             $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
         }
         if (tep_db_num_rows($stock_query) > 0) {
             $stock_values = tep_db_fetch_array($stock_query);
             //++++ QT Pro: Begin Changed code
             $actual_stock_bought = $order->products[$i]['qty'];
             $download_selected = false;
             if (DOWNLOAD_ENABLED == 'true' && isset($stock_values['products_attributes_filename']) && tep_not_null($stock_values['products_attributes_filename'])) {
                 $download_selected = true;
                 $products_stock_attributes = '$$DOWNLOAD$$';
             }
             // If not downloadable and attributes present, adjust attribute stock
             if (!$download_selected && is_array($products_attributes)) {
                 $all_nonstocked = true;
                 $products_stock_attributes_array = array();
                 foreach ($products_attributes as $attribute) {
                     if ($attribute['track_stock'] == 1) {
                         $products_stock_attributes_array[] = $attribute['option_id'] . "-" . $attribute['value_id'];
                         $all_nonstocked = false;
                     }
                 }
                 if ($all_nonstocked) {
                     $actual_stock_bought = $order->products[$i]['qty'];
                 } else {
                     asort($products_stock_attributes_array, SORT_NUMERIC);
                     $products_stock_attributes = implode(",", $products_stock_attributes_array);
                     $attributes_stock_query = tep_db_query("select products_stock_quantity from " . TABLE_PRODUCTS_STOCK . " where products_stock_attributes = '{$products_stock_attributes}' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                     if (tep_db_num_rows($attributes_stock_query) > 0) {
                         $attributes_stock_values = tep_db_fetch_array($attributes_stock_query);
                         $attributes_stock_left = $attributes_stock_values['products_stock_quantity'] - $order->products[$i]['qty'];
                         tep_db_query("update " . TABLE_PRODUCTS_STOCK . " set products_stock_quantity = '" . $attributes_stock_left . "' where products_stock_attributes = '{$products_stock_attributes}' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                         $actual_stock_bought = $attributes_stock_left < 1 ? $attributes_stock_values['products_stock_quantity'] : $order->products[$i]['qty'];
                     } else {
                         $attributes_stock_left = 0 - $order->products[$i]['qty'];
                         tep_db_query("insert into " . TABLE_PRODUCTS_STOCK . " (products_id, products_stock_attributes, products_stock_quantity) values ('" . tep_get_prid($order->products[$i]['id']) . "', '" . $products_stock_attributes . "', '" . $attributes_stock_left . "')");
                         $actual_stock_bought = 0;
                     }
                 }
             }
             //        $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
             //      }
             //      if (tep_db_num_rows($stock_query) > 0) {
             //        $stock_values = tep_db_fetch_array($stock_query);
             // do not decrement quantities if products_attributes_filename exists
             if (!$download_selected) {
                 $stock_left = $stock_values['products_quantity'] - $actual_stock_bought;
                 tep_db_query("UPDATE " . TABLE_PRODUCTS . " \n                        SET products_quantity = products_quantity - '" . $actual_stock_bought . "' \n                        WHERE products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                 //++++ QT Pro: End Changed Code
                 if ($stock_left < 1 && STOCK_ALLOW_CHECKOUT == 'false') {
                     tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                 }
             }
         }
         // Update products_ordered (for bestsellers list)
         tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
         //++++ QT Pro: Begin Changed code
         if (!isset($products_stock_attributes)) {
             $products_stock_attributes = null;
         }
         $sql_data_array = array('orders_id' => $insert_id, 'products_id' => tep_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'], 'products_stock_attributes' => $products_stock_attributes);
         //++++ QT Pro: End Changed Code
         tep_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array);
         $order_products_id = tep_db_insert_id();
         // Start - CREDIT CLASS Gift Voucher Contribution
         //       if (isset($order_total_modules)) {
         //            $order_total_modules->update_credit_account($i);
         //        }
         // End - CREDIT CLASS Gift Voucher Contribution
         //------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') {
                     $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 = '" . $languages_id . "'\n                                   and poval.language_id = '" . $languages_id . "'";
                     $attributes = tep_db_query($attributes_query);
                 } else {
                     $attributes = tep_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 = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");
                 }
                 $attributes_values = tep_db_fetch_array($attributes);
                 $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 += tep_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty'];
         $total_cost += $total_products_price;
         $products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . $products_ordered_attributes . "\n";
     }
     // Start - CREDIT CLASS Gift Voucher Contribution
     if (isset($order_total_modules)) {
         $order_total_modules->apply_credit();
     }
     // End - CREDIT CLASS Gift Voucher Contribution
     // lets start with the email confirmation
     $email_order = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . $order_id . "\n" . EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $order_id, 'SSL', false) . "\n" . EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";
     if ($order->info['comments']) {
         $email_order .= tep_db_output($order->info['comments']) . "\n\n";
     }
     $email_order .= EMAIL_TEXT_PRODUCTS . "\n" . EMAIL_SEPARATOR . "\n" . $products_ordered . EMAIL_SEPARATOR . "\n";
     for ($i = 0, $n = sizeof($order_totals); $i < $n; $i++) {
         $email_order .= strip_tags($order_totals[$i]['title']) . ' ' . strip_tags($order_totals[$i]['text']) . "\n";
     }
     /* One Page Checkout - BEGIN */
     $sendToFormatted = tep_address_label($customer_id, $sendto, 0, '', "\n");
     if (ONEPAGE_CHECKOUT_ENABLED == 'True') {
         $sendToFormatted = $onePageCheckout->getAddressFormatted('sendto');
     }
     $billToFormatted = tep_address_label($customer_id, $billto, 0, '', "\n");
     if (ONEPAGE_CHECKOUT_ENABLED == 'True') {
         $billToFormatted = $onePageCheckout->getAddressFormatted('billto');
     }
     /* One Page Checkout - END */
     if ($order->content_type != 'virtual') {
         $email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" . EMAIL_SEPARATOR . "\n" . tep_address_label($customer_id, $sendto, 0, '', "\n") . "\n";
     }
     $email_order .= "\n" . EMAIL_TEXT_BILLING_ADDRESS . "\n" . EMAIL_SEPARATOR . "\n" . tep_address_label($customer_id, $billto, 0, '', "\n") . "\n\n";
     if (is_object(${$payment})) {
         $email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" . EMAIL_SEPARATOR . "\n";
         $payment_class = ${$payment};
         $email_order .= $payment_class->title . "\n\n";
         if ($payment_class->email_footer) {
             $email_order .= $payment_class->email_footer . "\n\n";
         }
     }
     tep_mail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
     // send emails to other people
     if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
         tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
     }
     // load the after_process function from the payment modules
     $this->after_process();
     $cart->reset(true);
     // unregister session variables used during checkout
     tep_session_unregister('sendto');
     tep_session_unregister('billto');
     tep_session_unregister('shipping');
     tep_session_unregister('payment');
     tep_session_unregister('comments');
     // Added Bugfix 157
     if (tep_session_is_registered('credit_covers')) {
         tep_session_unregister('credit_covers');
     }
     if (isset($order_total_modules)) {
         $order_total_modules->clear_posts();
     }
     // End - CREDIT CLASS Gift Voucher Contribution
     tep_session_unregister('cart_PayPal_Standard_ID');
     tep_redirect(tep_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'SSL'));
 }
 function before_process()
 {
     /* ** Altered for CCGV **
           global $customer_id, $order, $order_totals, $sendto, $billto, $languages_id, $payment, $currencies, $cart, $cart_PayPal_Standard_ID, $$payment, $HTTP_GET_VARS, $HTTP_POST_VARS, $messageStack;
     
           $result = false;
     	*/
     global $customer_id, $order, $order_totals, $sendto, $billto, $languages_id, $payment, $currencies, $cart, $cart_PayPal_Standard_ID, ${$payment}, $HTTP_GET_VARS, $HTTP_POST_VARS, $messageStack, $order_total_modules;
     $result = false;
     $order_total_modules->apply_credit();
     /* **EOF alteration for CCGV ** */
     if (isset($HTTP_POST_VARS['receiver_email']) && ($HTTP_POST_VARS['receiver_email'] == MODULE_PAYMENT_PAYPAL_STANDARD_ID || defined('MODULE_PAYMENT_PAYPAL_STANDARD_PRIMARY_ID') && tep_not_null(MODULE_PAYMENT_PAYPAL_STANDARD_PRIMARY_ID) && $HTTP_POST_VARS['receiver_email'] == MODULE_PAYMENT_PAYPAL_STANDARD_PRIMARY_ID)) {
         $parameters = 'cmd=_notify-validate';
         foreach ($HTTP_POST_VARS as $key => $value) {
             $parameters .= '&' . $key . '=' . urlencode(stripslashes($value));
         }
         $result = $this->sendTransactionToGateway($this->form_action_url, $parameters);
     }
     if ($result != 'VERIFIED') {
         if (defined('MODULE_PAYMENT_PAYPAL_STANDARD_TEXT_INVALID_TRANSACTION')) {
             $messageStack->add_session('header', MODULE_PAYMENT_PAYPAL_STANDARD_TEXT_INVALID_TRANSACTION);
         }
         $this->sendDebugEmail($result);
         tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
     }
     $this->verifyTransaction();
     $order_id = substr($cart_PayPal_Standard_ID, strpos($cart_PayPal_Standard_ID, '-') + 1);
     $check_query = tep_db_query("select orders_status from " . TABLE_ORDERS . " where orders_id = '" . (int) $order_id . "' and customers_id = '" . (int) $customer_id . "'");
     if (!tep_db_num_rows($check_query) || $order_id != $HTTP_POST_VARS['invoice'] || $customer_id != $HTTP_POST_VARS['custom']) {
         tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
     }
     $check = tep_db_fetch_array($check_query);
     $new_order_status = DEFAULT_ORDERS_STATUS_ID;
     if ($check['orders_status'] != MODULE_PAYMENT_PAYPAL_STANDARD_PREPARE_ORDER_STATUS_ID) {
         $new_order_status = $check['orders_status'];
     }
     if (MODULE_PAYMENT_PAYPAL_STANDARD_ORDER_STATUS_ID > 0 && $check['orders_status'] == MODULE_PAYMENT_PAYPAL_STANDARD_ORDER_STATUS_ID) {
         $new_order_status = MODULE_PAYMENT_PAYPAL_STANDARD_ORDER_STATUS_ID;
     }
     tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . (int) $new_order_status . "', last_modified = now() where orders_id = '" . (int) $order_id . "'");
     $sql_data_array = array('orders_id' => $order_id, 'orders_status_id' => (int) $new_order_status, 'date_added' => 'now()', 'customer_notified' => SEND_EMAILS == 'true' ? '1' : '0', 'comments' => $order->info['comments']);
     tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
     // initialized for the email confirmation
     $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') {
             if (DOWNLOAD_ENABLED == 'true') {
                 $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 = '" . tep_get_prid($order->products[$i]['id']) . "'";
                 // 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'] . "'";
                 }
                 $stock_query = tep_db_query($stock_query_raw);
             } else {
                 $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
             }
             if (tep_db_num_rows($stock_query) > 0) {
                 $stock_values = tep_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'];
                 }
                 tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                 if ($stock_left < 1 && STOCK_ALLOW_CHECKOUT == 'false') {
                     tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                 }
             }
         }
         // Update products_ordered (for bestsellers list)
         tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
         //------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') {
                     $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 = '" . $languages_id . "'\n                                   and poval.language_id = '" . $languages_id . "'";
                     $attributes = tep_db_query($attributes_query);
                 } else {
                     $attributes = tep_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 = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");
                 }
                 $attributes_values = tep_db_fetch_array($attributes);
                 $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 += tep_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty'];
         $total_cost += $total_products_price;
         $products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . $products_ordered_attributes . "\n";
     }
     // lets start with the email confirmation
     $email_order = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . $order_id . "\n" . EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $order_id, 'SSL', false) . "\n" . EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";
     if ($order->info['comments']) {
         $email_order .= tep_db_output($order->info['comments']) . "\n\n";
     }
     $email_order .= EMAIL_TEXT_PRODUCTS . "\n" . EMAIL_SEPARATOR . "\n" . $products_ordered . EMAIL_SEPARATOR . "\n";
     for ($i = 0, $n = sizeof($order_totals); $i < $n; $i++) {
         $email_order .= strip_tags($order_totals[$i]['title']) . ' ' . strip_tags($order_totals[$i]['text']) . "\n";
     }
     if ($order->content_type != 'virtual') {
         $email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" . EMAIL_SEPARATOR . "\n" . tep_address_label($customer_id, $sendto, 0, '', "\n") . "\n";
     }
     $email_order .= "\n" . EMAIL_TEXT_BILLING_ADDRESS . "\n" . EMAIL_SEPARATOR . "\n" . tep_address_label($customer_id, $billto, 0, '', "\n") . "\n\n";
     if (is_object(${$payment})) {
         $email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" . EMAIL_SEPARATOR . "\n";
         $payment_class = ${$payment};
         $email_order .= $payment_class->title . "\n\n";
         if ($payment_class->email_footer) {
             $email_order .= $payment_class->email_footer . "\n\n";
         }
     }
     tep_mail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
     // send emails to other people
     if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
         tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
     }
     // load the after_process function from the payment modules
     $this->after_process();
     $cart->reset(true);
     // unregister session variables used during checkout
     tep_session_unregister('sendto');
     tep_session_unregister('billto');
     tep_session_unregister('shipping');
     tep_session_unregister('payment');
     tep_session_unregister('comments');
     tep_session_unregister('cart_PayPal_Standard_ID');
     tep_redirect(tep_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'SSL'));
 }
Beispiel #22
0
         $price = $product_info['specials_new_products_price'];
         $expires_date = substr($expires_date, 0, 4) . substr($expires_date, 5, 2) . substr($expires_date, 8, 2);
         // YYYY-mm-dd
         $old_price = $product_info['products_price'];
     }
 }
 if (!$isSpecial) {
     $price = $product_info['products_price'];
     $expires_date = '';
     $old_price = NULL;
 }
 if (NUR_POSITIVER_PREIS && $price <= 0) {
     continue;
 }
 $tax_rate = tep_get_tax_rate($product_info['products_tax_class_id']);
 $tax = tep_calculate_tax($price, $tax_rate);
 $price = tep_add_tax($price, $tax_rate);
 if (!is_null($old_price)) {
     $old_price = tep_add_tax($old_price, $tax_rate);
 }
 if ($free_shipping && $price >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) {
     $versandkosten = VERSANDKOSTENFREI;
 } else {
     if ($shipping_flat_status) {
         $versandkosten = $shipping_flat_cost;
     } else {
         $versandkosten = VERSANDKOSTEN_AB;
     }
     if (!empty($versandkosten)) {
         $versandkosten *= $currency_rate;
     }
Beispiel #23
0
 function _process()
 {
     global $osC_Database, $osC_Session, $osC_Customer, $osC_Currencies, $cart, $order, $payment_modules, $shipping_modules, $order_total_modules;
     // load selected payment module
     require DIR_WS_CLASSES . 'payment.php';
     $payment_modules = new payment($osC_Session->value('payment'));
     // load the selected shipping module
     require DIR_WS_CLASSES . 'shipping.php';
     $shipping_modules = new shipping($osC_Session->value('shipping'));
     $order = new order();
     // load the before_process function from the payment modules
     $payment_modules->before_process();
     require DIR_WS_CLASSES . 'order_total.php';
     $order_total_modules = new order_total();
     $order_totals = $order_total_modules->process();
     $Qorder = $osC_Database->query('insert into :table_orders (customers_id, customers_name, customers_company, customers_street_address, customers_suburb, customers_city, customers_postcode, customers_state, customers_country, customers_telephone, customers_email_address, customers_address_format_id, customers_ip_address, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_country, delivery_address_format_id, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_country, billing_address_format_id, payment_method, cc_type, cc_owner, cc_number, cc_expires, date_purchased, orders_status, currency, currency_value) values (:customers_id, :customers_name, :customers_company, :customers_street_address, :customers_suburb, :customers_city, :customers_postcode, :customers_state, :customers_country, :customers_telephone, :customers_email_address, :customers_address_format_id, :customers_ip_address, :delivery_name, :delivery_company, :delivery_street_address, :delivery_suburb, :delivery_city, :delivery_postcode, :delivery_state, :delivery_country, :delivery_address_format_id, :billing_name, :billing_company, :billing_street_address, :billing_suburb, :billing_city, :billing_postcode, :billing_state, :billing_country, :billing_address_format_id, :payment_method, :cc_type, :cc_owner, :cc_number, :cc_expires, :date_purchased, :orders_status, :currency, :currency_value)');
     $Qorder->bindTable(':table_orders', TABLE_ORDERS);
     $Qorder->bindInt(':customers_id', $osC_Customer->id);
     $Qorder->bindValue(':customers_name', $order->customer['firstname'] . ' ' . $order->customer['lastname']);
     $Qorder->bindValue(':customers_company', $order->customer['company']);
     $Qorder->bindValue(':customers_street_address', $order->customer['street_address']);
     $Qorder->bindValue(':customers_suburb', $order->customer['suburb']);
     $Qorder->bindValue(':customers_city', $order->customer['city']);
     $Qorder->bindValue(':customers_postcode', $order->customer['postcode']);
     $Qorder->bindValue(':customers_state', $order->customer['state']);
     $Qorder->bindValue(':customers_country', $order->customer['country']['title']);
     $Qorder->bindValue(':customers_telephone', $order->customer['telephone']);
     $Qorder->bindValue(':customers_email_address', $order->customer['email_address']);
     $Qorder->bindInt(':customers_address_format_id', $order->customer['format_id']);
     $Qorder->bindValue(':customers_ip_address', tep_get_ip_address());
     $Qorder->bindValue(':delivery_name', $order->delivery['firstname'] . ' ' . $order->delivery['lastname']);
     $Qorder->bindValue(':delivery_company', $order->delivery['company']);
     $Qorder->bindValue(':delivery_street_address', $order->delivery['street_address']);
     $Qorder->bindValue(':delivery_suburb', $order->delivery['suburb']);
     $Qorder->bindValue(':delivery_city', $order->delivery['city']);
     $Qorder->bindValue(':delivery_postcode', $order->delivery['postcode']);
     $Qorder->bindValue(':delivery_state', $order->delivery['state']);
     $Qorder->bindValue(':delivery_country', $order->delivery['country']['title']);
     $Qorder->bindInt(':delivery_address_format_id', $order->delivery['format_id']);
     $Qorder->bindValue(':billing_name', $order->billing['firstname'] . ' ' . $order->billing['lastname']);
     $Qorder->bindValue(':billing_company', $order->billing['company']);
     $Qorder->bindValue(':billing_street_address', $order->billing['street_address']);
     $Qorder->bindValue(':billing_suburb', $order->billing['suburb']);
     $Qorder->bindValue(':billing_city', $order->billing['city']);
     $Qorder->bindValue(':billing_postcode', $order->billing['postcode']);
     $Qorder->bindValue(':billing_state', $order->billing['state']);
     $Qorder->bindValue(':billing_country', $order->billing['country']['title']);
     $Qorder->bindInt(':billing_address_format_id', $order->billing['format_id']);
     $Qorder->bindValue(':payment_method', $order->info['payment_method']);
     $Qorder->bindValue(':cc_type', $order->info['cc_type']);
     $Qorder->bindValue(':cc_owner', $order->info['cc_owner']);
     $Qorder->bindValue(':cc_number', $order->info['cc_number']);
     $Qorder->bindValue(':cc_expires', $order->info['cc_expires']);
     $Qorder->bindRaw(':date_purchased', 'now()');
     $Qorder->bindValue(':orders_status', $order->info['order_status']);
     $Qorder->bindValue(':currency', $order->info['currency']);
     $Qorder->bindValue(':currency_value', $order->info['currency_value']);
     $Qorder->execute();
     $insert_id = $osC_Database->nextID();
     for ($i = 0, $n = sizeof($order_totals); $i < $n; $i++) {
         $Qtotals = $osC_Database->query('insert into :table_orders_total (orders_id, title, text, value, class, sort_order) values (:orders_id, :title, :text, :value, :class, :sort_order)');
         $Qtotals->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
         $Qtotals->bindInt(':orders_id', $insert_id);
         $Qtotals->bindValue(':title', $order_totals[$i]['title']);
         $Qtotals->bindValue(':text', $order_totals[$i]['text']);
         $Qtotals->bindValue(':value', $order_totals[$i]['value']);
         $Qtotals->bindValue(':class', $order_totals[$i]['code']);
         $Qtotals->bindInt(':sort_order', $order_totals[$i]['sort_order']);
         $Qtotals->execute();
     }
     $Qstatus = $osC_Database->query('insert into :table_orders_status_history (orders_id, orders_status_id, date_added, customer_notified, comments) values (:orders_id, :orders_status_id, :date_added, :customer_notified, :comments)');
     $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
     $Qstatus->bindInt(':orders_id', $insert_id);
     $Qstatus->bindInt(':orders_status_id', $order->info['order_status']);
     $Qstatus->bindRaw(':date_added', 'now()');
     $Qstatus->bindInt(':customer_notified', SEND_EMAILS == 'true' ? '1' : '0');
     $Qstatus->bindValue(':comments', $order->info['comments']);
     $Qstatus->execute();
     // initialized for the email confirmation
     $products_ordered = '';
     $subtotal = 0;
     $total_tax = 0;
     $total_weight = 0;
     $total_cost = 0;
     for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
         // Stock Update - Joao Correia
         if (STOCK_LIMITED == 'true') {
             if (DOWNLOAD_ENABLED == 'true') {
                 $Qstock = $osC_Database->query('select products_quantity, pad.products_attributes_filename from :table_products p left join :table_products_attributes pa on (p.products_id = pa.products_id) left join :table_products_attributes_download pad on (pa.products_attributes_id = pad.products_attributes_id) where p.products_id = :products_id');
                 $Qstock->bindTable(':table_products', TABLE_PRODUCTS);
                 $Qstock->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
                 $Qstock->bindTable(':table_products_attributes_download', TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD);
                 $Qstock->bindInt(':products_id', tep_get_prid($order->products[$i]['id']));
                 // 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)) {
                     $Qstock->appendQuery('and pa.options_id = :options_id and pa.options_values_id = :options_values_id');
                     $Qstock->bindInt(':options_id', $products_attributes[0]['option_id']);
                     $Qstock->bindInt(':options_values_id', $products_attributes[0]['value_id']);
                 }
             } else {
                 $Qstock = $osC_Database->query('select products_quantity from :table_products where products_id = :products_id');
                 $Qstock->bindTable(':table_products', TABLE_PRODUCTS);
                 $Qstock->bindInt(':products_id', tep_get_prid($order->products[$i]['id']));
             }
             $Qstock->execute();
             if ($Qstock->numberOfRows() > 0) {
                 $stock_left = $Qstock->valueInt('products_quantity');
                 // do not decrement quantities if products_attributes_filename exists
                 if (DOWNLOAD_ENABLED != 'true' || DOWNLOAD_ENABLED == 'true' && strlen($Qstock->value('products_attributes_filename')) < 1) {
                     $stock_left = $stock_left - $order->products[$i]['qty'];
                     $Qupdate = $osC_Database->query('update :table_products set products_quantity = :products_quantity where products_id = :products_id');
                     $Qupdate->bindTable(':table_products', TABLE_PRODUCTS);
                     $Qupdate->bindInt(':products_quantity', $stock_left);
                     $Qupdate->bindInt(':products_id', tep_get_prid($order->products[$i]['id']));
                     $Qupdate->execute();
                 }
                 if (STOCK_ALLOW_CHECKOUT == 'false' && $stock_left < 1) {
                     $Qupdate = $osC_Database->query('update :table_products set products_status = :products_status where products_id = :products_id');
                     $Qupdate->bindTable(':table_products', TABLE_PRODUCTS);
                     $Qupdate->bindInt(':products_status', 0);
                     $Qupdate->bindInt(':products_id', tep_get_prid($order->products[$i]['id']));
                     $Qupdate->execute();
                 }
             }
         }
         // Update products_ordered (for bestsellers list)
         $Qupdate = $osC_Database->query('update :table_products set products_ordered = products_ordered + :products_ordered where products_id = :products_id');
         $Qupdate->bindTable(':table_products', TABLE_PRODUCTS);
         $Qupdate->bindInt(':products_ordered', $order->products[$i]['qty']);
         $Qupdate->bindInt(':products_id', tep_get_prid($order->products[$i]['id']));
         $Qupdate->execute();
         $Qproducts = $osC_Database->query('insert into :table_orders_products (orders_id, products_id, products_model, products_name, products_price, final_price, products_tax, products_quantity) values (:orders_id, :products_id, :products_model, :products_name, :products_price, :final_price, :products_tax, :products_quantity)');
         $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
         $Qproducts->bindInt(':orders_id', $insert_id);
         $Qproducts->bindInt(':products_id', tep_get_prid($order->products[$i]['id']));
         $Qproducts->bindValue(':products_model', $order->products[$i]['model']);
         $Qproducts->bindValue(':products_name', $order->products[$i]['name']);
         $Qproducts->bindValue(':products_price', $order->products[$i]['price']);
         $Qproducts->bindValue(':final_price', $order->products[$i]['final_price']);
         $Qproducts->bindValue(':products_tax', $order->products[$i]['tax']);
         $Qproducts->bindInt(':products_quantity', $order->products[$i]['qty']);
         $Qproducts->execute();
         $order_products_id = $osC_Database->nextID();
         //------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') {
                     $Qattributes = $osC_Database->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 from :table_products_options popt, :table_products_options_values poval, :table_products_attributes pa left join :table_products_attributes_download pad on (pa.products_attributes_id = pad.products_attributes_id) where pa.products_id = :products_id and pa.options_id = :options_id and pa.options_id = popt.products_options_id and pa.options_values_id = :options_values_id and pa.options_values_id = poval.products_options_values_id and popt.language_id = :popt_language_id and poval.language_id = :poval_language_id');
                     $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
                     $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
                     $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
                     $Qattributes->bindTable(':table_products_attributes_download', TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD);
                     $Qattributes->bindInt(':products_id', $order->products[$i]['id']);
                     $Qattributes->bindInt(':options_id', $order->products[$i]['attributes'][$j]['option_id']);
                     $Qattributes->bindInt(':options_values_id', $order->products[$i]['attributes'][$j]['value_id']);
                     $Qattributes->bindInt(':popt_language_id', $osC_Session->value('languages_id'));
                     $Qattributes->bindInt(':poval_language_id', $osC_Session->value('languages_id'));
                 } else {
                     $Qattributes = $osC_Database->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 = :products_id and pa.options_id = :options_id and pa.options_id = popt.products_options_id and pa.options_values_id = :options_values_id and pa.options_values_id = poval.products_options_values_id and popt.language_id = :popt_language_id and poval.language_id = :poval_language_id');
                     $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
                     $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
                     $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
                     $Qattributes->bindInt(':products_id', $order->products[$i]['id']);
                     $Qattributes->bindInt(':options_id', $order->products[$i]['attributes'][$j]['option_id']);
                     $Qattributes->bindInt(':options_values_id', $order->products[$i]['attributes'][$j]['value_id']);
                     $Qattributes->bindInt(':popt_language_id', $osC_Session->value('languages_id'));
                     $Qattributes->bindInt(':poval_language_id', $osC_Session->value('languages_id'));
                 }
                 $Qattributes->execute();
                 $Qopa = $osC_Database->query('insert into :table_orders_products_attributes (orders_id, orders_products_id, products_options, products_options_values, options_values_price, price_prefix) values (:orders_id, :orders_products_id, :products_options, :products_options_values, :options_values_price, :price_prefix)');
                 $Qopa->bindTable(':table_orders_products_attributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES);
                 $Qopa->bindInt(':orders_id', $insert_id);
                 $Qopa->bindInt(':orders_products_id', $order_products_id);
                 $Qopa->bindValue(':products_options', $attributes_values['products_options_name']);
                 $Qopa->bindValue(':products_options_values', $attributes_values['products_options_values_name']);
                 $Qopa->bindValue(':options_values_price', $attributes_values['options_values_price']);
                 $Qopa->bindValue(':price_prefix', $attributes_values['price_prefix']);
                 $Qopa->execute();
                 if (DOWNLOAD_ENABLED == 'true' && strlen($Qattributes->value('products_attributes_filename')) > 0) {
                     $Qopd = $osC_Database->query('insert into :table_orders_products_download (orders_id, orders_products_id, orders_products_filename, download_maxdays, download_count) values (:orders_id, :orders_products_id, :orders_products_filename, :download_maxdays, :download_count)');
                     $Qopd->bindTable(':table_orders_products_download', TABLE_ORDERS_PRODUCTS_DOWNLOAD);
                     $Qopd->bindInt(':orders_id', $insert_id);
                     $Qopd->bindInt(':orders_products_id', $order_products_id);
                     $Qopd->bindValue(':orders_products_filename', $Qattributes->value('products_attributes_filename'));
                     $Qopd->bindValue(':download_maxdays', $Qattributes->value('products_attributes_maxdays'));
                     $Qopd->bindValue(':download_count', $Qattributes->value('products_attributes_maxcount'));
                     $Qopd->execute();
                 }
                 $products_ordered_attributes .= "\n\t" . $Qattributes->value('products_options_name') . ' ' . $Qattributes->value('products_options_values_name');
             }
         }
         //------insert customer choosen option eof ----
         $total_weight += $order->products[$i]['qty'] * $order->products[$i]['weight'];
         $total_tax += tep_calculate_tax($order->products[$i]['final_price'], $order->products[$i]['tax']) * $order->products[$i]['qty'];
         $total_cost += $order->products[$i]['final_price'];
         $products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $osC_Currencies->displayPrice($order->products[$i]['final_price'], $order->products[$i]['tax_class_id'], $order->products[$i]['qty']) . $products_ordered_attributes . "\n";
     }
     // lets start with the email confirmation
     $email_order = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . $insert_id . "\n" . EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT, 'orders=' . $insert_id, 'SSL', false) . "\n" . EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";
     if ($order->info['comments']) {
         $email_order .= tep_output_string_protected($order->info['comments']) . "\n\n";
     }
     $email_order .= EMAIL_TEXT_PRODUCTS . "\n" . EMAIL_SEPARATOR . "\n" . $products_ordered . EMAIL_SEPARATOR . "\n";
     for ($i = 0, $n = sizeof($order_totals); $i < $n; $i++) {
         $email_order .= strip_tags($order_totals[$i]['title']) . ' ' . strip_tags($order_totals[$i]['text']) . "\n";
     }
     if ($order->content_type != 'virtual') {
         $email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" . EMAIL_SEPARATOR . "\n" . tep_address_label($osC_Customer->id, $osC_Session->value('sendto'), 0, '', "\n") . "\n";
     }
     $email_order .= "\n" . EMAIL_TEXT_BILLING_ADDRESS . "\n" . EMAIL_SEPARATOR . "\n" . tep_address_label($osC_Customer->id, $osC_Session->value('billto'), 0, '', "\n") . "\n\n";
     $payment =& $osC_Session->value('payment');
     if (is_object(${$payment})) {
         $email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" . EMAIL_SEPARATOR . "\n";
         $payment_class = ${$payment};
         $email_order .= $payment_class->title . "\n\n";
         if (isset($payment_class->email_footer)) {
             $email_order .= $payment_class->email_footer . "\n\n";
         }
     }
     tep_mail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
     // send emails to other people
     if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
         tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
     }
     // load the after_process function from the payment modules
     $payment_modules->after_process();
     $cart->reset(true);
     // unregister session variables used during checkout
     $osC_Session->remove('sendto');
     $osC_Session->remove('billto');
     $osC_Session->remove('shipping');
     $osC_Session->remove('payment');
     $osC_Session->remove('comments');
     tep_redirect(tep_href_link(FILENAME_CHECKOUT, 'success', 'SSL'));
 }
 function process_button()
 {
     global $language, $customer_id, $order, $sendto, $currency, $cart_PayPal_Standard_ID, $shipping, $order_total_modules;
     $total_tax = $order->info['tax'];
     // remove shipping tax in total tax value
     if (isset($shipping['cost'])) {
         $total_tax -= $order->info['shipping_cost'] - $shipping['cost'];
     }
     $ipn_language = null;
     if (!class_exists('language')) {
         include 'includes/classes/language.php';
     }
     $lng = new language();
     if (count($lng->catalog_languages) > 1) {
         foreach ($lng->catalog_languages as $key => $value) {
             if ($value['directory'] == $language) {
                 $ipn_language = $key;
                 break;
             }
         }
     }
     $process_button_string = '';
     $parameters = array('cmd' => '_cart', 'upload' => '1', 'item_name_1' => STORE_NAME, 'shipping_1' => $this->_app->formatCurrencyRaw($order->info['shipping_cost']), 'business' => $this->_app->getCredentials('PS', 'email'), 'amount_1' => $this->_app->formatCurrencyRaw($order->info['total'] - $order->info['shipping_cost'] - $total_tax), 'currency_code' => $currency, 'invoice' => substr($cart_PayPal_Standard_ID, strpos($cart_PayPal_Standard_ID, '-') + 1), 'custom' => $customer_id, 'no_note' => '1', 'notify_url' => tep_href_link('ext/modules/payment/paypal/standard_ipn.php', isset($ipn_language) ? 'language=' . $ipn_language : '', 'SSL', false, false), 'rm' => '2', 'return' => tep_href_link('checkout_process.php', '', 'SSL'), 'cancel_return' => tep_href_link('checkout_payment.php', '', 'SSL'), 'bn' => 'OSCOM23_PS', 'paymentaction' => OSCOM_APP_PAYPAL_PS_TRANSACTION_METHOD == '1' ? 'sale' : 'authorization');
     $return_link_title = $this->_app->getDef('module_ps_button_return_to_store', array('storename' => STORE_NAME));
     if (strlen($return_link_title) <= 60) {
         $parameters['cbt'] = $return_link_title;
     }
     if (is_numeric($sendto) && $sendto > 0) {
         $parameters['address_override'] = '1';
         $parameters['first_name'] = $order->delivery['firstname'];
         $parameters['last_name'] = $order->delivery['lastname'];
         $parameters['address1'] = $order->delivery['street_address'];
         $parameters['city'] = $order->delivery['city'];
         $parameters['state'] = tep_get_zone_code($order->delivery['country']['id'], $order->delivery['zone_id'], $order->delivery['state']);
         $parameters['zip'] = $order->delivery['postcode'];
         $parameters['country'] = $order->delivery['country']['iso_code_2'];
     } else {
         $parameters['no_shipping'] = '1';
         $parameters['first_name'] = $order->billing['firstname'];
         $parameters['last_name'] = $order->billing['lastname'];
         $parameters['address1'] = $order->billing['street_address'];
         $parameters['city'] = $order->billing['city'];
         $parameters['state'] = tep_get_zone_code($order->billing['country']['id'], $order->billing['zone_id'], $order->billing['state']);
         $parameters['zip'] = $order->billing['postcode'];
         $parameters['country'] = $order->billing['country']['iso_code_2'];
     }
     if (tep_not_null(OSCOM_APP_PAYPAL_PS_PAGE_STYLE)) {
         $parameters['page_style'] = OSCOM_APP_PAYPAL_PS_PAGE_STYLE;
     }
     $item_params = array();
     $line_item_no = 1;
     foreach ($order->products as $product) {
         if (DISPLAY_PRICE_WITH_TAX == 'true') {
             $product_price = $this->_app->formatCurrencyRaw($product['final_price'] + tep_calculate_tax($product['final_price'], $product['tax']));
         } else {
             $product_price = $this->_app->formatCurrencyRaw($product['final_price']);
         }
         $item_params['item_name_' . $line_item_no] = $product['name'];
         $item_params['amount_' . $line_item_no] = $product_price;
         $item_params['quantity_' . $line_item_no] = $product['qty'];
         $line_item_no++;
     }
     $items_total = $this->_app->formatCurrencyRaw($order->info['subtotal']);
     $has_negative_price = false;
     // order totals are processed on checkout confirmation but not captured into a variable
     if (is_array($order_total_modules->modules)) {
         foreach ($order_total_modules->modules as $value) {
             $class = substr($value, 0, strrpos($value, '.'));
             if ($GLOBALS[$class]->enabled) {
                 for ($i = 0, $n = sizeof($GLOBALS[$class]->output); $i < $n; $i++) {
                     if (tep_not_null($GLOBALS[$class]->output[$i]['title']) && tep_not_null($GLOBALS[$class]->output[$i]['text'])) {
                         if (!in_array($GLOBALS[$class]->code, array('ot_subtotal', 'ot_shipping', 'ot_tax', 'ot_total'))) {
                             $item_params['item_name_' . $line_item_no] = $GLOBALS[$class]->output[$i]['title'];
                             $item_params['amount_' . $line_item_no] = $this->_app->formatCurrencyRaw($GLOBALS[$class]->output[$i]['value']);
                             $items_total += $item_params['amount_' . $line_item_no];
                             if ($item_params['amount_' . $line_item_no] < 0) {
                                 $has_negative_price = true;
                             }
                             $line_item_no++;
                         }
                     }
                 }
             }
         }
     }
     $paypal_item_total = $items_total + $parameters['shipping_1'];
     if (DISPLAY_PRICE_WITH_TAX == 'false') {
         $item_params['tax_cart'] = $this->_app->formatCurrencyRaw($total_tax);
         $paypal_item_total += $item_params['tax_cart'];
     }
     if ($has_negative_price == false && $this->_app->formatCurrencyRaw($paypal_item_total) == $this->_app->formatCurrencyRaw($order->info['total'])) {
         $parameters = array_merge($parameters, $item_params);
     } else {
         $parameters['tax_cart'] = $this->_app->formatCurrencyRaw($total_tax);
     }
     if (OSCOM_APP_PAYPAL_PS_EWP_STATUS == '1') {
         $parameters['cert_id'] = OSCOM_APP_PAYPAL_PS_EWP_PUBLIC_CERT_ID;
         $random_string = rand(100000, 999999) . '-' . $customer_id . '-';
         $data = '';
         foreach ($parameters as $key => $value) {
             $data .= $key . '=' . $value . "\n";
         }
         $fp = fopen(OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY . '/' . $random_string . 'data.txt', 'w');
         fwrite($fp, $data);
         fclose($fp);
         unset($data);
         if (function_exists('openssl_pkcs7_sign') && function_exists('openssl_pkcs7_encrypt')) {
             openssl_pkcs7_sign(OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY . '/' . $random_string . 'data.txt', OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt', file_get_contents(OSCOM_APP_PAYPAL_PS_EWP_PUBLIC_CERT), file_get_contents(OSCOM_APP_PAYPAL_PS_EWP_PRIVATE_KEY), array('From' => $this->_app->getCredentials('PS', 'email')), PKCS7_BINARY);
             unlink(OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY . '/' . $random_string . 'data.txt');
             // remove headers from the signature
             $signed = file_get_contents(OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt');
             $signed = explode("\n\n", $signed);
             $signed = base64_decode($signed[1]);
             $fp = fopen(OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt', 'w');
             fwrite($fp, $signed);
             fclose($fp);
             unset($signed);
             openssl_pkcs7_encrypt(OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt', OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY . '/' . $random_string . 'encrypted.txt', file_get_contents(OSCOM_APP_PAYPAL_PS_EWP_PAYPAL_CERT), array('From' => $this->_app->getCredentials('PS', 'email')), PKCS7_BINARY);
             unlink(OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt');
             // remove headers from the encrypted result
             $data = file_get_contents(OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY . '/' . $random_string . 'encrypted.txt');
             $data = explode("\n\n", $data);
             $data = '-----BEGIN PKCS7-----' . "\n" . $data[1] . "\n" . '-----END PKCS7-----';
             unlink(OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY . '/' . $random_string . 'encrypted.txt');
         } else {
             exec(OSCOM_APP_PAYPAL_PS_EWP_OPENSSL . ' smime -sign -in ' . OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY . '/' . $random_string . 'data.txt -signer ' . OSCOM_APP_PAYPAL_PS_EWP_PUBLIC_CERT . ' -inkey ' . OSCOM_APP_PAYPAL_PS_EWP_PRIVATE_KEY . ' -outform der -nodetach -binary > ' . OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt');
             unlink(OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY . '/' . $random_string . 'data.txt');
             exec(OSCOM_APP_PAYPAL_PS_EWP_OPENSSL . ' smime -encrypt -des3 -binary -outform pem ' . OSCOM_APP_PAYPAL_PS_EWP_PAYPAL_CERT . ' < ' . OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt > ' . OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY . '/' . $random_string . 'encrypted.txt');
             unlink(OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt');
             $fh = fopen(OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY . '/' . $random_string . 'encrypted.txt', 'rb');
             $data = fread($fh, filesize(OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY . '/' . $random_string . 'encrypted.txt'));
             fclose($fh);
             unlink(OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY . '/' . $random_string . 'encrypted.txt');
         }
         $process_button_string = tep_draw_hidden_field('cmd', '_s-xclick') . tep_draw_hidden_field('encrypted', $data);
         unset($data);
     } else {
         foreach ($parameters as $key => $value) {
             $process_button_string .= tep_draw_hidden_field($key, $value);
         }
     }
     return $process_button_string;
 }
Beispiel #25
0
 function before_process()
 {
     global $customer_id, $order, $order_totals, $sendto, $billto, $payment, $currencies;
     global ${$payment};
     $pass = false;
     if (isset($_GET['transaction_id']) && isset($_GET['msid'])) {
         if ($_GET['transaction_id'] == substr($GLOBALS[$this->_mbcartID], strpos($GLOBALS[$this->_mbcartID], '-') + 1)) {
             if ($_GET['msid'] == strtoupper(md5(MODULE_PAYMENT_MONEYBOOKERS_MERCHANT_ID . $_GET['transaction_id'] . strtoupper(md5(MODULE_PAYMENT_MONEYBOOKERS_SECRET_WORD))))) {
                 $pass = true;
             }
         }
     } elseif (isset($_GET['osig']) && $_GET['osig'] == md5(MODULE_PAYMENT_MONEYBOOKERS_SECRET_WORD . $GLOBALS[$this->_mbcartID])) {
         $pass = true;
     }
     if ($pass == true) {
         $order_id = substr($GLOBALS[$this->_mbcartID], strpos($GLOBALS[$this->_mbcartID], '-') + 1);
         $check_query = tep_db_query("select orders_status from " . TABLE_ORDERS . " where orders_id = '" . (int) $order_id . "'");
         if (tep_db_num_rows($check_query)) {
             $check = tep_db_fetch_array($check_query);
             if ($check['orders_status'] == MODULE_PAYMENT_MONEYBOOKERS_PREPARE_ORDER_STATUS_ID) {
                 $sql_data_array = array('orders_id' => $order_id, 'orders_status_id' => MODULE_PAYMENT_MONEYBOOKERS_PREPARE_ORDER_STATUS_ID, 'date_added' => 'now()', 'customer_notified' => '0', 'comments' => '');
                 tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
             }
         }
         tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . (MODULE_PAYMENT_MONEYBOOKERS_ORDER_STATUS_ID > 0 ? (int) MODULE_PAYMENT_MONEYBOOKERS_ORDER_STATUS_ID : (int) DEFAULT_ORDERS_STATUS_ID) . "', last_modified = now() where orders_id = '" . (int) $order_id . "'");
         $sql_data_array = array('orders_id' => $order_id, 'orders_status_id' => MODULE_PAYMENT_MONEYBOOKERS_ORDER_STATUS_ID > 0 ? (int) MODULE_PAYMENT_MONEYBOOKERS_ORDER_STATUS_ID : (int) DEFAULT_ORDERS_STATUS_ID, 'date_added' => 'now()', 'customer_notified' => SEND_EMAILS == 'true' ? '1' : '0', 'comments' => $order->info['comments']);
         tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
         // initialized for the email confirmation
         $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') {
                 if (DOWNLOAD_ENABLED == 'true') {
                     $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 = '" . tep_get_prid($order->products[$i]['id']) . "'";
                     // 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'] . "'";
                     }
                     $stock_query = tep_db_query($stock_query_raw);
                 } else {
                     $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                 }
                 if (tep_db_num_rows($stock_query) > 0) {
                     $stock_values = tep_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'];
                     }
                     tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                     if ($stock_left < 1 && STOCK_ALLOW_CHECKOUT == 'false') {
                         tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                     }
                 }
             }
             // Update products_ordered (for bestsellers list)
             tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
             //------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') {
                         $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 = '" . $_SESSION['languages_id'] . "'\n                                     and poval.language_id = '" . $_SESSION['languages_id'] . "'";
                         $attributes = tep_db_query($attributes_query);
                     } else {
                         $attributes = tep_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 = '" . $_SESSION['languages_id'] . "' and poval.language_id = '" . $_SESSION['languages_id'] . "'");
                     }
                     $attributes_values = tep_db_fetch_array($attributes);
                     $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 += tep_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty'];
             $total_cost += $total_products_price;
             $products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . $products_ordered_attributes . "\n";
         }
         // lets start with the email confirmation
         $email_order = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . $order_id . "\n" . EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $order_id, 'SSL', false) . "\n" . EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";
         if ($order->info['comments']) {
             $email_order .= tep_db_output($order->info['comments']) . "\n\n";
         }
         $email_order .= EMAIL_TEXT_PRODUCTS . "\n" . EMAIL_SEPARATOR . "\n" . $products_ordered . EMAIL_SEPARATOR . "\n";
         for ($i = 0, $n = sizeof($order_totals); $i < $n; $i++) {
             $email_order .= strip_tags($order_totals[$i]['title']) . ' ' . strip_tags($order_totals[$i]['text']) . "\n";
         }
         if ($order->content_type != 'virtual') {
             $email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" . EMAIL_SEPARATOR . "\n" . tep_address_label($customer_id, $sendto, 0, '', "\n") . "\n";
         }
         $email_order .= "\n" . EMAIL_TEXT_BILLING_ADDRESS . "\n" . EMAIL_SEPARATOR . "\n" . tep_address_label($customer_id, $billto, 0, '', "\n") . "\n\n";
         if (is_object(${$payment})) {
             $email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" . EMAIL_SEPARATOR . "\n";
             $payment_class = ${$payment};
             $email_order .= $payment_class->title . "\n\n";
             if ($payment_class->email_footer) {
                 $email_order .= $payment_class->email_footer . "\n\n";
             }
         }
         tep_mail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
         // send emails to other people
         if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
             tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
         }
         // load the after_process function from the payment modules
         $this->after_process();
         $_SESSION['cart']->reset(true);
         // unregister session variables used during checkout
         unset($_SESSION['sendto']);
         unset($_SESSION['billto']);
         unset($_SESSION['shipping']);
         unset($_SESSION['payment']);
         unset($_SESSION['comments']);
         unset($_SESSION[$this->_mbcartID]);
         tep_redirect(tep_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'SSL'));
     } else {
         tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
     }
 }
Beispiel #26
0
function tep_add_tax($price, $tax)
{
    global $currencies, $customer_group;
    if ($customer_group->gettax() == '1') {
        return tep_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']) + tep_calculate_tax($price, $tax);
    } else {
        return tep_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
    }
}
Beispiel #27
0
function tep_add_tax($price, $tax)
{
    global $currencies;
    if (DISPLAY_PRICE_WITH_TAX == 'true') {
        return $price + tep_calculate_tax($price, $tax);
    } else {
        return $price;
    }
}
 function before_process()
 {
     global $HTTP_GET_VARS, $customer_id, $order, $order_totals, $sendto, $billto, $languages_id, $payment, $currencies, $cart, $cart_Sofortueberweisung_Direct_ID;
     global ${$payment};
     $md5var4 = md5($HTTP_GET_VARS['sovar3'] . MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_CNT_PASSWORT);
     // Statusupdate nur wenn keine Cartänderung vorgenommen
     $order_total_integer = number_format($order->info['total'] * $currencies->get_value('EUR'), 2, '.', '') * 100;
     if ($order_total_integer < 1) {
         $order_total_integer = '000';
     } elseif ($order_total_integer < 10) {
         $order_total_integer = '00' . $order_total_integer;
     } elseif ($order_total_integer < 100) {
         $order_total_integer = '0' . $order_total_integer;
     }
     $order_id = substr($cart_Sofortueberweisung_Direct_ID, strpos($cart_Sofortueberweisung_Direct_ID, '-') + 1);
     $check_query = tep_db_query("select orders_status from " . TABLE_ORDERS . " where orders_id = '" . (int) $order_id . "'");
     if (tep_db_num_rows($check_query)) {
         $check = tep_db_fetch_array($check_query);
         if ($check['orders_status'] == MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_PREPARE_ORDER_STATUS_ID) {
             $sql_data_array = array('orders_id' => $order_id, 'orders_status_id' => MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_PREPARE_ORDER_STATUS_ID, 'date_added' => 'now()', 'customer_notified' => '0', 'comments' => '');
             if ($md5var4 == $HTTP_GET_VARS['sovar4'] && (int) $HTTP_GET_VARS['betrag_integer'] == (int) $order_total_integer) {
                 $sql_data_array['comments'] = 'Zahlung durch Sofortüberweisung Weiter-Button/Weiterleitung bestätigt!';
             } else {
                 $sql_data_array['comments'] = MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_TEXT_CHECK_ERROR . '\\n' . $HTTP_GET_VARS['betrag_integer'] / 100 . '!=' . $order_total_integer / 100;
             }
             if (MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_STORE_TRANSACTION_DETAILS == 'True') {
                 $sql_data_array['comments'] = (!empty($sql_data_array['comments']) ? $sql_data_array['comments'] . "\n\n" : '') . serialize($HTTP_GET_VARS) . "\n" . serialize($HTTP_POST_VARS);
             }
             tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
         }
     }
     tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . (MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_ORDER_STATUS_ID > 0 ? (int) MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_ORDER_STATUS_ID : (int) DEFAULT_ORDERS_STATUS_ID) . "', last_modified = now() where orders_id = '" . (int) $order_id . "'");
     $sql_data_array = array('orders_id' => $order_id, 'orders_status_id' => MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_ORDER_STATUS_ID > 0 ? (int) MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_ORDER_STATUS_ID : (int) DEFAULT_ORDERS_STATUS_ID, 'date_added' => 'now()', 'customer_notified' => SEND_EMAILS == 'true' ? '1' : '0', 'comments' => $order->info['comments']);
     tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
     // initialized for the email confirmation
     $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') {
             if (DOWNLOAD_ENABLED == 'true') {
                 $stock_query_raw = "SELECT products_quantity, pad.products_attributes_filename\r\n                                FROM " . TABLE_PRODUCTS . " p\r\n                                LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa\r\n                                ON p.products_id=pa.products_id\r\n                                LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad\r\n                                ON pa.products_attributes_id=pad.products_attributes_id\r\n                                WHERE p.products_id = '" . tep_get_prid($order->products[$i]['id']) . "'";
                 // 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'] . "'";
                 }
                 $stock_query = tep_db_query($stock_query_raw);
             } else {
                 $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
             }
             if (tep_db_num_rows($stock_query) > 0) {
                 $stock_values = tep_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'];
                 }
                 tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                 if ($stock_left < 1 && STOCK_ALLOW_CHECKOUT == 'false') {
                     tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                 }
             }
         }
         // Update products_ordered (for bestsellers list)
         tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
         //------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') {
                     $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\r\n                                   from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa\r\n                                   left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad\r\n                                   on pa.products_attributes_id=pad.products_attributes_id\r\n                                   where pa.products_id = '" . $order->products[$i]['id'] . "'\r\n                                   and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "'\r\n                                   and pa.options_id = popt.products_options_id\r\n                                   and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "'\r\n                                   and pa.options_values_id = poval.products_options_values_id\r\n                                   and popt.language_id = '" . $languages_id . "'\r\n                                   and poval.language_id = '" . $languages_id . "'";
                     $attributes = tep_db_query($attributes_query);
                 } else {
                     $attributes = tep_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 = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");
                 }
                 $attributes_values = tep_db_fetch_array($attributes);
                 $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 += tep_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty'];
         $total_cost += $total_products_price;
         $products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . $products_ordered_attributes . "\n";
     }
     // lets start with the email confirmation
     $email_order = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . $order_id . "\n" . EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $order_id, 'SSL', false) . "\n" . EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";
     if ($order->info['comments']) {
         $email_order .= tep_db_output($order->info['comments']) . "\n\n";
     }
     $email_order .= EMAIL_TEXT_PRODUCTS . "\n" . EMAIL_SEPARATOR . "\n" . $products_ordered . EMAIL_SEPARATOR . "\n";
     for ($i = 0, $n = sizeof($order_totals); $i < $n; $i++) {
         $email_order .= strip_tags($order_totals[$i]['title']) . ' ' . strip_tags($order_totals[$i]['text']) . "\n";
     }
     if ($order->content_type != 'virtual') {
         $email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" . EMAIL_SEPARATOR . "\n" . tep_address_label($customer_id, $sendto, 0, '', "\n") . "\n";
     }
     $email_order .= "\n" . EMAIL_TEXT_BILLING_ADDRESS . "\n" . EMAIL_SEPARATOR . "\n" . tep_address_label($customer_id, $billto, 0, '', "\n") . "\n\n";
     if (is_object(${$payment})) {
         $email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" . EMAIL_SEPARATOR . "\n";
         $payment_class = ${$payment};
         $email_order .= $payment_class->title . "\n\n";
         if ($payment_class->email_footer) {
             $email_order .= $payment_class->email_footer . "\n\n";
         }
     }
     tep_mail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
     // send emails to other people
     if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
         tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
     }
     // load the after_process function from the payment modules
     $this->after_process();
     $cart->reset(true);
     // unregister session variables used during checkout
     tep_session_unregister('sendto');
     tep_session_unregister('billto');
     tep_session_unregister('shipping');
     tep_session_unregister('payment');
     tep_session_unregister('comments');
     tep_session_unregister('cart_Sofortueberweisung_Direct_ID');
     tep_redirect(tep_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'SSL'));
 }
Beispiel #29
0
function tep_add_tax($price, $tax, $override = false)
{
    if ((DISPLAY_PRICE_WITH_TAX == 'true' || $override == true) && $tax > 0) {
        return $price + tep_calculate_tax($price, $tax);
    } else {
        return $price;
    }
}
 function before_process()
 {
     global $customer_id, $order, $order_totals, $sendto, $billto, $languages_id, $payment, $currencies, $cart, $cart_PayPal_Standard_ID;
     $insert_id = substr($cart_PayPal_Standard_ID, strpos($cart_PayPal_Standard_ID, '-') + 1);
     $check_query = tep_db_query("select orders_status from " . TABLE_ORDERS . " where orders_id = '" . (int) $insert_id . "'");
     if (tep_db_num_rows($check_query)) {
         $check = tep_db_fetch_array($check_query);
         if ($check['orders_status'] == MODULE_PAYMENT_PAYPAL_STANDARD_PREPARE_ORDER_STATUS_ID) {
             $sql_data_array = array('orders_id' => $insert_id, 'orders_status_id' => MODULE_PAYMENT_PAYPAL_STANDARD_PREPARE_ORDER_STATUS_ID, 'date_added' => 'now()', 'customer_notified' => '0', 'comments' => '');
             tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
         }
     }
     tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . (MODULE_PAYMENT_PAYPAL_STANDARD_ORDER_STATUS_ID > 0 ? (int) MODULE_PAYMENT_PAYPAL_STANDARD_ORDER_STATUS_ID : (int) DEFAULT_ORDERS_STATUS_ID) . "', last_modified = now() where orders_id = '" . (int) $insert_id . "'");
     $sql_data_array = array('orders_id' => $insert_id, 'orders_status_id' => MODULE_PAYMENT_PAYPAL_STANDARD_ORDER_STATUS_ID > 0 ? (int) MODULE_PAYMENT_PAYPAL_STANDARD_ORDER_STATUS_ID : (int) DEFAULT_ORDERS_STATUS_ID, 'date_added' => 'now()', 'customer_notified' => SEND_EMAILS == 'true' ? '1' : '0', 'comments' => $order->info['comments']);
     tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
     // initialized for the email confirmation
     $products_ordered = '';
     $subtotal = 0;
     $total_tax = 0;
     for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
         // Update products_ordered (for bestsellers list)
         tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
         //------insert customer choosen option eof ----
         $total_weight += $order->products[$i]['qty'] * $order->products[$i]['weight'];
         $total_tax += tep_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty'];
         $total_cost += $total_products_price;
         $products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . "\n";
     }
     // lets start with the email confirmation
     $email_order = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . $insert_id . "\n" . EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $insert_id, 'SSL', false) . "\n" . EMAIL_TEXT_DATE_ORDERED . ' ' . tep_date_long(DATE_FORMAT_LONG) . "\n\n";
     if ($order->info['comments']) {
         $email_order .= tep_db_output($order->info['comments']) . "\n\n";
     }
     $email_order .= EMAIL_TEXT_PRODUCTS . "\n" . EMAIL_SEPARATOR . "\n" . $products_ordered . EMAIL_SEPARATOR . "\n";
     for ($i = 0, $n = sizeof($order_totals); $i < $n; $i++) {
         $email_order .= strip_tags($order_totals[$i]['title']) . ' ' . strip_tags($order_totals[$i]['text']) . "\n";
     }
     if ($order->content_type != 'virtual') {
         $email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" . EMAIL_SEPARATOR . "\n" . tep_address_label($customer_id, $sendto, false) . "\n";
     }
     if ($billto != false) {
         //		$email_order .= "\n" . EMAIL_TEXT_BILLING_ADDRESS . "\n" .
         //						EMAIL_SEPARATOR . "\n" .
         //						tep_address_label($customer_id, $billto, false) . "\n\n";
     }
     if (is_object(${$payment})) {
         $email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" . EMAIL_SEPARATOR . "\n";
         $payment_class = ${$payment};
         $email_order .= $payment_class->title . "\n\n";
         if ($payment_class->email_footer) {
             $email_order .= strip_tags($payment_class->email_footer) . "\n\n";
         }
     }
     $email_subject = STORE_NAME . ' - ' . sprintf(EMAIL_TEXT_SUBJECT, $insert_id);
     tep_mail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], $email_subject, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
     // send emails to other people
     if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
         tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, $email_subject, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
     }
     // load the after_process function from the payment modules
     $this->after_process();
     $cart->reset(true);
     $order = new order($insert_id);
     $order_total_sum = 0;
     $order_shipping_sum = 0;
     reset($order->totals);
     while (list(, $order_total) = each($order->totals)) {
         if ($order_total['class'] == 'ot_total') {
             $order_total_sum = $order_total['value'];
         } elseif ($order_total['class'] == 'ot_shipping') {
             $order_shipping_sum = $order_total['value'];
         }
     }
     $order_shipping_title = strtolower($order->info['shipping_method']);
     if (mb_strpos($order_shipping_title, 'самовывоз', 0, 'CP1251') !== false) {
         $order_shipping_id = 1;
     } elseif (mb_strpos($order_shipping_title, 'подмосковье', 0, 'CP1251') !== false) {
         if ($order_shipping_sum == 0) {
             $order_shipping_id = 5;
         } else {
             $order_shipping_id = 4;
         }
     } elseif (mb_strpos($order_shipping_title, 'курьером', 0, 'CP1251') !== false) {
         if ($order_shipping_sum == 0) {
             $order_shipping_id = 3;
         } else {
             $order_shipping_id = 2;
         }
     } elseif (mb_strpos($order_shipping_title, 'почт', 0, 'CP1251') !== false) {
         if (DOMAIN_ZONE == 'ru') {
             $order_shipping_id = 6;
         } elseif (DOMAIN_ZONE == 'ua') {
             $order_shipping_id = 8;
         } elseif (DOMAIN_ZONE == 'by') {
             $order_shipping_id = 9;
         }
     } elseif (strpos($order_shipping_title, 'postal') !== false) {
         $order_shipping_id = 7;
     } elseif (strpos($order_shipping_title, 'deutsche') !== false) {
         $order_shipping_id = 10;
     } else {
         $order_shipping_id = 0;
     }
     $order_payment_id = 0;
     $order_payment_title = strtolower($order->info['payment_method']);
     if (mb_strpos($order_payment_title, 'налич', 0, 'CP1251') !== false) {
         $order_payment_id = 1;
     } elseif (strpos($order_payment_title, 'order') !== false) {
         $order_payment_id = 6;
     } elseif (strpos($order_payment_title, 'check') !== false) {
         $order_payment_id = 7;
     } elseif (strpos($order_payment_title, 'pal') !== false) {
         $order_payment_id = 8;
     } elseif (mb_strpos($order_payment_title, 'налож', 0, 'CP1251') !== false) {
         $order_payment_id = 2;
     } elseif (mb_strpos($order_payment_title, 'банк', 0, 'CP1251') !== false) {
         $order_payment_id = 3;
     } elseif (mb_strpos($order_payment_title, 'безнал', 0, 'CP1251') !== false) {
         $order_payment_id = 4;
     } elseif (mb_strpos($order_payment_title, 'почтовым', 0, 'CP1251') !== false) {
         $order_payment_id = 5;
     }
     $date_purchased = preg_replace('/(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})/', '$3-$2-$1 $4:$5:$6', $order->info['date_purchased']);
     $order_file = UPLOAD_DIR . 'orders/' . SHOP_PREFIX . 'im' . $insert_id . '.csv';
     $fp = fopen($order_file, 'w');
     reset($order->products);
     $common_data = array('ORDER_ID', 'ORDER_DATE_INSERT', 'USER_ID', 'PAY_SYSTEM_ID', 'DELIVERY_ID', 'PRICE_DELIVERY', 'ORDER_PRICE', 'REGION', 'RAYON', 'CITY', 'INDEX', 'ADDRESS', 'PHONE', 'COMMENTS', 'PRODUCT_ID', 'PRODUCT_QUANTITY', 'PRODUCT_PRICE');
     fputcsvsafe($fp, $common_data, ';');
     while (list(, $product) = each($order->products)) {
         $common_data = array();
         $common_data[] = $server_prefix . 'im' . $insert_id;
         $common_data[] = $date_purchased;
         $common_data[] = $order->customer['id'];
         $common_data[] = $order_payment_id;
         // тип оплаты
         $common_data[] = $order_shipping_id;
         // тип доставки
         $common_data[] = $order_shipping_sum;
         // стоимость доставки
         $common_data[] = $order_total_sum;
         // сумма заказа
         $common_data[] = $order->delivery['state'];
         $common_data[] = $order->delivery['suburb'];
         $common_data[] = $order->delivery['city'];
         $common_data[] = $order->delivery['postcode'];
         $common_data[] = $order->delivery['street_address'];
         $common_data[] = $order->customer['telephone'];
         $common_data[] = $order->info['comments'];
         $common_data[] = $product['code'];
         $common_data[] = $product['qty'];
         $common_data[] = $product['final_price'];
         fputcsvsafe($fp, $common_data, ';');
     }
     fclose($fp);
     // unregister session variables used during checkout
     tep_session_unregister('sendto');
     tep_session_unregister('billto');
     tep_session_unregister('shipping');
     tep_session_unregister('payment');
     tep_session_unregister('comments');
     tep_session_unregister('cart_PayPal_Standard_ID');
     tep_redirect(tep_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'SSL'));
 }