예제 #1
0
 function get_order_total($couponCode)
 {
     global $order;
     $orderTaxGroups = $order->info['tax_groups'];
     $orderTotalTax = $order->info['tax'];
     $orderTotal = $order->info['total'];
     // left for total order amount vs qualified order amount just switch the commented lines
     $orderTotalFull = $orderTotal;
     $products = $_SESSION['cart']->get_products();
     for ($i = 0; $i < sizeof($products); $i++) {
         if (!is_product_valid($products[$i]['id'], $couponCode)) {
             $products_tax = zen_get_tax_rate($products[$i]['tax_class_id']);
             $productsTaxAmount = zen_calculate_tax($products[$i]['final_price'], $products_tax) * $products[$i]['quantity'];
             $orderTotal -= $products[$i]['final_price'] * $products[$i]['quantity'];
             if ($this->include_tax == 'true') {
                 $orderTotal -= $productsTaxAmount;
             }
             if (DISPLAY_PRICE_WITH_TAX == 'true') {
                 $orderTotal -= $productsTaxAmount;
             }
             $orderTaxGroups[zen_get_tax_description($products[$i]['tax_class_id'])] -= $productsTaxAmount;
             $orderTotalTax -= zen_calculate_tax($products[$i]['final_price'], zen_get_tax_rate($products[$i]['tax_class_id'])) * $products[$i]['quantity'];
         }
     }
     if ($this->include_shipping != 'true') {
         $orderTotal -= $order->info['shipping_cost'];
         if (isset($_SESSION['shipping_tax_description']) && $_SESSION['shipping_tax_description'] != '') {
             $orderTaxGroups[$_SESSION['shipping_tax_description']] -= $order->info['shipping_tax'];
             $orderTotalTax -= $order->info['shipping_tax'];
         }
     }
     if (DISPLAY_PRICE_WITH_TAX != 'true') {
         $orderTotal -= $order->info['tax'];
     }
     // left for total order amount vs qualified order amount - $orderTotalFull
     return array('totalFull' => $orderTotalFull, 'orderTotal' => $orderTotal, 'orderTaxGroups' => $orderTaxGroups, 'orderTax' => $orderTotalTax, 'shipping' => $order->info['shipping_cost'], 'shippingTax' => $order->info['shipping_tax']);
 }
예제 #2
0
 /**
  * Enter description here...
  *
  * @return unknown
  */
 function get_order_total()
 {
     global $order;
     $order_total_tax = $order->info['tax'];
     $order_total = $order->info['total'];
     //    echo "order total = $order_total<br>";
     //    echo "order total shipping = {$order->info['shipping_cost']}<br>";
     //    echo "order total tax = {$order->info['tax']}<br>";
     if ($this->include_shipping != 'true') {
         $order_total -= $order->info['shipping_cost'];
     }
     if ($this->include_shipping != 'true') {
         $order_total_tax -= $order->info['shipping_tax'];
     }
     if ($this->include_tax != 'true') {
         $order_total -= $order->info['tax'];
     }
     //   if ($this->include_tax != "true" && $this->include_shipping != 'true') $order_total -= $order->info['shipping_tax'];
     //    echo "order total = $order_total<br>";
     $orderTotalFull = $order_total;
     $products = $_SESSION['cart']->get_products();
     for ($i = 0; $i < sizeof($products); $i++) {
         if (!is_product_valid($products[$i]['id'], $_SESSION['cc_id'])) {
             $order_total -= $products[$i]['final_price'] * $products[$i]['quantity'];
             if ($this->include_tax == 'true') {
                 $products_tax = zen_get_tax_rate($products[$i]['tax_class_id']);
                 $order_total -= zen_calculate_tax($products[$i]['final_price'], $products_tax) * $products[$i]['quantity'];
             }
             $order_total_tax -= zen_calculate_tax($products[$i]['final_price'], zen_get_tax_rate($products[$i]['tax_class_id'])) * $products[$i]['quantity'];
         }
     }
     $orderTotalInclusive = $order_total + $order_total_tax;
     if (DISPLAY_PRICE_WITH_TAX == 'true') {
         $order_total += $order_total_tax;
     }
     $order_total = array('totalFull' => $orderTotalFull, 'total' => $order_total, 'tax' => $order_total_tax, 'totalInclusive' => $orderTotalInclusive);
     return $order_total;
 }
예제 #3
0
 /**
  * Enter description here...
  *
  * @return unknown
  */
 function get_order_total()
 {
     global $order;
     $order_total_tax = $order->info['tax'];
     $order_total = $order->info['total'];
     if ($this->include_shipping != 'true') {
         $order_total -= $order->info['shipping_cost'];
     }
     if ($this->include_tax != 'true') {
         $order_total -= $order->info['tax'];
     }
     $orderTotalFull = $order_total;
     $products = $_SESSION['cart']->get_products();
     for ($i = 0; $i < sizeof($products); $i++) {
         if (!is_product_valid($products[$i]['id'], $_SESSION['cc_id'])) {
             $order_total -= $products[$i]['final_price'] * $products[$i]['quantity'];
             if ($this->include_tax == 'true') {
                 $products_tax = zen_get_tax_rate($products[$i]['tax_class_id']);
                 $order_total -= zen_calculate_tax($products[$i]['final_price'], $products_tax) * $products[$i]['quantity'];
             }
             $order_total_tax -= zen_calculate_tax($products[$i]['final_price'], zen_get_tax_rate($products[$i]['tax_class_id'])) * $products[$i]['quantity'];
         }
     }
     $order_total = array('totalFull' => $orderTotalFull, 'total' => $order_total, 'tax' => $order_total_tax);
     return $order_total;
 }
예제 #4
0
function calculate_coupons($Gresponse, &$merchant_result, $price = 0)
{
    global $order, $db, $googlepayment;
    list($root, $data) = $Gresponse->GetParsedXML();
    require_once DIR_FS_CATALOG . DIR_WS_FUNCTIONS . 'functions_general.php';
    $currencies = new currencies();
    require_once DIR_FS_CATALOG . DIR_WS_LANGUAGES . $_SESSION['language'] . '/discount_coupon.php';
    $codes = get_arr_result($data[$root]['calculate']['merchant-code-strings']['merchant-code-string']);
    //print_r($codes);
    $customer_exists = $db->Execute("select customers_id from " . $googlepayment->table_name . " where buyer_id = " . makeSqlString($data[$root]['buyer-id']['VALUE']));
    if ($customer_exists->RecordCount() != 0) {
        $customer_id = $customer_exists->fields['customers_id'];
    }
    $first_coupon = true;
    foreach ($codes as $curr_code) {
        $text_coupon_help = '';
        //Update this data as required to set whether the coupon is valid, the code and the amount
        // Check for valid zone...
        $sql = "select coupon_id, coupon_amount, coupon_type, coupon_minimum_order, uses_per_coupon, uses_per_user,\n                      restrict_to_products, restrict_to_categories, coupon_zone_restriction, coupon_code\n                      from " . TABLE_COUPONS . "\n                      where coupon_code= '" . zen_db_input($curr_code['code']) . "'\n                      and coupon_active='Y'";
        //      $sql = $db->bindVars($sql, ':couponIDEntered', , 'string');
        $coupon_result = $db->Execute($sql);
        $foundvalid = true;
        $check_flag = false;
        $check = $db->Execute("select zone_id, zone_country_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . $coupon_result->fields['coupon_zone_restriction'] . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
        if ($coupon_result->fields['coupon_zone_restriction'] > 0) {
            while (!$check->EOF) {
                if ($check->fields['zone_id'] < 1) {
                    $check_flag = true;
                    break;
                } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
                    $check_flag = true;
                    break;
                }
                $check->MoveNext();
            }
            $foundvalid = $check_flag;
        }
        $coupon_count = $db->Execute("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . "\n                                    where coupon_id = '" . (int) $coupon_result->fields['coupon_id'] . "'");
        $coupon_count_customer = $db->Execute("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . "\n                                           where coupon_id = '" . $coupon_result->fields['coupon_id'] . "' and\n                                           customer_id = '" . (int) $customer_id . "'");
        //  added code here to handle coupon product restrictions
        // look through the items in the cart to see if this coupon is valid for any item in the cart
        //    $items = get_arr_result($data[$root]['shopping-cart']['items']['item']);
        //    $products = array ();
        //    foreach ($items as $item) {
        //      if (isset ($item['merchant-private-item-data']['item']['VALUE'])) {
        //        $products[] = unserialize(base64_decode($item['merchant-private-item-data']['item']['VALUE']));
        //      }
        //    }
        if ($foundvalid == true) {
            $foundvalid = false;
            $products = $order->products;
            for ($i = 0; $i < sizeof($products); $i++) {
                if (is_product_valid($products[$i]['id'], $coupon_result->fields['coupon_id'])) {
                    $foundvalid = true;
                    continue;
                }
            }
        }
        $coupon = $db->Execute("select * from " . TABLE_COUPONS . " where coupon_code = '" . zen_db_input($curr_code['code']) . "' and  coupon_type != 'G'");
        if (!$foundvalid || !$first_coupon || $coupon->RecordCount() < 1) {
            // invalid discount coupon code or more than one entered!
            $text_coupon_help = $first_coupon ? sprintf(TEXT_COUPON_FAILED, $curr_code['code']) : GOOGLECHECKOUT_COUPON_ERR_ONE_COUPON;
            $coupons = new GoogleCoupons("false", $curr_code['code'], 0, $text_coupon_help);
            $merchant_result->AddCoupons($coupons);
            // BBG Start - Invalid discount coupon if coupon minimum order is over 0 and the order total doesn't meet the minimum
        } else {
            if ($coupon->fields['coupon_minimum_order'] > 0 && $order->info['total'] < $coupon->fields['coupon_minimum_order']) {
                $text_coupon_help = GOOGLECHECKOUT_COUPON_ERR_MIN_PURCHASE;
                $coupons = new GoogleCoupons("false", $curr_code['code'], 0, $text_coupon_help);
                $merchant_result->AddCoupons($coupons);
                // BBG End
            } else {
                if ($coupon_count->RecordCount() >= $coupon_result->fields['uses_per_coupon'] && $coupon_result->fields['uses_per_coupon'] > 0) {
                    $text_coupon_help = TEXT_INVALID_USES_COUPON . $coupon_result->fields['uses_per_coupon'] . TIMES;
                    $coupons = new GoogleCoupons("false", $curr_code['code'], 0, $text_coupon_help);
                    $merchant_result->AddCoupons($coupons);
                } else {
                    if ($coupon_count_customer->RecordCount() >= $coupon_result->fields['uses_per_user'] && $coupon_result->fields['uses_per_user'] > 0) {
                        $text_coupon_help = sprintf(TEXT_INVALID_USES_USER_COUPON, $curr_code['code']) . $coupon_result->fields['uses_per_user'] . ($coupon_result->fields['uses_per_user'] == 1 ? TIME : TIMES);
                        $coupons = new GoogleCoupons("false", $curr_code['code'], 0, $text_coupon_help);
                        $merchant_result->AddCoupons($coupons);
                    } else {
                        // valid discount coupon code
                        $lookup_coupon_id = $coupon->fields['coupon_id'];
                        $coupon_desc = $db->Execute("select * from " . TABLE_COUPONS_DESCRIPTION . " where coupon_id = '" . (int) $lookup_coupon_id . "' " . " and language_id = '" . (int) $_SESSION['languages_id'] . "'");
                        $coupon_amount = $coupon->fields['coupon_amount'];
                        switch ($coupon->fields['coupon_type']) {
                            case 'F':
                                $text_coupon_help = GOOGLECHECKOUT_COUPON_DISCOUNT . $curr_code['code'];
                                break;
                            case 'P':
                                $text_coupon_help = GOOGLECHECKOUT_COUPON_DISCOUNT . $curr_code['code'];
                                $coupon_amount = $coupon_amount * $order->info['subtotal'] / 100;
                                break;
                            case 'S':
                                $text_coupon_help = GOOGLECHECKOUT_COUPON_FREESHIP . $curr_code['code'];
                                $coupon_amount = $price;
                                break;
                            default:
                        }
                        $get_result = $db->Execute("select * from " . TABLE_COUPON_RESTRICT . " " . "where coupon_id='" . (int) $lookup_coupon_id . "' and category_id !='0'");
                        $cats = '';
                        while (!$get_result->EOF) {
                            if ($get_result->fields['coupon_restrict'] == 'N') {
                                $restrict = TEXT_CAT_ALLOWED;
                            } else {
                                $restrict = TEXT_CAT_DENIED;
                            }
                            $result = $db->Execute("SELECT * FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd WHERE c.categories_id = cd.categories_id " . "and cd.language_id = '" . (int) $_SESSION['languages_id'] . "' " . "and c.categories_id='" . $get_result->fields['category_id'] . "'");
                            $cats .= '<br />' . $result->fields["categories_name"] . $restrict;
                            $get_result->MoveNext();
                        }
                        if ($cats == '') {
                            $cats = TEXT_NO_CAT_RESTRICTIONS;
                        }
                        $get_result = $db->Execute("select * from " . TABLE_COUPON_RESTRICT . " where coupon_id='" . (int) $lookup_coupon_id . "' and product_id !='0'");
                        while (!$get_result->EOF) {
                            if ($get_result->fields['coupon_restrict'] == 'N') {
                                $restrict = TEXT_PROD_ALLOWED;
                            } else {
                                $restrict = TEXT_PROD_DENIED;
                            }
                            $result = $db->Execute("SELECT * FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd WHERE p.products_id = pd.products_id " . "and pd.language_id = '" . (int) $_SESSION['languages_id'] . "' " . "and p.products_id = '" . $get_result->fields['product_id'] . "'");
                            $prods .= '<br />' . $result->fields['products_name'] . $restrict;
                            $get_result->MoveNext();
                        }
                        if ($prods == '') {
                            $prods = TEXT_NO_PROD_RESTRICTIONS;
                        }
                        $coupons = new GoogleCoupons("true", $curr_code['code'], $currencies->get_value(DEFAULT_CURRENCY) * $coupon_amount, $text_coupon_help);
                        $merchant_result->AddCoupons($coupons);
                        $first_coupon = false;
                    }
                }
            }
        }
    }
}
예제 #5
0
 function get_order_total()
 {
     global $order;
     $products = $_SESSION['cart']->get_products();
     $order_total = 0;
     for ($i = 0; $i < sizeof($products); $i++) {
         if (is_product_valid($products[$i]['id'], $_SESSION['cc_id'])) {
             $order_total += $products[$i]['final_price'] * $products[$i]['quantity'];
             if ($this->include_tax == 'true') {
                 $products_tax = zen_get_tax_rate($products[$i]['tax_class_id']);
                 $order_total += zen_calculate_tax($products[$i]['final_price'], $products_tax) * $products[$i]['quantity'];
             }
         }
     }
     if ($this->include_shipping == 'true') {
         $order_total += $order->info['shipping_cost'];
     }
     return $order_total;
 }