/**
  * Get the shipping restrictions in the google filter module format for a specific zone
  * so we can add it as part of the shipping rules
  *
  * @return object
  **/
 private function GetShippingRestrictions($zone)
 {
     $Gfilter = new GoogleShippingFilters();
     // Handle the default zone
     if (!isset($zone['locationtype'])) {
         $Gfilter->SetAllowedWorldArea(true);
         return $Gfilter;
     }
     switch ($zone['locationtype']) {
         case 'zip':
             foreach ($zone['locations'] as $location) {
                 $pos = strpos($location['locationvalue'], '?');
                 if ($pos === false) {
                     $Gfilter->AddAllowedZipPattern($location['locationvalue']);
                 } else {
                     $tmp = substr($location['locationvalue'], 0, $pos);
                     $tmp .= '*';
                     $Gfilter->AddAllowedZipPattern($tmp);
                 }
             }
             break;
         case 'state':
             foreach ($zone['locations'] as $location) {
                 $country = GetCountryISO2ById($location['locationcountryid']);
                 $state = GetStateISO2ById($location['locationvalueid']);
                 if (empty($state)) {
                     $state = GetStateById($location['locationvalueid']);
                 }
                 if (empty($location['locationvalueid']) && $country == 'US') {
                     // If they have selected all states in the us, handle it differently
                     $Gfilter->SetAllowedCountryArea('ALL');
                     continue;
                 } elseif (empty($location['locationvalueid'])) {
                     $Gfilter->AddAllowedPostalArea($country);
                     continue;
                 }
                 if ($country == 'US' && $this->GetDefaultCurrencyCode() == 'USD') {
                     $Gfilter->AddAllowedStateArea($state);
                 } else {
                     $Gfilter->AddAllowedPostalArea($country, $state);
                 }
             }
             break;
         case 'country':
             foreach ($zone['locations'] as $location) {
                 $Gfilter->AddAllowedPostalArea(GetCountryISO2ById($location['locationvalueid']));
             }
             break;
     }
     return $Gfilter;
 }
Example #2
0
     $module = new $module_name();
     $quote = $module->quote($method);
     $price = $quote['methods'][0]['cost'];
     $shipping_price = $currencies->get_value(DEFAULT_CURRENCY) * ($price >= 0 ? $price : 0);
 }
 $Gfilter = new GoogleShippingFilters();
 if (MODULE_PAYMENT_GOOGLECHECKOUT_USPOBOX == 'False') {
     $Gfilter->SetAllowUsPoBox('false');
 }
 if (!empty($allowed_restriction_country)) {
     foreach ($allowed_restriction_state as $state_key => $state) {
         if ($allowed_restriction_country[$state_key][1] == 'US') {
             if ($state == 'All Areas') {
                 $Gfilter->SetAllowedCountryArea('ALL');
             } else {
                 $Gfilter->AddAllowedStateArea($state);
             }
         } else {
             // TODO here should go the non us area (not implemented in GC)
             // now just the country
             $Gfilter->AddAllowedPostalArea($allowed_restriction_country[$state_key][1]);
         }
     }
 } else {
     switch ($type) {
         case 'domestic_types':
             if ('US' == $shipping_origin_iso_code_2) {
                 $Gfilter->SetAllowedCountryArea('ALL');
             } else {
                 $Gfilter->AddAllowedPostalArea($shipping_origin_iso_code_2);
             }
function Usecase($separator, $sessionid, $fromcheckout)
{
    global $wpdb, $wpsc_cart;
    $purchase_log_sql = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid` = %s  LIMIT 1", $sessionid);
    $purchase_log = $wpdb->get_results($purchase_log_sql, ARRAY_A);
    $cart_sql = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid` = %d", $purchase_log[0]['id']);
    $wp_cart = $wpdb->get_results($cart_sql, ARRAY_A);
    $merchant_id = get_option('google_id');
    $merchant_key = get_option('google_key');
    $server_type = get_option('google_server_type');
    $currency = get_option('google_cur');
    $transact_url = get_option('transact_url');
    $returnURL = $transact_url . $separator . "sessionid=" . $sessionid . "&gateway=google";
    $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
    $cart->SetContinueShoppingUrl($returnURL);
    $cart->SetEditCartUrl(get_option('shopping_cart_url'));
    //google prohibited items not implemented
    $currency_converter = new CURRENCYCONVERTER();
    $currency_code = $wpdb->get_results("SELECT `code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id`='" . get_option('currency_type') . "' LIMIT 1", ARRAY_A);
    $local_currency_code = $currency_code[0]['code'];
    $google_curr = get_option('google_cur');
    $currentcy_rate = 1;
    if ($google_curr != $local_currency_code) {
        $currentcy_rate = $currency_converter->convert(1, $local_currency_code, $google_curr);
    }
    while (wpsc_have_cart_items()) {
        wpsc_the_cart_item();
        $google_currency_productprice = $currentcy_rate * (wpsc_cart_item_price(false) / wpsc_cart_item_quantity());
        $cart_item = new GoogleItem(wpsc_cart_item_name(), '', wpsc_cart_item_quantity(), $google_currency_productprice);
        $cart->AddItem($cart_item);
    }
    //If there are coupons applied add coupon as a product with negative price
    if ($wpsc_cart->coupons_amount > 0) {
        $google_currency_productprice = $currentcy_rate * $wpsc_cart->coupons_amount;
        $coupon = new GoogleItem('Discount', 'Discount Price', 1, '-' . $google_currency_productprice);
        $cart->AddItem($coupon);
    }
    $shipping_country = $purchase_log[0]['shipping_country'];
    $shipping_region = $purchase_log[0]['shipping_region'];
    if ($shipping_country == "UK") {
        $shipping_country = "GB";
    }
    // Add shipping options
    if (wpsc_uses_shipping()) {
        $shipping_name = ucfirst($wpsc_cart->selected_shipping_method) . " - " . $wpsc_cart->selected_shipping_option;
        if ($shipping_name == "") {
            $shipping_name = "Calculated";
        }
        $shipping = new GoogleFlatRateShipping($shipping_name, $wpsc_cart->calculate_total_shipping() * $currentcy_rate);
        if (!empty($shipping_country)) {
            $shipping_filter = new GoogleShippingFilters();
            if (!empty($shipping_region) && is_numeric($shipping_region)) {
                $shipping_filter->AddAllowedPostalArea($shipping_country, wpsc_get_state_by_id($shipping_region, "code"));
                $shipping_filter->AddAllowedStateArea(wpsc_get_state_by_id($shipping_region, "code"));
            } else {
                $shipping_filter->AddAllowedPostalArea($shipping_country);
            }
            $shipping->AddShippingRestrictions($shipping_filter);
        }
        $cart->AddShipping($shipping);
    }
    // Add tax rules
    if (!empty($shipping_country)) {
        $tax_rule = new GoogleDefaultTaxRule(wpsc_cart_tax(false) / $wpsc_cart->calculate_subtotal());
        $tax_rule->AddPostalArea($shipping_country);
        $cart->AddDefaultTaxRules($tax_rule);
    }
    // Display Google Checkout button
    if (get_option('google_button_size') == '0') {
        $google_button_size = 'BIG';
    } elseif (get_option('google_button_size') == '1') {
        $google_button_size = 'MEDIUM';
    } elseif (get_option('google_button_size') == '2') {
        $google_button_size = 'SMALL';
    }
    echo $cart->CheckoutButtonCode($google_button_size);
}
		/**
		 * Get the shipping restrictions in the google filter module format for a specific zone
		 * so we can add it as part of the shipping rules
		 *
		 * @return object
		 **/
		private function GetShippingRestrictions($zone)
		{
			$Gfilter = new GoogleShippingFilters();

			// Handle the default zone
			if (!isset($zone['locationtype'])) {
				$Gfilter->SetAllowedWorldArea(true);
				return $Gfilter;
			}

			switch ($zone['locationtype']) {
				case 'zip':
				{
					foreach ($zone['locations'] as $location) {

						$pos = strpos($location['locationvalue'], '?');
						$country = GetCountryISO2ById($location['locationcountryid']);

						if ($pos === false) {
							$Gfilter->AddAllowedPostalArea($country, $location['locationvalue']);
						}
						else {

							$tmp = substr($location['locationvalue'], 0, $pos);
							$tmp .= '*';
							$Gfilter->AddAllowedPostalArea($country, $tmp);
						}

					}
					break;
				}
				case 'state':
				{
					foreach ($zone['locations'] as $location) {
						$country = GetCountryISO2ById($location['locationcountryid']);
						$state = GetStateISO2ById($location['locationvalueid']);

						if (empty($state)) {
							$state = GetStateById($location['locationvalueid']);
						}

						if (empty($location['locationvalueid']) && $country == 'US') {
							// If they have selected all states in the us, handle it differently
							$Gfilter->SetAllowedCountryArea('ALL');
							continue;
						} elseif (empty($location['locationvalueid'])) {
							$Gfilter->AddAllowedPostalArea($country);
							continue;
						}

						if ($country == 'US' && $this->GetDefaultCurrencyCode() == 'USD') {
							// Google does not support Puerto Rico, Guam or the Marshall Islands as US-state-areas
							// Per Google Checkout support; ref ISC-155
							if ($state != 'PR' AND $state != 'MH' AND $state != 'GU')
							{
								$Gfilter->AddAllowedStateArea($state);
							}
						} else {
							$Gfilter->AddAllowedPostalArea($country, $state);
						}
					}
					break;
				}
				case 'country':
				{
					foreach ($zone['locations'] as $location) {
						$Gfilter->AddAllowedPostalArea(GetCountryISO2ById($location['locationvalueid']));
					}
					break;
				}
			}

			return $Gfilter;
		}