Example #1
0
 function noSymbolDisplayPrice()
 {
     return $this->noSymbolFormat(zen_add_tax($products_price, $products_tax) * $quantity);
 }
Example #2
0
 if ($flag_markup) {
     echo zen_draw_checkbox_field('markup_checked[' . $products->fields['products_id'] . ']', '1', !$flag_special && $_POST['marge']);
     //echo zen_draw_hidden_field('markup[' . $products->fields['products_id'] . ']', '1');
 } else {
     // this has become obsolete since we changed prices to update by default when markup is not set
     //echo zen_draw_hidden_field('update_price[' . $products->fields['products_id'] . ']', 'yes');
 }
 if ($flag_special) {
     echo '&nbsp;<a target=blank href="' . zen_href_link(FILENAME_SPECIALS, 'sID=' . $spec->fields['specials_id'] . '&action=edit') . '" target="_blank">' . zen_image(DIR_WS_IMAGES . 'icon_info.gif', TEXT_SPECIALS_PRODUCTS) . '</a>';
 }
 if (QUICKUPDATES_DISPLAY_TVA_PRICES == 'true') {
     $parameters = 'size="6"';
     $parameters .= ' onKeyUp="updateNet(' . $products->fields['products_id'] . '); updateMargin(' . $products->fields['products_id'] . ');"';
     // $taxprice needs the $currencies->currencies[DEFAULT_CURRENCY]['decimal_places'] to be set (done at top of file)
     // an alternative might be to use $price (i.s.o. $taxprice) and update it with updatGross('$products->fields['products_id']') for each product ?)
     $tax_price = zen_add_tax($price, $tax_rate->fields['tax_rate']);
     $tax_price = sprintf("%01.2f", round($tax_price, 4));
     echo '</td>' . "\n";
     echo '<td class="smallText">' . zen_draw_input_field('quick_updates_new[products_taxprice][' . $products->fields['products_id'] . ']', $tax_price, $parameters);
     //echo zen_draw_hidden_field('update_taxprice['.$products->fields['products_id'].']','yes');
     echo zen_draw_hidden_field('quick_updates_old[products_tax_value][' . $products->fields['products_id'] . ']', $tax_rate->fields['tax_rate']);
 }
 echo zen_draw_hidden_field('quick_updates_old[products_price][' . $products->fields['products_id'] . ']', $products->fields['products_price']);
 echo '<a target="_blank" href="' . zen_href_link(FILENAME_PRODUCTS_PRICE_MANAGER, 'products_filter=' . $products->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . 'icon_products_price_manager.gif', QUICKUPDATES_PPM_LINK_ALT) . '</a>';
 echo '</td>' . "\n";
 if (QUICKUPDATES_MODIFY_WEIGHT == 'true') {
     echo '<td class="smallText">' . zen_draw_input_field('quick_updates_new[products_weight][' . $products->fields['products_id'] . ']', $products->fields['products_weight'], 'size="4"') . zen_draw_hidden_field('quick_updates_old[products_weight][' . $products->fields['products_id'] . ']', $products->fields['products_weight']) . '</td>' . "\n";
 }
 if (QUICKUPDATES_MODIFY_TAX == 'true') {
     echo '<td class="smallText">' . zen_draw_pull_down_menu('quick_updates_new[products_tax_class_id][' . $products->fields['products_id'] . ']', $tax_class_array, $products->fields['products_tax_class_id'], 'style="width: 5em;"') . zen_draw_hidden_field('quick_updates_old[products_tax_class_id][' . $products->fields['products_id'] . ']', $products->fields['products_tax_class_id']) . '</td>' . "\n";
 }
Example #3
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;
     }
     $decimals = $currencies->get_decimal_places($_SESSION['currency']);
     // loop thru all products to prepare details of quantity and price.
     for ($i = 0, $n = sizeof($order->products), $k = -1; $i < $n; $i++) {
         // PayPal is inconsistent in how it handles zero-value line-items, so skip this entry if price is zero
         if ($order->products[$i]['final_price'] == 0) {
             continue;
         } else {
             $k++;
         }
         $optionsLI["L_NUMBER{$k}"] = $order->products[$i]['model'];
         $optionsLI["L_NAME{$k}"] = $order->products[$i]['name'] . ' [' . (int) $order->products[$i]['id'] . ']';
         // 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) {
             for ($j = 0, $n2 = sizeof($order->products[$i]['attributes']); $j < $n2; $j++) {
                 $optionsLI["L_NAME{$k}"] .= "\n " . $order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value'];
             }
             // end loop
         }
         // endif attribute-info
         // PayPal can't handle fractional-quantity values, so convert it to qty 1 here
         if ($order->products[$i]['qty'] > 1 && ($order->products[$i]['qty'] != (int) $order->products[$i]['qty'] || $flag_treat_as_partial)) {
             $optionsLI["L_NAME{$k}"] = '(' . $order->products[$i]['qty'] . ' x ) ' . $optionsLI["L_NAME{$k}"];
             // zen_add_tax already handles whether DISPLAY_PRICES_WITH_TAX is set
             $optionsLI["L_AMT{$k}"] = zen_round(zen_round(zen_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), $decimals) * $order->products[$i]['qty'], $decimals);
             $optionsLI["L_QTY{$k}"] = 1;
             // no line-item tax component
         } else {
             $optionsLI["L_QTY{$k}"] = $order->products[$i]['qty'];
             $optionsLI["L_AMT{$k}"] = zen_round(zen_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), $decimals);
         }
         $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}"] = zen_round(zen_add_tax($order->products[$i]['onetime_charges'], $order->products[$i]['tax']), $decimals);
             $optionsLI["L_QTY{$k}"] = 1;
             // $optionsLI["L_TAXAMT$k"] = zen_round(zen_calculate_tax($order->products[$i]['onetime_charges'], $order->products[$i]['tax']), $decimals);
             $subTotalLI += $optionsLI["L_AMT{$k}"];
             // $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_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_LONG;
         $optionsLI["L_AMT{$k}"] = -1 * $creditsApplied;
         $optionsLI["L_QTY{$k}"] = 1;
         $subTotalLI -= $creditsApplied;
     }
     // Reformat properly
     // Replace & and = and % with * if found.
     // reformat properly according to API specs
     // Remove HTML markup from name if found
     for ($k = 0, $n = $numberOfLineItemsProcessed + 1; $k < $n; $k++) {
         $optionsLI["L_NAME{$k}"] = str_replace(array('&', '=', '%'), '*', $optionsLI["L_NAME{$k}"]);
         $optionsLI["L_NAME{$k}"] = zen_clean_html($optionsLI["L_NAME{$k}"], 'strong');
         $optionsLI["L_NAME{$k}"] = substr($optionsLI["L_NAME{$k}"], 0, 127);
         $optionsLI["L_AMT{$k}"] = round($optionsLI["L_AMT{$k}"], 2);
         if (isset($optionsLI["L_NUMBER{$k}"])) {
             if ($optionsLI["L_NUMBER{$k}"] == '') {
                 unset($optionsLI["L_NUMBER{$k}"]);
             } else {
                 $optionsLI["L_NUMBER{$k}"] = str_replace(array('&', '=', '%'), '*', $optionsLI["L_NUMBER{$k}"]);
                 $optionsLI["L_NUMBER{$k}"] = substr($optionsLI["L_NUMBER{$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);
         // }
     }
     // 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);
     // $this->zcLog('tax sanity check', 'stDiffTaxOnly: ' . $stDiffTaxOnly . "\nsumOfLineItems: " . $sumOfLineItems . "\nsumOfLineTax: " . $sumOfLineTax . ' ' . $subTotalTax . ' ' . print_r(array_merge($optionsST, $optionsLI), true));
     // if (DISPLAY_PRICE_WITH_TAX == 'true' && $stDiffTaxOnly == 0 && ($optionsST['TAXAMT'] != 0 && $sumOfLineTax != 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;
     // }
     // 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}"]);
         }
     }
     // if ITEMAMT >0 and subTotalLI > 0 and they're not equal ... OR subTotalLI minus sumOfLineItems isn't 0
     // 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" . strval($sumOfLineItems) . ' ' . strval($subTotalLI) . ' ' . print_r(array_merge($optionsST, $optionsLI), true));
         $optionsLI = array();
         $optionsLI["L_NAME0"] = MODULES_PAYMENT_PAYPALWPP_AGGREGATE_CART_CONTENTS;
         $optionsLI["L_AMT0"] = $sumOfLineItems = $subTotalLI = $optionsST['ITEMAMT'];
     }
     // check whether discounts are causing a problem
     if (strval($optionsST['ITEMAMT']) <= 0) {
         $pre = array_merge($optionsST, $optionsLI);
         $optionsST['ITEMAMT'] = $optionsST['AMT'];
         $optionsLI = array();
         $optionsLI["L_NAME0"] = MODULES_PAYMENT_PAYPALWPP_AGGREGATE_CART_CONTENTS;
         $optionsLI["L_AMT0"] = $sumOfLineItems = $subTotalLI = $optionsST['ITEMAMT'];
         /* 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', 'HUF'))) {
         if (is_array($optionsST)) {
             foreach ($optionsST as $key => $value) {
                 $optionsST[$key] = number_format($value, (int) $currencies->get_decimal_places($restrictedCurrency) == 0 ? 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, (int) $currencies->get_decimal_places($restrictedCurrency) == 0 ? 0 : 2);
                     }
                 }
             }
         }
     }
     $this->zcLog('getLineItemDetails 8', 'checking subtotals... ' . "\n" . print_r(array_merge(array('calculated total' => number_format($stAll, (int) $currencies->get_decimal_places($restrictedCurrency) == 0 ? 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);
 }
 /**
  * Method to calculate cart totals(price and weight)
  *
  * @return void
  * @global object access to the db object
  */
 function calculate()
 {
     global $db, $currencies;
     $this->total = 0;
     $this->weight = 0;
     $this->total_before_discounts = 0;
     $decimalPlaces = $currencies->get_decimal_places($_SESSION['currency']);
     // shipping adjustment
     $this->free_shipping_item = 0;
     $this->free_shipping_price = 0;
     $this->free_shipping_weight = 0;
     $this->download_count = 0;
     if (!is_array($this->contents)) {
         return 0;
     }
     // By default, Price Factor is based on Price and is called from function zen_get_attributes_price_factor
     // Setting a define for ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL to 1 to calculate the Price Factor from Special rather than Price switches this to be based on Special, if it exists
     if (!defined('ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL')) {
         define('ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL', 1);
     }
     reset($this->contents);
     while (list($products_id, ) = each($this->contents)) {
         $total_before_discounts = 0;
         $freeShippingTotal = $productTotal = $totalOnetimeCharge = $totalOnetimeChargeNoDiscount = 0;
         $qty = $this->contents[$products_id]['qty'];
         // products price
         // Dual Pricing start
         $product_query = "select products_id, products_price, products_price_w, products_tax_class_id, products_weight,\n/* Dual Pricing end */\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 = $db->Execute($product_query)) {
             $prid = $product->fields['products_id'];
             $products_tax = zen_get_tax_rate($product->fields['products_tax_class_id']);
             // 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--;
                     $products_price_array = $product->fields['products_price_w'];
                     $productsprice = explode("-", $products_price_array);
                     $products_price = (double) $productsprice[$i];
                     if ($products_price == '0' || $products_price == '') {
                         $products_price = (double) $productsprice[0];
                     }
                     if ($products_price == '0') {
                         $products_price = $product->fields['products_price'];
                     }
                 } else {
                     $products_price = $product->fields['products_price'];
                 }
             } else {
                 $products_price = $product->fields['products_price'];
             }
             // Dual Pricing end
             // 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')) {
                 // reset for priced by attributes
                 //            $products_price = $products->fields['products_price'];
                 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'];
             }
             //        $this->total += zen_round(zen_add_tax($products_price, $products_tax),$currencies->get_decimal_places($_SESSION['currency'])) * $qty;
             $productTotal += $products_price;
             $this->weight += $qty * $products_weight;
             // ****** WARNING NEED TO ADD ATTRIBUTES AND QTY
             // calculate Product Price without Specials, Sales or Discounts
             $total_before_discounts += $product->fields['products_price'];
         }
         $adjust_downloads = 0;
         // attributes price
         $savedProductTotal = $productTotal;
         $attributesTotal = 0;
         if (isset($this->contents[$products_id]['attributes'])) {
             reset($this->contents[$products_id]['attributes']);
             while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
                 $productTotal = 0;
                 $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 = $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;
                 // calculate Product Price without Specials, Sales or Discounts
                 //          $new_attributes_price_before_discounts = 0;
                 $discount_type_id = '';
                 $sale_maker_discount = '';
                 // bottom total
                 //            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) $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'];
                         }
                         // calculate Product Price without Specials, Sales or Discounts
                         //            $this->total_before_discounts -= $attribute_price->fields['options_values_price'];
                         $total_before_discounts -= $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);
                             // Dual Pricing start
                             //$productTotal += $new_attributes_price;
                             if ($_SESSION['customer_id']) {
                                 if ($customer_check->fields['customers_whole'] != "0") {
                                     $new_attributes_price = zen_get_discount_calc($product->fields['products_id'], $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price_w'], $qty);
                                 }
                             }
                             $this->total += $qty * zen_add_tax($new_attributes_price, $products_tax);
                             // Dual Pricing end
                         } else {
                             $productTotal += $attribute_price->fields['options_values_price'];
                         }
                         // calculate Product Price without Specials, Sales or Discounts
                         $total_before_discounts += $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 = $db->Execute($sql);
                     if ($check_download->RecordCount()) {
                         // count number of downloads
                         $this->download_count += $check_download->RecordCount() * $qty;
                         // 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;
                         //die('I SEE B ' . $this->free_shipping_price);
                     }
                     //  echo 'I SEE ' . $this->total . ' vs ' . $this->free_shipping_price . ' items: ' . $this->free_shipping_item. '<br>';
                     ////////////////////////////////////////////////
                     // 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;
                         }
                         // calculate Product Price without Specials, Sales or Discounts
                         $total_before_discounts += $text_letters;
                         $total_before_discounts += $text_words;
                     }
                     // attributes_price_factor
                     $added_charge = 0;
                     if ($attribute_price->fields['attributes_price_factor'] > 0) {
                         //echo 'products_id: ' . $product->fields['products_id'] . ' Prices ' . '$chk_price: ' . $chk_price . ' $chk_special: ' . $chk_special . ' attributes_price_factor:' . $attribute_price->fields['attributes_price_factor'] . ' attributes_price_factor_offset: ' . $attribute_price->fields['attributes_price_factor_offset'] . '<br>';
                         $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;
                         }
                         // calculate Product Price without Specials, Sales or Discounts
                         $added_charge = zen_get_attributes_price_factor($chk_price, $chk_price, $attribute_price->fields['attributes_price_factor'], $attribute_price->fields['attributes_price_factor_offset']);
                         $total_before_discounts += $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;
                         }
                         // calculate Product Price without Specials, Sales or Discounts
                         $added_charge = zen_get_attributes_qty_prices_onetime($attribute_price->fields['attributes_qty_prices'], 1);
                         $total_before_discounts += $attribute_price->fields['options_values_price'] + $added_charge;
                     }
                     //// one time charges
                     // attributes_price_onetime
                     if ($attribute_price->fields['attributes_price_onetime'] > 0) {
                         $totalOnetimeCharge += $attribute_price->fields['attributes_price_onetime'];
                         // calculate Product Price without Specials, Sales or Discounts
                         $totalOnetimeChargeNoDiscount += $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;
                         // calculate Product Price without Specials, Sales or Discounts
                         $added_charge = zen_get_attributes_price_factor($chk_price, $chk_price, $attribute_price->fields['attributes_price_factor_onetime'], $attribute_price->fields['attributes_price_factor_onetime_offset']);
                         $totalOnetimeChargeNoDiscount += $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;
                         // calculate Product Price without Specials, Sales or Discounts
                         $added_charge = zen_get_attributes_qty_prices_onetime($chk_price, $chk_price, $attribute_price->fields['attributes_price_factor_onetime'], $attribute_price->fields['attributes_price_factor_onetime_offset']);
                         $totalOnetimeChargeNoDiscount += $added_charge;
                     }
                     ////////////////////////////////////////////////
                 }
                 $attributesTotal += zen_round($productTotal, $decimalPlaces);
             }
             // eof while
         }
         // attributes price
         $productTotal = $savedProductTotal + $attributesTotal;
         // 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 = $db->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;
               }
         */
         //echo 'shopping_cart class Price: ' . $productTotal . ' qty: ' . $qty . '<br>';
         $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);
         }
         // ******* WARNING ADD ONE TIME ATTRIBUTES, PRICE FACTOR
         // calculate Product Price without Specials, Sales or Discounts
         //echo 'Product Attribute before: ' . $new_attributes_price_before_discounts . '<br>';
         $total_before_discounts = $total_before_discounts * $qty;
         $total_before_discounts += $totalOnetimeChargeNoDiscount;
         $this->total_before_discounts += $total_before_discounts;
     }
 }
                            echo $currencies->format(zen_add_tax($quotes[$i]['methods'][$j]['cost'], $quotes[$i]['tax']));
                            ?>
</td>
		</tr>
<?php 
                        } else {
                            ?>
        <td><?php 
                            echo $quotes[$i]['module'];
                            ?>
&nbsp;(<?php 
                            echo $quotes[$i]['methods'][$j]['title'];
                            ?>
)</td>
		<td class="cartTotalDisplay"><?php 
                            echo $currencies->format(zen_add_tax($quotes[$i]['methods'][$j]['cost'], $quotes[$i]['tax']));
                            ?>
</td>
		</tr>
<?php 
                        }
                    }
                }
            }
        }
        ?>
</table>
<?php 
    }
}
?>
Example #6
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
 }
<?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++) {
    ?>
     <div class="amount larger forward"><?php 
    echo $order->totals[$i]['text'];
    ?>
Example #8
0
    }
    //end foreach [attributes]
    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"');
    $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']);
    $tmp = zen_add_tax($products[$i]['final_price'], zen_get_tax_rate($products[$i]['tax_class_id']));
    //  $productsPriceEach = $currencies->rateAdjusted($tmp);
    //  $productsPriceTotal = $productsPriceEach * $products[$i]['quantity'];
    $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) : '');
    $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) : '');
    //  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');
 function calculate($pForceRecalculate = FALSE)
 {
     global $gBitDb;
     if (is_null($this->total) || $pForceRecalculate) {
         $this->subtotal = 0;
         $this->total = 0;
         $this->weight = 0;
         $this->quantity = 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);
         foreach (array_keys($this->contents) as $productsKey) {
             $qty = $this->contents[$productsKey]['products_quantity'];
             // $productsKey will be unique joined string of products_id:hash for cart, eg: 17054:be19531ba04f4dc3fd33bca49a16dca8
             $prid = zen_get_prid($productsKey);
             // products price
             $product = $this->getProductObject($prid);
             // sometimes 0 hash things can get stuck in cart.
             if ($product && $product->isValid()) {
                 $productAttributes = !empty($this->contents[$productsKey]['attributes']) ? $this->contents[$productsKey]['attributes'] : array();
                 $products_tax = zen_get_tax_rate($product->getField('products_tax_class_id'));
                 $purchasePrice = $product->getPurchasePrice($qty, $productAttributes);
                 $onetimeCharges = $product->getOneTimeCharges($qty, $productAttributes);
                 // shipping adjustments
                 if ($product->getField('product_is_always_free_ship') == 1 or $product->isVirtual($this->contents[$productsKey]) == 1 or preg_match('/^GIFT/', addslashes($product->getField('products_model')))) {
                     $this->free_shipping_item += $qty;
                     $this->free_shipping_price += zen_add_tax($purchasePrice, $products_tax) * $qty;
                     $this->free_shipping_weight += $product->getWeight($qty, $productAttributes);
                 }
                 $productsTotal = zen_add_tax($purchasePrice * $qty + $onetimeCharges, $products_tax);
                 $this->total += $productsTotal;
                 $this->subtotal += $productsTotal;
                 $this->weight += $product->getWeight($qty, $productAttributes);
                 $this->quantity += $qty;
             }
         }
     }
 }
Example #10
0
 function process()
 {
     global $order, $currencies;
     if (MODULE_ORDER_TOTAL_LOWORDERFEE_LOW_ORDER_FEE == 'true') {
         switch (MODULE_ORDER_TOTAL_LOWORDERFEE_DESTINATION) {
             case 'national':
                 if ($order->delivery['country_id'] == STORE_COUNTRY) {
                     $pass = true;
                 }
                 break;
             case 'international':
                 if ($order->delivery['country_id'] != STORE_COUNTRY) {
                     $pass = true;
                 }
                 break;
             case 'both':
                 $pass = true;
                 break;
             default:
                 $pass = false;
                 break;
         }
         //        if ( ($pass == true) && ( ($order->info['total'] - $order->info['shipping_cost']) < MODULE_ORDER_TOTAL_LOWORDERFEE_ORDER_UNDER) ) {
         if ($pass == true && $order->subtotal < MODULE_ORDER_TOTAL_LOWORDERFEE_ORDER_UNDER) {
             $charge_it = 'true';
             $cart_content_type = $gBitCustomer->mCart->get_content_type();
             $gv_content_only = $gBitCustomer->mCart->gv_only();
             if ($cart_content_type == 'physical' or $cart_content_type == 'mixed') {
                 $charge_it = 'true';
             } else {
                 // check to see if everything is virtual, if so - skip the low order fee.
                 if ($cart_content_type == 'virtual' and MODULE_ORDER_TOTAL_LOWORDERFEE_VIRTUAL == 'true') {
                     $charge_it = 'false';
                     if ($gv_content_only > 0 and MODULE_ORDER_TOTAL_LOWORDERFEE_GV == 'false') {
                         $charge_it = 'true';
                     }
                 }
                 if ($gv_content_only > 0 and MODULE_ORDER_TOTAL_LOWORDERFEE_GV == 'true') {
                     // check to see if everything is gift voucher, if so - skip the low order fee.
                     $charge_it = 'false';
                     if ($cart_content_type == 'virtual' and MODULE_ORDER_TOTAL_LOWORDERFEE_VIRTUAL == 'false') {
                         $charge_it = 'true';
                     }
                 }
             }
             if ($charge_it == 'true') {
                 $tax = zen_get_tax_rate(MODULE_ORDER_TOTAL_LOWORDERFEE_TAX_CLASS, $order->delivery['country']['countries_id'], $order->delivery['zone_id']);
                 $tax_description = zen_get_tax_description(MODULE_ORDER_TOTAL_LOWORDERFEE_TAX_CLASS, $order->delivery['country']['countries_id'], $order->delivery['zone_id']);
                 // calculate from flat fee or percentage
                 if (substr(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, -1) == '%') {
                     $low_order_fee = $order->subtotal * (MODULE_ORDER_TOTAL_LOWORDERFEE_FEE / 100);
                 } else {
                     $low_order_fee = MODULE_ORDER_TOTAL_LOWORDERFEE_FEE;
                 }
                 $order->info['tax'] += zen_calculate_tax($low_order_fee, $tax);
                 $order->info['tax_groups']["{$tax_description}"] += zen_calculate_tax($low_order_fee, $tax);
                 $order->info['total'] += $low_order_fee + zen_calculate_tax($low_order_fee, $tax);
                 $this->output[] = array('title' => $this->title . ':', 'text' => $currencies->format(zen_add_tax($low_order_fee, $tax), true, $order->info['currency'], $order->info['currency_value']), 'value' => zen_add_tax($low_order_fee, $tax));
             }
         }
     }
 }
                } else {
                    // shipping method with sub methods (multipickup)
                    for ($j = 0, $n2 = sizeof($quotes[$i]['methods']); $j < $n2; $j++) {
                        $thisquoteid = $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'];
                        $ShipTxt .= '<tr class="' . $extra . '">';
                        $ShipTxt .= '<td class="main">' . $quotes[$i]['icon'] . '&nbsp;</td>';
                        if ($quotes[$i]['error']) {
                            $ShipTxt .= '<td colspan="2" class="main">' . $quotes[$i]['module'] . '&nbsp;';
                            $ShipTxt .= '(' . $quotes[$i]['error'] . ')</td></tr>';
                        } else {
                            if ($selected_shipping['id'] == $thisquoteid) {
                                $ShipTxt .= '<td class="main"><strong>' . $quotes[$i]['module'] . '&nbsp;';
                                $ShipTxt .= '(' . $quotes[$i]['methods'][$j]['title'] . ')</strong></td><td align="right" class="main"><strong>' . $currencies->format(zen_add_tax($quotes[$i]['methods'][$j]['cost'], $quotes[$i]['tax'])) . '</strong></td></tr>';
                            } else {
                                $ShipTxt .= '<td class="main">' . $quotes[$i]['module'] . '&nbsp;';
                                $ShipTxt .= '(' . $quotes[$i]['methods'][$j]['title'] . ')</td><td align="right" class="main">' . $currencies->format(zen_add_tax($quotes[$i]['methods'][$j]['cost'], $quotes[$i]['tax'])) . '</td></tr>';
                            }
                        }
                    }
                }
            }
        }
    }
    $ShipTxt .= '</table></form>';
    $info_box_contents = array();
    $info_box_contents[] = array('text' => $ShipTxt);
    new infoBox($info_box_contents);
}
// Only do when something is in the cart
?>
             </td></tr></table>
</strong></td>
        </tr>
<?php 
}
for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
    echo '        <tr>' . "\n" . '          <td class="main" align="right" valign="top" width="30">' . $order->products[$i]['qty'] . '&nbsp;x</td>' . "\n" . '          <td class="main" valign="top">' . $order->products[$i]['name'];
    if (isset($order->products[$i]['attributes']) && sizeof($order->products[$i]['attributes']) > 0) {
        for ($j = 0, $n2 = sizeof($order->products[$i]['attributes']); $j < $n2; $j++) {
            echo '<br /><nobr><small>&nbsp;<i> - ' . $order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value'] . '</i></small></nobr>';
        }
    }
    echo '          </td>' . "\n";
    if (sizeof($order->info['tax_groups']) > 1) {
        echo '        <td class="main" valign="top" align="right">' . zen_display_tax_value($order->products[$i]['tax']) . '%</td>' . "\n";
    }
    echo '          <td class="main" align="right" valign="top">' . $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']) : '') . '</td>' . "\n" . '        </tr>' . "\n";
}
?>
      </table>
      <table border="0" width="100%" cellspacing="0" cellpadding="2">
<?php 
for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
    echo '        <tr>' . "\n" . '          <td class="' . str_replace('_', '-', $order->totals[$i]['class']) . '-Text" align="right" width="100%">' . $order->totals[$i]['title'] . '</td>' . "\n" . '          <td class="' . str_replace('_', '-', $order->totals[$i]['class']) . '-Amount" align="right" nowrap="nowrap">' . $order->totals[$i]['text'] . '</td>' . "\n" . '        </tr>' . "\n";
}
?>
      </table>
    </td>
  </tr>
  <tr>
    <td colspan="2" width="100%">
<?php 
Example #13
0
 function display_price($products_price, $products_tax, $quantity = 1, $currency_type = '', $currency_value = '')
 {
     return $this->format(zen_add_tax($products_price, $products_tax) * $quantity, true, $currency_type, $currency_value);
 }
Example #14
0
 function quote($pShippingWeight, $method = '', $module = '')
 {
     global $currencies;
     $quotes_array = array();
     if (!empty($this->modules)) {
         $shipHash['method'] = $method;
         $shipHash['shipping_num_boxes'] = 1;
         $shipHash['shipping_weight'] = $pShippingWeight;
         $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];
         if (SHIPPING_MAX_WEIGHT <= $shipHash['shipping_weight']) {
             // large box add padding
             $shipHash['shipping_weight'] = $shipHash['shipping_weight'] + $shipHash['shipping_weight'] * ($zc_large_percent / 100) + $zc_large_weight;
         } else {
             // add tare weight < large
             $shipHash['shipping_weight'] = $shipHash['shipping_weight'] + $shipHash['shipping_weight'] * ($zc_tare_percent / 100) + $zc_tare_weight;
         }
         if ($shipHash['shipping_weight'] > SHIPPING_MAX_WEIGHT) {
             // Split into many boxes
             $shipHash['shipping_num_boxes'] = ceil($shipHash['shipping_weight'] / SHIPPING_MAX_WEIGHT);
             $shipHash['shipping_weight'] = $shipHash['shipping_weight'] / $shipHash['shipping_num_boxes'];
         }
         $include_quotes = array();
         reset($this->modules);
         while (list(, $value) = each($this->modules)) {
             $base = basename($value);
             $class = substr($base, 0, strrpos($base, '.'));
             if (zen_not_null($module)) {
                 if ($module == $class && $GLOBALS[$class]->enabled) {
                     $include_quotes[] = $class;
                 }
             } elseif ($GLOBALS[$class]->enabled) {
                 $include_quotes[] = $class;
             }
         }
         $size = sizeof($include_quotes);
         for ($i = 0; $i < $size; $i++) {
             if ($quotes = $GLOBALS[$include_quotes[$i]]->quote($shipHash)) {
                 if (!empty($quotes['methods'])) {
                     foreach (array_keys($quotes['methods']) as $j) {
                         $quotes['methods'][$j]['cost_add_tax'] = zen_add_tax($quotes['methods'][$j]['cost'], isset($quotes['tax']) ? $quotes['tax'] : 0);
                         $quotes['methods'][$j]['format_add_tax'] = $currencies->format($quotes['methods'][$j]['cost_add_tax']);
                     }
                 }
                 $quotes_array[] = $quotes;
             }
         }
     }
     return $quotes_array;
 }
Example #15
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 #16
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'];
     }
 }
 function process()
 {
     global $order, $currencies, $cod_cost;
     if (MODULE_ORDER_TOTAL_MONEY_COD_STATUS == 'true') {
         $tax = zen_get_tax_rate(MODULE_ORDER_TOTAL_MONEY_COD_TAX_CLASS);
         if ($_SESSION['payment'] == 'cod' && $_GET['main_page'] == 'checkout_confirmation') {
             // #8883 リクエストを改ざんして代金引替を指定した場合をエラーにする。
             //       代金引換を指定後、確認画面で離脱した場合は、代金引換がセッションに積まれたままになるので
             //       checkout_payment 画面でもこのチェックが実行される。
             //       従って画面をチェックする。
             if ($order->info['subtotal'] + $order->info['shipping_cost'] >= MODULE_ORDER_TOTAL_MONEY_COD_FEE_LIMIT) {
                 // コンテンツが出力されているのでリダイレクトできない。
                 die('Bad request.');
             }
         }
         $cod_fee_target_money = $order->info['subtotal'];
         /*
         // ot_subpoint 側の実装がよく分かってないので未対応とする
                 // #8883 ポイントによる支払いは手数料計算対象金額に含めない。
                 if ( isset($GLOBALS['otsubpoint']) ) {
                   $save_value = $GLOBALS['ot_subpoint']->pre_process_if_not_last_call();
         
                   $GLOBALS['ot_subpoint']->process();
                   $cod_fee_target_money = $cod_fee_target_money - $GLOBALS['ot_subpoint']->deduction;
         
                   $GLOBALS['ot_subpoint']->post_process_if_not_last_call($save_value);
                 }
         */
         // #8883 配送料は手数料計算対象金額に含める。
         $cod_fee_target_money = $cod_fee_target_money + $order->info['shipping_cost'];
         $cod_cost = "";
         if ($_SESSION['payment'] == 'cod' && $cod_fee_target_money < MODULE_ORDER_TOTAL_MONEY_COD_FEE_LIMIT) {
             $tmp_cod_fee_list = split("[:,]", MODULE_ORDER_TOTAL_MONEY_COD_FEE_LIST);
             $list = array();
             $i = 0;
             foreach ($tmp_cod_fee_list as $value) {
                 if ($i % 2 == 0) {
                     $list[] = array("limit" => $value, "fee" => $tmp_cod_fee_list[$i + 1]);
                 }
                 $i++;
             }
             //手数料計算
             foreach ($list as $k => $v) {
                 if ($v['limit'] >= $cod_fee_target_money) {
                     if ($k == 0) {
                         $cod_cost = $v['fee'];
                         break;
                     }
                 }
                 if (isset($list[$k + 1]) && $list[$k + 1]['limit'] >= $cod_fee_target_money) {
                     $cod_cost = $list[$k + 1]['fee'];
                     break;
                 }
             }
             if ($cod_cost == "") {
                 $cod_cost = 0;
             }
             $order->info['tax'] += zen_calculate_tax($cod_cost, $tax);
             $order->info['tax_groups']["{$tax}"] += zen_calculate_tax($cod_cost, $tax);
             $order->info['total'] += $cod_cost + zen_calculate_tax($cod_cost, $tax);
             $this->output[] = array('title' => TEXT_INFO_ORDER_TOTAL_MONEY_COD_TITLE . ':', 'text' => $currencies->format(zen_add_tax($cod_cost, $tax), true, $order->info['currency'], $order->info['currency_value']), 'value' => zen_add_tax($cod_cost, $tax));
         }
     }
 }
Example #18
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;
         }
     }
 }
function draw_packing_slip_order($order, &$pdf)
{
    global $db;
    require_once DIR_WS_CLASSES . 'currencies.php';
    $currencies = new currencies();
    // prepare order-status pulldown list
    $orders_statuses = array();
    $orders_status_array = array();
    $orders_status = $db->Execute("select orders_status_id, orders_status_name\n                from " . TABLE_ORDERS_STATUS . "\n                where language_id = '" . (int) $_SESSION['languages_id'] . "'");
    while (!$orders_status->EOF) {
        $orders_statuses[] = array('id' => $orders_status->fields['orders_status_id'], 'text' => $orders_status->fields['orders_status_name'] . ' [' . $orders_status->fields['orders_status_id'] . ']');
        $orders_status_array[$orders_status->fields['orders_status_id']] = $orders_status->fields['orders_status_name'];
        $orders_status->MoveNext();
    }
    /* display order information header */
    $pdf->SetFont('Arial', 'B', 6);
    /* order object doesn't include orderid.  added id to info so we can retrieve it here */
    $pdf->Cell(120, 14, ENTRY_ORDER_ID . $order->info['id']);
    $pdf->Cell(236, 14, ENTRY_DATE_PURCHASED . ' ' . zen_date_long($order->info['date_purchased']));
    $pdf->MultiCell(220, 14, ENTRY_PAYMENT_METHOD . ' ' . $order->info['payment_method']);
    $pdf->SetFont('Arial', '', 10);
    if (TAX_ID_NUMBER != '') {
        $pdf->SetFillColor(180, 180, 180);
        $pdf->Cell(30, 14, TABLE_HEADING_QTY, 1, 0, '', 1);
        $pdf->Cell(160, 14, TABLE_HEADING_PRODUCTS, 1, 0, '', 1);
        $pdf->Cell(160, 14, TABLE_HEADING_PRODUCTS_MODEL, 1, 0, '', 1);
        $pdf->Cell(60, 14, TABLE_HEADING_TAX, 1, 0, '', 1);
        $pdf->Cell(78, 14, TABLE_HEADING_PRICE_NO_TAX, 1, 0, 'R', 1);
        $pdf->MultiCell(78, 14, TABLE_HEADING_TOTAL_NO_TAX, 1, 'R', 1);
    } else {
        $pdf->SetFillColor(180, 180, 180);
        $pdf->Cell(25, 14, TABLE_HEADING_QTY, 1, 0, '', 1);
        $pdf->Cell(120, 14, TABLE_HEADING_PRODUCTS, 1, 0, '', 1);
        $pdf->Cell(120, 14, TABLE_HEADING_PRODUCTS_MODEL, 1, 0, '', 1);
        $pdf->Cell(40, 14, TABLE_HEADING_TAX, 1, 0, 'R', 1);
        $pdf->Cell(68, 14, TABLE_HEADING_PRICE_EXCLUDING_TAX, 1, 0, 'R', 1);
        $pdf->Cell(68, 14, TABLE_HEADING_PRICE_INCLUDING_TAX, 1, 0, 'R', 1);
        $pdf->Cell(68, 14, TABLE_HEADING_TOTAL_EXCLUDING_TAX, 1, 0, 'R', 1);
        $pdf->MultiCell(68, 14, TABLE_HEADING_TOTAL_INCLUDING_TAX, 1, 'R', 1);
    }
    $pdf->SetFillColor(256, 256, 256);
    if (TAX_ID_NUMBER != '') {
        /* draw order items in table when tax ID number is NOT null*/
        for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
            /* BEGIN update (Loose Chicken Software Development, david@loosechicken.com 01-03-2011) */
            /* break attributes onto new lines */
            $prod_name = $order->products[$i]['name'];
            $prod_attrs = array();
            if (isset($order->products[$i]['attributes']) && sizeof($order->products[$i]['attributes']) > 0) {
                for ($j = 0, $k = sizeof($order->products[$i]['attributes']); $j < $k; $j++) {
                    $prod_attrs[] = $order->products[$i]['attributes'][$j]['option'] . ': ' . zen_output_string_protected($order->products[$i]['attributes'][$j]['value']);
                }
            }
            /* BEGIN add (Loose Chicken Software Development, david@loosechicken.com 01-07-2011) */
            /* Find height of model and Product names */
            $h_model = $pdf->MultiCellHeight(160, 14, $order->products[$i]['model'], 'LRT', 'L', 1);
            $h = $h_model;
            $h_product_name = $pdf->MultiCellHeight(160, 14, $prod_name, 'LRT', 'L', 1);
            $h = $h_product_name > $h ? $h_product_name : $h;
            /* If cells would be too tall, force a page break */
            if ($pdf->y + $h > $pdf->PageBreakTrigger) {
                $pdf->AddPage();
            }
            /* Get current y, to use with $h_product_name later when placing attributes */
            $y_top = $pdf->getY();
            /* END add (Loose Chicken Software Development 01-07-2011) */
            $pdf->Cell(30, 14, $order->products[$i]['qty'], 'LRT', 0, '', 1);
            /* BEGIN update (Loose Chicken Software Development, david@loosechicken.com 01-07-2011) */
            /* 
             * Changed Cell to MultiCell for the test wrapping. 
             * Because MultiCell doesn't leave the cursor in the right place:
             * Retrived cursor before drawing cell, and placed it afterward base on origal location and cell width 
             */
            $y = $pdf->getY();
            $x = $pdf->getX();
            $pdf->MultiCell(160, 14, $prod_name, 'LRT', 'L', 1);
            $max_y = $pdf->getY();
            $pdf->setXY($x + 160, $y);
            $y = $pdf->getY();
            $x = $pdf->getX();
            $pdf->MultiCell(160, 14, $order->products[$i]['model'], 'LRT', 'L', 1);
            $max_y = $pdf->getY() > $max_y ? $pdf->getY() : $max_y;
            $pdf->setXY($x + 160, $y);
            /* END update (Loose Chicken Software Development, david@loosechicken.com 01-07-2011) */
            $pdf->Cell(60, 14, ENTRY_NO_TAX, 'LRT', 0, '', 1);
            $pdf->Cell(78, 14, $currencies->format($order->products[$i]['final_price'], true, $order->info['currency'], $order->info['currency_value']), 'LRT', 0, 'R', 1);
            $pdf->MultiCell(78, 14, $currencies->format($order->products[$i]['final_price'] * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']), 'LRT', 'R', 1);
            /* BEGIN add (Loose Chicken Software Development, david@loosechicken.com 01-07-2011) */
            /* 
             * Draw cell borders in case model or product name wrapped and thus would leave blank
             * spaces on the other cells. (This must be transparent so the cells are not overritten)
             */
            $x = $pdf->GetX();
            $y = $pdf->GetY();
            if ($max_y > $y) {
                $h = $max_y - $y;
                $pdf->Cell(30, $h, '', 'LR', 0, '', 0);
                $pdf->Cell(160, $h, '', 'LR', 0, '', 0);
                $pdf->Cell(160, $h, '', 'LR', 0, '', 0);
                $pdf->Cell(60, $h, '', 'LR', 0, '', 0);
                $pdf->Cell(78, $h, '', 'LR', 0, '', 0);
                $pdf->MultiCell(78, $h, '', 'LR', 'J', 0);
                $pdf->setXY($x, $y);
            }
            $max_y_page = $pdf->PageNo();
            /* Place attributes below product_name */
            $pdf->setXY($x, $y_top + $h_product_name);
            /* END add (Loose Chicken Software Development, david@loosechicken.com 01-07-2011) */
            $pdf->SetFont('Arial', '', 8);
            $pdf->SetTextColor(40, 40, 40);
            foreach ($prod_attrs as $prod_attr) {
                $pdf->Cell(30, 10, '', 'LR', 0, '', 1);
                $pdf->Cell(160, 10, '  - ' . $prod_attr, 'LR', 0, '', 1);
                $pdf->Cell(160, 10, '', 'LR', 0, '', 1);
                $pdf->Cell(60, 10, '', 'LR', 0, '', 1);
                $pdf->Cell(78, 10, '', 'LR', 0, '', 1);
                $pdf->MultiCell(78, 10, '', 'LR', 'J', 1);
            }
            $x = $pdf->GetX();
            $y = $pdf->GetY();
            /* BEGIN add (Loose Chicken Software Development, david@loosechicken.com 01-07-2011) */
            /* 
             * If after drawing the attributes the cursor is not as low as after drawing 
             * the model and product name lower the cursor for the drawing of the bottom line 
             */
            if ($max_y > $y && $max_y_page == $pdf->PageNo()) {
                $y = $max_y;
            }
            /* END add (Loose Chicken Software Development, david@loosechicken.com 01-07-2011) */
            $pdf->Line($x, $y, $x + 30 + 160 + 160 + 60 + 78 + 78, $y);
            $pdf->SetTextColor(0, 0, 0);
            $pdf->SetFont('Arial', '', 10);
            /* END modification (Loose Chicken Software Development 01-03-2011) */
        }
    } else {
        /* draw order items in table  when tax ID number IS null*/
        for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
            /* BEGIN update (Loose Chicken Software Development, david@loosechicken.com 01-03-2011) */
            /* break attributes onto new lines */
            $prod_name = $order->products[$i]['name'];
            $prod_attrs = array();
            if (isset($order->products[$i]['attributes']) && sizeof($order->products[$i]['attributes']) > 0) {
                for ($j = 0, $k = sizeof($order->products[$i]['attributes']); $j < $k; $j++) {
                    $prod_attrs[] = $order->products[$i]['attributes'][$j]['option'] . ': ' . zen_output_string_protected($order->products[$i]['attributes'][$j]['value']);
                }
            }
            /* BEGIN add (Loose Chicken Software Development, david@loosechicken.com 01-07-2011) */
            /* Find height of model and Product names */
            $h_model = $pdf->MultiCellHeight(120, 14, $order->products[$i]['model'], 'LRT', 'L', 1);
            $h = $h_model;
            $h_product_name = $pdf->MultiCellHeight(120, 14, $prod_name, 'LRT', 'L', 1);
            $h = $h_product_name > $h ? $h_product_name : $h;
            /* If cells would be too tall, force a page break */
            if ($pdf->y + $h > $pdf->PageBreakTrigger) {
                $pdf->AddPage();
            }
            /* Get current y, to use with $h_product_name later when placing attributes */
            $y_top = $pdf->getY();
            /* END add (Loose Chicken Software Development 01-07-2011) */
            $pdf->Cell(25, 14, $order->products[$i]['qty'], 'LRT', 0, '', 1);
            /* BEGIN update (Loose Chicken Software Development, david@loosechicken.com 01-07-2011) */
            /* 
             * Changed Cell to MultiCell for the test wrapping. 
             * Because MultiCell doesn't leave the cursor in the right place:
             * Retrived cursor before drawing cell, and placed it afterward base on origal location and cell width 
             */
            $y = $pdf->getY();
            $x = $pdf->getX();
            $pdf->MultiCell(120, 14, $prod_name, 'LRT', 'L', 1);
            $max_y = $pdf->getY();
            $pdf->setXY($x + 120, $y);
            $y = $pdf->getY();
            $x = $pdf->getX();
            $pdf->MultiCell(120, 14, $order->products[$i]['model'], 'LRT', 'L', 1);
            $max_y = $pdf->getY() > $max_y ? $pdf->getY() : $max_y;
            $pdf->setXY($x + 120, $y);
            /* END update (Loose Chicken Software Development, david@loosechicken.com 01-07-2011) */
            /*$pdf->Cell(40, 14, zen_display_tax_value($order->products[$i]['tax']) . '%', 'LRT', 0, 'R', 1);     
                      
            	     $pdf->Cell(68, 14, $currencies->format($order->products[$i]['final_price'], true, $order->info['currency'], $order->info['currency_value']), 'LRT', 0, 'R', 1);     
                      
            	   
            	    $pdf->Cell(68, 14, $currencies->format(zen_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']), 'LRT', 0, 'R', 1);
            		
            		
            		
                       $pdf->Cell(68, 14, $currencies->format($order->products[$i]['final_price'] * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']), 'LRT', 0, 'R', 1); 
            		
            		
            		    
                       $pdf->MultiCell(68, 14, $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']), 'LRT', 'R', 1);
                                */
            $pdf->Cell(40, 14, html_entity_decode(zen_display_tax_value($order->products[$i]['tax']) . '%', ENT_QUOTES, "ISO-8859-15"), 'LRT', 0, 'R', 1);
            if ($order->info['currency'] == 'EUR') {
                $f1 = str_replace('&euro;', '€', $currencies->format($order->products[$i]['final_price'], true, $order->info['currency'], $order->info['currency_value']));
                $pdf->Cell(68, 14, html_entity_decode($f1), 'LRT', 'R', 1);
            } else {
                $pdf->Cell(68, 14, html_entity_decode($currencies->format($order->products[$i]['final_price'], true, $order->info['currency'], $order->info['currency_value']), ENT_QUOTES, "ISO-8859-15"), 'LRT', 0, 'R', 1);
            }
            if ($order->info['currency'] == 'EUR') {
                $f2 = str_replace('&euro;', '€', $currencies->format(zen_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']));
                $pdf->Cell(68, 14, html_entity_decode($f2), 'LRT', 'R', 1);
            } else {
                $pdf->Cell(68, 14, html_entity_decode($currencies->format(zen_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']), ENT_QUOTES, "ISO-8859-15"), 'LRT', 0, 'R', 1);
            }
            if ($order->info['currency'] == 'EUR') {
                $f3 = str_replace('&euro;', '€', $currencies->format($order->products[$i]['final_price'] * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']));
                $pdf->Cell(68, 14, html_entity_decode($f3), 'LRT', 'R', 1);
            } else {
                $pdf->Cell(68, 14, html_entity_decode($currencies->format($order->products[$i]['final_price'] * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']), ENT_QUOTES, "ISO-8859-15"), 'LRT', 0, 'R', 1);
            }
            if ($order->info['currency'] == 'EUR') {
                $f = str_replace('&euro;', '€', $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']));
                $pdf->MultiCell(68, 14, html_entity_decode($f), 'LRT', 'R', 1);
            } else {
                $pdf->MultiCell(68, 14, html_entity_decode($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']), ENT_QUOTES, "ISO-8859-15"), 'LRT', 'R', 1);
            }
            /* BEGIN add (Loose Chicken Software Development, david@loosechicken.com 01-07-2011) */
            /* 
             * Draw cell borders in case model or product name wrapped and thus would leave blank
             * spaces on the other cells. (This must be transparent so the cells are not overritten)
             */
            $x = $pdf->GetX();
            $y = $pdf->GetY();
            if ($max_y > $y) {
                $h = $max_y - $y;
                $pdf->Cell(25, $h, '', 'LR', 0, '', 0);
                $pdf->Cell(120, $h, '', 'LR', 0, '', 0);
                $pdf->Cell(120, $h, '', 'LR', 0, '', 0);
                $pdf->Cell(40, $h, '', 'LR', 0, '', 0);
                $pdf->Cell(68, $h, '', 'LR', 0, '', 0);
                $pdf->Cell(68, $h, '', 'LR', 0, '', 0);
                $pdf->Cell(68, $h, '', 'LR', 0, '', 0);
                $pdf->MultiCell(68, $h, '', 'LR', 'J', 0);
                $pdf->setXY($x, $y);
            }
            $max_y_page = $pdf->PageNo();
            /* Place attributes below product_name */
            $pdf->setXY($x, $y_top + $h_product_name);
            /* END add (Loose Chicken Software Development, david@loosechicken.com 01-07-2011) */
            $pdf->SetFont('Arial', '', 8);
            $pdf->SetTextColor(40, 40, 40);
            foreach ($prod_attrs as $prod_attr) {
                $pdf->Cell(25, 10, '', 'LR', 0, '', 1);
                $pdf->Cell(120, 10, '  - ' . $prod_attr, 'LR', 0, '', 1);
                $pdf->Cell(120, 10, '', 'LR', 0, '', 1);
                $pdf->Cell(40, 10, '', 'LR', 0, '', 1);
                $pdf->Cell(68, 10, '', 'LR', 0, '', 1);
                $pdf->Cell(68, 10, '', 'LR', 0, '', 1);
                $pdf->Cell(68, 10, '', 'LR', 0, '', 1);
                $pdf->MultiCell(68, 10, '', 'LR', 'J', 1);
            }
            $x = $pdf->GetX();
            $y = $pdf->GetY();
            /* BEGIN add (Loose Chicken Software Development, david@loosechicken.com 01-07-2011) */
            /* 
             * If after drawing the attributes the cursor is not as low as after drawing 
             * the model and product name lower the cursor for the drawing of the bottom line 
             */
            if ($max_y > $y && $max_y_page == $pdf->PageNo()) {
                $y = $max_y;
            }
            /* END add (Loose Chicken Software Development, david@loosechicken.com 01-07-2011) */
            $pdf->Line($x, $y, $x + 25 + 120 + 120 + 40 + 68 + 68 + 68 + 68, $y);
            $pdf->SetTextColor(0, 0, 0);
            $pdf->SetFont('Arial', '', 10);
            /* END modification (Loose Chicken Software Development 01-03-2011) */
        }
    }
    /* order cost summary */
    $pdf->Ln();
    for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
        $title = strip_tags($order->totals[$i]['title']);
        $text = strip_tags($order->totals[$i]['text']);
        /* $pdf->Cell(516, 14, $title, 0, 0, 'R');             
           $pdf->MultiCell(50, 14, $text, 0, 'R'); */
        $pdf->Cell(516, 14, html_entity_decode($title, ENT_QUOTES, "ISO-8859-15"), 0, 0, 'R');
        //echo substr($text,0,5);
        if (substr($text, 0, 5) == '&euro') {
            $a = str_replace('&euro;', '€', $text);
            $pdf->MultiCell(50, 14, html_entity_decode($a, ENT_QUOTES, "ISO-8859-15"), 0, 0, 'R');
        } else {
            $pdf->MultiCell(50, 14, html_entity_decode($text, ENT_QUOTES, "ISO-8859-15"), 0, 0, 'R');
        }
    }
    /* order balance */
    /*$orders_balance = $db->Execute("select orders_id , balance_due
    				from " . TABLE_ORDERS . "
    					where orders_id = '" . zen_db_input($order->info['id']) . "'
    					order by orders_id");
    		$balance_due = $orders_balance->fields['balance_due'];*/
    $pdf->SetFont('Arial', 'B', '');
    require_once DIR_WS_CLASSES . 'super_order.php';
    $so = new super_order($order->info['id']);
    $pdf->Cell(516, 14, 'Amount Paid: ', 0, 0, 'R');
    // $pdf->MultiCell(50, 14, $currencies->format($so->amount_applied), 0, 'R');
    //  $pdf->MultiCell(50, 14, $currencies->format($balance_due), 0, 'R');
    // $pdf->MultiCell(50, 14, $currencies->format($so->balance_due), 0, 'R');
    $var1 = substr($currencies->format($so->amount_applied), 0, 5);
    if ($var1 == '&euro') {
        $pdf->MultiCell(50, 14, '€' . $so->amount_applied, 0, 'R');
    } else {
        $pdf->MultiCell(50, 14, html_entity_decode($currencies->format($so->amount_applied), ENT_QUOTES, "ISO-8859-15"), 0, 'R');
    }
    $pdf->Cell(516, 14, 'Balance Due:', 0, 0, 'R');
    $var = substr($currencies->format($so->balance_due), 0, 5);
    if ($var == '&euro') {
        $pdf->MultiCell(50, 14, '€' . $so->balance_due, 0, 'R');
    } else {
        $pdf->MultiCell(50, 14, html_entity_decode($currencies->format($so->balance_due), ENT_QUOTES, "ISO-8859-15"), 0, 'R');
    }
    //$pdf->SetFont('Arial','', 7);
    if (ORDER_COMMENTS_PACKING_SLIP > 0) {
        $pdf->Ln();
        $pdf->SetFillColor(180, 180, 180);
        $pdf->SetFont('Arial', 'B', 10);
        $pdf->MultiCell(576, 14, 'Order Comments & Status', 'B');
        $pdf->SetFont('Arial', '', 7);
        $pdf->SetFillColor(256, 256, 256);
        $orders_history = $db->Execute("select orders_status_id, date_added, customer_notified, comments\n                    from " . TABLE_ORDERS_STATUS_HISTORY . "\n                    where orders_id = '" . zen_db_input($order->info['id']) . "' and customer_notified >= 0\n                    order by date_added");
        $count_comments = 0;
        if ($orders_history->RecordCount() >= 1 && ORDER_COMMENTS_PACKING_SLIP == 1) {
            while (!$orders_history->EOF) {
                if ($orders_history->fields['comments'] != '' && strpos($orders_history->fields['comments'], 'PayPal status:') === false) {
                    $count_comments++;
                    $pdf->Cell(120, 14, zen_datetime_short($orders_history->fields['date_added']));
                    $pdf->MultiCell(456, 14, $orders_status_array[$orders_history->fields['orders_status_id']]);
                    $pdf->Cell(27, 14, '', 0, 0, '', 1);
                    /* BEGIN modify (Loose Chicken Software Development, david@loosechicken.com 01-07-2011) */
                    /* removed function zen_db_output, which was converting output into html code */
                    //$pdf->MultiCell(549, 14, (zen_db_output($orders_history->fields['comments'])), 'B');
                    $pdf->MultiCell(549, 14, $orders_history->fields['comments'], 'B');
                    /* END modify (Loose Chicken Software Development, david@loosechicken.com 01-07-2011) */
                    $pdf->SetLineWidth(0.5);
                    $pdf->Line(18, $pdf->GetY(), 594, $pdf->GetY());
                }
                $orders_history->MoveNext();
                /*if (ORDER_COMMENTS_PACKING_SLIP == 1 && $count_comments >= 1) {
                     break;
                  } */
            }
        }
        if ($count_comments == 0) {
            $pdf->MultiCell(576, 14, TEXT_NO_ORDER_HISTORY, 'B');
        }
    }
}
                echo $quotes[$i]['error'];
                ?>
</div><?php 
            } else {
                $quote_id = $quotes[$i]['id'];
                for ($j = 0, $n2 = sizeof($quotes[$i]['methods']); $j < $n2; $j++) {
                    $method_id = $quotes[$i]['methods'][$j]['id'];
                    $checked = $quote_id . $method_id == $_SESSION['shipping']['id'] ? 'true' : 'false';
                    $method_cost = $quotes[$i]['methods'][$j]['cost'];
                    ?>
              <div class='clearfix'>
                <div class="pull-right"><strong><?php 
                    if ($n > 1 || $n2 > 1) {
                        echo $currencies->format(zen_add_tax($method_cost, isset($quotes[$i]['tax']) ? $quotes[$i]['tax'] : 0));
                    } else {
                        echo $currencies->format(zen_add_tax($method_cost, $quotes[$i]['tax'])) . zen_draw_hidden_field('shipping', $quote_id . '_' . $method_id);
                    }
                    ?>
                </strong></div>
                <div class='form-group'>
                  <label for="ship-<?php 
                    echo $quote_id . '-' . $method_id;
                    ?>
" class="checkbox-inline" ><?php 
                    echo zen_draw_radio_field('shipping', $quote_id . '_' . $method_id, $checked, 'id="ship-' . $quote_id . '-' . $method_id . '"');
                    echo $quotes[$i]['methods'][$j]['title'];
                    ?>
                  </label>
                </div>
              </div><?php 
                    $radio_buttons++;
            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" valign="top">';
    if ($display_tax) {
        echo zen_display_tax_value($order->products[$i]['tax']) . '%';
    } else {
        echo ENTRY_NO_TAX;
    }
    echo '</td>' . "\n";
    if ($display_tax) {
        echo '        <td class="dataTableContent" align="right" valign="top"><strong>' . $currencies->format($order->products[$i]['final_price'], true, $order->info['currency'], $order->info['currency_value']) . '</strong></td>' . "\n" . '        <td class="dataTableContent" align="right" valign="top"><strong>' . $currencies->format(zen_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']) . '</strong></td>' . "\n" . '        <td class="dataTableContent" align="right" valign="top"><strong>' . $currencies->format($order->products[$i]['final_price'] * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . '</strong></td>' . "\n" . '        <td class="dataTableContent" align="right" valign="top"><strong>' . $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']) . '</strong></td>' . "\n";
        echo '      </tr>' . "\n";
    } else {
        echo '        <td class="dataTableContent" align="right" valign="top"><strong>' . $currencies->format($order->products[$i]['final_price'], true, $order->info['currency'], $order->info['currency_value']) . '</strong></td>' . "\n" . '        <td class="dataTableContent" align="right" valign="top"><strong>' . $currencies->format($order->products[$i]['final_price'] * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . '</strong></td>' . "\n" . '      </tr>' . "\n";
    }
}
?>
      <tr>
        <td colspan="8" align="right"><table border="0" cellpadding="2" cellspacing="0">

<!-- BOF added to get currency type and value for totals (modified for ZenCart 1.5.3 and beyond by retched) -->
                <?php 
$dbc = $db->Execute("select currency, currency_value from " . TABLE_ORDERS . " where orders_id ='" . $_GET['oID'] . "'");
$cu = $dbc->fields['currency'];
$cv = $dbc->fields['currency_value'];
?>
                    if ($checked == true || $n == 1 && $n2 == 1) {
                        //echo '      <div id="defaultSelected" class="moduleRowSelected">' . "\n";
                        //} else {
                        //echo '      <div class="moduleRow">' . "\n";
                    }
                    if ($n > 1 || $n2 > 1) {
                        ?>
<div class="important forward"><?php 
                        echo $currencies->format(zen_add_tax($quotes[$i]['methods'][$j]['cost'], isset($quotes[$i]['tax']) ? $quotes[$i]['tax'] : 0));
                        ?>
</div>
<?php 
                    } else {
                        ?>
<div class="important forward"><?php 
                        echo $currencies->format(zen_add_tax($quotes[$i]['methods'][$j]['cost'], $quotes[$i]['tax'])) . zen_draw_hidden_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id']);
                        ?>
</div>
<?php 
                    }
                    ?>

<?php 
                    echo zen_draw_radio_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'], $checked, 'id="ship-' . $quotes[$i]['id'] . '-' . $quotes[$i]['methods'][$j]['id'] . '"');
                    ?>
 
<label for="ship-<?php 
                    echo $quotes[$i]['id'] . '-' . $quotes[$i]['methods'][$j]['id'];
                    ?>
" class="checkboxLabel" ><?php 
                    echo $quotes[$i]['methods'][$j]['title'];
            echo '            <td class="dataTableContent" valign="top" width="10">' . zen_draw_checkbox_field('incl_product_' . $i, 'yes') . '</td>' . "\n";
        }
        echo '            <td class="dataTableContent" valign="middle" align="left">' . $order->products[$i]['qty'] . '&nbsp;x&nbsp;' . $order->products[$i]['name'];
        if (isset($order->products[$i]['attributes']) && sizeof($order->products[$i]['attributes']) > 0) {
            for ($j = 0, $k = sizeof($order->products[$i]['attributes']); $j < $k; $j++) {
                echo '<br /><nobr><small>&nbsp;<i> - ' . $order->products[$i]['attributes'][$j]['option'] . ': ' . $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="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']) . ($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($order->products[$i]['final_price'] * $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>' . $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']) : '') . '</strong></td>' . "\n";
        echo '          </tr>' . "\n";
    }
    ?>
          <tr>
            <?php 
    if (sizeof($order->products) > 1) {
        ?>
            <td valign="top" colspan="2"><table border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td valign="top">&nbsp;&nbsp;<?php 
        echo zen_image(DIR_WS_IMAGES . 'arrow_south_east.gif');
        ?>
</td>
                <td valign="bottom" class="main"><input type="submit" value="<?php 
        echo BUTTON_SPLIT;
Example #24
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');
 function display_price($products_price, $products_tax, $quantity = 1)
 {
     return $this->format(zen_add_tax($products_price, $products_tax) * $quantity);
 }
 /**
  * Method to calculate cart totals(price and weight)
  *
  * @return void
  * @global object access to the db object
  */
 function calculate()
 {
     global $db;
     $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)) {
         $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 = $db->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')) {
                 // reset for priced by attributes
                 //            $products_price = $products->fields['products_price'];
                 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;
                 $this->free_shipping_price += zen_add_tax($products_price, $products_tax) * $qty;
                 $this->free_shipping_weight += $qty * $product->fields['products_weight'];
             }
             $this->total += zen_add_tax($products_price, $products_tax) * $qty;
             $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 = $db->Execute($attribute_price_query);
                 $new_attributes_price = 0;
                 $discount_type_id = '';
                 $sale_maker_discount = '';
                 // bottom total
                 //            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) $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);
                             $this->free_shipping_price -= $qty * zen_add_tax($shipping_attributes_price, $products_tax);
                         }
                         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);
                             $this->total -= $qty * zen_add_tax($new_attributes_price, $products_tax);
                         } else {
                             $this->total -= $qty * zen_add_tax($attribute_price->fields['options_values_price'], $products_tax);
                         }
                     } 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);
                             $this->free_shipping_price += $qty * zen_add_tax($shipping_attributes_price, $products_tax);
                         }
                         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);
                             $this->total += $qty * zen_add_tax($new_attributes_price, $products_tax);
                         } else {
                             $this->total += $qty * zen_add_tax($attribute_price->fields['options_values_price'], $products_tax);
                         }
                     }
                     // 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 = $db->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) {
                             $this->free_shipping_price += zen_add_tax($products_price, $products_tax) * $qty;
                             $this->free_shipping_item += $qty;
                         }
                         // adjust for attributes price
                         $this->free_shipping_price += $qty * zen_add_tax($new_attributes_price, $products_tax);
                         //die('I SEE B ' . $this->free_shipping_price);
                     }
                     //  echo 'I SEE ' . $this->total . ' vs ' . $this->free_shipping_price . ' items: ' . $this->free_shipping_item. '<br>';
                     ////////////////////////////////////////////////
                     // 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']);
                         $this->total += $qty * zen_add_tax($text_letters, $products_tax);
                         $this->total += $qty * zen_add_tax($text_words, $products_tax);
                     }
                     // 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']);
                         $this->total += $qty * zen_add_tax($added_charge, $products_tax);
                     }
                     // 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);
                         $this->total += $qty * zen_add_tax($added_charge, $products_tax);
                     }
                     //// one time charges
                     // attributes_price_onetime
                     if ($attribute_price->fields['attributes_price_onetime'] > 0) {
                         $this->total += zen_add_tax($attribute_price->fields['attributes_price_onetime'], $products_tax);
                     }
                     // 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']);
                         $this->total += zen_add_tax($added_charge, $products_tax);
                     }
                     // 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);
                         $this->total += zen_add_tax($added_charge, $products_tax);
                     }
                     ////////////////////////////////////////////////
                 }
             }
         }
         // 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 = $db->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
     }
 }
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
function zen_rss_products($sql_products, $random)
{
    global $db, $currencies, $rss, $additionalURL;
    $imageSize = isset($_GET['imgsize']) ? $_GET['imgsize'] : RSS_DEFAULT_IMAGE_SIZE;
    //IFNULL(, 0)??????
    $sql_maxdate = "SELECT GREATEST(MAX(products_date_added), MAX(IFNULL(products_last_modified, 0))) as max_date\n                    FROM " . TABLE_PRODUCTS . "\n                    WHERE products_status = 1";
    $maxdate = $db->Execute($sql_maxdate);
    if (!$maxdate->EOF) {
        $rss->rss_feed_set('lastBuildDate', date('r', strtotime($maxdate->fields['max_date'])));
    }
    if ($random) {
        $products = zen_random_select($sql_products);
    } else {
        $products = $db->Execute($sql_products);
    }
    $cashTaxRate = array();
    while (!$products->EOF) {
        $info_page = zen_get_info_page($products->fields['products_id']);
        $xtags = array();
        if (RSS_PRODUCTS_PRICE == 'true' && $products->fields['price'] > 0) {
            if (!isset($cashTaxRate[$products->fields['products_tax_class_id']])) {
                $cashTaxRate[$products->fields['products_tax_class_id']] = zen_get_tax_rate($products->fields['products_tax_class_id']);
            }
            $xtags['g:price'] = number_format(zen_add_tax($products->fields['price'] * $currencies->get_value($_SESSION['currency']), $cashTaxRate[$products->fields['products_tax_class_id']]), $currencies->get_decimal_places($_SESSION['currency']), '.', '');
            //      $xtags['c:price_formatted type="string"'] = zen_get_products_display_price($products->fields['products_id']);
            //        $xtags['c:price_formatted type="string"'] = $currencies->display_price($products->fields['price'], $cashTaxRate[$products->fields['products_tax_class_id']]);
        }
        if (RSS_PRODUCTS_CURRENCY == 'true') {
            $xtags['g:currency'] = $_SESSION["currency"] == 'RUR' ? 'RUB' : $_SESSION["currency"];
        }
        if (RSS_PRODUCTS_ID == 'true') {
            $xtags['g:id'] = $products->fields['products_id'];
        }
        if (RSS_PRODUCTS_WEIGHT == 'true' && $products->fields['products_weight'] > 0) {
            $xtags['g:weight'] = $products->fields['products_weight'];
        }
        if (RSS_PRODUCTS_BRAND == 'true' && zen_not_null($products->fields['manufacturers_name'])) {
            $xtags['g:brand'] = $rss->_clear_string($products->fields['manufacturers_name']);
        }
        if (RSS_PRODUCTS_QUANTITY == 'true' && $products->fields['products_quantity'] > 0) {
            $xtags['g:quantity'] = $products->fields['products_quantity'];
        }
        if (RSS_PRODUCTS_MODEL == 'true' && zen_not_null($products->fields['products_model'])) {
            $xtags['g:model_number'] = $rss->_clear_string($products->fields['products_model']);
        }
        if (RSS_PRODUCTS_RATING == 'true' && zen_not_null($products->fields['reviews_rating'])) {
            $xtags['g:rating'] = $products->fields['reviews_rating'];
        }
        // rating - The rating of the item. Format: Text. XML example: <g:rating>4 stars</g:rating>
        /*
        image_link
        The URL of an associated image for the item. Use your full-sized images; do not use thumbnail images.
        If you do not have an image available, leave the attribute blank.
        Do not include logos or an image that says, "Image not available."
        Format:
        URL. (Must include the http:// portion.) Up to 10 URLs can be included.
        For XML, include each URL as a separate <image_link> attribute.
        XML example:
        <g:image_link>http://www.example.com/image1.jpg</g:image_link>
        <g:image_link>http://www.example.com/image2.jpg</g:image_link>
        */
        if (RSS_PRODUCTS_IMAGES == 'true' && zen_not_null($products->fields['products_image'])) {
            $products_image = ltrim($products->fields['products_image'], '/');
            require DIR_WS_MODULES . zen_get_module_directory(FILENAME_MAIN_PRODUCT_IMAGE);
            switch ($imageSize) {
                case 'small':
                    $xtags['g:image_link'][0] = HTTP_SERVER . DIR_WS_CATALOG . DIR_WS_IMAGES . $rss->_clear_url($products_image);
                    break;
                case 'medium':
                    $xtags['g:image_link'][0] = HTTP_SERVER . DIR_WS_CATALOG . $rss->_clear_url($products_image_medium);
                    break;
                case 'large':
                default:
                    $xtags['g:image_link'][0] = HTTP_SERVER . DIR_WS_CATALOG . $rss->_clear_url($products_image_large);
                    break;
            }
            if (isset($_GET['products_id']) || isset($_GET['products_model'])) {
                require DIR_WS_MODULES . zen_get_module_directory('additional_images.php');
                $num_images = min(9, $num_images);
                for ($i = 0, $n = $num_images; $i < $n; $i++) {
                    $file = $images_array[$i];
                    $products_image_large = str_replace(DIR_WS_IMAGES, DIR_WS_IMAGES . 'large/', $products_image_directory) . str_replace($products_image_extension, '', $file) . IMAGE_SUFFIX_LARGE . $products_image_extension;
                    $flag_has_large = file_exists($products_image_large);
                    $products_image_large = $flag_has_large ? $products_image_large : $products_image_directory . $file;
                    $xtags['g:image_link'][] = HTTP_SERVER . DIR_WS_CATALOG . $rss->_clear_url($products_image_large);
                }
            }
        }
        $link = zen_href_link($info_page, 'products_id=' . $products->fields['products_id'] . $additionalURL, 'NONSSL', false);
        $products_description = $products->fields['products_description'];
        if (RSS_PRODUCTS_DESCRIPTION_IMAGE == 'true' && zen_not_null($products->fields['products_image'])) {
            $image_url = zen_image(DIR_WS_IMAGES . $products->fields['products_image'], $products->fields['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'style="float: left; margin: 0px 8px 8px 0px;"');
            $image_url = str_replace('<img src="', '<img src="' . HTTP_SERVER . DIR_WS_CATALOG, $image_url);
            $image_link = '<a href="' . $link . '">' . $image_url . '</a>';
            if (RSS_STRIP_TAGS == 'true') {
                $products_description = '<![CDATA[' . $image_link . ']]>' . $products_description;
            } else {
                $products_description = $image_link . $products_description;
            }
        }
        if (RSS_PRODUCTS_DESCRIPTION_BUYNOW == 'true') {
            /*
                    $buynow_link = '<br /><br />' . zen_draw_form('cart_quantity', $link . '&action=add_product', 'post', 'enctype="multipart/form-data" target="_blank"') . "\n";
            //        $buynow_link .= '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($products->fields['products_id'])) . '" maxlength="6" size="4" />' . zen_get_products_quantity_min_units_display((int)$products->fields['products_id']);
                    $buynow_link .= zen_draw_hidden_field('cart_quantity', zen_get_buy_now_qty($products->fields['products_id']));
                    $buynow_link .= zen_draw_hidden_field('products_id', (int)$products->fields['products_id']);
                    $buynow_link .= str_replace('<img src="', '<img src="' . HTTP_SERVER . DIR_WS_CATALOG, zen_image_submit(BUTTON_IMAGE_BUY_NOW, BUTTON_BUY_NOW_ALT));
                    $buynow_link .= '</form>';
            */
            $buynow_button = str_replace('<img src="', '<img src="' . HTTP_SERVER . DIR_WS_CATALOG, zen_image_button(BUTTON_IMAGE_BUY_NOW, BUTTON_BUY_NOW_ALT));
            $buynow_button = preg_replace('@onmouseover="[^"]*"@i', '', $buynow_button);
            $buynow_button = preg_replace('@onmouseout="[^"]*"@i', '', $buynow_button);
            $buynow_button = str_replace(' >', '>', $buynow_button);
            //        $buynow_link = '<br /><br />' . '<a href="' . $link . '&action=buy_now' . '" target="_blank">' . $buynow_button . '</a>' . "\n";
            $buynow_link = '<br /><br />' . '<a href="' . zen_href_link(FILENAME_SHOPPING_CART, 'products_id=' . $products->fields['products_id'] . '&action=buy_now' . $additionalURL, 'SSL', false) . '" target="_blank">' . $buynow_button . '</a>' . "\n";
            if (RSS_STRIP_TAGS == 'true') {
                $products_description .= "\n" . '<![CDATA[' . $buynow_link . ']]>';
            } else {
                $products_description .= "\n" . $buynow_link;
            }
        }
        if (RSS_BUYNOW_LINK == 'true') {
            /*
                    $buynow_link = '<br /><br />' . zen_draw_form('cart_quantity', $link . '&action=add_product', 'post', 'enctype="multipart/form-data" target="_blank"') . "\n";
            //        $buynow_link .= '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($products->fields['products_id'])) . '" maxlength="6" size="4" />' . zen_get_products_quantity_min_units_display((int)$products->fields['products_id']);
                    $buynow_link .= zen_draw_hidden_field('cart_quantity', zen_get_buy_now_qty($products->fields['products_id']));
                    $buynow_link .= zen_draw_hidden_field('products_id', (int)$products->fields['products_id']);
                    $buynow_link .= str_replace('<img src="', '<img src="' . HTTP_SERVER . DIR_WS_CATALOG, zen_image_submit(BUTTON_IMAGE_BUY_NOW, BUTTON_BUY_NOW_ALT));
                    $buynow_link .= '</form>';
            */
            $buynow_button = str_replace('<img src="', '<img src="' . HTTP_SERVER . DIR_WS_CATALOG, zen_image_button(BUTTON_IMAGE_BUY_NOW, BUTTON_BUY_NOW_ALT));
            $buynow_button = preg_replace('@onmouseover="[^"]*"@i', '', $buynow_button);
            $buynow_button = preg_replace('@onmouseout="[^"]*"@i', '', $buynow_button);
            $buynow_button = str_replace(' >', '>', $buynow_button);
            //        $buynow_link = $link . '&action=buy_now';
            $buynow_link = zen_href_link(FILENAME_SHOPPING_CART, 'products_id=' . $products->fields['products_id'] . '&action=buy_now' . $additionalURL, 'SSL', false);
            $xtags['zencart:buynow_link'] = $buynow_link;
            $xtags['zencart:buynow_button'] = $buynow_button;
        }
        // TODO:
        // Attribute processing
        // Model, weight, brand & etc...
        $rss->rss_feed_item($products->fields['products_name'], $link, array('url' => $link, 'PermaLink' => true), date('r', strtotime($products->fields['products_date'])), $products_description, $rss->_clear_url($products->fields['products_image']), zen_href_link(FILENAME_PRODUCT_REVIEWS, 'products_id=' . $products->fields['products_id'] . $additionalURL, 'NONSSL', false), RSS_AUTHOR == '' ? STORE_OWNER_EMAIL_ADDRESS . " <" . STORE_OWNER . ">" : RSS_AUTHOR, false, false, $xtags);
        if ($random) {
            break;
        }
        $products->MoveNext();
    }
}
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');
 }
function amazon_process_order($pAmazonOrderId)
{
    global $gAmazonMWS, $gBitUser, $gCommerceSystem, $gBitCustomer, $currencies, $order;
    $ret = NULL;
    $request = new MarketplaceWebServiceOrders_Model_GetOrderRequest();
    $request->setSellerId(MERCHANT_ID);
    // @TODO: set request. Action can be passed as MarketplaceWebServiceOrders_Model_GetOrderRequest
    // object or array of parameters
    // Set the list of AmazonOrderIds
    $orderIds = new MarketplaceWebServiceOrders_Model_OrderIdList();
    $orderIds->setId(array($pAmazonOrderId));
    $request->setAmazonOrderId($orderIds);
    $holdUser = $gBitUser;
    $azUser = new BitPermUser($holdUser->lookupHomepage($gCommerceSystem->getConfig('MODULE_PAYMENT_AMAZONMWS_LOCAL_USERNAME', 'amazonmws')));
    $azUser->load();
    $gBitUser = $azUser;
    $gBitCustomer = new CommerceCustomer($gBitUser->mUserId);
    $gBitCustomer->syncBitUser($gBitUser->mInfo);
    $_SESSION['customer_id'] = $gBitUser->mUserId;
    try {
        $response = $gAmazonMWS->getOrder($request);
        if ($response->isSetGetOrderResult()) {
            $getOrderResult = $response->getGetOrderResult();
            if ($getOrderResult->isSetOrders()) {
                $oldCwd = getcwd();
                chdir(BITCOMMERCE_PKG_PATH);
                $azOrderList = $getOrderResult->getOrders();
                if ($azOrders = $azOrderList->getOrder()) {
                    require_once BITCOMMERCE_PKG_PATH . 'classes/CommerceOrder.php';
                    $order = new order();
                    $order->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, 'subtotal' => 0, 'tax' => 0, 'total' => 0, 'tax_groups' => array(), 'comments' => isset($_SESSION['comments']) ? $_SESSION['comments'] : '', 'ip_address' => $_SERVER['REMOTE_ADDR']);
                    $azOrder = current($azOrders);
                    // Setup delivery address
                    if ($orderTotal = $azOrder->getOrderTotal()) {
                        $order->info['total'] = $orderTotal->getAmount();
                        $order->info['currency'] = $orderTotal->getCurrencyCode();
                        $order->info['currency_value'] = $currencies->currencies[$order->info['currency']]['currency_value'];
                    }
                    if ($shippingAddress = $azOrder->getShippingAddress()) {
                        $country = zen_get_countries(zen_get_country_id($shippingAddress->getCountryCode()), TRUE);
                        $zoneName = zen_get_zone_name_by_code($country['countries_id'], $shippingAddress->getStateOrRegion());
                        $order->delivery = array('firstname' => substr($shippingAddress->getName(), 0, strpos($shippingAddress->getName(), ' ')), 'lastname' => substr($shippingAddress->getName(), strpos($shippingAddress->getName(), ' ') + 1), 'company' => NULL, 'street_address' => $shippingAddress->getAddressLine1(), 'suburb' => trim($shippingAddress->getAddressLine2() . ' ' . $shippingAddress->getAddressLine3()), 'city' => $shippingAddress->getCity(), 'postcode' => $shippingAddress->getPostalCode(), 'state' => $zoneName, 'country' => $country, 'format_id' => $country['address_format_id'], 'telephone' => $shippingAddress->getPhone(), 'email_address' => NULL);
                        $order->customer = $order->delivery;
                        $order->billing = $order->delivery;
                    }
                    // Setup shipping
                    $shipping = array('cost' => 0);
                    switch ($azOrder->getShipServiceLevel()) {
                        case 'Std US Dom':
                            $shipping['id'] = 'usps_MEDIA';
                            $shipping['title'] = 'United States Postal Service (USPS Media Mail (1 - 2 Weeks))';
                            $shipping['code'] = 'USPSREG';
                            break;
                    }
                    $azOrderItems = amazon_mws_get_order_items($azOrder->getAmazonOrderId());
                    $azOrderItem = $azOrderItems->getOrderItem();
                    foreach ($azOrderItem as $azi) {
                        $testSku = $azi->getSellerSKU();
                        list($productsId, $attrString) = explode(':', $testSku, 2);
                        $productsKey = $productsId . ':ASIN-' . $azi->getASIN();
                        $order->contents[$productsKey] = $gBitCustomer->mCart->getProductHash($productsKey);
                        $order->contents[$productsKey]['products_quantity'] = $azi->getQuantityOrdered();
                        $order->contents[$productsKey]['products_name'] = $azi->getTitle();
                        if ($itemPrice = $azi->getItemPrice()) {
                            //							{$itemTax->getCurrencyCode()}
                            $order->contents[$productsKey]['price'] = $itemPrice->getAmount();
                            $order->contents[$productsKey]['final_price'] = $itemPrice->getAmount();
                        }
                        if ($itemTax = $azi->getItemTax()) {
                            //							{$itemTax->getCurrencyCode()}
                            $order->contents[$productsKey]['tax'] = $itemTax->getAmount();
                        }
                        if ($shippingPrice = $azi->getShippingPrice()) {
                            //							{$itemTax->getCurrencyCode()}
                            $order->info['shipping_cost'] = $shippingPrice->getAmount();
                        }
                        if (empty($attrString)) {
                            $attrString = $gCommerceSystem->getConfig('MODULE_PAYMENT_AMAZONMWS_DEFAULT_ATTRIBUTES');
                        }
                        // stock up the attributes
                        if ($attrString && ($attrs = explode(',', $attrString))) {
                            foreach ($attrs as $optionValueId) {
                                $optionId = $order->mDb->getOne("SELECT cpa.`products_options_id` FROM " . TABLE_PRODUCTS_ATTRIBUTES . " cpa WHERE cpa.`products_options_values_id`=?", array($optionValueId));
                                $order->contents[$productsKey]['attributes'][$optionId . '_' . $optionValueId] = $optionValueId;
                            }
                        }
                        if (!empty($order->contents[$productsKey]['attributes'])) {
                            $attributes = $order->contents[$productsKey]['attributes'];
                            $order->contents[$productsKey]['attributes'] = array();
                            $subindex = 0;
                            foreach ($attributes as $option => $value) {
                                $optionValues = zen_get_option_value(zen_get_options_id($option), (int) $value);
                                // Determine if attribute is a text attribute and change products array if it is.
                                if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID) {
                                    $attr_value = $order->contents[$productsKey]['attributes_values'][$option];
                                } else {
                                    $attr_value = $optionValues['products_options_values_name'];
                                }
                                $order->contents[$productsKey]['attributes'][$subindex] = array('option' => $optionValues['products_options_name'], 'value' => $attr_value, 'option_id' => $option, 'value_id' => $value, 'prefix' => $optionValues['price_prefix'], 'price' => $optionValues['options_values_price']);
                                $subindex++;
                            }
                        }
                        $shown_price = zen_add_tax($order->contents[$productsKey]['final_price'], $order->contents[$productsKey]['tax']) * $order->contents[$productsKey]['products_quantity'] + zen_add_tax($order->contents[$productsKey]['onetime_charges'], $order->contents[$productsKey]['tax']);
                        $order->subtotal += $shown_price;
                        $products_tax = $order->contents[$productsKey]['tax'];
                        $products_tax_description = $order->contents[$productsKey]['tax_description'];
                        if (DISPLAY_PRICE_WITH_TAX == 'true') {
                            $order->info['tax'] += $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
                            if (isset($order->info['tax_groups']["{$products_tax_description}"])) {
                                $order->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 {
                                $order->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 {
                            $order->info['tax'] += $products_tax / 100 * $shown_price;
                            if (isset($order->info['tax_groups']["{$products_tax_description}"])) {
                                $order->info['tax_groups']["{$products_tax_description}"] += $products_tax / 100 * $shown_price;
                            } else {
                                $order->info['tax_groups']["{$products_tax_description}"] = $products_tax / 100 * $shown_price;
                            }
                        }
                        $order->info['tax'] = zen_round($order->info['tax'], 2);
                        if ($azi->isSetShippingPrice()) {
                            $shippingPrice = $azi->getShippingPrice();
                            $shipping['cost'] += $shippingPrice->getAmount();
                        }
                    }
                    foreach (array('cc_type', 'cc_owner', 'cc_number', 'cc_expires', 'coupon_code') as $key) {
                        $order->info[$key] = NULL;
                    }
                    $order->info['shipping_method'] = $shipping['title'];
                    $order->info['shipping_method_code'] = $shipping['code'];
                    $order->info['shipping_module_code'] = $shipping['id'];
                    $order->info['payment_module_code'] = 'amazonmws';
                    $order->info['payment_method'] = 'Amazon Order';
                    $_SESSION['sendto'] = NULL;
                    $_SESSION['shipping'] = $shipping;
                    unset($_SESSION['cot_gv']);
                    require_once DIR_FS_CLASSES . 'order_total.php';
                    global $order_total_modules;
                    $order_total_modules = new order_total();
                    $order_totals = $order_total_modules->pre_confirmation_check();
                    require_once DIR_WS_MODULES . 'payment/amazonmws.php';
                    $amazon = new amazonmws($azOrder->getAmazonOrderId());
                    $amazonOutput = $amazon->process();
                    $order_totals = $order_total_modules->process();
                    array_splice($order_totals, count($order_totals) - 1, 0, array($amazonOutput));
                    if ($ordersId = $order->create($order_totals, 2)) {
                        $order->create_add_products($ordersId);
                        $ret = $ordersId;
                        $order->updateStatus(array('status' => MODULE_PAYMENT_AMAZONMWS_INITIAL_ORDER_STATUS_ID));
                    }
                }
                chdir($oldCwd);
            }
        }
    } catch (MarketplaceWebServiceOrders_Exception $ex) {
        echo "Caught Exception: " . $ex->getMessage() . "\n";
        echo "Response Status Code: " . $ex->getStatusCode() . "\n";
        echo "Error Code: " . $ex->getErrorCode() . "\n";
        echo "Error Type: " . $ex->getErrorType() . "\n";
        echo "Request ID: " . $ex->getRequestId() . "\n";
        echo "XML: " . $ex->getXML() . "\n";
    }
    $gBitUser = $holdUser;
    $gBitCustomer = new CommerceCustomer($gBitUser->mUserId);
    $_SESSION['customer_id'] = $gBitUser->mUserId;
    return $ret;
}