function zen_calculate_tax($price, $tax)
{
    global $currencies;
    //    $result = bcmul($price, $tax, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
    //    $result = bcdiv($result, 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
    //    return $result;
    return zen_round($price * $tax / 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
}
 function value($number, $calculate_currency_value = true, $currency_type = '', $currency_value = '')
 {
     if (empty($currency_type)) {
         $currency_type = $_SESSION['currency'];
     }
     if ($calculate_currency_value == true) {
         if ($currency_type == DEFAULT_CURRENCY) {
             $rate = zen_not_null($currency_value) ? $currency_value : 1 / $this->currencies[$_SESSION['currency']]['value'];
         } else {
             $rate = zen_not_null($currency_value) ? $currency_value : $this->currencies[$currency_type]['value'];
         }
         $currency_value = zen_round($number * $rate, $this->currencies[$currency_type]['decimal_places']);
     } else {
         $currency_value = zen_round($number, $this->currencies[$currency_type]['decimal_places']);
     }
     return $currency_value;
 }
Example #3
0
 function process()
 {
     global $order, $currencies;
     if ($this->enabled && $this->selection_test()) {
         $order_total = $this->get_order_total();
         $this->deduction = $this->calculate_credit($order_total);
         // Calculate the credit to be applied
         $order->info['total'] = zen_round($order->info['total'] - $this->deduction, 2);
         if ($this->deduction > 0 && $this->selection_test()) {
             $this->output[] = array('title' => $this->title . ':', 'text' => '-' . $currencies->format($this->deduction), 'value' => $this->deduction);
         }
         if ($this->deduction >= $order->info['total']) {
             $_SESSION['credit_covers'] = true;
         } else {
             $_SESSION['credit_covers'] = false;
         }
     } else {
         $_SESSION['credit_covers'] = false;
     }
 }
    function get_products_attributes($products_id, $languageId = 1)
    {
        global $db;
        // Added the following to query "and pa.attributes_display_only != 1" This removed read only attributes from the stock selection.
        $query = '	select pa.products_attributes_id, pa.options_values_price, pa.price_prefix,
			 				po.products_options_name, pov.products_options_values_name
			 			from ' . TABLE_PRODUCTS_ATTRIBUTES . ' pa
			 			left join ' . TABLE_PRODUCTS_OPTIONS . ' po on (pa.options_id = po.products_options_id)
			 			left join ' . TABLE_PRODUCTS_OPTIONS_VALUES . ' pov on (pa.options_values_id = pov.products_options_values_id)
			 			where pa.products_id = "' . $products_id . '" 
			 				AND po.language_id = "' . $languageId . '" and po.language_id = pov.language_id
							and pa.attributes_display_only != 1';
        $attributes = $db->Execute($query);
        if ($attributes->RecordCount() > 0) {
            while (!$attributes->EOF) {
                $attributes_array[$attributes->fields['products_options_name']][] = array('id' => $attributes->fields['products_attributes_id'], 'text' => $attributes->fields['products_options_values_name'] . ' (' . $attributes->fields['price_prefix'] . '$' . zen_round($attributes->fields['options_values_price'], 2) . ')');
                $attributes->MoveNext();
            }
            return $attributes_array;
        } else {
            return false;
        }
    }
Example #5
0
 /**
  * Prepare and submit the authorization to the gateway
  */
 function before_process()
 {
     global $order, $order_totals, $db, $messageStack, $lp_avs, $lp_trans_num;
     $myorder = array();
     // Calculate the next expected order id
     $last_order_id = $db->Execute("select * from " . TABLE_ORDERS . " order by orders_id desc limit 1");
     $new_order_id = $last_order_id->fields['orders_id'];
     $new_order_id = $new_order_id + 1;
     // add randomized suffix to order id to produce uniqueness ... since it's unwise to submit the same order-number twice to the gateway
     $new_order_id = (string) $new_order_id . '-' . zen_create_random_value(6);
     // Build Info to send to Gateway
     $myorder["result"] = "LIVE";
     switch (MODULE_PAYMENT_LINKPOINT_API_TRANSACTION_MODE_RESPONSE) {
         case "TESTING: Successful":
             $myorder["result"] = "GOOD";
             break;
         case "TESTING: Decline":
             $myorder["result"] = "DECLINE";
             break;
         case "TESTING: Duplicate":
             $myorder["result"] = "DUPLICATE";
             break;
     }
     // "oid" - Order ID number must be unique. If not set, gateway will assign one.
     //$oid = zen_create_random_value(16, 'digits'); // Create a UID for the order
     $myorder["oid"] = $new_order_id;
     //"";    // time(); ????
     // prepare totals for submission
     $surcharges = 0;
     $creditsApplied = 0;
     global $order_totals;
     reset($order_totals);
     $myorder['subtotal'] = $myorder['tax'] = $myorder['shipping'] = $myorder['chargetotal'] = 0;
     for ($i = 0, $n = sizeof($order_totals); $i < $n; $i++) {
         if ($order_totals[$i]['code'] == '') {
             continue;
         }
         if (in_array($order_totals[$i]['code'], array('ot_total', 'ot_subtotal', 'ot_tax', 'ot_shipping'))) {
             if ($order_totals[$i]['code'] == 'ot_subtotal') {
                 $myorder["subtotal"] = round($order_totals[$i]['value'], 2);
             }
             if ($order_totals[$i]['code'] == 'ot_tax') {
                 $myorder["tax"] += round($order_totals[$i]['value'], 2);
             }
             if ($order_totals[$i]['code'] == 'ot_shipping') {
                 $myorder["shipping"] = round($order_totals[$i]['value'], 2);
             }
             if ($order_totals[$i]['code'] == 'ot_total') {
                 $myorder["chargetotal"] = round($order_totals[$i]['value'], 2);
             }
         } else {
             global ${$order_totals[$i]['code']};
             if (substr($order_totals[$i]['text'], 0, 1) == '-' || isset(${$order_totals[$i]['code']}->credit_class) && ${$order_totals[$i]['code']}->credit_class == true) {
                 $creditsApplied += round($order_totals[$i]['value'], 2);
             } else {
                 $surcharges += round($order_totals[$i]['value'], 2);
             }
         }
     }
     foreach (array('subtotal', 'tax', 'chargetotal', 'shipping') as $i) {
         if (isset($myorder[$i])) {
             $myorder[$i] = number_format($myorder[$i], 2, '.', '');
         }
     }
     if ($surcharges == 0 && $creditsApplied == 0 && $order->info['total'] >= $order->info['subtotal'] && sizeof($order->products) <= 20) {
         // itemized contents
         $num_line_items = 0;
         reset($order->products);
         for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
             $num_line_items++;
             $myorder["items"][$num_line_items]['id'] = $order->products[$i]['id'];
             $myorder["items"][$num_line_items]['description'] = substr(htmlentities($order->products[$i]['name'], ENT_QUOTES, 'UTF-8'), 0, 128);
             $myorder["items"][$num_line_items]['quantity'] = $order->products[$i]['qty'];
             $myorder["items"][$num_line_items]['price'] = number_format(zen_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), 2, '.', '');
             // check and adjust for fractional quantities, which cannot be submitted as line-item details
             $q = $order->products[$i]['qty'];
             $q1 = strval($q);
             $q2 = (int) $q;
             $q3 = strval($q2);
             if ($q1 != $q3 || $myorder["items"][$num_line_items]['quantity'] * $myorder["items"][$num_line_items]['price'] != number_format($order->products[$i]['qty'] * $order->products[$i]['final_price'], 2, '.', '')) {
                 $myorder["items"][$num_line_items]['quantity'] = 1;
                 $myorder["items"][$num_line_items]['price'] = number_format(zen_round(zen_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), $decimals) * $order->products[$i]['qty'], 2, '.', '');
                 $myorder["items"][$num_line_items]['description'] = '(' . $order->products[$i]['qty'] . ' x )' . substr($myorder["items"][$num_line_items]['description'], 115);
             }
             if (isset($order->products[$i]['attributes'])) {
                 $options_text_length = 0;
                 for ($j = 0, $m = sizeof($order->products[$i]['attributes']); $j < $m; $j++) {
                     $options_text_length += strlen($order->products[$i]['attributes'][$j]['option'] . $order->products[$i]['attributes'][$j]['value']);
                 }
                 if ($options_text_length < 128) {
                     for ($j = 0, $m = sizeof($order->products[$i]['attributes']); $j < $m; $j++) {
                         $myorder["items"][$num_line_items]['options' . $j]['name'] = substr(htmlentities($order->products[$i]['attributes'][$j]['option'], ENT_QUOTES, 'UTF-8'), 0, 128);
                         $myorder["items"][$num_line_items]['options' . $j]['value'] = substr(htmlentities($order->products[$i]['attributes'][$j]['value'], ENT_QUOTES, 'UTF-8'), 0, 128);
                     }
                 }
             }
             // track one-time charges
             if ($order->products[$i]['onetime_charges'] != 0) {
                 $num_line_items++;
                 $myorder["items"][$num_line_items]['id'] = 'OTC';
                 $myorder["items"][$num_line_items]['description'] = 'One Time Charges';
                 $myorder["items"][$num_line_items]['quantity'] = 1;
                 $myorder["items"][$num_line_items]['price'] = number_format(zen_add_tax($order->products[$i]['onetime_charges'], $order->products[$i]['tax']), 2, '.', '');
             }
         }
         /*
                 // deal with surcharges/fees
                 $num_line_items++;
                 $myorder["items"][$num_line_items]['id']          = 'Surcharge';
                 $myorder["items"][$num_line_items]['description'] = $order_totals[$i]['title'];
                 $myorder["items"][$num_line_items]['quantity']    = 1;
                 $myorder["items"][$num_line_items]['price']       = number_format($order_totals[$i]['value'], 2, '.', '');
                 $myorder["subtotal"] += $surcharges;
         */
         // FirstData can't accept more than 20 line-item submissions per transaction
         if ($num_line_items > 20) {
             unset($myorder["items"]);
             $num_line_items = 0;
         }
         // Verify that the line-item math works
         for ($i = 1, $n = $num_line_items; $i <= $n; $i++) {
             $sum2 += $myorder["items"][$i]['quantity'] * $myorder["items"][$i]['price'];
         }
         if (strval($sum2) != strval($myorder['subtotal'])) {
             unset($myorder['items']);
             $num_line_items = 0;
         }
     }
     // Subtotal Sanity Check in case there are addon modules affecting calculations
     $sum1 = strval($myorder['subtotal'] + $myorder['shipping'] + $myorder['tax']);
     if ($sum1 > $myorder['chargetotal']) {
         foreach (array('subtotal', 'tax', 'shipping', 'items') as $i) {
             if (isset($myorder[$i])) {
                 unset($myorder[$i]);
             }
         }
     } elseif ($sum1 < $myorder['chargetotal']) {
         if ($num_line_items > 0 && $num_line_items < 20 && isset($myorder['items'])) {
             $num_line_items++;
             $myorder["items"][$num_line_items]['id'] = 'Adj';
             $myorder["items"][$num_line_items]['description'] = 'Rounding Adjustment';
             $myorder["items"][$num_line_items]['quantity'] = 1;
             $myorder["items"][$num_line_items]['price'] = number_format($myorder['chargetotal'] - $sum1, 2, '.', '');
             $myorder['subtotal'] += round($myorder['chargetotal'] - $sum1, 2);
             $myorder['subtotal'] = number_format($myorder['subtotal'], 2, '.', '');
         } else {
             foreach (array('subtotal', 'tax', 'shipping', 'items') as $i) {
                 if (isset($myorder[$i])) {
                     unset($myorder[$i]);
                 }
             }
         }
     }
     // clean up zeros
     foreach (array('subtotal', 'tax', 'shipping') as $i) {
         if (isset($myorder[$i]) && $myorder[$i] == 0) {
             unset($myorder[$i]);
         }
     }
     $myorder["ip"] = current(explode(':', str_replace(',', ':', zen_get_ip_address())));
     $myorder["ponumber"] = "";
     // CARD INFO
     $myorder["cardnumber"] = $_POST['cc_number'];
     $myorder["cardexpmonth"] = $_POST['cc_expires_month'];
     $myorder["cardexpyear"] = $_POST['cc_expires_year'];
     $myorder["cvmindicator"] = "provided";
     $myorder["cvmvalue"] = $_POST['cc_cvv'];
     // BILLING INFO
     $myorder["userid"] = $_SESSION['customer_id'];
     $myorder["customerid"] = $_SESSION['customer_id'];
     $myorder["name"] = htmlentities($_POST['cc_owner'], ENT_QUOTES, 'UTF-8');
     //$order->billing['firstname'] . ' ' . $order->billing['lastname']);
     $myorder["company"] = htmlentities($order->billing['company'], ENT_QUOTES, 'UTF-8');
     $myorder["address1"] = htmlentities($order->billing['street_address'], ENT_QUOTES, 'UTF-8');
     $myorder["address2"] = htmlentities($order->billing['suburb'], ENT_QUOTES, 'UTF-8');
     $myorder["city"] = $order->billing['city'];
     $myorder["state"] = $order->billing['state'];
     $myorder["country"] = $order->billing['country']['iso_code_2'];
     $myorder["phone"] = $order->customer['telephone'];
     //$myorder["fax"]      = $order->customer['fax'];
     $myorder["email"] = $order->customer['email_address'];
     $myorder["addrnum"] = $order->billing['street_address'];
     // Required for AVS. If not provided, transactions will downgrade.
     $myorder["zip"] = $order->billing['postcode'];
     // Required for AVS. If not provided, transactions will downgrade.
     // SHIPPING INFO
     $myorder["sname"] = htmlentities($order->delivery['firstname'] . ' ' . $order->delivery['lastname'], ENT_QUOTES, 'UTF-8');
     $myorder["saddress1"] = htmlentities($order->delivery['street_address'], ENT_QUOTES, 'UTF-8');
     $myorder["saddress2"] = htmlentities($order->delivery['suburb'], ENT_QUOTES, 'UTF-8');
     $myorder["scity"] = $order->delivery['city'];
     $myorder["sstate"] = $order->delivery['state'];
     $myorder["szip"] = $order->delivery['postcode'];
     $myorder["scountry"] = $order->delivery['country']['iso_code_2'];
     // MISC
     $myorder["comments"] = "Website Order";
     // $myorder["referred"] = "";
     $myorder["ordertype"] = MODULE_PAYMENT_LINKPOINT_API_AUTHORIZATION_MODE == 'Authorize Only' ? 'PREAUTH' : 'SALE';
     $this->payment_status = $myorder["ordertype"];
     // send request to gateway
     $result = $this->_sendRequest($myorder);
     // alert to customer if communication failure
     if (!is_array($result)) {
         $messageStack->add_session('checkout_payment', MODULE_PAYMENT_LINKPOINT_API_TEXT_FAILURE_MESSAGE, 'error');
         zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
     }
     // resubmit without subtotals if subtotal error occurs
     if ($result["r_approved"] != "APPROVED" && !($result["r_approved"] == "SUBMITTED" && $result["r_message"] == 'APPROVED')) {
         if (in_array(substr($result['r_error'], 0, 10), array('SGS-002301', 'SGS-010503', 'SGS-005003'))) {
             foreach (array('items', 'subtotal', 'tax', 'shipping') as $i) {
                 if (isset($myorder[$i])) {
                     unset($myorder[$i]);
                 }
             }
             $myorder["oid"] .= '-b';
             $myorder["chargetotal"] = $myorder["chargetotal"] - 0.01;
             $result = $this->_sendRequest($myorder);
             if (!is_array($result)) {
                 $messageStack->add_session('checkout_payment', MODULE_PAYMENT_LINKPOINT_API_TEXT_FAILURE_MESSAGE, 'error');
                 zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
             }
         }
     }
     // PARSE Results
     $all_response_info = '';
     foreach ($result as $key => $value) {
         $all_response_info .= ' ' . $key . '=' . $value;
     }
     if ($this->code_debug) {
         $messageStack->add_session('header', $all_response_info, 'caution');
     }
     $chargetotal = $myorder["chargetotal"];
     // prepare transaction logging info
     $cust_info = '';
     $cc_number = substr($myorder["cardnumber"], 0, 4) . str_repeat('X', abs(strlen($myorder["cardnumber"]) - 8)) . substr($myorder["cardnumber"], -4);
     foreach ($myorder as $key => $value) {
         if ($key != 'cardnumber') {
             if ($key == 'cvmvalue') {
                 $value = '****';
             }
             if ($key == 'cardexpmonth') {
                 $cc_month = $value;
             }
             if ($key == 'cardexpyear') {
                 $cc_year = $value;
             }
             if (is_array($value)) {
                 $value = print_r($value, true);
             }
             if (!in_array($key, array('keyfile', 'configfile', 'transactionorigin', 'terminaltype', 'host', 'port'))) {
                 $cust_info .= ' ' . $key . '=' . $value . ';';
             }
         } else {
             $cust_info .= ' ' . $key . '=' . $cc_number . ';';
         }
     }
     // store last 4 digits of CC number
     //    $order->info['cc_number'] = str_repeat('X', (strlen($myorder["cardnumber"]) - 4)) . substr($myorder["cardnumber"], -4);
     // store first and last 4 digits of CC number ... which is the Visa-standards-compliant approach, same as observed by Linkpoint's services
     $order->info['cc_number'] = $cc_number;
     $order->info['cc_type'] = $_POST['cc_type'];
     $order->info['cc_owner'] = $_POST['cc_owner'];
     $order->info['cc_cvv'] = '***';
     $order->info['cc_expires'] = '';
     // $_POST['cc_expires'];
     $lp_trans_num = $result['r_ordernum'];
     $transaction_tax = $result['r_tax'];
     // The calculated tax for the order, when the ordertype is calctax.
     $transaction_shipping = $result['r_shipping'];
     // The calculated shipping charges for the order, when the ordertype is calcshipping.
     $this->response_codes = $result['r_avs'];
     // AVS Response for transaction
     // these are used to update the order-status-history upon order completion
     $this->transaction_id = $result['r_tdate'] . ' Order Number/Code: ' . $result['r_ordernum'];
     $this->auth_code = $result['r_code'];
     // The approval code for this transaction.
     //  Store Transaction history in Database
     $sql_data_array = array(array('fieldName' => 'lp_trans_num', 'value' => $result['r_ordernum'], 'type' => 'string'), array('fieldName' => 'order_id', 'value' => $result['r_ordernum'], 'type' => 'integer'), array('fieldName' => 'approval_code', 'value' => $result['r_code'], 'type' => 'string'), array('fieldName' => 'transaction_response_time', 'value' => $result['r_time'], 'type' => 'string'), array('fieldName' => 'r_error', 'value' => $result['r_error'], 'type' => 'string'), array('fieldName' => 'customer_id', 'value' => $_SESSION['customer_id'], 'type' => 'integer'), array('fieldName' => 'avs_response', 'value' => $result['r_avs'], 'type' => 'string'), array('fieldName' => 'transaction_result', 'value' => $result['r_approved'], 'type' => 'string'), array('fieldName' => 'message', 'value' => $result['r_message'] . "\n" . $all_response_info, 'type' => 'string'), array('fieldName' => 'transaction_time', 'value' => $result['r_tdate'], 'type' => 'string'), array('fieldName' => 'transaction_reference_number', 'value' => $result['r_ref'], 'type' => 'string'), array('fieldName' => 'fraud_score', 'value' => $result['r_score'], 'type' => 'integer'), array('fieldName' => 'cc_number', 'value' => $cc_number, 'type' => 'string'), array('fieldName' => 'cust_info', 'value' => $cust_info, 'type' => 'string'), array('fieldName' => 'chargetotal', 'value' => $chargetotal, 'type' => 'string'), array('fieldName' => 'ordertype', 'value' => $myorder['ordertype'], 'type' => 'string'), array('fieldName' => 'date_added', 'value' => 'now()', 'type' => 'noquotestring'));
     if (MODULE_PAYMENT_LINKPOINT_API_STORE_DATA == 'True') {
         $db->perform(TABLE_LINKPOINT_API, $sql_data_array);
     }
     //  Begin check of specific error conditions
     if ($result["r_approved"] != "APPROVED" && !($result["r_approved"] == "SUBMITTED" && $result["r_message"] == 'APPROVED')) {
         if (substr($result['r_error'], 0, 10) == 'SGS-020005') {
             $messageStack->add_session('checkout_payment', $result['r_error'], 'error');
         }
         // Error (Merchant config file is missing, empty or cannot be read)
         if (substr($result['r_error'], 0, 10) == 'SGS-005000') {
             $messageStack->add_session('checkout_payment', MODULE_PAYMENT_LINKPOINT_API_TEXT_GENERAL_ERROR . '<br />' . $result['r_error'], 'error');
         }
         // The server encountered a database error
         if (substr($result['r_error'], 0, 10) == 'SGS-000001' || strstr($result['r_error'], 'D:Declined') || strstr($result['r_error'], 'R:Referral')) {
             $messageStack->add_session('checkout_payment', MODULE_PAYMENT_LINKPOINT_API_TEXT_DECLINED_MESSAGE . '<br />' . $result['r_error'], 'error');
         }
         if (substr($result['r_error'], 0, 10) == 'SGS-005005' || strstr($result['r_error'], 'Duplicate transaction')) {
             $messageStack->add_session('checkout_payment', MODULE_PAYMENT_LINKPOINT_API_TEXT_DUPLICATE_MESSAGE . '<br />' . $result['r_error'], 'error');
         }
         if (substr($result['r_error'], 0, 10) == 'SGS-002301') {
             $messageStack->add_session('checkout_payment', 'Subtotal miscalculation. Please notify the storeowner.' . '<br />' . $result['r_error'], 'error');
         }
     }
     //  End specific error conditions
     //  Begin Transaction Status does not equal APPROVED
     if ($result["r_approved"] != "APPROVED") {
         // alert to customer:
         $messageStack->add_session('checkout_payment', MODULE_PAYMENT_LINKPOINT_API_TEXT_DECLINED_MESSAGE, 'caution');
         zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
     }
     //  End Transaction Status does not equal APPROVED
     $avs_meanings = array();
     $avs_meanings['YY'] = ' - Street Address and Zip Code match.';
     $avs_meanings['YN'] = ' - Street Address matches but Zip Code does NOT match.';
     $avs_meanings['YX'] = ' - Street Address matches, but Zip Code comparison unavailable.';
     $avs_meanings['NY'] = ' - Street Address DOES NOT match, but Zip Code matches.';
     $avs_meanings['XY'] = ' - Street Address check not available, but Zip Code matches.';
     $avs_meanings['NN'] = ' - Street Address DOES NOT MATCH and Zip Code DOES NOT MATCH.';
     $avs_meanings['NX'] = ' - Street Address DOES NOT MATCH and Zip Code comparison unavailable.';
     $avs_meanings['XN'] = ' - Street Address check not available. Zip Code DOES NOT MATCH.';
     $avs_meanings['XX'] = ' - No validation for address or zip code could be performed (not available from issuing bank).';
     // Possible Fraud order. Allow transaction to process, but notify shop for owner to take appropriate action on order
     if ($result["r_approved"] == "APPROVED" && substr($result['r_code'], 17, 2) != "YY" && MODULE_PAYMENT_LINKPOINT_API_FRAUD_ALERT == 'Yes') {
         //DEBUG: $messageStack->add_session('header', 'possible fraud situation--> ' . $result['r_code'], 'caution');
         $message = 'Potential Fraudulent Order - Bad Address - Action Required' . "\n" . 'This alert occurs because the "Approval Code" below does not contain the expected YY response.' . "\n" . 'Thus, you might want to verify the address with the customer prior to shipping, or be sure to use Registered Mail with Signature Required in case they file a chargeback.' . "\n\n" . 'Customer Name: ' . $order->customer['firstname'] . ' ' . $order->customer['lastname'] . "\n\n" . 'AVS Result: ' . $result['r_avs'] . $avs_meanings[substr($result['r_avs'], 0, 2)] . "\n\n" . 'Order Number: ' . $lp_trans_num . "\n" . 'Transaction Date and Time: ' . $result['r_time'] . "\n" . 'Approval Code: ' . $result['r_code'] . "\n" . 'Reference Number: ' . $result['r_ref'] . "\n\n" . 'Error Message: ' . $result['r_error'] . "\n\n" . 'Transaction Result: ' . $result['r_approved'] . "\n\n" . 'Message: ' . $result['r_message'] . "\n\n" . 'Fraud Score: ' . ($result['r_score'] == '' ? 'Not Enabled' : $result['r_score']) . "\n\n" . 'AVS CODE MEANINGS: ' . "\n" . 'YY** = Street Address and Zip Code match.' . "\n" . 'YN** = Street Address matches but Zip Code does NOT match.' . "\n" . 'YX** = Street Address matches, but Zip Code comparison unavailable.' . "\n" . 'NY** = Street Address DOES NOT match, but Zip Code matches.' . "\n" . 'XY** = Street Address check not available, but Zip Code matches.' . "\n" . 'NN** = Street Address DOES NOT MATCH and Zip Code DOES NOT MATCH.' . "\n" . 'NX** = Street Address DOES NOT MATCH and Zip Code comparison unavailable.' . "\n" . 'XN** = Street Address check not available. Zip Code DOES NOT MATCH.' . "\n" . 'XX** = Neither validation is available.' . "\n";
         $html_msg['EMAIL_MESSAGE_HTML'] = nl2br($result['r_message']);
         zen_mail(STORE_NAME, STORE_OWNER_EMAIL_ADDRESS, 'Potential Fraudulent Order - Bad Address - Action Required - ' . $lp_trans_num, $message, STORE_NAME, EMAIL_FROM, $html_msg, 'fraudalert');
     }
     // end fraud alert
 }
Example #6
0
function zen_calculate_tax($price, $tax)
{
    global $currencies;
    return zen_round($price * $tax / 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
}
/**
 * @param $average
 * @return string
 */
function average_product_reviews_font_awesome($average)
{
    $reviews_string = '';
    $rating = zen_round($average * 2, 0) / 2;
    $full_stars = floor($rating);
    $empty_stars = 5 - ceil($rating);
    $half_stars = 5 - $full_stars - $empty_stars;
    $full_stars_count = 0;
    while ($full_stars != $full_stars_count) {
        $reviews_string .= '<i class="fa fa-star"></i>';
        $full_stars_count++;
    }
    if ($half_stars != 0) {
        $reviews_string .= '<i class="fa fa-star-half-o"></i>';
    }
    $empty_stars_count = 0;
    while ($empty_stars != $empty_stars_count) {
        $reviews_string .= '<i class="fa fa-star"></i>';
        $empty_stars_count++;
    }
    return $reviews_string;
}
Example #8
0
 /**
  * Only exists in storefront
  *
  * @copyright Copyright 2003-2010 Zen Cart Development Team
  * @copyright Portions Copyright 2003 osCommerce
  * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  */
 public function value($number, $calculate_value = true, $currency_type = '', $currency_value = '')
 {
     if (empty($currency_type)) {
         $currency_type = $this->getSessionVar('currency');
     }
     if ($calculate_value) {
         if ($currency_type == DEFAULT_CURRENCY) {
             $rate = $currency_value ?: 1 / $this->currencies[$this->getSessionVar('currency')]['value'];
         } else {
             $rate = $currency_value ?: $this->currencies[$currency_type]['value'];
         }
         $currency_value = zen_round($number * $rate, $this->currencies[$currency_type]['decimal_places']);
     } else {
         $currency_value = zen_round($number, $this->currencies[$currency_type]['decimal_places']);
     }
     return $currency_value;
 }
 /**
  * Method to calculate price of attributes for a given item
  *
  * @param mixed the product ID of the item to check
  * @return decimal the pice of the items attributes
  * @global object access to the db object
  */
 function attributes_price($products_id)
 {
     global $db, $currencies;
     $total_attributes_price = 0;
     $qty = $this->contents[$products_id]['qty'];
     if (isset($this->contents[$products_id]['attributes'])) {
         reset($this->contents[$products_id]['attributes']);
         while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
             $attributes_price = 0;
             $attribute_price_query = "select *\n                                    from " . TABLE_PRODUCTS_ATTRIBUTES . "\n                                    where products_id = '" . (int) $products_id . "'\n                                    and options_id = '" . (int) $option . "'\n                                    and options_values_id = '" . (int) $value . "'";
             $attribute_price = $db->Execute($attribute_price_query);
             // Dual Pricing start
             if ($_SESSION['customer_id']) {
                 $customers_id = $_SESSION['customer_id'];
                 $customer_check = $db->Execute("select * from " . TABLE_CUSTOMERS . " where customers_id = '{$customers_id}'");
                 if ($customer_check->fields['customers_whole'] != "0") {
                     $i = $customer_check->fields['customers_whole'];
                     $i--;
                     $options_value_price = (double) $attribute_price->fields['options_values_price_w'];
                 } else {
                     $options_value_price = $attribute_price->fields['options_values_price'];
                 }
             } else {
                 $options_value_price = $attribute_price->fields['options_values_price'];
             }
             // Dual Pricing end
             $new_attributes_price = 0;
             $discount_type_id = '';
             $sale_maker_discount = '';
             //          if ($attribute_price->fields['product_attribute_is_free']) {
             if ($attribute_price->fields['product_attribute_is_free'] == '1' and zen_get_products_price_is_free((int) $products_id)) {
                 // no charge
             } else {
                 // + or blank adds
                 if ($attribute_price->fields['price_prefix'] == '-') {
                     // calculate proper discount for attributes
                     if ($attribute_price->fields['attributes_discounted'] == '1') {
                         $discount_type_id = '';
                         $sale_maker_discount = '';
                         $new_attributes_price = zen_get_discount_calc($products_id, $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty);
                         $attributes_price -= $new_attributes_price;
                     } else {
                         $attributes_price -= $attribute_price->fields['options_values_price'];
                     }
                 } else {
                     if ($attribute_price->fields['attributes_discounted'] == '1') {
                         // calculate proper discount for attributes
                         $discount_type_id = '';
                         $sale_maker_discount = '';
                         $new_attributes_price = zen_get_discount_calc($products_id, $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty);
                         // Dual Pricing start
                         if ($_SESSION['customer_id']) {
                             if ($customer_check->fields['customers_whole'] != "0") {
                                 $new_attributes_price = zen_get_discount_calc($products_id, $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price_w'], $qty);
                             }
                         }
                         // Dual Pricing end
                         $attributes_price += $new_attributes_price;
                     } else {
                         $attributes_price += $attribute_price->fields['options_values_price'];
                     }
                 }
                 //////////////////////////////////////////////////
                 // calculate additional charges
                 // products_options_value_text
                 if (zen_get_attributes_type($attribute_price->fields['products_attributes_id']) == PRODUCTS_OPTIONS_TYPE_TEXT) {
                     $text_words = zen_get_word_count_price($this->contents[$products_id]['attributes_values'][$attribute_price->fields['options_id']], $attribute_price->fields['attributes_price_words_free'], $attribute_price->fields['attributes_price_words']);
                     $text_letters = zen_get_letters_count_price($this->contents[$products_id]['attributes_values'][$attribute_price->fields['options_id']], $attribute_price->fields['attributes_price_letters_free'], $attribute_price->fields['attributes_price_letters']);
                     $attributes_price += $text_letters;
                     $attributes_price += $text_words;
                 }
                 // attributes_price_factor
                 $added_charge = 0;
                 if ($attribute_price->fields['attributes_price_factor'] > 0) {
                     $chk_price = zen_get_products_base_price($products_id);
                     $chk_special = zen_get_products_special_price($products_id, false);
                     $added_charge = zen_get_attributes_price_factor($chk_price, $chk_special, $attribute_price->fields['attributes_price_factor'], $attribute_price->fields['attributes_price_factor_offset']);
                     $attributes_price += $added_charge;
                 }
                 // attributes_qty_prices
                 $added_charge = 0;
                 if ($attribute_price->fields['attributes_qty_prices'] != '') {
                     $chk_price = zen_get_products_base_price($products_id);
                     $chk_special = zen_get_products_special_price($products_id, false);
                     $added_charge = zen_get_attributes_qty_prices_onetime($attribute_price->fields['attributes_qty_prices'], $this->contents[$products_id]['qty']);
                     $attributes_price += $added_charge;
                 }
                 //////////////////////////////////////////////////
             }
             // Validate Attributes
             if ($attribute_price->fields['attributes_display_only']) {
                 $_SESSION['valid_to_checkout'] = false;
                 $_SESSION['cart_errors'] .= zen_get_products_name($attribute_price->fields['products_id'], $_SESSION['languages_id']) . ERROR_PRODUCT_OPTION_SELECTION . '<br />';
             }
             /*
             //// extra testing not required on text attribute this is done in application_top before it gets to the cart
             if ($attribute_price->fields['attributes_required']) {
             $_SESSION['valid_to_checkout'] = false;
             $_SESSION['cart_errors'] .= zen_get_products_name($attribute_price->fields['products_id'], $_SESSION['languages_id'])  . ERROR_PRODUCT_OPTION_SELECTION . '<br />';
             }
             */
             $total_attributes_price += zen_round($attributes_price, $currencies->get_decimal_places($_SESSION['currency']));
         }
     }
     return $total_attributes_price;
 }
Example #10
0
 /**
  * Get quote from shipping provider's API:
  *
  * @param string $method
  * @return array of quotation results
  */
 function quote($method = '')
 {
     // BOF: UPS USPS
     global $order, $shipping_weight, $shipping_num_boxes, $transittime;
     if (zen_not_null($method) && (isset($this->types[$method]) || in_array($method, $this->intl_types))) {
         $this->_setService($method);
     }
     // usps doesnt accept zero weight send 1 ounce (0.0625) minimum
     $usps_shipping_weight = $shipping_weight <= 0.0 ? 0.0625 : $shipping_weight;
     $shipping_pounds = floor($usps_shipping_weight);
     $shipping_ounces = 16 * ($usps_shipping_weight - floor($usps_shipping_weight));
     // usps currently cannot handle more than 5 digits on international
     $shipping_ounces = zen_round($shipping_ounces, 3);
     // weight must be less than 35lbs and greater than 6 ounces or it is not machinable
     switch (true) {
         case $shipping_pounds == 0 and $shipping_ounces < 6:
             // override admin choice too light
             $is_machinable = 'False';
             break;
         case $usps_shipping_weight > 35:
             // override admin choice too heavy
             $is_machinable = 'False';
             break;
         default:
             // admin choice on what to use
             $is_machinable = MODULE_SHIPPING_USPS_MACHINABLE;
     }
     $this->_setMachinable($is_machinable);
     $this->_setContainer('None');
     $this->_setSize('REGULAR');
     $this->_setFirstClassType('FLAT');
     $this->_setWeight($shipping_pounds, $shipping_ounces);
     $uspsQuote = $this->_getQuote();
     if (is_array($uspsQuote)) {
         if (isset($uspsQuote['error'])) {
             $this->quotes = array('module' => $this->title, 'error' => $uspsQuote['error']);
         } else {
             // BOF: UPS USPS
             if (in_array('Display weight', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))) {
                 switch (SHIPPING_BOX_WEIGHT_DISPLAY) {
                     case 0:
                         $show_box_weight = '';
                         break;
                     case 1:
                         $show_box_weight = ' (' . $shipping_num_boxes . ' ' . TEXT_SHIPPING_BOXES . ')';
                         break;
                     case 2:
                         $show_box_weight = ' (' . number_format($usps_shipping_weight * $shipping_num_boxes, 2) . TEXT_SHIPPING_WEIGHT . ')';
                         break;
                     default:
                         $show_box_weight = ' (' . $shipping_num_boxes . ' x ' . number_format($usps_shipping_weight, 2) . TEXT_SHIPPING_WEIGHT . ')';
                         break;
                 }
             }
             // EOF: UPS USPS
             // BOF: UPS USPS
             $this->quotes = array('id' => $this->code, 'module' => $this->title . $show_box_weight);
             // EOF: UPS USPS
             $methods = array();
             $size = sizeof($uspsQuote);
             for ($i = 0; $i < $size; $i++) {
                 list($type, $cost) = each($uspsQuote[$i]);
                 // BOF: UPS USPS
                 $title = isset($this->types[$type]) ? $this->types[$type] : $type;
                 if (in_array('Display transit time', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))) {
                     $title .= $transittime[$type];
                 }
                 /*
                 $methods[] = array('id' => $type,
                 'title' => ((isset($this->types[$type])) ? $this->types[$type] : $type),
                 'cost' => ($cost + MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);
                 */
                 $cost = preg_replace('/[^0-9.]/', '', $cost);
                 $methods[] = array('id' => $type, 'title' => $title, 'cost' => $cost * $shipping_num_boxes + (MODULE_SHIPPING_USPS_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_USPS_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_USPS_HANDLING));
             }
             $this->quotes['methods'] = $methods;
             if ($this->tax_class > 0) {
                 $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             }
         }
     } elseif ($uspsQuote == -1) {
         $this->quotes = array('module' => $this->title, 'error' => MODULE_SHIPPING_USPS_TEXT_SERVER_ERROR . (MODULE_SHIPPING_USPS_SERVER == 'test' ? MODULE_SHIPPING_USPS_TEXT_TEST_MODE_NOTICE : ''));
     } else {
         $this->quotes = array('module' => $this->title, 'error' => MODULE_SHIPPING_USPS_TEXT_ERROR . (MODULE_SHIPPING_USPS_SERVER == 'test' ? MODULE_SHIPPING_USPS_TEXT_TEST_MODE_NOTICE : ''));
     }
     if (zen_not_null($this->icon)) {
         $this->quotes['icon'] = zen_image($this->icon, $this->title);
     }
     return $this->quotes;
 }
Example #11
0
 /**
  * Calculate GV claim amount (GV amounts are always based on the STORE's default currency value)
  */
 function calculate_credit($save_total_cost)
 {
     global $db, $order, $currencies;
     // calculate value based on default currency
     $gv_payment_amount = $currencies->value($_SESSION['cot_gv'], true, DEFAULT_CURRENCY);
     $full_cost = $save_total_cost - $gv_payment_amount;
     if ($full_cost < 0) {
         $full_cost = 0;
         $gv_payment_amount = $save_total_cost;
     }
     return zen_round($gv_payment_amount, 2);
 }
Example #12
0
 function cart()
 {
     global $db, $currencies;
     $this->content_type = $_SESSION['cart']->get_content_type();
     $customer_address_query = "select c.customers_firstname, c.customers_lastname, c.customers_telephone,\r\n                                        c.customers_email_address, ab.entry_company, ab.entry_street_address,\r\n                                        ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id,\r\n                                        z.zone_name, co.countries_id, co.countries_name,\r\n                                        co.countries_iso_code_2, co.countries_iso_code_3,\r\n                                        co.address_format_id, ab.entry_state\r\n                                 from " . TABLE_CUSTOMERS . " c, " . TABLE_ADDRESS_BOOK . " ab\r\n                                 left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\r\n                                 left join " . TABLE_COUNTRIES . " co on (ab.entry_country_id = co.countries_id)\r\n                                 where c.customers_id = '" . (int) $_SESSION['customer_id'] . "'\r\n                                 and ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\r\n                                 and c.customers_default_address_id = ab.address_book_id";
     $customer_address = $db->Execute($customer_address_query);
     $shipping_address_query = "select ab.entry_firstname, ab.entry_lastname, ab.entry_company,\r\n                                        ab.entry_street_address, ab.entry_suburb, ab.entry_postcode,\r\n                                        ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id,\r\n                                        c.countries_id, c.countries_name, c.countries_iso_code_2,\r\n                                        c.countries_iso_code_3, c.address_format_id, ab.entry_state\r\n                                 from " . TABLE_ADDRESS_BOOK . " ab\r\n                                 left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\r\n                                 left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id)\r\n                                 where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\r\n                                 and ab.address_book_id = '" . (int) $_SESSION['sendto'] . "'";
     $shipping_address = $db->Execute($shipping_address_query);
     $billing_address_query = "select ab.entry_firstname, ab.entry_lastname, ab.entry_company,\r\n                                       ab.entry_street_address, ab.entry_suburb, ab.entry_postcode,\r\n                                       ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id,\r\n                                       c.countries_id, c.countries_name, c.countries_iso_code_2,\r\n                                       c.countries_iso_code_3, c.address_format_id, ab.entry_state\r\n                                from " . TABLE_ADDRESS_BOOK . " ab\r\n                                left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\r\n                                left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id)\r\n                                where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\r\n                                and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'";
     $billing_address = $db->Execute($billing_address_query);
     //STORE_PRODUCT_TAX_BASIS
     switch (STORE_PRODUCT_TAX_BASIS) {
         case 'Shipping':
             $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\r\n                                from " . TABLE_ADDRESS_BOOK . " ab\r\n                                left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\r\n                                where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\r\n                                and ab.address_book_id = '" . (int) ($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto']) . "'";
             $tax_address = $db->Execute($tax_address_query);
             break;
         case 'Billing':
             $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\r\n                                from " . TABLE_ADDRESS_BOOK . " ab\r\n                                left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\r\n                                where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\r\n                                and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'";
             $tax_address = $db->Execute($tax_address_query);
             break;
         case 'Store':
             if ($billing_address->fields['entry_zone_id'] == STORE_ZONE) {
                 $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\r\n                                  from " . TABLE_ADDRESS_BOOK . " ab\r\n                                  left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\r\n                                  where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\r\n                                  and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'";
             } else {
                 $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\r\n                                  from " . TABLE_ADDRESS_BOOK . " ab\r\n                                  left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\r\n                                  where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\r\n                                  and ab.address_book_id = '" . (int) ($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto']) . "'";
             }
             $tax_address = $db->Execute($tax_address_query);
     }
     $class =& $_SESSION['payment'];
     if (isset($_SESSION['cc_id'])) {
         $coupon_code_query = "select coupon_code\r\n                              from " . TABLE_COUPONS . "\r\n                              where coupon_id = '" . (int) $_SESSION['cc_id'] . "'";
         $coupon_code = $db->Execute($coupon_code_query);
     }
     $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, 'currency' => $_SESSION['currency'], 'currency_value' => $currencies->currencies[$_SESSION['currency']]['value'], 'payment_method' => $GLOBALS[$class]->title, 'payment_module_code' => $GLOBALS[$class]->code, 'coupon_code' => $coupon_code->fields['coupon_code'], 'shipping_method' => $_SESSION['shipping']['title'], 'shipping_module_code' => $_SESSION['shipping']['id'], 'shipping_cost' => $_SESSION['shipping']['cost'], 'subtotal' => 0, 'tax' => 0, 'total' => 0, 'tax_groups' => array(), 'comments' => isset($_SESSION['comments']) ? $_SESSION['comments'] : '', 'ip_address' => $_SERVER['REMOTE_ADDR']);
     //print_r($GLOBALS[$class]);
     //echo $class;
     //print_r($GLOBALS);
     //echo $_SESSION['payment'];
     /*
     // this is set above to the module filename it should be set to the module title like Checks/Money Order rather than moneyorder
           if (isset($$_SESSION['payment']) && is_object($$_SESSION['payment'])) {
             $this->info['payment_method'] = $$_SESSION['payment']->title;
           }
     */
     if ($this->info['total'] == 0) {
         if (DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID == 0) {
             $this->info['order_status'] = DEFAULT_ORDERS_STATUS_ID;
         } else {
             $this->info['order_status'] = DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID;
         }
     }
     if (isset($GLOBALS[$class]) && is_object($GLOBALS[$class])) {
         if (isset($GLOBALS[$class]->order_status) && is_numeric($GLOBALS[$class]->order_status) && $GLOBALS[$class]->order_status > 0) {
             $this->info['order_status'] = $GLOBALS[$class]->order_status;
         }
     }
     $this->customer = array('firstname' => $customer_address->fields['customers_firstname'], 'lastname' => $customer_address->fields['customers_lastname'], 'company' => $customer_address->fields['entry_company'], 'street_address' => $customer_address->fields['entry_street_address'], 'suburb' => $customer_address->fields['entry_suburb'], 'city' => $customer_address->fields['entry_city'], 'postcode' => $customer_address->fields['entry_postcode'], 'state' => zen_not_null($customer_address->fields['entry_state']) ? $customer_address->fields['entry_state'] : $customer_address->fields['zone_name'], 'zone_id' => $customer_address->fields['entry_zone_id'], 'country' => array('id' => $customer_address->fields['countries_id'], 'title' => $customer_address->fields['countries_name'], 'iso_code_2' => $customer_address->fields['countries_iso_code_2'], 'iso_code_3' => $customer_address->fields['countries_iso_code_3']), 'format_id' => $customer_address->fields['address_format_id'], 'telephone' => $customer_address->fields['customers_telephone'], 'email_address' => $customer_address->fields['customers_email_address']);
     $this->delivery = array('firstname' => $shipping_address->fields['entry_firstname'], 'lastname' => $shipping_address->fields['entry_lastname'], 'company' => $shipping_address->fields['entry_company'], 'street_address' => $shipping_address->fields['entry_street_address'], 'suburb' => $shipping_address->fields['entry_suburb'], 'city' => $shipping_address->fields['entry_city'], 'postcode' => $shipping_address->fields['entry_postcode'], 'state' => zen_not_null($shipping_address->fields['entry_state']) ? $shipping_address->fields['entry_state'] : $shipping_address->fields['zone_name'], 'zone_id' => $shipping_address->fields['entry_zone_id'], 'country' => array('id' => $shipping_address->fields['countries_id'], 'title' => $shipping_address->fields['countries_name'], 'iso_code_2' => $shipping_address->fields['countries_iso_code_2'], 'iso_code_3' => $shipping_address->fields['countries_iso_code_3']), 'country_id' => $shipping_address->fields['entry_country_id'], 'format_id' => $shipping_address->fields['address_format_id']);
     $this->billing = array('firstname' => $billing_address->fields['entry_firstname'], 'lastname' => $billing_address->fields['entry_lastname'], 'company' => $billing_address->fields['entry_company'], 'street_address' => $billing_address->fields['entry_street_address'], 'suburb' => $billing_address->fields['entry_suburb'], 'city' => $billing_address->fields['entry_city'], 'postcode' => $billing_address->fields['entry_postcode'], 'state' => zen_not_null($billing_address->fields['entry_state']) ? $billing_address->fields['entry_state'] : $billing_address->fields['zone_name'], 'zone_id' => $billing_address->fields['entry_zone_id'], 'country' => array('id' => $billing_address->fields['countries_id'], 'title' => $billing_address->fields['countries_name'], 'iso_code_2' => $billing_address->fields['countries_iso_code_2'], 'iso_code_3' => $billing_address->fields['countries_iso_code_3']), 'country_id' => $billing_address->fields['entry_country_id'], 'format_id' => $billing_address->fields['address_format_id']);
     $index = 0;
     $products = $_SESSION['cart']->get_products();
     for ($i = 0, $n = sizeof($products); $i < $n; $i++) {
         $this->products[$index] = array('qty' => $products[$i]['quantity'], 'name' => $products[$i]['name'], 'model' => $products[$i]['model'], 'tax' => zen_get_tax_rate($products[$i]['tax_class_id'], $tax_address->fields['entry_country_id'], $tax_address->fields['entry_zone_id']), 'tax_description' => zen_get_tax_description($products[$i]['tax_class_id'], $tax_address->fields['entry_country_id'], $tax_address->fields['entry_zone_id']), 'price' => $products[$i]['price'], 'final_price' => $products[$i]['price'] + $_SESSION['cart']->attributes_price($products[$i]['id']), 'onetime_charges' => $_SESSION['cart']->attributes_price_onetime_charges($products[$i]['id'], $products[$i]['quantity']), 'weight' => $products[$i]['weight'], 'products_priced_by_attribute' => $products[$i]['products_priced_by_attribute'], 'product_is_free' => $products[$i]['product_is_free'], 'products_discount_type' => $products[$i]['products_discount_type'], 'products_discount_type_from' => $products[$i]['products_discount_type_from'], 'id' => $products[$i]['id']);
         if ($products[$i]['attributes']) {
             $subindex = 0;
             reset($products[$i]['attributes']);
             while (list($option, $value) = each($products[$i]['attributes'])) {
                 /*
                 	//clr 030714 Determine if attribute is a text attribute and change products array if it is.
                             if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID){
                               $attr_value = $products[$i]['attributes_values'][$option];
                             } else {
                               $attr_value = $attributes->fields['products_options_values_name'];
                             }
                 */
                 $attributes_query = "select popt.products_options_name, poval.products_options_values_name,\r\n                                        pa.options_values_price, pa.price_prefix\r\n                                 from " . TABLE_PRODUCTS_OPTIONS . " popt,\r\n                                      " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval,\r\n                                      " . TABLE_PRODUCTS_ATTRIBUTES . " pa\r\n                                 where pa.products_id = '" . (int) $products[$i]['id'] . "'\r\n                                 and pa.options_id = '" . (int) $option . "'\r\n                                 and pa.options_id = popt.products_options_id\r\n                                 and pa.options_values_id = '" . (int) $value . "'\r\n                                 and pa.options_values_id = poval.products_options_values_id\r\n                                 and popt.language_id = '" . (int) $_SESSION['languages_id'] . "'\r\n                                 and poval.language_id = '" . (int) $_SESSION['languages_id'] . "'";
                 $attributes = $db->Execute($attributes_query);
                 //clr 030714 Determine if attribute is a text attribute and change products array if it is.
                 if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID) {
                     $attr_value = $products[$i]['attributes_values'][$option];
                 } else {
                     $attr_value = $attributes->fields['products_options_values_name'];
                 }
                 $this->products[$index]['attributes'][$subindex] = array('option' => $attributes->fields['products_options_name'], 'value' => $attr_value, 'option_id' => $option, 'value_id' => $value, 'prefix' => $attributes->fields['price_prefix'], 'price' => $attributes->fields['options_values_price']);
                 $subindex++;
             }
         }
         // add onetime charges here
         //$_SESSION['cart']->attributes_price_onetime_charges($products[$i]['id'], $products[$i]['quantity'])
         $shown_price = zen_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty'] + zen_add_tax($this->products[$index]['onetime_charges'], $this->products[$index]['tax']);
         $this->info['subtotal'] += $shown_price;
         $products_tax = $this->products[$index]['tax'];
         $products_tax_description = $this->products[$index]['tax_description'];
         if (DISPLAY_PRICE_WITH_TAX == 'true') {
             $this->info['tax'] += $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
             if (isset($this->info['tax_groups']["{$products_tax_description}"])) {
                 $this->info['tax_groups']["{$products_tax_description}"] += $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
             } else {
                 $this->info['tax_groups']["{$products_tax_description}"] = $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
             }
         } else {
             $this->info['tax'] += $products_tax / 100 * $shown_price;
             if (isset($this->info['tax_groups']["{$products_tax_description}"])) {
                 $this->info['tax_groups']["{$products_tax_description}"] += $products_tax / 100 * $shown_price;
             } else {
                 $this->info['tax_groups']["{$products_tax_description}"] = $products_tax / 100 * $shown_price;
             }
         }
         $this->info['tax'] = zen_round($this->info['tax'], 2);
         $index++;
     }
     if (DISPLAY_PRICE_WITH_TAX == 'true') {
         $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'];
     } else {
         $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost'];
     }
 }
Example #13
0
 function cart()
 {
     global $db, $currencies;
     $this->content_type = $_SESSION['cart']->get_content_type();
     $customer_address_query = "select c.customers_firstname, c.customers_lastname, c.customers_telephone,\n\n                                    c.customers_email_address, ab.entry_company, ab.entry_street_address,\n\n                                    ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id,\n\n                                    z.zone_name, co.countries_id, co.countries_name,\n\n                                    co.countries_iso_code_2, co.countries_iso_code_3,\n\n                                    co.address_format_id, ab.entry_state\n\n                                   from (" . TABLE_CUSTOMERS . " c, " . TABLE_ADDRESS_BOOK . " ab )\n\n                                   left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n\n                                   left join " . TABLE_COUNTRIES . " co on (ab.entry_country_id = co.countries_id)\n\n                                   where c.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n\n                                   and ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n\n                                   and c.customers_default_address_id = ab.address_book_id";
     $customer_address = $db->Execute($customer_address_query);
     $shipping_address_query = "select ab.entry_firstname, ab.entry_lastname, ab.entry_company,\n\n                                    ab.entry_street_address, ab.entry_suburb, ab.entry_postcode,\n\n                                    ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id,\n\n                                    c.countries_id, c.countries_name, c.countries_iso_code_2,\n\n                                    c.countries_iso_code_3, c.address_format_id, ab.entry_state\n\n                                   from " . TABLE_ADDRESS_BOOK . " ab\n\n                                   left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n\n                                   left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id)\n\n                                   where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n\n                                   and ab.address_book_id = '" . (int) $_SESSION['sendto'] . "'";
     $shipping_address = $db->Execute($shipping_address_query);
     $billing_address_query = "select ab.entry_firstname, ab.entry_lastname, ab.entry_company,\n\n                                   ab.entry_street_address, ab.entry_suburb, ab.entry_postcode,\n\n                                   ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id,\n\n                                   c.countries_id, c.countries_name, c.countries_iso_code_2,\n\n                                   c.countries_iso_code_3, c.address_format_id, ab.entry_state\n\n                                  from " . TABLE_ADDRESS_BOOK . " ab\n\n                                  left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n\n                                  left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id)\n\n                                  where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n\n                                  and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'";
     $billing_address = $db->Execute($billing_address_query);
     //STORE_PRODUCT_TAX_BASIS
     switch (STORE_PRODUCT_TAX_BASIS) {
         case 'Shipping':
             $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\n\n                              from " . TABLE_ADDRESS_BOOK . " ab\n\n                              left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n\n                              where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n\n                              and ab.address_book_id = '" . (int) ($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto']) . "'";
             $tax_address = $db->Execute($tax_address_query);
             break;
         case 'Billing':
             $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\n\n                              from " . TABLE_ADDRESS_BOOK . " ab\n\n                              left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n\n                              where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n\n                              and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'";
             $tax_address = $db->Execute($tax_address_query);
             break;
         case 'Store':
             if ($billing_address->fields['entry_zone_id'] == STORE_ZONE) {
                 $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\n\n                                from " . TABLE_ADDRESS_BOOK . " ab\n\n                                left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n\n                                where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n\n                                and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'";
             } else {
                 $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\n\n                                from " . TABLE_ADDRESS_BOOK . " ab\n\n                                left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n\n                                where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n\n                                and ab.address_book_id = '" . (int) ($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto']) . "'";
             }
             $tax_address = $db->Execute($tax_address_query);
     }
     $class =& $_SESSION['payment'];
     if (isset($_SESSION['cc_id'])) {
         $coupon_code_query = "select coupon_code\n\n                              from " . TABLE_COUPONS . "\n\n                              where coupon_id = '" . (int) $_SESSION['cc_id'] . "'";
         $coupon_code = $db->Execute($coupon_code_query);
     }
     $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, 'currency' => $_SESSION['currency'], 'currency_value' => $currencies->currencies[$_SESSION['currency']]['value'], 'payment_method' => $GLOBALS[$class]->title, 'payment_module_code' => $GLOBALS[$class]->code, 'coupon_code' => $coupon_code->fields['coupon_code'], 'shipping_method' => $_SESSION['shipping']['title'], 'shipping_module_code' => $_SESSION['shipping']['id'], 'shipping_cost' => $_SESSION['shipping']['cost'], 'subtotal' => 0, 'tax' => 0, 'total' => 0, 'tax_groups' => array(), 'comments' => isset($_SESSION['comments']) ? $_SESSION['comments'] : '', 'ip_address' => $_SESSION['customers_ip_address'] . ' - ' . $_SERVER['REMOTE_ADDR']);
     //echo  "<br>".__FILE__.' line:'.__LINE__.'============'."<pre>";print_r($_SESSION['shipping']);echo '--';print_r($_SESSION['shipping']['cost']);exit;
     //print_r($GLOBALS[$class]);
     //echo $class;
     //print_r($GLOBALS);
     //echo $_SESSION['payment'];
     /*
     // this is set above to the module filename it should be set to the module title like Checks/Money Order rather than moneyorder
     if (isset($$_SESSION['payment']) && is_object($$_SESSION['payment'])) {
     $this->info['payment_method'] = $$_SESSION['payment']->title;
     }
     */
     /*
     // bof: move below calculations
         if ($this->info['total'] == 0) {
           if (DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID == 0) {
             $this->info['order_status'] = DEFAULT_ORDERS_STATUS_ID;
           } else {
             $this->info['order_status'] = DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID;
           }
         }
         if (isset($GLOBALS[$class]) && is_object($GLOBALS[$class])) {
           if ( isset($GLOBALS[$class]->order_status) && is_numeric($GLOBALS[$class]->order_status) && ($GLOBALS[$class]->order_status > 0) ) {
             $this->info['order_status'] = $GLOBALS[$class]->order_status;
           }
         }
     // eof: move below calculations
     */
     $this->customer = array('firstname' => $customer_address->fields['customers_firstname'], 'lastname' => $customer_address->fields['customers_lastname'], 'company' => $customer_address->fields['entry_company'], 'street_address' => $customer_address->fields['entry_street_address'], 'suburb' => $customer_address->fields['entry_suburb'], 'city' => $customer_address->fields['entry_city'], 'postcode' => $customer_address->fields['entry_postcode'], 'state' => zen_not_null($customer_address->fields['entry_state']) ? $customer_address->fields['entry_state'] : $customer_address->fields['zone_name'], 'zone_id' => $customer_address->fields['entry_zone_id'], 'country' => array('id' => $customer_address->fields['countries_id'], 'title' => $customer_address->fields['countries_name'], 'iso_code_2' => $customer_address->fields['countries_iso_code_2'], 'iso_code_3' => $customer_address->fields['countries_iso_code_3']), 'format_id' => (int) $customer_address->fields['address_format_id'], 'telephone' => $customer_address->fields['customers_telephone'], 'email_address' => $customer_address->fields['customers_email_address']);
     $this->delivery = array('firstname' => $shipping_address->fields['entry_firstname'], 'lastname' => $shipping_address->fields['entry_lastname'], 'company' => $shipping_address->fields['entry_company'], 'street_address' => $shipping_address->fields['entry_street_address'], 'suburb' => $shipping_address->fields['entry_suburb'], 'city' => $shipping_address->fields['entry_city'], 'postcode' => $shipping_address->fields['entry_postcode'], 'state' => zen_not_null($shipping_address->fields['entry_state']) ? $shipping_address->fields['entry_state'] : $shipping_address->fields['zone_name'], 'zone_id' => $shipping_address->fields['entry_zone_id'], 'country' => array('id' => $shipping_address->fields['countries_id'], 'title' => $shipping_address->fields['countries_name'], 'iso_code_2' => $shipping_address->fields['countries_iso_code_2'], 'iso_code_3' => $shipping_address->fields['countries_iso_code_3']), 'country_id' => $shipping_address->fields['entry_country_id'], 'format_id' => (int) $shipping_address->fields['address_format_id']);
     $this->billing = array('firstname' => $billing_address->fields['entry_firstname'], 'lastname' => $billing_address->fields['entry_lastname'], 'company' => $billing_address->fields['entry_company'], 'street_address' => $billing_address->fields['entry_street_address'], 'suburb' => $billing_address->fields['entry_suburb'], 'city' => $billing_address->fields['entry_city'], 'postcode' => $billing_address->fields['entry_postcode'], 'state' => zen_not_null($billing_address->fields['entry_state']) ? $billing_address->fields['entry_state'] : $billing_address->fields['zone_name'], 'zone_id' => $billing_address->fields['entry_zone_id'], 'country' => array('id' => $billing_address->fields['countries_id'], 'title' => $billing_address->fields['countries_name'], 'iso_code_2' => $billing_address->fields['countries_iso_code_2'], 'iso_code_3' => $billing_address->fields['countries_iso_code_3']), 'country_id' => $billing_address->fields['entry_country_id'], 'format_id' => (int) $billing_address->fields['address_format_id']);
     $index = 0;
     $products = $_SESSION['cart']->get_products(true);
     for ($i = 0, $n = sizeof($products); $i < $n; $i++) {
         if ($i / 2 == floor($i / 2)) {
             $rowClass = "rowEven";
         } else {
             $rowClass = "rowOdd";
         }
         $this->products[$index] = array('qty' => $products[$i]['quantity'], 'name' => $products[$i]['name'], 'model' => $products[$i]['model'], 'tax' => zen_get_tax_rate($products[$i]['tax_class_id'], $tax_address->fields['entry_country_id'], $tax_address->fields['entry_zone_id']), 'tax_description' => zen_get_tax_description($products[$i]['tax_class_id'], $tax_address->fields['entry_country_id'], $tax_address->fields['entry_zone_id']), 'price' => $products[$i]['price'], 'final_price' => $products[$i]['price'] + $_SESSION['cart']->attributes_price(zen_get_uprid($products[$i]['id'], $products[$i]['attributes'])), 'onetime_charges' => $_SESSION['cart']->attributes_price_onetime_charges($products[$i]['id'], $products[$i]['quantity']), 'weight' => $products[$i]['weight'], 'products_priced_by_attribute' => $products[$i]['products_priced_by_attribute'], 'product_is_free' => $products[$i]['product_is_free'], 'products_discount_type' => $products[$i]['products_discount_type'], 'products_discount_type_from' => $products[$i]['products_discount_type_from'], 'id' => $products[$i]['id'], 'rowClass' => $rowClass);
         if ($products[$i]['attributes']) {
             $subindex = 0;
             reset($products[$i]['attributes']);
             while (list($option, $value) = each($products[$i]['attributes'])) {
                 /*
                 //clr 030714 Determine if attribute is a text attribute and change products array if it is.
                 if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID){
                 $attr_value = $products[$i]['attributes_values'][$option];
                 } else {
                 $attr_value = $attributes->fields['products_options_values_name'];
                 }
                 */
                 $attributes_query = "select popt.products_options_name, poval.products_options_values_name,\n\n                                          pa.options_values_price, pa.price_prefix\n\n                                   from " . TABLE_PRODUCTS_OPTIONS . " popt,\n\n                                        " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval,\n\n                                        " . TABLE_PRODUCTS_ATTRIBUTES . " pa\n\n                                   where pa.products_id = '" . (int) $products[$i]['id'] . "'\n\n                                   and pa.options_id = '" . (int) $option . "'\n\n                                   and pa.options_id = popt.products_options_id\n\n                                   and pa.options_values_id = '" . (int) $value . "'\n\n                                   and pa.options_values_id = poval.products_options_values_id\n\n                                   and popt.language_id = '" . (int) $_SESSION['languages_id'] . "'\n\n                                   and poval.language_id = '" . (int) $_SESSION['languages_id'] . "'";
                 $attributes = $db->Execute($attributes_query);
                 //clr 030714 Determine if attribute is a text attribute and change products array if it is.
                 if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID) {
                     $attr_value = $products[$i]['attributes_values'][$option];
                 } else {
                     $attr_value = $attributes->fields['products_options_values_name'];
                 }
                 $this->products[$index]['attributes'][$subindex] = array('option' => $attributes->fields['products_options_name'], 'value' => $attr_value, 'option_id' => $option, 'value_id' => $value, 'prefix' => $attributes->fields['price_prefix'], 'price' => $attributes->fields['options_values_price']);
                 $subindex++;
             }
         }
         // add onetime charges here
         //$_SESSION['cart']->attributes_price_onetime_charges($products[$i]['id'], $products[$i]['quantity'])
         /*********************************************
          * Calculate taxes for this product
          *********************************************/
         $shown_price = zen_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty'] + zen_add_tax($this->products[$index]['onetime_charges'], $this->products[$index]['tax']);
         $this->info['subtotal'] += $shown_price;
         // find product's tax rate and description
         $products_tax = $this->products[$index]['tax'];
         $products_tax_description = $this->products[$index]['tax_description'];
         if (DISPLAY_PRICE_WITH_TAX == 'true') {
             // calculate the amount of tax "inc"luded in price (used if tax-in pricing is enabled)
             $tax_add = $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
         } else {
             // calculate the amount of tax for this product (assuming tax is NOT included in the price)
             $tax_add = zen_round($products_tax / 100 * $shown_price, $currencies->currencies[$this->info['currency']]['decimal_places']);
         }
         $this->info['tax'] += $tax_add;
         if (isset($this->info['tax_groups'][$products_tax_description])) {
             $this->info['tax_groups'][$products_tax_description] += $tax_add;
         } else {
             $this->info['tax_groups'][$products_tax_description] = $tax_add;
         }
         /*********************************************
          * END: Calculate taxes for this product
          *********************************************/
         $index++;
     }
     // Update the final total to include tax if not already tax-inc
     if (DISPLAY_PRICE_WITH_TAX == 'true') {
         if ($_SESSION['insurance'] != "") {
             //判断保险是否选中 2011-3-29 du
             if ($_SESSION['insurance'] == 1) {
                 $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'] + $this->info['subtotal'] * 0.031;
             } else {
                 $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'];
             }
         } else {
             $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'];
         }
     } else {
         if ($_SESSION['insurance'] != "") {
             //判断保险是否选中 2011-3-29 du
             if ($_SESSION['insurance'] == 1) {
                 $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost'] + $this->info['subtotal'] * 0.031;
             } else {
                 $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost'];
             }
         } else {
             $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost'];
         }
     }
     /*
     // moved to function create
         if ($this->info['total'] == 0) {
           if (DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID == 0) {
             $this->info['order_status'] = DEFAULT_ORDERS_STATUS_ID;
           } else {
             $this->info['order_status'] = DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID;
           }
         }
     */
     if (isset($GLOBALS[$class]) && is_object($GLOBALS[$class])) {
         if (isset($GLOBALS[$class]->order_status) && is_numeric($GLOBALS[$class]->order_status) && $GLOBALS[$class]->order_status > 0) {
             $this->info['order_status'] = $GLOBALS[$class]->order_status;
         }
     }
 }
Example #14
0
 function calculate_boxes_weight_and_tare()
 {
     global $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes;
     $this->abort_legacy_calculations = FALSE;
     $this->notify('NOTIFY_SHIPPING_MODULE_PRE_CALCULATE_BOXES_AND_TARE');
     if ($this->abort_legacy_calculations) {
         return;
     }
     if (is_array($this->modules)) {
         $shipping_quoted = '';
         $shipping_num_boxes = 1;
         $shipping_weight = $total_weight;
         $za_tare_array = preg_split("/[:,]/", SHIPPING_BOX_WEIGHT);
         $zc_tare_percent = $za_tare_array[0];
         $zc_tare_weight = $za_tare_array[1];
         $za_large_array = preg_split("/[:,]/", SHIPPING_BOX_PADDING);
         $zc_large_percent = $za_large_array[0];
         $zc_large_weight = $za_large_array[1];
         // SHIPPING_BOX_WEIGHT = tare
         // SHIPPING_BOX_PADDING = Large Box % increase
         // SHIPPING_MAX_WEIGHT = Largest package
         /*
         if (SHIPPING_BOX_WEIGHT >= $shipping_weight*SHIPPING_BOX_PADDING/100) {
           $shipping_weight = $shipping_weight+SHIPPING_BOX_WEIGHT;
         } else {
           $shipping_weight = $shipping_weight + ($shipping_weight*SHIPPING_BOX_PADDING/100);
         }
         */
         switch (true) {
             // large box add padding
             case SHIPPING_MAX_WEIGHT <= $shipping_weight:
                 $shipping_weight = $shipping_weight + $shipping_weight * ($zc_large_percent / 100) + $zc_large_weight;
                 break;
             default:
                 // add tare weight < large
                 $shipping_weight = $shipping_weight + $shipping_weight * ($zc_tare_percent / 100) + $zc_tare_weight;
                 break;
         }
         if ($shipping_weight > SHIPPING_MAX_WEIGHT) {
             // Split into many boxes
             //        $shipping_num_boxes = ceil($shipping_weight/SHIPPING_MAX_WEIGHT);
             $zc_boxes = zen_round($shipping_weight / SHIPPING_MAX_WEIGHT, 2);
             $shipping_num_boxes = ceil($zc_boxes);
             $shipping_weight = $shipping_weight / $shipping_num_boxes;
         }
     }
     $this->notify('NOTIFY_SHIPPING_MODULE_CALCULATE_BOXES_AND_TARE');
 }
function zen_add_tax_invoice($price, $tax)
{
    global $currencies;
    return zen_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']) + zen_calculate_tax($price, $tax);
}
Example #16
0
        }
      }
      echo '            </td>' . "\n" .
           '            <td class="dataTableContent" valign="middle">' . $order->products[$i]['model'] . '</td>' . "\n" .
           '            <td class="dataTableContent" align="right" valign="middle">' . zen_display_tax_value($order->products[$i]['tax']) . '%</td>' . "\n" .
           '            <td class="dataTableContent" align="right" valign="middle"><strong>' .
                          $currencies->format($order->products[$i]['final_price'], true, $order->info['currency'], $order->info['currency_value']) .
// (Formating modified for Super Orders)
                          ($order->products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->format($order->products[$i]['onetime_charges'], true, $order->info['currency'], $order->info['currency_value']) : '') .
                        '</strong></td>' . "\n" .
           '            <td class="dataTableContent" align="right" valign="middle"><strong>' .
                          $currencies->format(zen_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']) .
                          ($order->products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->format(zen_add_tax($order->products[$i]['onetime_charges'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']) : '') .
                        '</strong></td>' . "\n" .
           '            <td class="dataTableContent" align="right" valign="middle"><strong>' .
                          $currencies->format(zen_round($order->products[$i]['final_price'], $currencies->get_decimal_places($order->info['currency']))  * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) .
                          ($order->products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->format($order->products[$i]['onetime_charges'], true, $order->info['currency'], $order->info['currency_value']) : '') .
                        '</strong></td>' . "\n" .
           '            <td class="dataTableContent" align="right" valign="middle"><strong>' .
                          $priceIncTax .
                          ($order->products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->format(zen_add_tax($order->products[$i]['onetime_charges'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']) : '') .
// (Formating modified for Super Orders)
                        '</strong></td>' . "\n";
      echo '          </tr>' . "\n";
    }
?>
<!-- End Products Detail //-->
          <tr>
            <?php 
	    		if ($parent_child->fields['split_from_order']) {
			 ?>
Example #17
0
/**
 * Add tax to a products price
 */
function zen_add_tax($price, $tax)
{
    global $currencies;
    if (DISPLAY_PRICE_WITH_TAX_ADMIN == 'true') {
        return zen_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']) + zen_calculate_tax($price, $tax);
    } else {
        return zen_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
    }
}
Example #18
0
 function calculate_deductions()
 {
     global $db, $order, $messageStack, $currencies;
     $currencyDecimalPlaces = $currencies->get_decimal_places($_SESSION['currency']);
     $od_amount = array('tax' => 0, 'total' => 0);
     if ($_SESSION['cc_id']) {
         $coupon = $db->Execute("select * from " . TABLE_COUPONS . " where coupon_id = '" . (int) $_SESSION['cc_id'] . "'");
         $this->coupon_code = $coupon->fields['coupon_code'];
         $orderTotalDetails = $this->get_order_total($_SESSION['cc_id']);
         if ($coupon->RecordCount() > 0 && $orderTotalDetails['orderTotal'] != 0) {
             // left for total order amount vs qualified order amount just switch the commented lines
             //        if (strval($orderTotalDetails['totalFull']) >= $coupon->fields['coupon_minimum_order'])
             if (strval($orderTotalDetails['orderTotal']) >= $coupon->fields['coupon_minimum_order']) {
                 switch ($coupon->fields['coupon_type']) {
                     case 'S':
                         // Free Shipping
                         $od_amount['total'] = $orderTotalDetails['shipping'];
                         $od_amount['type'] = 'S';
                         $od_amount['tax'] = $this->calculate_tax == 'Standard' ? $orderTotalDetails['shippingTax'] : 0;
                         if (isset($_SESSION['shipping_tax_description']) && $_SESSION['shipping_tax_description'] != '') {
                             $od_amount['tax_groups'][$_SESSION['shipping_tax_description']] = $od_amount['tax'];
                         }
                         return $od_amount;
                         break;
                     case 'P':
                         // percentage
                         $od_amount['total'] = zen_round($orderTotalDetails['orderTotal'] * ($coupon->fields['coupon_amount'] / 100), $currencyDecimalPlaces);
                         $od_amount['type'] = $coupon->fields['coupon_type'];
                         $ratio = $od_amount['total'] / $orderTotalDetails['orderTotal'];
                         break;
                     case 'E':
                         // percentage & Free Shipping
                         $od_amount['total'] = zen_round($orderTotalDetails['orderTotal'] * ($coupon->fields['coupon_amount'] / 100), $currencyDecimalPlaces);
                         $od_amount['type'] = $coupon->fields['coupon_type'];
                         $ratio = $od_amount['total'] / $orderTotalDetails['orderTotal'];
                         // add in Free Shipping
                         $od_amount['total'] = $od_amount['total'] + $orderTotalDetails['shipping'];
                         $od_amount['tax'] = $this->calculate_tax == 'Standard' ? $orderTotalDetails['shippingTax'] : 0;
                         if (isset($_SESSION['shipping_tax_description']) && $_SESSION['shipping_tax_description'] != '') {
                             $od_amount['tax_groups'][$_SESSION['shipping_tax_description']] = $od_amount['tax'];
                         }
                         break;
                     case 'F':
                         // amount Off
                         $od_amount['total'] = zen_round(($coupon->fields['coupon_amount'] > $orderTotalDetails['orderTotal'] ? $orderTotalDetails['orderTotal'] : $coupon->fields['coupon_amount']) * ($orderTotalDetails['orderTotal'] > 0), $currencyDecimalPlaces);
                         $od_amount['type'] = $coupon->fields['coupon_type'];
                         // amount off 'F' or amount off and free shipping 'O'
                         $ratio = $od_amount['total'] / $orderTotalDetails['orderTotal'];
                         break;
                     case 'O':
                         // amount off & Free Shipping
                         $od_amount['total'] = zen_round(($coupon->fields['coupon_amount'] > $orderTotalDetails['orderTotal'] ? $orderTotalDetails['orderTotal'] : $coupon->fields['coupon_amount']) * ($orderTotalDetails['orderTotal'] > 0), $currencyDecimalPlaces);
                         $od_amount['type'] = $coupon->fields['coupon_type'];
                         // amount off 'F' or amount off and free shipping 'O'
                         $ratio = $od_amount['total'] / $orderTotalDetails['orderTotal'];
                         // add in Free Shipping
                         if ($this->include_shipping == 'false') {
                             $od_amount['total'] = $od_amount['total'] + $orderTotalDetails['shipping'];
                         }
                         $od_amount['tax'] = $this->calculate_tax == 'Standard' ? $orderTotalDetails['shippingTax'] : 0;
                         if (isset($_SESSION['shipping_tax_description']) && $_SESSION['shipping_tax_description'] != '') {
                             $od_amount['tax_groups'][$_SESSION['shipping_tax_description']] = $od_amount['tax'];
                         }
                         break;
                 }
                 switch ($this->calculate_tax) {
                     case 'None':
                         break;
                     case 'Standard':
                         if ($od_amount['total'] >= $orderTotalDetails['orderTotal']) {
                             $ratio = 1;
                         }
                         foreach ($orderTotalDetails['orderTaxGroups'] as $key => $value) {
                             $od_amount['tax_groups'][$key] = zen_round($orderTotalDetails['orderTaxGroups'][$key] * $ratio, $currencyDecimalPlaces);
                             $od_amount['tax'] += $od_amount['tax_groups'][$key];
                             if ($od_amount['tax_groups'][$key] == 0) {
                                 unset($od_amount['tax_groups'][$key]);
                             }
                         }
                         if (DISPLAY_PRICE_WITH_TAX == 'true' && $coupon->fields['coupon_type'] == 'F') {
                             $od_amount['total'] = $od_amount['total'] + $od_amount['tax'];
                         }
                         break;
                     case 'Credit Note':
                         $tax_rate = zen_get_tax_rate($this->tax_class);
                         $od_amount['tax'] = zen_calculate_tax($od_amount['total'], $tax_rate);
                         $tax_description = zen_get_tax_description($this->tax_class);
                         $od_amount['tax_groups'][$tax_description] = $od_amount['tax'];
                 }
             }
         }
     }
     //    print_r($order->info);
     //    print_r($orderTotalDetails);echo "<br><br>";
     //    echo 'RATIo = '. $ratio;
     //    print_r($od_amount);
     return $od_amount;
 }
 /**
  * Build the data and actions to process when the "Submit" button is pressed on the order-confirmation screen.
  * This sends the data to the payment gateway for processing.
  * (These are hidden fields on the checkout confirmation page)
  *
  * @return string
  */
 function process_button()
 {
     global $db, $order, $currencies, $currency;
     $options = array();
     $_SESSION['cn_key_to_remove'] = session_id();
     $db->Execute("delete from " . TABLE_CASHNET_SESSION . " where session_id = '" . zen_db_input($_SESSION['cn_key_to_remove']) . "'");
     $sql = "insert into " . TABLE_CASHNET_SESSION . " (session_id, saved_session, expiry) values (\n          '" . zen_db_input($_SESSION['cn_key_to_remove']) . "',\n          '" . base64_encode(serialize($_SESSION)) . "',\n          '" . (time() + 1 * 60 * 60 * 24 * 2) . "')";
     $db->Execute($sql);
     $key = $this->getCashNetKey();
     $itemcode = $this->getCashNetItemCode();
     $this->transaction_currency = $_SESSION['currency'];
     $this->totalsum = $order->info['total'] = number_format($order->info['total'], 2);
     $this->transaction_amount = zen_round($this->totalsum * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));
     $options = array('itemcode' => $itemcode, 'amount' => $this->totalsum, 'digest' => md5(trim($key) . $this->totalsum), 'custcode' => $order->customer['id'], 'email' => trim($order->customer['email_address']), 'acctname' => trim($order->customer['firstname'] . ' ' . $order->customer['lastname']), 'addr' => trim($order->customer['street_address']), 'city' => trim($order->customer['city']), 'state' => trim($order->customer['state']), 'zip' => trim($order->customer['postcode']), 'signouturl' => zen_href_link(FILENAME_CHECKOUT_PROCESS, 'referer=cashnet', 'SSL'));
     // build the button fields
     foreach ($options as $name => $value) {
         // remove quotation marks
         $value = str_replace('"', '', $value);
         // check for invalid chars
         if (preg_match('/[^a-zA-Z_0-9]/', $name)) {
             ipn_debug_email('datacheck - ABORTING - preg_match found invalid submission key: ' . $name . ' (' . $value . ')');
             break;
         }
         $buttonArray[] = zen_draw_hidden_field($name, $value);
     }
     $process_button_string = "\n" . implode("\n", $buttonArray) . "\n";
     $_SESSION['cashnet_transaction_info'] = array($this->transaction_amount, $this->transaction_currency);
     return $process_button_string;
 }
Example #20
0
    if (STOCK_CHECK == 'true') {
        $flagStockCheck = zen_check_stock($products[$i]['id'], $products[$i]['quantity']);
        if ($flagStockCheck == true) {
            $flagAnyOutOfStock = true;
        }
    }
    $linkProductsImage = zen_href_link(zen_get_info_page($products[$i]['id']), 'products_id=' . $products[$i]['id']);
    $linkProductsName = zen_href_link(zen_get_info_page($products[$i]['id']), 'products_id=' . $products[$i]['id']);
    $productsImage = IMAGE_SHOPPING_CART_STATUS == 1 ? zen_image(DIR_WS_IMAGES . $products[$i]['image'], $products[$i]['name'], IMAGE_SHOPPING_CART_WIDTH, IMAGE_SHOPPING_CART_HEIGHT) : '';
    $show_products_quantity_max = zen_get_products_quantity_order_max($products[$i]['id']);
    $showFixedQuantity = ($show_products_quantity_max == 1 or zen_get_products_qty_box_status($products[$i]['id']) == 0) ? true : false;
    //  $showFixedQuantityAmount = $products[$i]['quantity'] . zen_draw_hidden_field('products_id[]', $products[$i]['id']) . zen_draw_hidden_field('cart_quantity[]', 1);
    //  $showFixedQuantityAmount = $products[$i]['quantity'] . zen_draw_hidden_field('cart_quantity[]', 1);
    $showFixedQuantityAmount = $products[$i]['quantity'] . zen_draw_hidden_field('cart_quantity[]', $products[$i]['quantity']);
    $showMinUnits = zen_get_products_quantity_min_units_display($products[$i]['id']);
    $quantityField = zen_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4"');
    $ppe = $products[$i]['final_price'];
    $ppe = zen_round(zen_add_tax($ppe, zen_get_tax_rate($products[$i]['tax_class_id'])), $currencies->get_decimal_places($_SESSION['currency']));
    $ppt = $ppe * $products[$i]['quantity'];
    $productsPriceEach = $currencies->format($ppe) . ($products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->display_price($products[$i]['onetime_charges'], zen_get_tax_rate($products[$i]['tax_class_id']), 1) : '');
    $productsPriceTotal = $currencies->format($ppt) . ($products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->display_price($products[$i]['onetime_charges'], zen_get_tax_rate($products[$i]['tax_class_id']), 1) : '');
    $buttonUpdate = ((SHOW_SHOPPING_CART_UPDATE == 1 or SHOW_SHOPPING_CART_UPDATE == 3) ? zen_image_submit(ICON_IMAGE_UPDATE, ICON_UPDATE_ALT) : '') . zen_draw_hidden_field('products_id[]', $products[$i]['id']);
    //  $productsPriceEach = $currencies->display_price($products[$i]['final_price'], zen_get_tax_rate($products[$i]['tax_class_id']), 1) . ($products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->display_price($products[$i]['onetime_charges'], zen_get_tax_rate($products[$i]['tax_class_id']), 1) : '');
    //  $productsPriceTotal = $currencies->display_price($products[$i]['final_price'], zen_get_tax_rate($products[$i]['tax_class_id']), $products[$i]['quantity']) . ($products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->display_price($products[$i]['onetime_charges'], zen_get_tax_rate($products[$i]['tax_class_id']), 1) : '');
    //  $productsPriceTotal = $currencies->display_price($products[$i]['final_price'], zen_get_tax_rate($products[$i]['tax_class_id']), $products[$i]['quantity']) . ($products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->display_price($products[$i]['onetime_charges'], zen_get_tax_rate($products[$i]['tax_class_id']), 1) : '');
    //  echo  $currencies->rateAdjusted($tmp);
    $productArray[$i] = array('attributeHiddenField' => $attributeHiddenField, 'flagStockCheck' => $flagStockCheck, 'flagShowFixedQuantity' => $showFixedQuantity, 'linkProductsImage' => $linkProductsImage, 'linkProductsName' => $linkProductsName, 'productsImage' => $productsImage, 'productsName' => $productsName, 'showFixedQuantity' => $showFixedQuantity, 'showFixedQuantityAmount' => $showFixedQuantityAmount, 'showMinUnits' => $showMinUnits, 'quantityField' => $quantityField, 'buttonUpdate' => $buttonUpdate, 'productsPrice' => $productsPriceTotal, 'productsPriceEach' => $productsPriceEach, 'rowClass' => $rowClass, 'buttonDelete' => $buttonDelete, 'checkBoxDelete' => $checkBoxDelete, 'id' => $products[$i]['id'], 'attributes' => $attrArray);
}
// end FOR loop
// This should be last line of the script:
$zco_notifier->notify('NOTIFY_HEADER_END_SHOPPING_CART');
    }
    ?>
        </td>
<?php 
    if (sizeof($order->info['tax_groups']) > 1) {
        ?>
        <td class="accountTaxDisplay"><?php 
        echo zen_display_tax_value($order->products[$i]['tax']) . '%';
        ?>
</td>
<?php 
    }
    ?>
        <td class="accountTotalDisplay">
        <?php 
    $ppe = zen_round(zen_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), $currencies->get_decimal_places($order->info['currency']));
    $ppt = $ppe * $order->products[$i]['qty'];
    //        echo $currencies->format(zen_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']) * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . ($order->products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->format(zen_add_tax($order->products[$i]['onetime_charges'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']) : '')
    echo $currencies->format($ppt, true, $order->info['currency'], $order->info['currency_value']) . ($order->products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->format(zen_add_tax($order->products[$i]['onetime_charges'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']) : '');
    ?>
</td>
    </tr>
<?php 
}
?>
</table>
<hr />
<div id="orderTotals">
<?php 
for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
    ?>
Example #22
0
 function format_raw($number, $currency_code = '', $currency_value = '')
 {
     global $currencies;
     if (!isset($currency_code) || empty($currency_code)) {
         $currency_code = DEFAULT_CURRENCY;
     }
     if (empty($currency_value) || !is_numeric($currency_value)) {
         $currency_value = $currencies->currencies[$currency_code]['value'];
     }
     $decimal_places = $currencies->currencies[$currency_code]['decimal_places'];
     return number_format(zen_round($number * $currency_value, $decimal_places), $decimal_places, '.', '');
 }
    echo TABLE_HEADING_PRICE_NO_TAX;
    ?>
</td>
        <td class="dataTableHeadingContent" align="right" width="20%"><?php 
    echo TABLE_HEADING_TOTAL_NO_TAX;
    ?>
</td>
        <?php 
}
?>
      </tr>
<?php 
$decimals = $currencies->get_decimal_places($order->info['currency']);
for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
    if (DISPLAY_PRICE_WITH_TAX_ADMIN == 'true') {
        $priceIncTax = $currencies->format(zen_round(zen_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), $decimals) * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']);
    } else {
        $priceIncTax = $currencies->format(zen_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']) * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']);
    }
    echo '      <tr class="dataTableRow">' . "\n" . '        <td class="dataTableContent" valign="top">' . $order->products[$i]['qty'] . '&nbsp;x</td>' . "\n" . '        <td class="dataTableContent" valign="top">' . $order->products[$i]['name'];
    if (isset($order->products[$i]['attributes']) && ($k = sizeof($order->products[$i]['attributes'])) > 0) {
        for ($j = 0; $j < $k; $j++) {
            echo '<br><nobr><small>&nbsp;<i> - ' . $order->products[$i]['attributes'][$j]['option'] . ': ' . nl2br(zen_output_string_protected($order->products[$i]['attributes'][$j]['value']));
            if ($order->products[$i]['attributes'][$j]['price'] != '0') {
                echo ' (' . $order->products[$i]['attributes'][$j]['prefix'] . $currencies->format($order->products[$i]['attributes'][$j]['price'] * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . ')';
            }
            if ($order->products[$i]['attributes'][$j]['product_attribute_is_free'] == '1' and $order->products[$i]['product_is_free'] == '1') {
                echo TEXT_INFO_ATTRIBUTE_FREE;
            }
            echo '</i></small></nobr>';
        }
Example #24
0
 /**
  * Prepare subtotal and line-item detail content to send to PayPal
  */
 function getLineItemDetails($restrictedCurrency)
 {
     global $order, $currencies, $order_totals, $order_total_modules;
     // if not default currency, do not send subtotals or line-item details
     if (DEFAULT_CURRENCY != $order->info['currency'] || $restrictedCurrency != DEFAULT_CURRENCY) {
         $this->zcLog('getLineItemDetails 1', 'Not using default currency. Thus, no line-item details can be submitted.');
         return array();
     }
     if ($currencies->currencies[$_SESSION['currency']]['value'] != 1 || $currencies->currencies[$order->info['currency']]['value'] != 1) {
         $this->zcLog('getLineItemDetails 2', 'currency val not equal to 1.0000 - cannot proceed without coping with currency conversions. Aborting line-item details.');
         return array();
     }
     $optionsST = array();
     $optionsLI = array();
     $optionsNB = array();
     $numberOfLineItemsProcessed = 0;
     $creditsApplied = 0;
     $surcharges = 0;
     $sumOfLineItems = 0;
     $sumOfLineTax = 0;
     $optionsST['AMT'] = 0;
     $optionsST['ITEMAMT'] = 0;
     $optionsST['TAXAMT'] = 0;
     $optionsST['SHIPPINGAMT'] = 0;
     $optionsST['SHIPDISCAMT'] = 0;
     $optionsST['HANDLINGAMT'] = 0;
     $optionsST['INSURANCEAMT'] = 0;
     $flagSubtotalsUnknownYet = true;
     $subTotalLI = 0;
     $subTotalTax = 0;
     $subTotalShipping = 0;
     $subtotalPRE = array('no data');
     $discountProblemsFlag = FALSE;
     $flag_treat_as_partial = FALSE;
     if (sizeof($order_totals)) {
         // prepare subtotals
         for ($i = 0, $n = sizeof($order_totals); $i < $n; $i++) {
             if ($order_totals[$i]['code'] == '') {
                 continue;
             }
             if (in_array($order_totals[$i]['code'], array('ot_total', 'ot_subtotal', 'ot_tax', 'ot_shipping')) || strstr($order_totals[$i]['code'], 'insurance')) {
                 if ($order_totals[$i]['code'] == 'ot_shipping') {
                     $optionsST['SHIPPINGAMT'] = round($order_totals[$i]['value'], 2);
                 }
                 if ($order_totals[$i]['code'] == 'ot_total') {
                     $optionsST['AMT'] = round($order_totals[$i]['value'], 2);
                 }
                 if ($order_totals[$i]['code'] == 'ot_tax') {
                     $optionsST['TAXAMT'] = round($order_totals[$i]['value'], 2);
                 }
                 if ($order_totals[$i]['code'] == 'ot_subtotal') {
                     $optionsST['ITEMAMT'] = round($order_totals[$i]['value'], 2);
                 }
                 if (strstr($order_totals[$i]['code'], 'insurance')) {
                     $optionsST['INSURANCEAMT'] += round($order_totals[$i]['value'], 2);
                 }
                 //$optionsST['SHIPDISCAMT'] = '';  // Not applicable
             } else {
                 // handle other order totals:
                 global ${$order_totals[$i]['code']};
                 if (substr($order_totals[$i]['text'], 0, 1) == '-' || isset(${$order_totals[$i]['code']}->credit_class) && ${$order_totals[$i]['code']}->credit_class == true) {
                     // handle credits
                     $creditsApplied += round($order_totals[$i]['value'], 2);
                 } else {
                     // treat all other OT's as if they're related to handling fees or other extra charges to be added/included
                     $surcharges += $order_totals[$i]['value'];
                 }
             }
         }
         if ($creditsApplied > 0) {
             $optionsST['ITEMAMT'] -= $creditsApplied;
         }
         if ($surcharges > 0) {
             $optionsST['ITEMAMT'] += $surcharges;
         }
         // Handle tax-included scenario
         if (DISPLAY_PRICE_WITH_TAX == 'true') {
             $optionsST['TAXAMT'] = 0;
         }
         $subtotalPRE = $optionsST;
         // Move shipping tax amount from Tax subtotal into Shipping subtotal for submission to PayPal, since PayPal applies tax to each line-item individually
         $module = substr($_SESSION['shipping']['id'], 0, strpos($_SESSION['shipping']['id'], '_'));
         if (zen_not_null($order->info['shipping_method']) && DISPLAY_PRICE_WITH_TAX != 'true') {
             if ($GLOBALS[$module]->tax_class > 0) {
                 $shipping_tax_basis = !isset($GLOBALS[$module]->tax_basis) ? STORE_SHIPPING_TAX_BASIS : $GLOBALS[$module]->tax_basis;
                 $shippingOnBilling = zen_get_tax_rate($GLOBALS[$module]->tax_class, $order->billing['country']['id'], $order->billing['zone_id']);
                 $shippingOnDelivery = zen_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                 if ($shipping_tax_basis == 'Billing') {
                     $shipping_tax = $shippingOnBilling;
                 } elseif ($shipping_tax_basis == 'Shipping') {
                     $shipping_tax = $shippingOnDelivery;
                 } else {
                     if (STORE_ZONE == $order->billing['zone_id']) {
                         $shipping_tax = $shippingOnBilling;
                     } elseif (STORE_ZONE == $order->delivery['zone_id']) {
                         $shipping_tax = $shippingOnDelivery;
                     } else {
                         $shipping_tax = 0;
                     }
                 }
                 $taxAdjustmentForShipping = zen_round(zen_calculate_tax($order->info['shipping_cost'], $shipping_tax), $currencies->currencies[$_SESSION['currency']]['decimal_places']);
                 $optionsST['SHIPPINGAMT'] += $taxAdjustmentForShipping;
                 $optionsST['TAXAMT'] -= $taxAdjustmentForShipping;
             }
         }
         $flagSubtotalsUnknownYet = $optionsST['SHIPPINGAMT'] + $optionsST['SHIPDISCAMT'] + $optionsST['AMT'] + $optionsST['TAXAMT'] + $optionsST['ITEMAMT'] + $optionsST['INSURANCEAMT'] == 0;
     } else {
         // if we get here, we don't have any order-total information yet because the customer has clicked Express before starting normal checkout flow
         // thus, we must make a note to manually calculate subtotals, rather than relying on the more robust order-total infrastructure
         $flagSubtotalsUnknownYet = TRUE;
     }
     // loop thru all products to prepare details of quantity and price.
     for ($i = 0, $n = sizeof($order->products), $k = 0; $i < $n; $i++, $k++) {
         // PayPal won't accept zero-value line-items, so skip this entry if price is zero
         if ($order->products[$i]['final_price'] == 0) {
             continue;
         }
         $optionsLI["L_NUMBER{$k}"] = $order->products[$i]['model'];
         $optionsLI["L_NAME{$k}"] = $order->products[$i]['name'];
         // Append *** if out-of-stock.
         $optionsLI["L_NAME{$k}"] .= zen_get_products_stock($order->products[$i]['id']) - $order->products[$i]['qty'] < 0 ? STOCK_MARK_PRODUCT_OUT_OF_STOCK : '';
         // if there are attributes, loop thru them and add to description
         if (isset($order->products[$i]['attributes']) && sizeof($order->products[$i]['attributes']) > 0) {
             $optionsLI["L_DESC{$k}"] = '';
             for ($j = 0, $n2 = sizeof($order->products[$i]['attributes']); $j < $n2; $j++) {
                 $optionsLI["L_DESC{$k}"] .= "\n " . $order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value'];
             }
             // end loop
         }
         // endif attribute-info
         // check for rounding problems with taxes
         $m1 = zen_round($order->products[$i]['qty'] * $order->products[$i]['final_price'], $currencies->currencies[$_SESSION['currency']]['decimal_places']);
         $m2 = $order->products[$i]['qty'] * zen_round($order->products[$i]['final_price'], $currencies->currencies[$_SESSION['currency']]['decimal_places']);
         $n1 = $order->products[$i]['qty'] * zen_calculate_tax($order->products[$i]['final_price'], $order->products[$i]['tax']);
         $n2 = zen_calculate_tax($order->products[$i]['qty'] * $order->products[$i]['final_price'], $order->products[$i]['tax']);
         if ($m1 != $m2 || zen_round($n1, $currencies->currencies[$_SESSION['currency']]['decimal_places']) != zen_round($n2, $currencies->currencies[$_SESSION['currency']]['decimal_places'])) {
             $flag_treat_as_partial = true;
         }
         // PayPal can't handle partial-quantity values, so fudge it here
         if ($flag_treat_as_partial || $order->products[$i]['qty'] != (int) $order->products[$i]['qty']) {
             $optionsLI["L_NAME{$k}"] = '(' . $order->products[$i]['qty'] . ' x ) ' . $optionsLI["L_NAME{$k}"];
             $optionsLI["L_AMT{$k}"] = zen_round($order->products[$i]['qty'] * $order->products[$i]['final_price'], $currencies->currencies[$_SESSION['currency']]['decimal_places']);
             $optionsLI["L_TAXAMT{$k}"] = zen_calculate_tax(zen_round($order->products[$i]['qty'] * $order->products[$i]['final_price'], $currencies->currencies[$_SESSION['currency']]['decimal_places']), $order->products[$i]['tax']);
             $optionsLI["L_QTY{$k}"] = 1;
         } else {
             $optionsLI["L_AMT{$k}"] = $order->products[$i]['final_price'];
             $optionsLI["L_QTY{$k}"] = $order->products[$i]['qty'];
             $optionsLI["L_TAXAMT{$k}"] = zen_calculate_tax(1 * $order->products[$i]['final_price'], $order->products[$i]['tax']);
         }
         // For tax-included pricing, combine tax with price instead of treating separately:
         if (DISPLAY_PRICE_WITH_TAX == 'true') {
             $optionsLI["L_AMT{$k}"] += $optionsLI["L_TAXAMT{$k}"];
             $optionsLI["L_TAXAMT{$k}"] = 0;
         }
         $subTotalLI += $optionsLI["L_QTY{$k}"] * $optionsLI["L_AMT{$k}"];
         $subTotalTax += $optionsLI["L_QTY{$k}"] * $optionsLI["L_TAXAMT{$k}"];
         // add line-item for one-time charges on this product
         if ($order->products[$i]['onetime_charges'] != 0) {
             $k++;
             $optionsLI["L_NAME{$k}"] = MODULES_PAYMENT_PAYPALWPP_LINEITEM_TEXT_ONETIME_CHARGES_PREFIX . substr(htmlentities($order->products[$i]['name'], ENT_QUOTES, 'UTF-8'), 0, 120);
             $optionsLI["L_AMT{$k}"] = $order->products[$i]['onetime_charges'];
             $optionsLI["L_QTY{$k}"] = 1;
             $optionsLI["L_TAXAMT{$k}"] = zen_calculate_tax($order->products[$i]['onetime_charges'], $order->products[$i]['tax']);
             $subTotalLI += $order->products[$i]['onetime_charges'];
             $subTotalTax += $optionsLI["L_TAXAMT{$k}"];
         }
         $numberOfLineItemsProcessed = $k;
     }
     // end for loopthru all products
     // add line items for any surcharges added by order-total modules
     if ($surcharges > 0) {
         $numberOfLineItemsProcessed++;
         $k = $numberOfLineItemsProcessed;
         $optionsLI["L_NAME{$k}"] = MODULES_PAYMENT_PAYPALWPP_LINEITEM_TEXT_SURCHARGES_SHORT;
         $optionsLI["L_DESC{$k}"] = MODULES_PAYMENT_PAYPALWPP_LINEITEM_TEXT_SURCHARGES_LONG;
         $optionsLI["L_AMT{$k}"] = $surcharges;
         $optionsLI["L_QTY{$k}"] = 1;
         $subTotalLI += $surcharges;
     }
     // add line items for discounts such as gift certificates and coupons
     if ($creditsApplied > 0) {
         $numberOfLineItemsProcessed++;
         $k = $numberOfLineItemsProcessed;
         $optionsLI["L_NAME{$k}"] = MODULES_PAYMENT_PAYPALWPP_LINEITEM_TEXT_DISCOUNTS_SHORT;
         $optionsLI["L_DESC{$k}"] = MODULES_PAYMENT_PAYPALWPP_LINEITEM_TEXT_DISCOUNTS_LONG;
         $optionsLI["L_AMT{$k}"] = -1 * $creditsApplied;
         $optionsLI["L_QTY{$k}"] = 1;
         $subTotalLI -= $creditsApplied;
     }
     // Reformat properly
     for ($k = 0, $n = $numberOfLineItemsProcessed + 1; $k < $n; $k++) {
         // Replace & and = and % with * if found.
         $optionsLI["L_NAME{$k}"] = str_replace(array('&', '=', '%'), '*', $optionsLI["L_NAME{$k}"]);
         if (isset($optionsLI["L_DESC{$k}"])) {
             $optionsLI["L_DESC{$k}"] = str_replace(array('&', '=', '%'), '*', $optionsLI["L_DESC{$k}"]);
         }
         if (isset($optionsLI["L_NUMBER{$k}"])) {
             $optionsLI["L_NUMBER{$k}"] = str_replace(array('&', '=', '%'), '*', $optionsLI["L_NUMBER{$k}"]);
         }
         // Remove HTML markup if found
         $optionsLI["L_NAME{$k}"] = zen_clean_html($optionsLI["L_NAME{$k}"], 'strong');
         if (isset($optionsLI["L_DESC{$k}"])) {
             $optionsLI["L_DESC{$k}"] = zen_clean_html($optionsLI["L_DESC{$k}"], 'strong');
         }
         // reformat properly according to API specs
         $optionsLI["L_NAME{$k}"] = substr($optionsLI["L_NAME{$k}"], 0, 127);
         if (isset($optionsLI["L_NUMBER{$k}"])) {
             $optionsLI["L_NUMBER{$k}"] = substr($optionsLI["L_NUMBER{$k}"], 0, 127);
         }
         if (isset($optionsLI["L_DESC{$k}"]) && $optionsLI["L_DESC{$k}"] == '') {
             unset($optionsLI["L_DESC{$k}"]);
         }
         if (isset($optionsLI["L_DESC{$k}"])) {
             $optionsLI["L_DESC{$k}"] = substr($optionsLI["L_DESC{$k}"], 0, 127);
         }
         if (isset($optionsLI["L_TAXAMT{$k}"]) && ($optionsLI["L_TAXAMT{$k}"] != '' || $optionsLI["L_TAXAMT{$k}"] > 0)) {
             $optionsLI["L_TAXAMT{$k}"] = round($optionsLI["L_TAXAMT{$k}"], 2);
         }
     }
     /**
      * PayPal says their math works like this:
      * a) ITEMAMT = L_AMTn * L_QTYn
      * b) TAXAMT = L_QTYn * L_TAXAMTn
      * c) AMT = ITEMAMT + SHIPPINGAMT + HANDLINGAMT + TAXAMT
      */
     // Sanity Check of line-item subtotals
     for ($j = 0; $j < $k; $j++) {
         $itemAMT = $optionsLI["L_AMT{$j}"];
         $itemQTY = $optionsLI["L_QTY{$j}"];
         $itemTAX = isset($optionsLI["L_TAXAMT{$j}"]) ? $optionsLI["L_TAXAMT{$j}"] : 0;
         $sumOfLineItems += $itemQTY * $itemAMT;
         $sumOfLineTax += $itemQTY * $itemTAX;
     }
     $sumOfLineItems = round($sumOfLineItems, 2);
     $sumOfLineTax = round($sumOfLineTax, 2);
     if ($sumOfLineItems == 0) {
         $sumOfLineTax = 0;
         $optionsLI = array();
         $discountProblemsFlag = TRUE;
         if ($optionsST['SHIPPINGAMT'] == $optionsST['AMT']) {
             $optionsST['SHIPPINGAMT'] = 0;
         }
     }
     // Sanity check -- if tax-included pricing is causing problems, remove the numbers and put them in a comment instead:
     $stDiffTaxOnly = strval($sumOfLineItems - $sumOfLineTax - round($optionsST['AMT'], 2)) + 0;
     if (DISPLAY_PRICE_WITH_TAX == 'true' && $stDiffTaxOnly == 0) {
         $optionsNB['DESC'] = 'Tax included in prices: ' . $sumOfLineTax . ' (' . $optionsST['TAXAMT'] . ') ';
         $optionsST['TAXAMT'] = 0;
         for ($k = 0, $n = $numberOfLineItemsProcessed + 1; $k < $n; $k++) {
             if (isset($optionsLI["L_TAXAMT{$k}"])) {
                 unset($optionsLI["L_TAXAMT{$k}"]);
             }
         }
     }
     // Do sanity check -- if any of the line-item subtotal math doesn't add up properly, skip line-item details,
     // so that the order can go through even though PayPal isn't being flexible to handle Zen Cart's diversity
     if (strval($subTotalTax) - strval($sumOfLineTax) > 0.02) {
         $this->zcLog('getLineItemDetails 3', 'Tax Subtotal does not match sum of taxes for line-items. Tax details are being removed from line-item submission data.' . "\n" . $sumOfLineTax . ' ' . $subTotalTax . print_r(array_merge($optionsST, $optionsLI), true));
         for ($k = 0, $n = $numberOfLineItemsProcessed + 1; $k < $n; $k++) {
             if (isset($optionsLI["L_TAXAMT{$k}"])) {
                 unset($optionsLI["L_TAXAMT{$k}"]);
             }
         }
         $subTotalTax = 0;
         $sumOfLineTax = 0;
     }
     // If coupons exist and there's a calculation problem, then it's likely that taxes are incorrect, so reset L_TAXAMTn values
     if ($creditsApplied > 0 && strval($optionsST['TAXAMT']) != strval($sumOfLineTax)) {
         $pre = $optionsLI;
         for ($k = 0, $n = $numberOfLineItemsProcessed + 1; $k < $n; $k++) {
             if (isset($optionsLI["L_TAXAMT{$k}"])) {
                 unset($optionsLI["L_TAXAMT{$k}"]);
             }
         }
         $this->zcLog('getLineItemDetails 4', 'Coupons/Discounts have affected tax calculations, so tax details are being removed from line-item submission data.' . "\n" . $sumOfLineTax . ' ' . $optionsST['TAXAMT'] . "\n" . print_r(array_merge($optionsST, $pre, $optionsNB), true) . "\nAFTER:" . print_r(array_merge($optionsST, $optionsLI, $optionsNB), TRUE));
         $subTotalTax = 0;
         $sumOfLineTax = 0;
     }
     if (TRUE) {
         // disable line-item tax details, leaving only TAXAMT subtotal as tax indicator
         for ($k = 0, $n = $numberOfLineItemsProcessed + 1; $k < $n; $k++) {
             if (isset($optionsLI["L_TAXAMT{$k}"])) {
                 unset($optionsLI["L_TAXAMT{$k}"]);
             }
         }
     }
     // check subtotals
     if (strval($optionsST['ITEMAMT']) > 0 && strval($subTotalLI) > 0 && strval($subTotalLI) != strval($optionsST['ITEMAMT']) || strval($subTotalLI) - strval($sumOfLineItems) != 0) {
         $this->zcLog('getLineItemDetails 5', 'Line-item subtotals do not add up properly. Line-item-details skipped.' . "\n" . (double) $sumOfLineItems . ' ' . (double) $subTotalTax . print_r(array_merge($optionsST, $optionsLI), true));
         $optionsLI = array();
     }
     // check whether discounts are causing a problem
     if (strval($optionsST['ITEMAMT']) < 0) {
         $pre = array_merge($optionsST, $optionsLI);
         $optionsLI = array();
         $optionsST['ITEMAMT'] = $optionsST['AMT'];
         if ($optionsST['AMT'] < $optionsST['TAXAMT']) {
             $optionsST['TAXAMT'] = 0;
         }
         if ($optionsST['AMT'] < $optionsST['SHIPPINGAMT']) {
             $optionsST['SHIPPINGAMT'] = 0;
         }
         $discountProblemsFlag = TRUE;
         $this->zcLog('getLineItemDetails 6', 'Discounts have caused the subtotal to calculate incorrectly. Line-item-details cannot be submitted.' . "\nBefore:" . print_r($pre, TRUE) . "\nAfter:" . print_r(array_merge($optionsST, $optionsLI), true));
     }
     // if AMT or ITEMAMT values are 0 (ie: certain OT modules disabled) or we've started express checkout without going through normal checkout flow, we have to get subtotals manually
     if ((!isset($optionsST['AMT']) || $optionsST['AMT'] == 0 || $flagSubtotalsUnknownYet == TRUE || $optionsST['ITEMAMT'] == 0) && $discountProblemsFlag != TRUE) {
         $optionsST['ITEMAMT'] = $sumOfLineItems;
         $optionsST['TAXAMT'] = $sumOfLineTax;
         if ($subTotalShipping > 0) {
             $optionsST['SHIPPINGAMT'] = $subTotalShipping;
         }
         $optionsST['AMT'] = $sumOfLineItems + $optionsST['TAXAMT'] + $optionsST['SHIPPINGAMT'];
     }
     $this->zcLog('getLineItemDetails 7 - subtotal comparisons', 'BEFORE line-item calcs: ' . print_r($subtotalPRE, true) . ($flagSubtotalsUnknownYet == TRUE ? 'Subtotals Unknown Yet' : '') . ' - AFTER doing line-item calcs: ' . print_r(array_merge($optionsST, $optionsLI, $optionsNB), true));
     // if subtotals are not adding up correctly, then skip sending any line-item or subtotal details to PayPal
     $stAll = round(strval($optionsST['ITEMAMT'] + $optionsST['TAXAMT'] + $optionsST['SHIPPINGAMT'] + $optionsST['SHIPDISCAMT'] + $optionsST['HANDLINGAMT'] + $optionsST['INSURANCEAMT']), 2);
     $stDiff = strval($optionsST['AMT'] - $stAll);
     $stDiffRounded = strval($stAll - round($optionsST['AMT'], 2)) + 0;
     // unset any subtotal values that are zero
     if (isset($optionsST['ITEMAMT']) && $optionsST['ITEMAMT'] == 0) {
         unset($optionsST['ITEMAMT']);
     }
     if (isset($optionsST['TAXAMT']) && $optionsST['TAXAMT'] == 0) {
         unset($optionsST['TAXAMT']);
     }
     if (isset($optionsST['SHIPPINGAMT']) && $optionsST['SHIPPINGAMT'] == 0) {
         unset($optionsST['SHIPPINGAMT']);
     }
     if (isset($optionsST['SHIPDISCAMT']) && $optionsST['SHIPDISCAMT'] == 0) {
         unset($optionsST['SHIPDISCAMT']);
     }
     if (isset($optionsST['HANDLINGAMT']) && $optionsST['HANDLINGAMT'] == 0) {
         unset($optionsST['HANDLINGAMT']);
     }
     if (isset($optionsST['INSURANCEAMT']) && $optionsST['INSURANCEAMT'] == 0) {
         unset($optionsST['INSURANCEAMT']);
     }
     // tidy up all values so that they comply with proper format (number_format(xxxx,2) for PayPal US use )
     if (!defined('PAYPALWPP_SKIP_LINE_ITEM_DETAIL_FORMATTING') || PAYPALWPP_SKIP_LINE_ITEM_DETAIL_FORMATTING != 'true' || in_array($order->info['currency'], array('JPY', 'NOK'))) {
         if (is_array($optionsST)) {
             foreach ($optionsST as $key => $value) {
                 $optionsST[$key] = number_format($value, $order->info['currency'] == 'JPY' ? 0 : 2);
             }
         }
         if (is_array($optionsLI)) {
             foreach ($optionsLI as $key => $value) {
                 if (substr($key, 0, 8) == 'L_TAXAMT' && ($optionsLI[$key] == '' || $optionsLI[$key] == 0)) {
                     unset($optionsLI[$key]);
                 } else {
                     if (strstr($key, 'AMT')) {
                         $optionsLI[$key] = number_format($value, $order->info['currency'] == 'JPY' ? 0 : 2);
                     }
                 }
             }
         }
     }
     $this->zcLog('getLineItemDetails 8', 'checking subtotals... ' . "\n" . print_r(array_merge(array('calculated total' => number_format($stAll, $order->info['currency'] == 'JPY' ? 0 : 2)), $optionsST), true) . "\n-------------------\ndifference: " . ($stDiff + 0) . '  (abs+rounded: ' . ($stDiffRounded + 0) . ')');
     if ($stDiffRounded != 0) {
         $this->zcLog('getLineItemDetails 9', 'Subtotals Bad. Skipping line-item/subtotal details');
         return array();
     }
     $this->zcLog('getLineItemDetails 10', 'subtotals balance - okay');
     // Send Subtotal and LineItem results back to be submitted to PayPal
     return array_merge($optionsST, $optionsLI, $optionsNB);
 }
Example #25
0
 function calculate_tax_deduction($amount, $od_amount, $method, $finalise = false)
 {
     global $order;
     $tax_address = zen_get_tax_locations();
     switch ($method) {
         case 'Standard':
             $ratio1 = zen_round($od_amount / $amount, 2);
             $tod_amount = 0;
             reset($order->info['tax_groups']);
             while (list($key, $value) = each($order->info['tax_groups'])) {
                 $tax_rate = zen_get_tax_rate_from_desc($key, $tax_address['country_id'], $tax_address['zone_id']);
                 $total_net += $tax_rate * $value;
             }
             if ($od_amount > $total_net) {
                 $od_amount = $total_net;
             }
             reset($order->info['tax_groups']);
             while (list($key, $value) = each($order->info['tax_groups'])) {
                 $tax_rate = zen_get_tax_rate_from_desc($key, $tax_address['country_id'], $tax_address['zone_id']);
                 $net = $tax_rate * $value;
                 if ($net > 0) {
                     $god_amount = $value * $ratio1;
                     $tod_amount += $god_amount;
                     if ($finalise) {
                         $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
                     }
                 }
             }
             if ($finalise) {
                 $order->info['tax'] -= $tod_amount;
             }
             if ($finalise) {
                 $order->info['total'] -= $tod_amount;
             }
             break;
         case 'Credit Note':
             $tax_rate = zen_get_tax_rate($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']);
             $tax_desc = zen_get_tax_description($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']);
             $tod_amount = $this->deduction / (100 + $tax_rate) * $tax_rate;
             if ($finalise) {
                 $order->info['tax_groups'][$tax_desc] -= $tod_amount;
             }
             if ($finalise) {
                 $order->info['tax'] -= $tod_amount;
             }
             if ($finalise) {
                 $order->info['total'] -= $tod_amount;
             }
             break;
         default:
     }
     return $tod_amount;
 }
 function pre_confirmation_check($order_total)
 {
     global $order, $db;
     if ($this->include_shipping == 'false') {
         $order_total -= $order->info['shipping_cost'];
     }
     if ($this->include_tax == 'false') {
         $order_total -= $order->info['tax'];
     }
     $group_query = $db->Execute("select customers_group_pricing from " . TABLE_CUSTOMERS . " where customers_id = '" . $_SESSION['customer_id'] . "'");
     if ($group_query->fields['customers_group_pricing'] != '0') {
         $group_discount = $db->Execute("select group_name, group_percentage from " . TABLE_GROUP_PRICING . " where\r\n                                        group_id = '" . $group_query->fields['customers_group_pricing'] . "'");
         $discount = $order_total * $group_discount->fields['group_percentage'] / 100;
         $od_amount = zen_round($discount, 2);
         if ($this->calculate_tax != "none") {
             $tod_amount = $this->calculate_tax_deduction($order_total, $od_amount, $this->calculate_tax);
             $od_amount = $od_amount + $tod_amount;
         }
     }
     return $od_amount + $tod_amount;
 }
Example #27
0
    }
    echo '      <tr class="dataTableRow">' . "\n" . '        <td class="dataTableContent" valign="top" align="right">' . $order->products[$i]['qty'] . '&nbsp;x</td>' . "\n" . '        <td class="dataTableContent" valign="top">' . $order->products[$i]['name'];
    if (isset($order->products[$i]['attributes']) && ($k = sizeof($order->products[$i]['attributes'])) > 0) {
        for ($j = 0; $j < $k; $j++) {
            echo '<br><nobr><small>&nbsp;<i> - ' . $order->products[$i]['attributes'][$j]['option'] . ': ' . nl2br(zen_output_string_protected($order->products[$i]['attributes'][$j]['value']));
            if ($order->products[$i]['attributes'][$j]['price'] != '0') {
                echo ' (' . $order->products[$i]['attributes'][$j]['prefix'] . $currencies->format($order->products[$i]['attributes'][$j]['price'] * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . ')';
            }
            if ($order->products[$i]['attributes'][$j]['product_attribute_is_free'] == '1' and $order->products[$i]['product_is_free'] == '1') {
                echo TEXT_INFO_ATTRIBUTE_FREE;
            }
            echo '</i></small></nobr>';
        }
    }
    echo '        </td>' . "\n" . '        <td class="dataTableContent" valign="top">' . $order->products[$i]['model'] . '</td>' . "\n";
    echo '        <td class="dataTableContent" align="right" valign="top">' . zen_display_tax_value($order->products[$i]['tax']) . '%</td>' . "\n" . '        <td class="dataTableContent" align="right" valign="top"><b>' . $currencies->format($order->products[$i]['final_price'], true, $order->info['currency'], $order->info['currency_value']) . ($order->products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->format($order->products[$i]['onetime_charges'], true, $order->info['currency'], $order->info['currency_value']) : '') . '</b></td>' . "\n" . '        <td class="dataTableContent" align="right" valign="top"><b>' . $currencies->format(zen_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']) . ($order->products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->format(zen_add_tax($order->products[$i]['onetime_charges'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']) : '') . '</b></td>' . "\n" . '        <td class="dataTableContent" align="right" valign="top"><b>' . $currencies->format(zen_round($order->products[$i]['final_price'], $decimals) * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . ($order->products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->format($order->products[$i]['onetime_charges'], true, $order->info['currency'], $order->info['currency_value']) : '') . '</b></td>' . "\n" . '        <td class="dataTableContent" align="right" valign="top"><b>' . $priceIncTax . ($order->products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->format(zen_add_tax($order->products[$i]['onetime_charges'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']) : '') . '</b></td>' . "\n";
    echo '      </tr>' . "\n";
}
?>
      <tr>
        <td align="right" colspan="8"><table border="0" cellspacing="0" cellpadding="2">
<?php 
for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
    echo '          <tr>' . "\n" . '            <td align="right" class="' . str_replace('_', '-', $order->totals[$i]['class']) . '-Text">' . $order->totals[$i]['title'] . '</td>' . "\n" . '            <td align="right" class="' . str_replace('_', '-', $order->totals[$i]['class']) . '-Amount">' . $order->totals[$i]['text'] . '</td>' . "\n" . '          </tr>' . "\n";
}
?>
        </table></td>
      </tr>
    </table></td>
  </tr>
Example #28
0
 /**
  * Method to calculate cart totals(price and weight)
  *
  * @return void
  */
 public function calculate()
 {
     $currencies = $this->getContainer()->get('zencart.currencies');
     $decimalPlaces = $currencies->get_decimal_places($this->getSessionVar('currency'));
     $this->total = 0;
     $this->weight = 0;
     // shipping adjustment
     $this->free_shipping_item = 0;
     $this->free_shipping_price = 0;
     $this->free_shipping_weight = 0;
     if (!is_array($this->contents)) {
         return 0;
     }
     reset($this->contents);
     while (list($products_id, ) = each($this->contents)) {
         $freeShippingTotal = $productTotal = $totalOnetimeCharge = 0;
         $qty = $this->contents[$products_id]['qty'];
         // products price
         $product_query = "select products_id, products_price, products_tax_class_id, products_weight,\n                products_priced_by_attribute, product_is_always_free_shipping, products_discount_type, products_discount_type_from,\n                products_virtual, products_model\n                from %table.products%\n                where products_id = '" . (int) $products_id . "'";
         if ($product = $this->getDb()->Execute($product_query)) {
             $prid = $product->fields['products_id'];
             $products_tax = zen_get_tax_rate($product->fields['products_tax_class_id']);
             $products_price = $product->fields['products_price'];
             // adjusted count for free shipping
             if ($product->fields['product_is_always_free_shipping'] != 1 and $product->fields['products_virtual'] != 1) {
                 $products_weight = $product->fields['products_weight'];
             } else {
                 $products_weight = 0;
             }
             $special_price = zen_get_products_special_price($prid);
             if ($special_price and $product->fields['products_priced_by_attribute'] == 0) {
                 $products_price = $special_price;
             } else {
                 $special_price = 0;
             }
             if (zen_get_products_price_is_free($product->fields['products_id'])) {
                 // no charge
                 $products_price = 0;
             }
             // adjust price for discounts when priced by attribute
             if ($product->fields['products_priced_by_attribute'] == '1' and zen_has_product_attributes($product->fields['products_id'], 'false')) {
                 if ($special_price) {
                     $products_price = $special_price;
                 } else {
                     $products_price = $product->fields['products_price'];
                 }
             } else {
                 // discount qty pricing
                 if ($product->fields['products_discount_type'] != '0') {
                     $products_price = zen_get_products_discount_price_qty($product->fields['products_id'], $qty);
                 }
             }
             // shipping adjustments for Product
             if ($product->fields['product_is_always_free_shipping'] == 1 or $product->fields['products_virtual'] == 1 or preg_match('/^GIFT/', addslashes($product->fields['products_model']))) {
                 $this->free_shipping_item += $qty;
                 $freeShippingTotal += $products_price;
                 $this->free_shipping_weight += $qty * $product->fields['products_weight'];
             }
             $productTotal += $products_price;
             $this->weight += $qty * $products_weight;
         }
         $adjust_downloads = 0;
         // attributes price
         if (isset($this->contents[$products_id]['attributes'])) {
             reset($this->contents[$products_id]['attributes']);
             while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
                 $adjust_downloads++;
                 /*
                           products_attributes_id, options_values_price, price_prefix,
                           attributes_display_only, product_attribute_is_free,
                           attributes_discounted
                 */
                 $attribute_price_query = "select *\n                        from %table.products_attributes%\n                        where products_id = '" . (int) $prid . "'\n                        and options_id = '" . (int) $option . "'\n                        and options_values_id = '" . (int) $value . "'";
                 $attribute_price = $this->getDb()->Execute($attribute_price_query);
                 $new_attributes_price = 0;
                 $discount_type_id = '';
                 $sale_maker_discount = '';
                 // bottom total
                 if ($attribute_price->fields['product_attribute_is_free'] == '1' and zen_get_products_price_is_free((int) $prid)) {
                     // no charge for attribute
                 } else {
                     // + or blank adds
                     if ($attribute_price->fields['price_prefix'] == '-') {
                         // appears to confuse products priced by attributes
                         if ($product->fields['product_is_always_free_shipping'] == '1' or $product->fields['products_virtual'] == '1') {
                             $shipping_attributes_price = zen_get_discount_calc($product->fields['products_id'], $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty);
                             $freeShippingTotal -= $shipping_attributes_price;
                         }
                         if ($attribute_price->fields['attributes_discounted'] == '1') {
                             // calculate proper discount for attributes
                             $new_attributes_price = zen_get_discount_calc($product->fields['products_id'], $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty);
                             $productTotal -= $new_attributes_price;
                         } else {
                             $productTotal -= $attribute_price->fields['options_values_price'];
                         }
                     } else {
                         // appears to confuse products priced by attributes
                         if ($product->fields['product_is_always_free_shipping'] == '1' or $product->fields['products_virtual'] == '1') {
                             $shipping_attributes_price = zen_get_discount_calc($product->fields['products_id'], $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty);
                             $freeShippingTotal += $shipping_attributes_price;
                         }
                         if ($attribute_price->fields['attributes_discounted'] == '1') {
                             // calculate proper discount for attributes
                             $new_attributes_price = zen_get_discount_calc($product->fields['products_id'], $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty);
                             $productTotal += $new_attributes_price;
                         } else {
                             $productTotal += $attribute_price->fields['options_values_price'];
                         }
                     }
                     // eof: attribute price
                     // adjust for downloads
                     // adjust products price
                     $check_attribute = $attribute_price->fields['products_attributes_id'];
                     $sql = "select *\n                            from %table.products_attributes_download%\n                            where products_attributes_id = '" . $check_attribute . "'";
                     $check_download = $this->getDb()->Execute($sql);
                     if ($check_download->RecordCount()) {
                         // do not count download as free when set to product/download combo
                         if ($adjust_downloads == 1 and $product->fields['product_is_always_free_shipping'] != 2) {
                             $freeShippingTotal += $products_price;
                             $this->free_shipping_item += $qty;
                         }
                         // adjust for attributes price
                         $freeShippingTotal += $new_attributes_price;
                     }
                     ////////////////////////////////////////////////
                     // calculate additional attribute charges
                     $chk_price = zen_get_products_base_price($products_id);
                     $chk_special = zen_get_products_special_price($products_id, false);
                     // products_options_value_text
                     if (zen_get_attributes_type($attribute_price->fields['products_attributes_id']) == PRODUCTS_OPTIONS_TYPE_TEXT) {
                         $text_words = zen_get_word_count_price($this->contents[$products_id]['attributes_values'][$attribute_price->fields['options_id']], $attribute_price->fields['attributes_price_words_free'], $attribute_price->fields['attributes_price_words']);
                         $text_letters = zen_get_letters_count_price($this->contents[$products_id]['attributes_values'][$attribute_price->fields['options_id']], $attribute_price->fields['attributes_price_letters_free'], $attribute_price->fields['attributes_price_letters']);
                         $productTotal += $text_letters;
                         $productTotal += $text_words;
                         if ($product->fields['product_is_always_free_shipping'] == 1 or $product->fields['products_virtual'] == 1 or preg_match('/^GIFT/', addslashes($product->fields['products_model']))) {
                             $freeShippingTotal += $text_letters;
                             $freeShippingTotal += $text_words;
                         }
                     }
                     // attributes_price_factor
                     $added_charge = 0;
                     if ($attribute_price->fields['attributes_price_factor'] > 0) {
                         $added_charge = zen_get_attributes_price_factor($chk_price, $chk_special, $attribute_price->fields['attributes_price_factor'], $attribute_price->fields['attributes_price_factor_offset']);
                         $productTotal += $added_charge;
                         if ($product->fields['product_is_always_free_shipping'] == 1 or $product->fields['products_virtual'] == 1 or preg_match('/^GIFT/', addslashes($product->fields['products_model']))) {
                             $freeShippingTotal += $added_charge;
                         }
                     }
                     // attributes_qty_prices
                     $added_charge = 0;
                     if ($attribute_price->fields['attributes_qty_prices'] != '') {
                         $added_charge = zen_get_attributes_qty_prices_onetime($attribute_price->fields['attributes_qty_prices'], $qty);
                         $productTotal += $added_charge;
                         if ($product->fields['product_is_always_free_shipping'] == 1 or $product->fields['products_virtual'] == 1 or preg_match('/^GIFT/', addslashes($product->fields['products_model']))) {
                             $freeShippingTotal += $added_charge;
                         }
                     }
                     //// one time charges
                     // attributes_price_onetime
                     if ($attribute_price->fields['attributes_price_onetime'] > 0) {
                         $totalOnetimeCharge += $attribute_price->fields['attributes_price_onetime'];
                     }
                     // attributes_price_factor_onetime
                     $added_charge = 0;
                     if ($attribute_price->fields['attributes_price_factor_onetime'] > 0) {
                         $chk_price = zen_get_products_base_price($products_id);
                         $chk_special = zen_get_products_special_price($products_id, false);
                         $added_charge = zen_get_attributes_price_factor($chk_price, $chk_special, $attribute_price->fields['attributes_price_factor_onetime'], $attribute_price->fields['attributes_price_factor_onetime_offset']);
                         $totalOnetimeCharge += $added_charge;
                     }
                     // attributes_qty_prices_onetime
                     $added_charge = 0;
                     if ($attribute_price->fields['attributes_qty_prices_onetime'] != '') {
                         $chk_price = zen_get_products_base_price($products_id);
                         $chk_special = zen_get_products_special_price($products_id, false);
                         $added_charge = zen_get_attributes_qty_prices_onetime($attribute_price->fields['attributes_qty_prices_onetime'], $qty);
                         $totalOnetimeCharge += $added_charge;
                     }
                     ////////////////////////////////////////////////
                 }
             }
         }
         // attributes price
         // attributes weight
         if (isset($this->contents[$products_id]['attributes'])) {
             reset($this->contents[$products_id]['attributes']);
             while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
                 $attribute_weight_query = "select products_attributes_weight, products_attributes_weight_prefix\n                        from %table.products_attributes%\n                        where products_id = '" . (int) $prid . "'\n                        and options_id = '" . (int) $option . "'\n                        and options_values_id = '" . (int) $value . "'";
                 $attribute_weight = $this->getDb()->Execute($attribute_weight_query);
                 // adjusted count for free shipping
                 if ($product->fields['product_is_always_free_shipping'] != 1) {
                     $new_attributes_weight = $attribute_weight->fields['products_attributes_weight'];
                 } else {
                     $new_attributes_weight = 0;
                 }
                 // shipping adjustments for Attributes
                 if ($product->fields['product_is_always_free_shipping'] == 1 or $product->fields['products_virtual'] == 1 or preg_match('/^GIFT/', addslashes($product->fields['products_model']))) {
                     if ($attribute_weight->fields['products_attributes_weight_prefix'] == '-') {
                         $this->free_shipping_weight -= $qty * $attribute_weight->fields['products_attributes_weight'];
                     } else {
                         $this->free_shipping_weight += $qty * $attribute_weight->fields['products_attributes_weight'];
                     }
                 }
                 // + or blank adds
                 if ($attribute_weight->fields['products_attributes_weight_prefix'] == '-') {
                     $this->weight -= $qty * $new_attributes_weight;
                 } else {
                     $this->weight += $qty * $new_attributes_weight;
                 }
             }
         }
         // attributes weight
         /*
         // uncomment for odd shipping requirements needing this:
         
              // if 0 weight defined as free shipping adjust for functions free_shipping_price and free_shipping_item
              if (($product->fields['products_weight'] == 0 && ORDER_WEIGHT_ZERO_STATUS == 1) && !($product->fields['products_virtual'] == 1) && !(preg_match('/^GIFT/', addslashes($product->fields['products_model']))) && !($product->fields['product_is_always_free_shipping'] == 1)) {
                $freeShippingTotal += $products_price;
                $this->free_shipping_item += $qty;
              }
         */
         $this->total += zen_round(zen_add_tax($productTotal, $products_tax), $decimalPlaces) * $qty;
         $this->total += zen_round(zen_add_tax($totalOnetimeCharge, $products_tax), $decimalPlaces);
         $this->free_shipping_price += zen_round(zen_add_tax($freeShippingTotal, $products_tax), $decimalPlaces) * $qty;
         if ($product->fields['product_is_always_free_shipping'] == 1 or $product->fields['products_virtual'] == 1 or preg_match('/^GIFT/', addslashes($product->fields['products_model']))) {
             $this->free_shipping_price += zen_round(zen_add_tax($totalOnetimeCharge, $products_tax), $decimalPlaces);
         }
     }
 }
Example #29
0
 function cart()
 {
     global $db, $currencies;
     $decimals = $currencies->get_decimal_places($_SESSION['currency']);
     $this->content_type = $_SESSION['cart']->get_content_type();
     /* Dual Pricing start */
     $customer_address_query = "select c.customers_firstname, c.customers_lastname, c.customers_telephone, c.customers_whole,\n/* Dual Pricing end */\n                                    c.customers_email_address, ab.entry_company, ab.entry_street_address,\n                                    ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id,\n                                    z.zone_name, co.countries_id, co.countries_name,\n                                    co.countries_iso_code_2, co.countries_iso_code_3,\n                                    co.address_format_id, ab.entry_state\n                                   from (" . TABLE_CUSTOMERS . " c, " . TABLE_ADDRESS_BOOK . " ab )\n                                   left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n                                   left join " . TABLE_COUNTRIES . " co on (ab.entry_country_id = co.countries_id)\n                                   where c.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n                                   and ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n                                   and c.customers_default_address_id = ab.address_book_id";
     $customer_address = $db->Execute($customer_address_query);
     $shipping_address_query = "select ab.entry_firstname, ab.entry_lastname, ab.entry_company,\n                                    ab.entry_street_address, ab.entry_suburb, ab.entry_postcode,\n                                    ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id,\n                                    c.countries_id, c.countries_name, c.countries_iso_code_2,\n                                    c.countries_iso_code_3, c.address_format_id, ab.entry_state\n                                   from " . TABLE_ADDRESS_BOOK . " ab\n                                   left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n                                   left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id)\n                                   where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n                                   and ab.address_book_id = '" . (int) $_SESSION['sendto'] . "'";
     $shipping_address = $db->Execute($shipping_address_query);
     $billing_address_query = "select ab.entry_firstname, ab.entry_lastname, ab.entry_company,\n                                   ab.entry_street_address, ab.entry_suburb, ab.entry_postcode,\n                                   ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id,\n                                   c.countries_id, c.countries_name, c.countries_iso_code_2,\n                                   c.countries_iso_code_3, c.address_format_id, ab.entry_state\n                                  from " . TABLE_ADDRESS_BOOK . " ab\n                                  left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n                                  left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id)\n                                  where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n                                  and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'";
     $billing_address = $db->Execute($billing_address_query);
     // set default tax calculation for not-logged-in visitors
     $taxCountryId = $taxZoneId = 0;
     // get tax zone info for logged-in visitors
     if (isset($_SESSION['customer_id']) && (int) $_SESSION['customer_id'] > 0) {
         $taxCountryId = $taxZoneId = -1;
         $tax_address_query = '';
         switch (STORE_PRODUCT_TAX_BASIS) {
             case 'Shipping':
                 $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\n                                from " . TABLE_ADDRESS_BOOK . " ab\n                                left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n                                where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n                                and ab.address_book_id = '" . (int) ($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto']) . "'";
                 break;
             case 'Billing':
                 $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\n                                from " . TABLE_ADDRESS_BOOK . " ab\n                                left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n                                where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n                                and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'";
                 break;
             case 'Store':
                 if ($billing_address->fields['entry_zone_id'] == STORE_ZONE) {
                     $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\n                                  from " . TABLE_ADDRESS_BOOK . " ab\n                                  left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n                                  where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n                                  and ab.address_book_id = '" . (int) $_SESSION['billto'] . "'";
                 } else {
                     $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id\n                                  from " . TABLE_ADDRESS_BOOK . " ab\n                                  left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)\n                                  where ab.customers_id = '" . (int) $_SESSION['customer_id'] . "'\n                                  and ab.address_book_id = '" . (int) ($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto']) . "'";
                 }
         }
         if ($tax_address_query != '') {
             $tax_address = $db->Execute($tax_address_query);
             if ($tax_address->recordCount() > 0) {
                 $taxCountryId = $tax_address->fields['entry_country_id'];
                 $taxZoneId = $tax_address->fields['entry_zone_id'];
             }
         }
     }
     $class =& $_SESSION['payment'];
     if (isset($_SESSION['cc_id'])) {
         $coupon_code_query = "select coupon_code\n                              from " . TABLE_COUPONS . "\n                              where coupon_id = '" . (int) $_SESSION['cc_id'] . "'";
         $coupon_code = $db->Execute($coupon_code_query);
     }
     $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, 'currency' => $_SESSION['currency'], 'currency_value' => $currencies->currencies[$_SESSION['currency']]['value'], 'payment_method' => $GLOBALS[$class]->title, 'payment_module_code' => $GLOBALS[$class]->code, 'coupon_code' => $coupon_code->fields['coupon_code'], 'shipping_method' => isset($_SESSION['shipping']['title']) ? $_SESSION['shipping']['title'] : '', 'shipping_module_code' => isset($_SESSION['shipping']['id']) && strpos($_SESSION['shipping']['id'], '_') > 0 ? $_SESSION['shipping']['id'] : $_SESSION['shipping'], 'shipping_cost' => isset($_SESSION['shipping']['cost']) ? $_SESSION['shipping']['cost'] : 0, 'subtotal' => 0, 'shipping_tax' => 0, 'tax' => 0, 'total' => 0, 'tax_groups' => array(), 'comments' => isset($_SESSION['comments']) ? $_SESSION['comments'] : '', 'ip_address' => $_SESSION['customers_ip_address'] . ' - ' . $_SERVER['REMOTE_ADDR']);
     //print_r($GLOBALS[$class]);
     //echo $class;
     //print_r($GLOBALS);
     //echo $_SESSION['payment'];
     /*
     // this is set above to the module filename it should be set to the module title like Checks/Money Order rather than moneyorder
     if (isset(${$_SESSION['payment']}) && is_object(${$_SESSION['payment']})) {
     $this->info['payment_method'] = ${$_SESSION['payment']}->title;
     }
     */
     /*
     // bof: move below calculations
         if ($this->info['total'] == 0) {
           if (DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID == 0) {
             $this->info['order_status'] = DEFAULT_ORDERS_STATUS_ID;
           } else {
             $this->info['order_status'] = DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID;
           }
         }
         if (isset($GLOBALS[$class]) && is_object($GLOBALS[$class])) {
           if ( isset($GLOBALS[$class]->order_status) && is_numeric($GLOBALS[$class]->order_status) && ($GLOBALS[$class]->order_status > 0) ) {
             $this->info['order_status'] = $GLOBALS[$class]->order_status;
           }
         }
     // eof: move below calculations
     */
     $this->customer = array('firstname' => $customer_address->fields['customers_firstname'], 'lastname' => $customer_address->fields['customers_lastname'], 'company' => $customer_address->fields['entry_company'], 'street_address' => $customer_address->fields['entry_street_address'], 'suburb' => $customer_address->fields['entry_suburb'], 'city' => $customer_address->fields['entry_city'], 'postcode' => $customer_address->fields['entry_postcode'], 'state' => zen_not_null($customer_address->fields['entry_state']) ? $customer_address->fields['entry_state'] : $customer_address->fields['zone_name'], 'zone_id' => $customer_address->fields['entry_zone_id'], 'country' => array('id' => $customer_address->fields['countries_id'], 'title' => $customer_address->fields['countries_name'], 'iso_code_2' => $customer_address->fields['countries_iso_code_2'], 'iso_code_3' => $customer_address->fields['countries_iso_code_3']), 'format_id' => (int) $customer_address->fields['address_format_id'], 'telephone' => $customer_address->fields['customers_telephone'], 'email_address' => $customer_address->fields['customers_email_address']);
     $this->delivery = array('firstname' => $shipping_address->fields['entry_firstname'], 'lastname' => $shipping_address->fields['entry_lastname'], 'company' => $shipping_address->fields['entry_company'], 'street_address' => $shipping_address->fields['entry_street_address'], 'suburb' => $shipping_address->fields['entry_suburb'], 'city' => $shipping_address->fields['entry_city'], 'postcode' => $shipping_address->fields['entry_postcode'], 'state' => zen_not_null($shipping_address->fields['entry_state']) ? $shipping_address->fields['entry_state'] : $shipping_address->fields['zone_name'], 'zone_id' => $shipping_address->fields['entry_zone_id'], 'country' => array('id' => $shipping_address->fields['countries_id'], 'title' => $shipping_address->fields['countries_name'], 'iso_code_2' => $shipping_address->fields['countries_iso_code_2'], 'iso_code_3' => $shipping_address->fields['countries_iso_code_3']), 'country_id' => $shipping_address->fields['entry_country_id'], 'format_id' => (int) $shipping_address->fields['address_format_id']);
     $this->billing = array('firstname' => $billing_address->fields['entry_firstname'], 'lastname' => $billing_address->fields['entry_lastname'], 'company' => $billing_address->fields['entry_company'], 'street_address' => $billing_address->fields['entry_street_address'], 'suburb' => $billing_address->fields['entry_suburb'], 'city' => $billing_address->fields['entry_city'], 'postcode' => $billing_address->fields['entry_postcode'], 'state' => zen_not_null($billing_address->fields['entry_state']) ? $billing_address->fields['entry_state'] : $billing_address->fields['zone_name'], 'zone_id' => $billing_address->fields['entry_zone_id'], 'country' => array('id' => $billing_address->fields['countries_id'], 'title' => $billing_address->fields['countries_name'], 'iso_code_2' => $billing_address->fields['countries_iso_code_2'], 'iso_code_3' => $billing_address->fields['countries_iso_code_3']), 'country_id' => $billing_address->fields['entry_country_id'], 'format_id' => (int) $billing_address->fields['address_format_id']);
     $index = 0;
     $products = $_SESSION['cart']->get_products();
     for ($i = 0, $n = sizeof($products); $i < $n; $i++) {
         if ($i / 2 == floor($i / 2)) {
             $rowClass = "rowEven";
         } else {
             $rowClass = "rowOdd";
         }
         $taxRates = zen_get_multiple_tax_rates($products[$i]['tax_class_id'], $taxCountryId, $taxZoneId);
         $this->products[$index] = array('qty' => $products[$i]['quantity'], 'name' => $products[$i]['name'], 'model' => $products[$i]['model'], 'tax_groups' => $taxRates, 'tax_description' => zen_get_tax_description($products[$i]['tax_class_id'], $taxCountryId, $taxZoneId), 'price' => $products[$i]['price'], 'final_price' => zen_round($products[$i]['price'] + $_SESSION['cart']->attributes_price($products[$i]['id']), $decimals), 'onetime_charges' => $_SESSION['cart']->attributes_price_onetime_charges($products[$i]['id'], $products[$i]['quantity']), 'weight' => $products[$i]['weight'], 'products_priced_by_attribute' => $products[$i]['products_priced_by_attribute'], 'product_is_free' => $products[$i]['product_is_free'], 'products_discount_type' => $products[$i]['products_discount_type'], 'products_discount_type_from' => $products[$i]['products_discount_type_from'], 'id' => $products[$i]['id'], 'rowClass' => $rowClass);
         if (STORE_PRODUCT_TAX_BASIS == 'Shipping' && isset($_SESSION['shipping']['id']) && stristr($_SESSION['shipping']['id'], 'storepickup') == TRUE) {
             $taxRates = zen_get_multiple_tax_rates($products[$i]['tax_class_id'], STORE_COUNTRY, STORE_ZONE);
             $this->products[$index]['tax'] = zen_get_tax_rate($products[$i]['tax_class_id'], STORE_COUNTRY, STORE_ZONE);
         } else {
             $taxRates = zen_get_multiple_tax_rates($products[$i]['tax_class_id'], $taxCountryId, $taxZoneId);
             $this->products[$index]['tax'] = zen_get_tax_rate($products[$i]['tax_class_id'], $taxCountryId, $taxZoneId);
         }
         $this->notify('NOTIFY_ORDER_CART_ADD_PRODUCT_LIST', array('index' => $index, 'products' => $products[$i]));
         if ($products[$i]['attributes']) {
             $subindex = 0;
             reset($products[$i]['attributes']);
             while (list($option, $value) = each($products[$i]['attributes'])) {
                 /*
                 //clr 030714 Determine if attribute is a text attribute and change products array if it is.
                 if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID){
                 $attr_value = $products[$i]['attributes_values'][$option];
                 } else {
                 $attr_value = $attributes->fields['products_options_values_name'];
                 }
                 */
                 $attributes_query = "select popt.products_options_name, poval.products_options_values_name,\n                                          pa.options_values_price, pa.price_prefix\n                                   from " . TABLE_PRODUCTS_OPTIONS . " popt,\n                                        " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval,\n                                        " . TABLE_PRODUCTS_ATTRIBUTES . " pa\n                                   where pa.products_id = '" . (int) $products[$i]['id'] . "'\n                                   and pa.options_id = '" . (int) $option . "'\n                                   and pa.options_id = popt.products_options_id\n                                   and pa.options_values_id = '" . (int) $value . "'\n                                   and pa.options_values_id = poval.products_options_values_id\n                                   and popt.language_id = '" . (int) $_SESSION['languages_id'] . "'\n                                   and poval.language_id = '" . (int) $_SESSION['languages_id'] . "'";
                 $attributes = $db->Execute($attributes_query);
                 //clr 030714 Determine if attribute is a text attribute and change products array if it is.
                 if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID) {
                     $attr_value = $products[$i]['attributes_values'][$option];
                 } else {
                     $attr_value = $attributes->fields['products_options_values_name'];
                 }
                 $this->products[$index]['attributes'][$subindex] = array('option' => $attributes->fields['products_options_name'], 'value' => $attr_value, 'option_id' => $option, 'value_id' => $value, 'prefix' => $attributes->fields['price_prefix'], 'price' => $attributes->fields['options_values_price']);
                 $this->notify('NOTIFY_ORDER_CART_ADD_ATTRIBUTE_LIST', array('index' => $index, 'subindex' => $subindex, 'products' => $products[$i], 'attributes' => $attributes));
                 $subindex++;
             }
         }
         // add onetime charges here
         //$_SESSION['cart']->attributes_price_onetime_charges($products[$i]['id'], $products[$i]['quantity'])
         /**************************************
          * Check for external tax handling code
          **************************************/
         $this->use_external_tax_handler_only = FALSE;
         $this->notify('NOTIFY_ORDER_CART_EXTERNAL_TAX_HANDLING', array(), $index, $taxCountryId, $taxZoneId);
         if ($this->use_external_tax_handler_only == FALSE) {
             /*********************************************
              * Calculate taxes for this product
              *********************************************/
             $shown_price = zen_add_tax($this->products[$index]['final_price'] * $this->products[$index]['qty'], $this->products[$index]['tax']) + zen_add_tax($this->products[$index]['onetime_charges'], $this->products[$index]['tax']);
             $this->info['subtotal'] += $shown_price;
             $this->notify('NOTIFIY_ORDER_CART_SUBTOTAL_CALCULATE', array('shown_price' => $shown_price));
             // find product's tax rate and description
             $products_tax = $this->products[$index]['tax'];
             $products_tax_description = $this->products[$index]['tax_description'];
             // Dual Pricing start - no taxes for wholesale customers
             if ($customer_address->fields['customers_whole'] > 0) {
                 $products_tax = 0;
                 $this->products[$index]['tax'] = 0;
                 $tax_add = 0;
                 $this->products[$index]['tax_description'] = '';
             }
             if ($customer_address->fields['customers_whole'] == 0) {
                 // Dual pricing end -  no taxes for wholesale customers
                 if (DISPLAY_PRICE_WITH_TAX == 'true') {
                     // calculate the amount of tax "inc"luded in price (used if tax-in pricing is enabled)
                     $tax_add = $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
                 } else {
                     // calculate the amount of tax for this product (assuming tax is NOT included in the price)
                     //        $tax_add = zen_round(($products_tax / 100) * $shown_price, $currencies->currencies[$this->info['currency']]['decimal_places']);
                     $tax_add = $products_tax / 100 * $shown_price;
                 }
                 $this->info['tax'] += $tax_add;
                 foreach ($taxRates as $taxDescription => $taxRate) {
                     $taxAdd = zen_calculate_tax($this->products[$index]['final_price'] * $this->products[$index]['qty'], $taxRate) + zen_calculate_tax($this->products[$index]['onetime_charges'], $taxRate);
                     if (isset($this->info['tax_groups'][$taxDescription])) {
                         $this->info['tax_groups'][$taxDescription] += $taxAdd;
                     } else {
                         $this->info['tax_groups'][$taxDescription] = $taxAdd;
                     }
                 }
                 //Dual Pricing start -  no taxes for wholesale customers
             }
             // Dual pricing end -  no taxes for wholesale customers
             /*********************************************
              * END: Calculate taxes for this product
              *********************************************/
         }
         $index++;
     }
     // Update the final total to include tax if not already tax-inc
     if (DISPLAY_PRICE_WITH_TAX == 'true') {
         $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'];
     } else {
         $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost'];
     }
     /*
     // moved to function create
         if ($this->info['total'] == 0) {
           if (DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID == 0) {
             $this->info['order_status'] = DEFAULT_ORDERS_STATUS_ID;
           } else {
             $this->info['order_status'] = DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID;
           }
         }
     */
     if (isset($GLOBALS[$class]) && is_object($GLOBALS[$class])) {
         if (isset($GLOBALS[$class]->order_status) && is_numeric($GLOBALS[$class]->order_status) && $GLOBALS[$class]->order_status > 0) {
             $this->info['order_status'] = $GLOBALS[$class]->order_status;
         }
     }
     $this->notify('NOTIFY_ORDER_CART_FINISHED');
 }
Example #30
0
 /**
  * Build the data and actions to process when the "Submit" button is pressed on the order-confirmation screen.
  * This sends the data to the payment gateway for processing.
  * (These are hidden fields on the checkout confirmation page)
  *
  * @return string
  */
 function process_button()
 {
     global $db, $order, $currencies, $currency;
     $options = array();
     $optionsCore = array();
     $optionsPhone = array();
     $optionsShip = array();
     $optionsLineItems = array();
     $optionsAggregate = array();
     $optionsTrans = array();
     $buttonArray = array();
     // save the session stuff permanently in case paypal loses the session
     $_SESSION['ppipn_key_to_remove'] = session_id();
     $db->Execute("delete from " . TABLE_PAYPAL_SESSION . " where session_id = '" . zen_db_input($_SESSION['ppipn_key_to_remove']) . "'");
     $sql = "insert into " . TABLE_PAYPAL_SESSION . " (session_id, saved_session, expiry) values (\n            '" . zen_db_input($_SESSION['ppipn_key_to_remove']) . "',\n            '" . base64_encode(serialize($_SESSION)) . "',\n            '" . (time() + 1 * 60 * 60 * 24 * 2) . "')";
     $db->Execute($sql);
     $my_currency = select_pp_currency();
     $this->transaction_currency = $my_currency;
     $this->totalsum = $order->info['total'] = zen_round($order->info['total'], 2);
     $this->transaction_amount = zen_round($this->totalsum * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));
     $telephone = preg_replace('/\\D/', '', $order->customer['telephone']);
     if ($telephone != '') {
         $optionsPhone['H_PhoneNumber'] = $telephone;
         if (in_array($order->customer['country']['iso_code_2'], array('US', 'CA'))) {
             $optionsPhone['night_phone_a'] = substr($telephone, 0, 3);
             $optionsPhone['night_phone_b'] = substr($telephone, 3, 3);
             $optionsPhone['night_phone_c'] = substr($telephone, 6, 4);
             $optionsPhone['day_phone_a'] = substr($telephone, 0, 3);
             $optionsPhone['day_phone_b'] = substr($telephone, 3, 3);
             $optionsPhone['day_phone_c'] = substr($telephone, 6, 4);
         } else {
             $optionsPhone['night_phone_b'] = $telephone;
             $optionsPhone['day_phone_b'] = $telephone;
         }
     }
     $optionsCore = array('lc' => $this->getLanguageCode(), 'charset' => CHARSET, 'page_style' => MODULE_PAYMENT_PAYPAL_PAGE_STYLE, 'custom' => zen_session_name() . '=' . zen_session_id(), 'business' => MODULE_PAYMENT_PAYPAL_BUSINESS_ID, 'return' => zen_href_link(FILENAME_CHECKOUT_PROCESS, 'referer=paypal', 'SSL'), 'cancel_return' => zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'), 'shopping_url' => zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL'), 'notify_url' => zen_href_link('ipn_main_handler.php', '', 'SSL', false, false, true), 'redirect_cmd' => '_xclick', 'rm' => 2, 'bn' => 'CNZcart_Cart_EC', 'mrb' => 'R-4DM17246PS436904F', 'pal' => 'GR5QUVVL9AFGN');
     $optionsCust = array('first_name' => replace_accents($order->customer['firstname']), 'last_name' => replace_accents($order->customer['lastname']), 'address1' => replace_accents($order->customer['street_address']), 'city' => replace_accents($order->customer['city']), 'state' => zen_get_zone_code($order->customer['country']['id'], $order->customer['zone_id'], $order->customer['state']), 'zip' => $order->customer['postcode'], 'country' => $order->customer['country']['iso_code_2'], 'email' => $order->customer['email_address']);
     // address line 2 is optional
     if ($order->customer['suburb'] != '') {
         $optionsCust['address2'] = $order->customer['suburb'];
     }
     // different format for Japanese address layout:
     if ($order->customer['country']['iso_code_2'] == 'JP') {
         $optionsCust['zip'] = substr($order->customer['postcode'], 0, 3) . '-' . substr($order->customer['postcode'], 3);
     }
     if (MODULE_PAYMENT_PAYPAL_ADDRESS_REQUIRED == 2) {
         $optionsCust = array('first_name' => replace_accents($order->delivery['firstname'] != '' ? $order->delivery['firstname'] : $order->billing['firstname']), 'last_name' => replace_accents($order->delivery['lastname'] != '' ? $order->delivery['lastname'] : $order->billing['lastname']), 'address1' => replace_accents($order->delivery['street_address'] != '' ? $order->delivery['street_address'] : $order->billing['street_address']), 'city' => replace_accents($order->delivery['city'] != '' ? $order->delivery['city'] : $order->billing['city']), 'state' => $order->delivery['country']['id'] != '' ? zen_get_zone_code($order->delivery['country']['id'], $order->delivery['zone_id'], $order->delivery['state']) : zen_get_zone_code($order->billing['country']['id'], $order->billing['zone_id'], $order->billing['state']), 'zip' => $order->delivery['postcode'] != '' ? $order->delivery['postcode'] : $order->billing['postcode'], 'country' => $order->delivery['country']['title'] != '' ? $order->delivery['country']['title'] : $order->billing['country']['title'], 'country_code' => $order->delivery['country']['iso_code_2'] != '' ? $order->delivery['country']['iso_code_2'] : $order->billing['country']['iso_code_2'], 'email' => $order->customer['email_address']);
         if ($order->delivery['suburb'] != '') {
             $optionsCust['address2'] = $order->delivery['suburb'];
         }
         if ($order->delivery['country']['iso_code_2'] == 'JP') {
             $optionsCust['zip'] = substr($order->delivery['postcode'], 0, 3) . '-' . substr($order->delivery['postcode'], 3);
         }
     }
     $optionsShip['no_shipping'] = MODULE_PAYMENT_PAYPAL_ADDRESS_REQUIRED;
     if (MODULE_PAYMENT_PAYPAL_ADDRESS_OVERRIDE == '1') {
         $optionsShip['address_override'] = MODULE_PAYMENT_PAYPAL_ADDRESS_OVERRIDE;
     }
     // prepare cart contents details where possible
     if (MODULE_PAYMENT_PAYPAL_DETAILED_CART == 'Yes') {
         $optionsLineItems = ipn_getLineItemDetails($my_currency);
     }
     if (sizeof($optionsLineItems) > 0) {
         $optionsLineItems['cmd'] = '_cart';
         // $optionsLineItems['num_cart_items'] = sizeof($order->products);
         if (isset($optionsLineItems['shipping'])) {
             $optionsLineItems['shipping_1'] = $optionsLineItems['shipping'];
             unset($optionsLineItems['shipping']);
         }
         unset($optionsLineItems['subtotal']);
         // if line-item details couldn't be kept due to calculation mismatches or discounts etc, default to aggregate mode
         if (!isset($optionsLineItems['item_name_1']) || $optionsLineItems['creditsExist'] == TRUE) {
             $optionsLineItems = array();
         }
         // if ($optionsLineItems['amount'] != $this->transaction_amount) $optionsLineItems = array();
         // debug:
         // ipn_debug_email('Line Item Details (if blank, this means there was a data mismatch or credits applied, and thus bypassed): ' . "\n" . print_r($optionsLineItems, true));
         unset($optionsLineItems['creditsExist']);
     }
     $optionsAggregate = array('cmd' => '_ext-enter', 'item_name' => MODULE_PAYMENT_PAYPAL_PURCHASE_DESCRIPTION_TITLE, 'item_number' => MODULE_PAYMENT_PAYPAL_PURCHASE_DESCRIPTION_ITEMNUM, 'amount' => number_format($this->transaction_amount, $currencies->get_decimal_places($my_currency)), 'shipping' => '0.00');
     if (MODULE_PAYMENT_PAYPAL_TAX_OVERRIDE == 'true') {
         $optionsAggregate['tax'] = '0.00';
     }
     if (MODULE_PAYMENT_PAYPAL_TAX_OVERRIDE == 'true') {
         $optionsAggregate['tax_cart'] = '0.00';
     }
     $optionsTrans = array('upload' => (int) (sizeof($order->products) > 0), 'currency_code' => $my_currency);
     // if line-item info is invalid, use aggregate:
     if (sizeof($optionsLineItems) > 0) {
         $optionsAggregate = $optionsLineItems;
     }
     if (defined('MODULE_PAYMENT_PAYPAL_LOGO_IMAGE')) {
         $optionsCore['cpp_logo_image'] = urlencode(MODULE_PAYMENT_LOGO_IMAGE);
     }
     if (defined('MODULE_PAYMENT_PAYPAL_CART_BORDER_COLOR')) {
         $optionsCore['cpp_cart_border_color'] = MODULE_PAYMENT_PAYPAL_CART_BORDER_COLOR;
     }
     // prepare submission
     $options = array_merge($optionsCore, $optionsCust, $optionsPhone, $optionsShip, $optionsTrans, $optionsAggregate);
     // ipn_debug_email('Keys for submission: ' . print_r($options, true));
     // build the button fields
     foreach ($options as $name => $value) {
         // remove quotation marks
         $value = str_replace('"', '', $value);
         // check for invalid chars
         if (preg_match('/[^a-zA-Z_0-9]/', $name)) {
             ipn_debug_email('datacheck - ABORTING - preg_match found invalid submission key: ' . $name . ' (' . $value . ')');
             break;
         }
         // do we need special handling for & and = symbols?
         // if (strpos($value, '&') !== false || strpos($value, '=') !== false) $value = urlencode($value);
         $buttonArray[] = zen_draw_hidden_field($name, $value);
     }
     $process_button_string = "\n" . implode("\n", $buttonArray) . "\n";
     $_SESSION['paypal_transaction_info'] = array($this->transaction_amount, $this->transaction_currency);
     return $process_button_string;
 }