/** * 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; }
function UseCase2() { // Create a new shopping cart object $merchant_id = ""; // Your Merchant ID $merchant_key = ""; // Your Merchant Key $server_type = "sandbox"; $currency = "USD"; $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency); // Add items to the cart $item_1 = new GoogleItem("Dry Food Pack AA1453", "A pack of highly nutritious dried food for emergency", 2, 24.99); $item_1->SetTaxTableSelector("food"); $item_2 = new GoogleItem("MegaSound 2GB MP3 Player", "Portable MP3 player - stores 500 songs", 1, 175.49); $item_2->SetMerchantPrivateItemData(new MerchantPrivateItemData(array("color" => "blue", "weight" => "3.2"))); $item_2->SetMerchantItemId("Item#012345"); $cart->AddItem($item_1); $cart->AddItem($item_2); // Add shipping options $ship_1 = new GoogleFlatRateShipping("Ground", 15); $restriction_1 = new GoogleShippingFilters(); $restriction_1->SetAllowedWorldArea(true); $ship_1->AddShippingRestrictions($restriction_1); $ship_2 = new GooglePickup("Pick Up", 5); $cart->AddShipping($ship_1); $cart->AddShipping($ship_2); // Add default tax rules $tax_rule_1 = new GoogleDefaultTaxRule(0.17); $tax_rule_1->AddPostalArea("GB", "SW*"); $tax_rule_1->AddPostalArea("FR"); $tax_rule_1->AddPostalArea("DE"); $tax_rule_2 = new GoogleDefaultTaxRule(0.1); $tax_rule_2->SetWorldArea(true); $cart->AddDefaultTaxRules($tax_rule_1); $cart->AddDefaultTaxRules($tax_rule_2); // Add alternate tax table $tax_table = new GoogleAlternateTaxTable("food"); $tax_rule_1 = new GoogleAlternateTaxRule(0.05); $tax_rule_1->AddPostalArea("GB"); $tax_rule_1->AddPostalArea("FR"); $tax_rule_1->AddPostalArea("DE"); $tax_rule_2 = new GoogleAlternateTaxRule(0.03); $tax_rule_2->SetWorldArea(true); $tax_table->AddAlternateTaxRules($tax_rule_1); $tax_table->AddAlternateTaxRules($tax_rule_2); $cart->AddAlternateTaxTables($tax_table); // Add <merchant-private-data> $cart->SetMerchantPrivateData(new MerchantPrivateData(array("animals" => array("type" => "cat,dog")))); // Specify <edit-cart-url> $cart->SetEditCartUrl("http://www.example.com/edit"); // Specify "Return to xyz" link $cart->SetContinueShoppingUrl("http://www.example.com/continue"); // Request buyer's phone number $cart->SetRequestBuyerPhone(true); // Define rounding policy $cart->AddRoundingPolicy("CEILING", "TOTAL"); // Display XML data // echo "<pre>"; // echo htmlentities($cart->GetXML()); // echo "</pre>"; // Display a medium size button echo $cart->GetXML(); }
function Usecase($seperator, $sessionid, $fromcheckout) { global $wpdb, $wpsc_cart; $purchase_log_sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= " . $sessionid . " LIMIT 1"; $purchase_log = $wpdb->get_results($purchase_log_sql, ARRAY_A); $cart_sql = "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='" . $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'); $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency); $transact_url = get_option('transact_url'); $returnURL = $transact_url . $seperator . "sessionid=" . $sessionid . "&gateway=google"; $cart->SetContinueShoppingUrl($returnURL); $cart->SetEditCartUrl(get_option('shopping_cart_url')); $no = 1; //exit("<pre>".print_r($wpsc_cart,true)."</pre>"); //new item code $no = 0; // $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency); // foreach($wpsc_cart->cart_items as $item){ //google prohibited items not implemented $curr = 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']; // exit('<pre>'.print_r($_REQUEST,true).'</pre>'); $google_curr = get_option('google_cur'); while (wpsc_have_cart_items()) { wpsc_the_cart_item(); if ($google_curr != $local_currency_code) { $google_currency_productprice = $curr->convert(wpsc_cart_item_price(false) / wpsc_cart_item_quantity(), $google_curr, $local_currency_code); $google_currency_shipping = $curr->convert($wpsc_cart->selected_shipping_amount, $google_curr, $local_currency_code); } else { $google_currency_productprice = wpsc_cart_item_price(false) / wpsc_cart_item_quantity() + wpsc_cart_item_shipping(false); $google_currency_shipping = $wpsc_cart->selected_shipping_amount; } // exit('<pre>'.print_r(wpsc_cart_item_name(),true).'</pre>'); $cartitem["{$no}"] = new GoogleItem(wpsc_cart_item_name(), '', wpsc_cart_item_quantity(), $google_currency_productprice); $cart->AddItem($cartitem["{$no}"]); $no++; } //If there are coupons applied add coupon as a product with negative price if ($wpsc_cart->coupons_amount > 0) { if ($google_curr != $local_currency_code) { $google_currency_productprice = $curr->convert($wpsc_cart->coupons_amount, $google_curr, $local_currency_code); } else { $google_currency_productprice = $wpsc_cart->coupons_amount; } $cartitem[$no] = new GoogleItem('Discount', 'Discount Price', 1, '-' . $google_currency_productprice); // Unit price $cart->AddItem($cartitem[$no]); } // } // Add shipping options if (wpsc_uses_shipping() && $google_currency_shipping > 0) { $Gfilter = new GoogleShippingFilters(); $google_checkout_shipping = get_option("google_shipping_country"); $googleshippingcountries = count($google_checkout_shipping); //exit('<pre>'.print_r($googleshipping, true).'</pre>'); if ($googleshippingcountries == 242) { $Gfilter->SetAllowedWorldArea(true); } else { if (is_array($google_checkout_shipping)) { $google_shipping_country_ids = implode(",", $google_checkout_shipping); } $google_shipping_country = $wpdb->get_col("SELECT `isocode` FROM " . WPSC_TABLE_CURRENCY_LIST . " WHERE id IN (" . $google_shipping_country_ids . ")"); foreach ($google_shipping_country as $isocode) { //exit($isocode); $Gfilter->AddAllowedPostalArea($isocode); if ($isocode == 'US') { $Gfilter->SetAllowedCountryArea('ALL'); } } } $Gfilter->SetAllowUsPoBox(false); $ship_1 = new GoogleFlatRateShipping('Flat Rate Shipping', $google_currency_shipping); $ship_1->AddShippingRestrictions($Gfilter); $cart->AddShipping($ship_1); } //wpsc_google_shipping_quotes(); // Add tax rules //if ($_SESSION['wpsc_selected_country']=='US'){ //set default tax //exit('<pre>'.print_r($_SESSION,true).'</pre>'); $sql = "SELECT `name`, `tax` FROM " . WPSC_TABLE_REGION_TAX . " WHERE id='" . $_SESSION['wpsc_selected_region'] . "'"; //exit('<pre>'.print_r($sql, true).'</pre>'); $state_name = $wpdb->get_row($sql, ARRAY_A); //exit('<pre>'.print_r($state_name, true).'</pre>'); $defaultTax = $state_name['tax'] / 100; $tax_rule = new GoogleDefaultTaxRule($defaultTax); $sql = "SELECT `code` FROM " . WPSC_TABLE_REGION_TAX . " WHERE `country_id`='136' AND `tax` = " . $state_name['tax']; $states = $wpdb->get_col($sql); //exit('<pre>'.print_r($states, true).'</pre>'); $tax_rule->SetStateAreas((array) $states); $cart->AddDefaultTaxRules($tax_rule); //get alternative tax rates $sql = "SELECT DISTINCT `tax` FROM " . WPSC_TABLE_REGION_TAX . " WHERE `tax` != 0 AND `tax` !=" . $state_name['tax'] . " AND `country_id`='136' ORDER BY `tax`"; $othertax = $wpdb->get_col($sql); $i = 1; //exit('<pre>'.print_r($othertax, true).'</pre>'); foreach ($othertax as $altTax) { $sql = "SELECT `code` FROM " . WPSC_TABLE_REGION_TAX . " WHERE `country_id`='136' AND `tax`=" . $altTax; $alt = $wpdb->get_col($sql); $altTax = $altTax / 100; $alt_google_tax = new GoogleDefaultTaxRule($altTax); $alt_google_tax->SetStateAreas($alt); //$g = new GoogleAlternateTaxTable('Alt Tax'.$i); //$g->AddAlternateTaxRules($alt_google_tax); $cart->AddDefaultTaxRules($alt_google_tax); // exit(print_r($alt,true)); $i++; } //} 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'; } // Display Google Checkout button //echo '<pre>'.print_r($cart, true).'</pre>'; //unset($_SESSION['wpsc_sessionid']); //if($fromCheckout){ echo $cart->CheckoutButtonCode($google_button_size); //} }
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); }
function UseCase3() { //Create a new shopping cart object $merchant_id = ""; // Your Merchant ID $merchant_key = ""; // Your Merchant Key $server_type = "sandbox"; $currency = "USD"; $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency); // Add items to the cart $item = new GoogleItem("MegaSound 2GB MP3 Player", "Portable MP3 player - stores 500 songs", 1, 175.49); $item->SetMerchantPrivateItemData("<color>blue</color><weight>3.2</weight>"); $cart->AddItem($item); // Add merchant calculations options $cart->SetMerchantCalculations("http://200.69.205.154/~brovagnati/tools/unitTest/demo/responsehandlerdemo.php", "false", "true", "true"); // accept-merchant-gift-certificates // Add merchant-calculated-shipping option $ship = new GoogleMerchantCalculatedShipping("2nd Day Air", 10.0); // Default, fallback price $restriction = new GoogleShippingFilters(); $restriction->AddAllowedPostalArea("GB"); $restriction->AddAllowedPostalArea("US"); $restriction->SetAllowUsPoBox(false); $ship->AddShippingRestrictions($restriction); $address_filter = new GoogleShippingFilters(); $address_filter->AddAllowedPostalArea("GB"); $address_filter->AddAllowedPostalArea("US"); $address_filter->SetAllowUsPoBox(false); $ship->AddAddressFilters($address_filter); $cart->AddShipping($ship); // Set default tax options $tax_rule = new GoogleDefaultTaxRule(0.15); $tax_rule->SetWorldArea(true); $cart->AddDefaultTaxRules($tax_rule); $cart->AddRoundingPolicy("UP", "TOTAL"); // Display XML data // echo "<pre>"; // echo htmlentities($cart->GetXML()); // echo "</pre>"; // Display a disabled, small button echo $cart->CheckoutButtonCode("SMALL", false); }
/** * Generate the Google Checkout button link **/ public function generate_googlecheckout_form($order_id) { global $woocommerce; require_once GOOGLE_CHECKOUT_LIB . 'googlecart.php'; require_once GOOGLE_CHECKOUT_LIB . 'googleitem.php'; require_once GOOGLE_CHECKOUT_LIB . 'googleshipping.php'; require_once GOOGLE_CHECKOUT_LIB . 'googletax.php'; $order = new WC_Order($order_id); $shipping_name = explode(' ', $order->shipping_method); // Check if this is a test purchase if ($this->testmode == 'yes') { $server_type = "sandbox"; } else { $server_type = "checkout"; } $merchant_id = $this->merchant_id; // Your Merchant ID $merchant_key = $this->merchant_key; // Your Merchant Key $currency = get_option('woocommerce_currency'); $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency); // Specify <edit-cart-url> $cart->SetEditCartUrl(get_permalink(get_option('woocommerce_cart_page_id'))); // Specify "Return to xyz" link $cart->SetContinueShoppingUrl(add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink(get_option('woocommerce_thanks_page_id'))))); // Order key $cart->SetMerchantPrivateData(new MerchantPrivateData(array("cart-id" => $order->id))); // Request buyer's phone number $cart->SetRequestBuyerPhone(true); // Default tax - for shipping, if used if ($order->order_shipping_tax > 0) { // We manually calculate the shipping tax percentage here $calculated_shipping_tax_percentage = $order->order_shipping_tax / $order->order_shipping; $tax_rule_for_shipping = new GoogleDefaultTaxRule($calculated_shipping_tax_percentage, 'true'); $tax_rule_for_shipping->SetWorldArea(true); $cart->AddDefaultTaxRules($tax_rule_for_shipping); } // Shipping Cost if ($order->order_shipping > 0) { $ship_1 = new GoogleFlatRateShipping($order->shipping_method, number_format($order->order_shipping, 2)); $restriction_1 = new GoogleShippingFilters(); $restriction_1->SetAllowedWorldArea(true); $ship_1->AddShippingRestrictions($restriction_1); $cart->AddShipping($ship_1); } // Cart Contents $item_loop = 0; $myvat = array(); if (sizeof($order->get_items()) > 0) { foreach ($order->get_items() as $item) { $_product = new WC_Product($item['id']); if ($_product->exists() && $item['qty']) { $item_loop++; // Change tax format from 25.00 to 0.25 $item_tax_percentage = number_format($order->get_item_tax($item, false) / $order->get_item_total($item, false, false) * 100, 2, '.', ''); $item_vat = $item_tax_percentage / 100; $myvat[$item_loop] = $item_vat; ${"item_" . $item_loop} = new GoogleItem($item['name'], "", $item['qty'], $order->get_item_total($item, false, false)); // Name the alternate-tax-table $vat_name = "vat" . $item_vat; ${"item_" . $item_loop}->SetMerchantItemId($item['id']); ${"item_" . $item_loop}->SetTaxTableSelector($vat_name); $cart->AddItem(${"item_" . $item_loop}); } } } // Discount if ($order->order_discount > 0) { $item_loop++; ${"item_" . $item_loop} = new GoogleItem(__('Discount', 'woothemes'), "", "1", -$order->order_discount); ${"item_" . $item_loop}->SetTaxTableSelector("no_tax"); $cart->AddItem(${"item_" . $item_loop}); } // Tax // Loops through all tax classes that has been added to the cart and add these as Alternate tax tables to google Checkout. $taxrule_loop = 1; $no_duplicate_vat = array_unique($myvat); foreach ($no_duplicate_vat as $value) { // Name the alternate-tax-table $vat_name = "vat" . $value; $tax_table = new GoogleAlternateTaxTable($vat_name); ${"tax_rule_" . $taxrule_loop} = new GoogleAlternateTaxRule($value); ${"tax_rule_" . $taxrule_loop}->SetWorldArea(true); $tax_table->AddAlternateTaxRules(${"tax_rule_" . $taxrule_loop}); $cart->AddAlternateTaxTables($tax_table); $taxrule_loop++; } // The form return $cart->CheckoutButtonCode("SMALL") . '<script type="text/javascript"> jQuery(function(){ jQuery("body").block( { message: "<img src=\\"' . $woocommerce->plugin_url() . '/assets/images/ajax-loader.gif\\" alt=\\"Redirecting...\\" />' . __('Thank you for your order. We are now redirecting you to Google Checkout to make payment.', 'woothemes') . '", overlayCSS: { background: "#fff", opacity: 0.6 }, css: { padding: 20, textAlign: "center", color: "#555", border: "3px solid #aaa", backgroundColor:"#fff", cursor: "wait", lineHeight: "32px" } }); jQuery("#submit_googlecheckout_payment_form").click(); }); </script>'; }
$total_weight = $cart->show_weight(); $total_count = $cart->count_contents(); // merchant calculated shipping $shipping_name = $googlepayment->mc_shipping_methods_names[$module_info[$key]['code']] . ': ' . $name; // merchant calculated - use defaults if (!in_array($module_info[$key]['code'], $googlepayment->shipping_support)) { $default_value = compare($module_info[$key]['code'] . $method . $type, $key_values); $shipping_price = $currencies->get_value(DEFAULT_CURRENCY) * $default_value; } else { $default_value = 1; $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]);
/** * 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; }
function Usecase($seperator, $sessionid) { global $wpdb; $purchase_log_sql = "SELECT * FROM `" . $wpdb->prefix . "purchase_logs` WHERE `sessionid`= " . $sessionid . " LIMIT 1"; $purchase_log = $wpdb->get_results($purchase_log_sql, ARRAY_A); $cart_sql = "SELECT * FROM `" . $wpdb->prefix . "cart_contents` WHERE `purchaseid`='" . $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'); $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency); $cart->SetContinueShoppingUrl(get_option('product_list_url')); $cart->SetEditCartUrl(get_option('shopping_cart_url')); $no = 1; //exit("<pre>".print_r($wp_cart,true)."</pre>"); foreach ($wp_cart as $item) { $product_data = $wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . "product_list` WHERE `id`='" . $item['prodid'] . "' LIMIT 1", ARRAY_A); $product_data = $product_data[0]; $prohibited = $wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . "wpsc_productmeta` WHERE `product_id`='" . $item['prodid'] . "' AND meta_key='google_prohibited' LIMIT 1", ARRAY_A); $prohibited_data = $prohibited_data[0]; if (count($prohibited) > 0) { $_SESSION['google_prohibited'] = '1'; } else { $_SESSION['google_prohibited'] = '0'; } $variation_count = count($product_variations); $variation_sql = "SELECT * FROM `" . $wpdb->prefix . "cart_item_variations` WHERE `cart_id`='" . $item['id'] . "'"; $variation_data = $wpdb->get_results($variation_sql, ARRAY_A); $variation_count = count($variation_data); $extras_sql = "SELECT * FROM `" . $wpdb->prefix . "cart_item_extras` WHERE `cart_id`='" . $item['id'] . "'"; $extras_data = $wpdb->get_results($extras_sql, ARRAY_A); $extras_count = count($extras_data); $price = nzshpcrt_calculate_tax($item['price'], $_SESSION['selected_country'], $_SESSION['selected_region']); if ($extras_count > 0) { foreach ($extras_data as $extras_datum) { $price += $wpdb->get_var("SELECT `price` FROM `" . $wpdb->prefix . "extras_values_associations` WHERE `product_id` = '" . $item['prodid'] . "' AND `extras_id` = '" . $extras_datum['extra_id'] . "' LIMIT 1"); } } //exit("------->".$price); $local_currency_shipping = $item['pnp']; $base_shipping = $purchase_log[0]['base_shipping']; $total_shipping = $local_currency_shipping + $base_shipping; $cartitem["{$no}"] = new GoogleItem($product_data['name'], $product_data['description'], $item['quantity'], $price); // Unit price $cart->AddItem($cartitem["{$no}"]); $no++; } // Add shipping options $Gfilter = new GoogleShippingFilters(); $Gfilter->SetAllowedCountryArea('ALL'); $google_checkout_shipping = get_option("google_shipping_country"); $google_shipping_country_ids = implode(",", $google_checkout_shipping); $google_shipping_country = $wpdb->get_var("SELECT isocode FROM " . $wpdb->prefix . "currency_list WHERE id IN (" . $google_shipping_country_ids . ")"); $Gfilter->AddAllowedPostalArea($google_shipping_country); $ship_1 = new GoogleFlatRateShipping('Flat Rate Shipping', $total_shipping); $ship_1->AddShippingRestrictions($Gfilter); $cart->AddShipping($ship_1); // Add tax rules if ($_SESSION['selected_country'] == 'US') { $tax_rule = new GoogleDefaultTaxRule(0.05); $state_name = $wpdb->get_var("SELECT name FROM " . $wpdb->prefix . "region_tax WHERE id='" . $_SESSION['selected_region'] . "'"); $tax_rule->SetStateAreas(array($state_name)); $cart->AddDefaultTaxRules($tax_rule); } $_SESSION['nzshpcrt_cart'] = null; // Specify <edit-cart-url> // $cart->SetEditCartUrl("https://www.example.com/cart/"); // Specify "Return to xyz" link //$cart->SetContinueShoppingUrl("https://www.example.com/goods/"); // Request buyer's phone number //$cart->SetRequestBuyerPhone(true); // Display Google Checkout button echo $cart->CheckoutButtonCode("BIG"); }
function nzshpcrt_shopping_basket_internals($cart, $quantity_limit = false, $no_title = false) { global $wpdb; if (get_option('permalink_structure') != '') { $seperator = "?"; } else { $seperator = "&"; } if (get_option('show_sliding_cart') == 1) { if (is_numeric($_SESSION['slider_state'])) { if ($_SESSION['slider_state'] == 0) { $collapser_image = 'plus.png'; } else { $collapser_image = 'minus.png'; } $fancy_collapser = "<a href='#' onclick='return shopping_cart_collapser()' id='fancy_collapser_link'><img src='" . WPSC_URL . "/images/{$collapser_image}' title='' alt='' id='fancy_collapser' /></a>"; } else { if ($_SESSION['nzshpcrt_cart'] == null) { $collapser_image = 'plus.png'; } else { $collapser_image = 'minus.png'; } $fancy_collapser = "<a href='#' onclick='return shopping_cart_collapser()' id='fancy_collapser_link'><img src='" . WPSC_URL . "/images/{$collapser_image}' title='' alt='' id='fancy_collapser' /></a>"; } } else { $fancy_collapser = ""; } $current_url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; if (get_option('cart_location') == 4) { $no_title = true; } switch (get_option('cart_location')) { case 1: if ($no_title !== true) { $output .= "<h2>" . TXT_WPSC_SHOPPINGCART . " {$fancy_collapser}</h2>"; $output .= "<span id='alt_loadingindicator'><img id='alt_loadingimage' src='" . WPSC_URL . "/images/indicator.gif' alt='Loading' title='Loading' /> " . TXT_WPSC_UDPATING . "...</span></strong><br />"; } $spacing = ""; break; case 3: if ($no_title !== true) { $output .= "<strong class='cart_title'>" . TXT_WPSC_SHOPPINGCART . " {$fancy_collapser}</strong>"; } //$output .= "<a href='#' onclick='return shopping_cart_collapser()' class='cart_title' id='fancy_collapser_link'>".TXT_WPSC_SHOPPINGCART." </a>"; break; case 4: if ($no_title !== true) { if (is_array($GLOBALS['registered_sidebars'])) { $sidebar_args = end($GLOBALS['registered_sidebars']); } else { $sidebar_args['before_title'] = "<h2>"; $sidebar_args['after_title'] = "</h2>"; } $output .= $sidebar_args['before_title'] . TXT_WPSC_SHOPPINGCART . " {$fancy_collapser}" . $sidebar_args['after_title']; } break; default: if ($no_title !== true) { //$output .= "<strong class='cart_title'>".TXT_WPSC_SHOPPINGCART." $fancy_collapser</strong>"; } break; } $cart_count = 0; foreach ((array) $cart as $item) { $cart_count += $item->quantity; } $output .= "<div id='sliding_cart'>"; if ($cart != null) { if ($quantity_limit == true || $_SESSION['out_of_stock'] == true) { $output .= "<span class='items'><span class='numberitems'>" . TXT_WPSC_NUMBEROFITEMS . ": </span><span class='cartcount'>" . $cart_count . "</span></span>"; $output .= "<span class='nomore'>" . TXT_WPSC_NOMOREAVAILABLE . "</span>"; $_SESSION['out_of_stock'] = false; } else { $output .= "<span class='items'><span class='numberitems'>" . TXT_WPSC_NUMBEROFITEMS . ": </span><span class='cartcount'>" . $cart_count . "</span></span>"; } $output .= "<table class='shoppingcart'>\n\r"; $output .= "<tr><th id='thproduct'>" . TXT_WPSC_PRODUCT . "</th><th id='thqty'>" . TXT_WPSC_QUANTITY_SHORT . "</th><th id='thprice'>" . TXT_WPSC_PRICE . "</th></tr>\n\r"; $all_donations = true; $all_no_shipping = true; $tax = 0; //written by allen $merchant_id = get_option('google_id'); // Your Merchant ID $merchant_key = get_option('google_key'); // Your Merchant Key $server_type = get_option('google_server_type'); $currency = get_option('google_cur'); if (get_option('payment_gateway') == 'google') { $google_cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency); } foreach ($cart as $cart_item) { $product_id = $cart_item->product_id; $quantity = $cart_item->quantity; //echo("<pre>".print_r($cart_item->product_variations,true)."</pre>"); $product = $wpdb->get_row("SELECT * FROM `" . $wpdb->prefix . "product_list` WHERE `id` = '{$product_id}' LIMIT 1", ARRAY_A); if ($product['donation'] == 1) { if (get_option('payment_gateway') == 'google') { $google_unit_price = $cart_item->donation_price; } $price = $quantity * $cart_item->donation_price; } else { if (get_option('payment_gateway') == 'google') { $google_unit_price = calculate_product_price($product_id, $cart_item->product_variations, 'stay', $cart_item->extras); } $price = $quantity * calculate_product_price($product_id, $cart_item->product_variations, 'stay', $cart_item->extras); if ($product['notax'] != 1) { $tax += nzshpcrt_calculate_tax($price, $_SESSION['selected_country'], $_SESSION['selected_region']) - $price; } $all_donations = false; } if ($product['no_shipping'] != 1) { $all_no_shipping = false; } if ($_SESSION['delivery_country'] != null) { $total_shipping += nzshpcrt_determine_item_shipping($product['id'], $quantity, $_SESSION['delivery_country']); } $total += $price; //exit(utf8_encode('™')); $product['name'] = str_replace("™", "™", $product['name']); $product['description'] = str_replace("™", "™", $product['description']); if (get_option('payment_gateway') == 'google') { $google_item = new GoogleItem(utf8_decode($product['name']), utf8_decode($product['description']), $quantity, $google_unit_price); $google_item->SetMerchantItemId($product['id']); $google_cart->SetMerchantCalculations(get_option('siteurl'), "false", "false", "false"); //echo serialize($cart_item->product_variations); $google_item->SetMerchantPrivateItemData("some variations"); $google_cart->AddItem($google_item); } $output .= "<tr>"; if (get_option("hide_name_link") == '1') { $output .= "<td class='tdproduct'>" . $product['name'] . "</td>"; } else { $output .= "<td><a href='" . wpsc_product_url($product['id']) . "' >" . stripslashes($product['name']) . "</a></td>"; } $output .= "<td class='tdqty'>" . $quantity . "</td>"; $output .= "<td class='tdprice'>" . nzshpcrt_currency_display($price, 1) . "</td>"; $output .= "</tr>\n\r"; } //google checkout stuff. // if (get_option('payment_gateway') == 'google') { // $google_shipping = new GoogleFlatRateShipping("Flat Rate Shipping", $total_shipping); // $Gfilter = new GoogleShippingFilters(); // $google_checkout_shipping=get_option("google_shipping_country"); // $google_shipping_country_ids = implode(",",(array)$google_checkout_shipping); // if($google_shipping_country_ids != null) { // $google_shipping_country = $wpdb->get_var("SELECT isocode FROM ".$wpdb->prefix."currency_list WHERE id IN (".$google_shipping_country_ids.")"); // } // $Gfilter->AddAllowedPostalArea($google_shipping_country); // $google_shipping->AddShippingRestrictions($Gfilter); // $google_cart->AddShipping($google_shipping); // // if ($_SESSION['selected_country']=='US'){ // $tax_rule = new GoogleDefaultTaxRule(0.05); // $state_name = $wpdb->get_var("SELECT name FROM ".$wpdb->prefix."region_tax WHERE id='".$_SESSION['selected_region']."'"); // $tax_rule->SetStateAreas(array($state_name)); // $tax_rule->AddPostalArea($google_shipping_country); // $google_cart->AddDefaultTaxRules($tax_rule); // } // } //end of google checkout. $output .= "</table>"; if ($_SESSION['delivery_country'] != null) { $total_shipping = nzshpcrt_determine_base_shipping($total_shipping, $_SESSION['delivery_country']); $output .= "<span class='subtotal'><span class='subtotalhead'>" . TXT_WPSC_SUBTOTAL . ":</span>" . nzshpcrt_currency_display($total, 1) . "</span>"; if (get_option('do_not_use_shipping') != 1 && $all_donations == false && $all_no_shipping == false) { $output .= "<span class='postage'><span class='postagehead'>" . TXT_WPSC_POSTAGE . ":</span>" . nzshpcrt_currency_display($total_shipping, 1) . "</span> "; } if ($tax > 0) { $output .= "<span class='tax'><span class='taxhead'>" . TXT_WPSC_TAX . ":</span> " . nzshpcrt_currency_display($tax, 1) . "</span>"; } if ($_SESSION['coupon_num']) { $overall_total = nzshpcrt_overall_total_price_numeric($_SESSION['selected_country'], true); $discount = $overall_total - nzshpcrt_apply_coupon($overall_total, $_SESSION['coupon_num']); $total_after_discount = $overall_total - $discount; $_SESSION['wpsc_discount'] = $discount; } else { $_SESSION['wpsc_discount'] = 0; } if ($discount > 0) { $output .= "<span class='discount'><span class='discounthead'>" . TXT_WPSC_DISCOUNT . ":</span>" . nzshpcrt_currency_display($discount, 1) . "</span>"; } $output .= "<span class='total'><span class='totalhead'>" . TXT_WPSC_TOTAL . ":</span>" . nzshpcrt_overall_total_price($_SESSION['delivery_country'], true) . "</span>"; } else { if ($discount > 0) { $output .= "<span class='discount'><span class='discounthead'>" . TXT_WPSC_DISCOUNT . ":</span>" . nzshpcrt_currency_display($discount, 1) . "</span>"; } $output .= "<span class='total'><span class='totalhead'>" . TXT_WPSC_TOTAL . ":</span>" . nzshpcrt_overall_total_price($_SESSION['delivery_country'], true) . "</span>"; } if (get_option('permalink_structure') != '') { $seperator = "?"; } else { $seperator = "&"; } if ($discount > 0) { if (get_option('payment_gateway') == 'google') { $google_item = new GoogleItem(utf8_decode("Coupon Code: '" . $_SESSION['coupon_num'] . "'"), utf8_decode("A coupon redeem"), 1, -$discount); $google_item->SetMerchantPrivateItemData("Coupon Deduction"); $google_cart->AddItem($google_item); } } if (get_option('payment_gateway') == 'google') { if (!$total_shipping) { $total_shipping = 0; } $pnp = $wpdb->get_var("SELECT SUM(pnp) FROM " . $wpdb->prefix . "product_list WHERE id IN (" . $google_product_id . ")"); $local_shipping_price = nzshpcrt_determine_base_shipping($total_shipping, get_option('base_country')); $google_local_shipping = new GoogleFlatRateShipping("Local Shipping", $local_shipping_price + $pnp); $international_shipping_price = nzshpcrt_determine_base_shipping($total_shipping, get_option('base_country') . "-"); $google_international_shipping = new GoogleFlatRateShipping("International Shipping", $international_shipping_price + $pnp); $Gfilter2 = new GoogleShippingFilters(); $Gfilter = new GoogleShippingFilters(); $google_checkout_shipping = get_option("google_shipping_country"); if (!empty($google_checkout_shipping)) { $google_shipping_country_ids = implode(",", (array) $google_checkout_shipping); $google_shipping_country = $wpdb->get_results("SELECT isocode FROM " . $wpdb->prefix . "currency_list WHERE id IN (" . $google_shipping_country_ids . ")", ARRAY_A); } //exit(print_r($google_shipping_country,1)); foreach ((array) $google_shipping_country as $country) { $Gfilter->AddAllowedPostalArea($country['isocode']); $Gfilter2->AddAllowedPostalArea($country['isocode']); $Gfilter2->AddExcludedPostalArea(get_option('base_country')); if ($country['isocode'] != get_option('base_country')) { $Gfilter->AddExcludedPostalArea($country['isocode']); } } $google_local_shipping->AddShippingRestrictions($Gfilter); $google_international_shipping->AddShippingRestrictions($Gfilter2); $google_cart->AddShipping($google_local_shipping); $google_cart->AddShipping($google_international_shipping); $local_tax = $wpdb->get_var("SELECT tax from " . $wpdb->prefix . "currency_list WHERE isocode='" . get_option('base_country') . "'"); //exit($local_tax); $tax_rule = new GoogleDefaultTaxRule($local_tax / 100); if ($_SESSION['selected_country'] == 'US' && get_option('base_country') == 'US') { $state_name = $wpdb->get_var("SELECT name FROM " . $wpdb->prefix . "region_tax WHERE id='" . $_SESSION['selected_region'] . "'"); //foreach ($state_name as $state) $tax_rule->SetStateAreas(array($state_name)); } else { $tax_rule->AddPostalArea(get_option('base_country')); } $google_cart->AddDefaultTaxRules($tax_rule); $alter_tax_rule = new GoogleDefaultTaxRule(0.0); foreach ((array) $google_shipping_country as $country) { if (get_option('base_country') != $country['isocode']) { $alter_tax_rule->AddPostalArea($country['isocode']); } } if ($alter_tax_rule != '') { $google_cart->AddDefaultTaxRules($alter_tax_rule); } } $output .= "<span class='emptycart'><a href='" . get_option('product_list_url') . $seperator . "category=" . $_GET['category'] . "&cart=empty' onclick='emptycart();return false;'>" . TXT_WPSC_EMPTYYOURCART . "</a><span>"; $output .= "<span class='gocheckout'><a href='" . get_option('shopping_cart_url') . "'>" . TXT_WPSC_GOTOCHECKOUT . "</a></span>"; if (get_option('payment_gateway') == 'google') { 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'; } $google_cart->SetMerchantCalculations(get_option('siteurl'), "false", "false"); $google_cart->SetRequestBuyerPhone("true"); $google_session = md5(time()); $_SESSION['google_session'] = $google_session; if (!preg_match("/\\?/", get_option('product_list_url'))) { $seperator = "?"; } else { $seperator = "&"; } $continueshoppingurl = get_option('product_list_url') . $seperator . "action=bfg&session=" . $google_session; $google_cart->SetContinueShoppingUrl($continueshoppingurl); $google_cart->SetEditCartUrl(get_option('shopping_cart_url')); $_SESSION['google_shopping_cart'] = serialize($google_cart); // $output .= $google_cart->getXML(); $output .= "<br>" . $google_cart->CheckoutButtonCode($google_button_size); } //$output .= "<a href='".get_option('product_list_url')."'>".TXT_WPSC_CONTINUESHOPPING."</a>"; } else { $output .= $spacing; $output .= "<p class='empty'>" . TXT_WPSC_YOURSHOPPINGCARTISEMPTY . ".</p>"; $output .= "<p class='visitshop'><a href='" . get_option('product_list_url') . "'>" . TXT_WPSC_VISITTHESHOP . "</a></p>"; } $output .= "</div>"; return $output; }