PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/wp-shopping-cart/shopping_cart.php

https://github.com/alx/barceloneta
PHP | 598 lines | 445 code | 54 blank | 99 comment | 119 complexity | cab940ca80705cb6eb76989661132bc7 MD5 | raw file
  1. <?php
  2. global $wpdb, $user_ID;
  3. //$_SESSION['coupon_num'] = '';
  4. $saved_data_sql = "SELECT * FROM `".$wpdb->prefix."usermeta` WHERE `user_id` = '".$user_ID."' AND `meta_key` = 'wpshpcrt_usr_profile';";
  5. $saved_data = $wpdb->get_row($saved_data_sql,ARRAY_A);
  6. $meta_data = unserialize($saved_data['meta_value']);
  7. if($_POST['country'] != null) {
  8. $_SESSION['delivery_country'] = $_POST['country'];
  9. if($_SESSION['selected_country'] == null) {
  10. $_SESSION['selected_country'] = $_POST['country'];
  11. }
  12. } else if($_SESSION['selected_country'] == '') {
  13. $_SESSION['selected_country'] = get_option('base_country');
  14. $_SESSION['delivery_country'] = get_option('base_country');
  15. }
  16. if($_SESSION['delivery_country'] == '') {
  17. $_SESSION['delivery_country'] = $_SESSION['selected_country'];
  18. }
  19. if($_POST['region'] != null) {
  20. $_SESSION['selected_region'] = $_POST['region'];
  21. } else if($_SESSION['selected_region'] == '') {
  22. $_SESSION['selected_region'] = get_option('base_region');
  23. }
  24. if(get_option('permalink_structure') != '') {
  25. $seperator ="?";
  26. } else {
  27. $seperator ="&amp;";
  28. }
  29. if($_POST['coupon_num']){
  30. $_SESSION['coupon_num'] = $_POST['coupon_num'];
  31. }
  32. //exit($_SESSION['coupon_num']);
  33. $rawnum = null;
  34. $number = null;
  35. $cart = $_SESSION['nzshpcrt_cart'];
  36. function wpsc_shipping_country_list($selected_country = null) {
  37. global $wpdb;
  38. if($selected_country == null) {
  39. $selected_country = get_option('base_country');
  40. }
  41. if($selected_region == null) {
  42. $selected_region = get_option('base_region');
  43. }
  44. $country_data = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."currency_list` ORDER BY `country` ASC",ARRAY_A);
  45. $output .= "<select name='country' id='current_country' onchange='submit_change_country();' >";
  46. foreach ($country_data as $country) {
  47. $selected ='';
  48. if($selected_country == $country['isocode']) {
  49. $selected = "selected='true'";
  50. }
  51. $output .= "<option value='".$country['isocode']."' $selected>".$country['country']."</option>";
  52. }
  53. $output .= "</select>";
  54. return $output;
  55. }
  56. ?>
  57. <div class="wrap wpsc_container">
  58. <?php
  59. if($_SESSION['nzshpcrt_cart'] != null) {
  60. echo "<span>".TXT_WPSC_CONFIRM_TOTALS."</span>\n\r";
  61. echo "<hr class='productcart' />\n\r";
  62. echo "<table class='productcart'>\n\r";
  63. echo "<tr class='firstrow'>\n\r";
  64. echo " <td class='firstcol'>".TXT_WPSC_PRODUCT.":</td>\n\r";
  65. echo " <td>".TXT_WPSC_QUANTITY.":</td>\n\r";
  66. echo " <td>". TXT_WPSC_PRICE.":</td>\n\r";
  67. echo " <td></td>\n\r";
  68. echo "</tr>\n\r";
  69. $num = 1;
  70. $total = 0;
  71. $total_shipping = 0;
  72. $all_donations = true;
  73. $all_no_shipping = true;
  74. $tax =0;
  75. foreach($cart as $key => $cart_item) {
  76. $product_id = $cart_item->product_id;
  77. $quantity = $cart_item->quantity;
  78. $extras = $cart_item->extras;
  79. $number =& $quantity;
  80. $product_variations = $cart_item->product_variations;
  81. $extras_count = count($cart_item->extras);
  82. $variation_count = count($product_variations);
  83. //exit("<pre>".print_r($product_variations,true)."</pre>");
  84. if($variation_count >= 1) {
  85. $variation_list = "&nbsp;(";
  86. $i = 0;
  87. //exit(print_r($product_variations,1));
  88. foreach($product_variations as $value_id) {
  89. if($i > 0) {
  90. $variation_list .= ",&nbsp;";
  91. }
  92. $value_data = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."variation_values` WHERE `id`='".$value_id."' LIMIT 1",ARRAY_A);
  93. #$variation_list .= str_replace(" ", "&nbsp;",$value_data[0]['name']);
  94. $variation_list .= str_replace("", " ",$value_data[0]['name']);
  95. //echo("<pre>".print_r($variation,true)."</pre>");
  96. $i++;
  97. }
  98. $variation_list .= ")";
  99. } else {
  100. $variation_list = '';
  101. }
  102. $sql = "SELECT * FROM `".$wpdb->prefix."product_list` WHERE `id`='$product_id' LIMIT 1";
  103. $product_list = $wpdb->get_row($sql,ARRAY_A) ;
  104. echo "<tr class='product_row'>\n\r";
  105. echo " <td class='firstcol'>\n\r";
  106. echo $product_list['name'] . $variation_list;
  107. echo " </td>\n\r";
  108. echo " <td>\n\r";
  109. echo "<form class='adjustform' method='POST' action='".get_option('shopping_cart_url')."'><input type='text' value='".$number."' size='2' name='quantity' /><input type='hidden' value='".$key."' name='key' />&nbsp; <input type='submit' name='submit' value='".TXT_WPSC_APPLY."' /></form>";
  110. echo " </td>\n\r";
  111. echo " <td>\n\r";
  112. if($product_list['donation'] == 1) {
  113. $price = $quantity * $cart_item->donation_price;
  114. } else {
  115. $price = $quantity * calculate_product_price($product_id, $cart_item->product_variations,'stay',$extras);
  116. if($product_list['notax'] != 1) {
  117. $tax += nzshpcrt_calculate_tax($price, $_SESSION['selected_country'], $_SESSION['selected_region']) - $price;
  118. }
  119. $all_donations = false;
  120. }
  121. if($product_list['no_shipping'] != 1) {
  122. $all_no_shipping = false;
  123. }
  124. echo nzshpcrt_currency_display($price, $product_list['notax']);
  125. $total += $price;
  126. echo " </td>\n\r";
  127. $shipping = nzshpcrt_determine_item_shipping($product_id, $number, $_SESSION['delivery_country']);
  128. $total_shipping += $shipping;
  129. echo " <td>\n\r";
  130. echo "<a href='".get_option('shopping_cart_url').$seperator."remove=".$key."'>Remove</a>";
  131. echo " </td>\n\r";
  132. echo "</tr>\n\r";
  133. }
  134. $siteurl = get_option('siteurl');
  135. if(($all_donations == false) && ($all_no_shipping == false)) {
  136. $total_shipping = nzshpcrt_determine_base_shipping($total_shipping, $_SESSION['delivery_country']);
  137. $total += $total_shipping;
  138. }
  139. //Written by allen
  140. $status = get_product_meta($cart[0]->product_id,'is_membership',true);
  141. $coupon_info = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.'wpsc_coupon_codes WHERE active="1"',ARRAY_A);
  142. if (($status[0]=='1')||(count($coupon_info)<1)){
  143. } else {
  144. echo "<tr>";
  145. echo " <form method='POST' action='".get_option('shopping_cart_url')."'>";
  146. echo " <td>Enter your coupon number:</td>";
  147. echo " <td colspan='2' align='left'>";
  148. echo " <input type='text' name='coupon_num' id='coupon_num' value='".$_SESSION['coupon_num']."'>";
  149. echo " </td>";
  150. echo " <td>";
  151. echo " <input type='submit' value='".TXT_WPSC_APPLY."'>";
  152. echo " </td>";
  153. echo " </form>";
  154. echo "</tr>";
  155. }
  156. //End of written by allen
  157. if((get_option('do_not_use_shipping') != 1) && (get_option('base_country') != null))
  158. {
  159. //if (!function_exists('getdistance')) {
  160. if (get_option("payment_gateway")!='google') {
  161. echo "<tr class='product_shipping'>\n\r";
  162. echo " <td colspan='2'>\n\r";
  163. ?>
  164. <h2><?php echo TXT_WPSC_SHIPPING_COUNTRY; ?></h2>
  165. <?php
  166. echo " </td>\n\r";
  167. echo " <td colspan='2' style='vertical-align: middle;'>";
  168. echo "</td>\n\r";
  169. echo "</tr>\n\r";
  170. }
  171. echo "<tr class='total_price'>\n\r";
  172. echo " <td colspan='2' >\n\r";
  173. if (get_option('payment_gateway')=='google') {
  174. echo TXT_WPSC_POSTAGE.":";
  175. } else {
  176. ?>
  177. <div class='select_country'>
  178. <form name='change_country' action='' method='POST'>
  179. <?php
  180. echo wpsc_shipping_country_list($_SESSION['delivery_country'], $_SESSION['selected_region']);
  181. ?>
  182. </form>
  183. <!--usps changes-->
  184. <div id='usps_shipping_methods'>
  185. <?php
  186. $dest = $_SESSION['delivery_country'];
  187. if ($dest == get_option('base_country')) {
  188. // $request = '<RateV3Request USERID="' . "221ALLEN1967" . '" PASSWORD="' . "651AC00ZD570" . '">';
  189. // $allowed_types = explode(", ", MODULE_SHIPPING_USPS_TYPES);
  190. //
  191. // while (list($key, $value) = each($this->types)) {
  192. // if ( !in_array($key, $allowed_types) ) continue;
  193. //
  194. // if ($key == 'FIRST CLASS'){
  195. // $this->FirstClassMailType = '<FirstClassMailType>LETTER</FirstClassMailType>';
  196. // } else {
  197. // $this->FirstClassMailType = '';
  198. // }
  199. //
  200. // if ($key == 'PRIORITY'){
  201. // $this->container = 'FLAT RATE ENVELOPE';
  202. // }
  203. //
  204. // if ($key == 'EXPRESS'){
  205. // $this->container = 'FLAT RATE ENVELOPE';
  206. // }
  207. //
  208. // if ($key == 'PARCEL POST'){
  209. // $this->container = 'REGULAR';
  210. // $this->machinable = 'false';
  211. // }
  212. //
  213. // $request .= '<Package ID="' . $services_count . '">' .
  214. // '<Service>' . $key . '</Service>' .
  215. // $this->FirstClassMailType .
  216. // '<ZipOrigination>' . SHIPPING_ORIGIN_ZIP . '</ZipOrigination>' .
  217. // '<ZipDestination>' . $dest_zip . '</ZipDestination>' .
  218. // '<Pounds>' . $this->pounds . '</Pounds>' .
  219. // '<Ounces>' . $this->ounces . '</Ounces>' .
  220. // '<Container>' . $this->container . '</Container>' .
  221. // '<Size>' . $this->size . '</Size>' .
  222. // '<Machinable>' . $this->machinable . '</Machinable>' .
  223. // '</Package>';
  224. //
  225. // if ($transit) {
  226. // $transitreq = 'USERID="' . MODULE_SHIPPING_USPS_USERID .
  227. // '" PASSWORD="' . MODULE_SHIPPING_USPS_PASSWORD . '">' .
  228. // '<OriginZip>' . STORE_ORIGIN_ZIP . '</OriginZip>' .
  229. // '<DestinationZip>' . $dest_zip . '</DestinationZip>';
  230. //
  231. // switch ($key) {
  232. // case 'EXPRESS': $transreq[$key] = 'API=ExpressMail&XML=' .
  233. // urlencode( '<ExpressMailRequest ' . $transitreq . '</ExpressMailRequest>');
  234. // break;
  235. // case 'PRIORITY': $transreq[$key] = 'API=PriorityMail&XML=' .
  236. // urlencode( '<PriorityMailRequest ' . $transitreq . '</PriorityMailRequest>');
  237. // break;
  238. // case 'PARCEL': $transreq[$key] = 'API=StandardB&XML=' .
  239. // urlencode( '<StandardBRequest ' . $transitreq . '</StandardBRequest>');
  240. // break;
  241. // default: $transreq[$key] = '';
  242. // break;
  243. // }
  244. // }
  245. //
  246. // $services_count++;
  247. // }
  248. // $request .= '</RateV3Request>'; //'</RateRequest>'; //Changed by Greg Deeth April 30, 2008
  249. // $request = 'API=RateV3&XML=' . urlencode($request);
  250. } else {
  251. $dest=$wpdb->get_var("SELECT country FROM ".$wpdb->prefix."currency_list WHERE isocode='".$dest."'");
  252. $weight = shopping_cart_total_weight();
  253. $request = '<IntlRateRequest USERID="' . get_option('usps_user_id') . '" PASSWORD="' . get_option('usps_user_password') . '">' .
  254. '<Package ID="0">' .
  255. '<Pounds>' . $weight . '</Pounds>' .
  256. '<Ounces>' . '0' . '</Ounces>' .
  257. '<MailType>Package</MailType>' .
  258. '<Country>' . $dest . '</Country>' .
  259. '</Package>' .
  260. '</IntlRateRequest>';
  261. $request = 'API=IntlRate&XML=' . urlencode($request);
  262. }
  263. //$http = new httpClient();
  264. $usps_server = 'production.shippingapis.com'; //'stg-production.shippingapis.com'; // or stg-secure.shippingapis.com //'production.shippingapis.com';
  265. $api_dll = 'shippingapi.dll'; //'shippingapi.dll';
  266. //if ($http->Connect($usps_server, 80)) {
  267. $url = 'http://'.$usps_server.'/' . $api_dll . '?' . $request;
  268. $ch=curl_init();
  269. curl_setopt($ch, CURLOPT_URL, $url);
  270. curl_setopt($ch, CURLOPT_NOPROGRESS, 1);
  271. curl_setopt($ch, CURLOPT_VERBOSE, 1);
  272. //curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
  273. curl_setopt($ch, CURLOPT_TIMEOUT, 120);
  274. curl_setopt($ch, CURLOPT_USERAGENT, 'osCommerce');
  275. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  276. $body = curl_exec($ch);
  277. curl_close($ch);
  278. //exit();
  279. // $http->addHeader('Host', $usps_server);
  280. // $http->addHeader('User-Agent', 'osCommerce');
  281. // $http->addHeader('Connection', 'Close');
  282. //if ($http->Get('/' . $api_dll . '?' . $request)) $body = $http->getBody();
  283. // if ($transit && is_array($transreq) && ($order->delivery['country']['id'] == STORE_COUNTRY)) {
  284. // while (list($key, $value) = each($transreq)) {
  285. // if ($http->Get('/' . $api_dll . '?' . $value)) $transresp[$key] = $http->getBody();
  286. // }
  287. // }
  288. //$http->Disconnect();
  289. if($body == '') {
  290. //return false;
  291. }
  292. $response=array();
  293. while (true) {
  294. if ($start = strpos($body, '<Package ID=')) {
  295. $body = substr($body, $start);
  296. $end = strpos($body, '</Package>');
  297. $response[] = substr($body, 0, $end+10);
  298. $body = substr($body, $end+9);
  299. } else {
  300. break;
  301. }
  302. }
  303. $rates = array();
  304. if ($dest == get_option('base_country')) {
  305. if (sizeof($response) == '1') {
  306. if (ereg('<Error>', $response[0])) {
  307. $number = ereg('<Number>(.*)</Number>', $response[0], $regs);
  308. $number = $regs[1];
  309. $description = ereg('<Description>(.*)</Description>', $response[0], $regs);
  310. $description = $regs[1];
  311. //return array('error' => $number . ' - ' . $description);
  312. }
  313. }
  314. $n = sizeof($response);
  315. for ($i=0; $i<$n; $i++) {
  316. if (strpos($response[$i], '<Rate>')) {
  317. $service = ereg('<MailService>(.*)</MailService>', $response[$i], $regs);
  318. $service = $regs[1];
  319. $postage = ereg('<Rate>(.*)</Rate>', $response[$i], $regs);
  320. $postage = $regs[1];
  321. $rates[] = array($service => $postage);
  322. if ($transit) {
  323. switch ($service) {
  324. case 'EXPRESS': $time = ereg('<MonFriCommitment>(.*)</MonFriCommitment>', $transresp[$service], $tregs);
  325. $time = $tregs[1];
  326. if ($time == '' || $time == 'No Data') {
  327. $time = 'Estimated 1 - 2 ' . 'Days';
  328. } else {
  329. $time = 'Tomorrow by ' . $time;
  330. }
  331. break;
  332. case 'PRIORITY': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs);
  333. $time = $tregs[1];
  334. if ($time == '' || $time == 'No Data') {
  335. $time = 'Estimated 1 - 3 ' . 'Days';
  336. } elseif ($time == '1') {
  337. $time .= ' ' . 'Day';
  338. } else {
  339. $time .= ' ' . 'Days';
  340. }
  341. break;
  342. case 'PARCEL': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs);
  343. $time = $tregs[1];
  344. if ($time == '' || $time == 'No Data') {
  345. $time = 'Estimated 2 - 9 ' . 'Days';
  346. } elseif ($time == '1') {
  347. $time .= ' ' . 'Day';
  348. } else {
  349. $time .= ' ' . 'Days';
  350. }
  351. break;
  352. case 'First-Class Mail':
  353. $time = 'Estimated 1 - 5 ' . 'Days';
  354. break;
  355. case 'MEDIA':
  356. $time = 'Estimated 2 - 9 ' . 'Days';
  357. break;
  358. case 'BPM':
  359. $time = 'Estimated 2 - 9 ' . 'Days';
  360. break;
  361. default:
  362. $time = '';
  363. break;
  364. }
  365. if ($time != '') $transittime[$service] = ': ' . $time . '';
  366. }
  367. }
  368. }
  369. } else {
  370. if (ereg('<Error>', $response[0])) {
  371. $number = ereg('<Number>(.*)</Number>', $response[0], $regs);
  372. $number = $regs[1];
  373. $description = ereg('<Description>(.*)</Description>', $response[0], $regs);
  374. $description = $regs[1];
  375. return array('error' => $number . ' - ' . $description);
  376. } else {
  377. $body = $response[0];
  378. $services = array();
  379. while (true) {
  380. if ($start = strpos($body, '<Service ID=')) {
  381. $body = substr($body, $start);
  382. $end = strpos($body, '</Service>');
  383. $services[] = substr($body, 0, $end+10);
  384. $body = substr($body, $end+9);
  385. } else {
  386. break;
  387. }
  388. }
  389. $allowed_types = Array( 'EXPRESS MAIL INT' => "Express Mail International (EMS)", 'EXPRESS MAIL INT FLAT RATE ENV' => "Express Mail International (EMS) Flat-Rate Envelope", 'PRIORITY MAIL INT' => "Priority Mail International", 'PRIORITY MAIL INT FLAT RATE ENV' => "Priority Mail International Flat-Rate Envelope", 'PRIORITY MAIL INT FLAT RATE BOX' => "Priority Mail International Flat-Rate Box", 'FIRST-CLASS MAIL INT' => "First Class Mail International Letters" );
  390. //foreach( explode(", ", MODULE_SHIPPING_USPS_TYPES_INTL) as $value ) $allowed_types[$value] = $this->intl_types[$value];
  391. $size = sizeof($services);
  392. for ($i=0, $n=$size; $i<$n; $i++) {
  393. if (strpos($services[$i], '<Postage>')) {
  394. $service = ereg('<SvcDescription>(.*)</SvcDescription>', $services[$i], $regs);
  395. $service = $regs[1];
  396. $postage = ereg('<Postage>(.*)</Postage>', $services[$i], $regs);
  397. $postage = $regs[1];
  398. $time = ereg('<SvcCommitments>(.*)</SvcCommitments>', $services[$i], $tregs);
  399. $time = $tregs[1];
  400. $time = preg_replace('/Weeks$/', 'Weeks',$time);
  401. $time = preg_replace('/Days$/', 'Days', $time);
  402. $time = preg_replace('/Day$/', 'Day', $time);
  403. if( !in_array($service, $allowed_types) ) continue;
  404. // if (isset($this->service) && ($service != $this->service) ) {
  405. // continue;
  406. // }
  407. $rates[] = array($service => $postage);
  408. if ($time != '') $transittime[$service] = ' (' . $time . ')';
  409. }
  410. }
  411. $uspsQuote=$rates;
  412. }
  413. }
  414. // usps changes ends
  415. ?>
  416. </div>
  417. </div>
  418. <?php
  419. }
  420. echo " </td>\n\r";
  421. echo " <td colspan='2' style='vertical-align: middle;'>\n\r";
  422. if($all_donations == false)
  423. {
  424. echo "" . nzshpcrt_currency_display($total_shipping, 1) . "";
  425. }
  426. else
  427. {
  428. echo TXT_WPSC_DONATION_SHIPPING;
  429. }
  430. echo " </td>\n\r";
  431. echo "</tr>\n\r";
  432. }
  433. //// usps changes
  434. $_SESSION['uspsQuote']=$uspsQuote;
  435. foreach ((array)$uspsQuote as $quotes) {
  436. foreach($quotes as $key=>$quote) {
  437. echo "<tr><td colspan='2'>".$key."</td><td>".nzshpcrt_currency_display($quote,1)."</td><td><input type='radio' onclick='switchmethod(\"$key\")' value='$key' name='shipping_method'></td></tr>";
  438. }
  439. }
  440. // usps changes ends
  441. //echo "<tr style='total-price'>\n\r";
  442. if($tax > 0)
  443. {
  444. echo "<tr class='total_price'>\n\r";
  445. echo " <td colspan='2'>\n\r";
  446. echo "".TXT_WPSC_TAX.":";
  447. echo " </td>\n\r";
  448. echo " <td colspan='2' id='checkout_tax' style='vertical-align: middle;'>\n\r";
  449. echo "" . nzshpcrt_currency_display($tax, 1) . "";
  450. echo " </td>\n\r";
  451. echo "</tr>\n\r";
  452. $total += $tax;
  453. }
  454. if(!empty($_SESSION['coupon_num'])) {
  455. $discount = $total - nzshpcrt_apply_coupon($total,$_SESSION['coupon_num']) ;
  456. $total_after_discount = $total-$discount;
  457. }
  458. if ($_SESSION['coupon_num']) {
  459. echo "<tr class='total_price'>\n\r";
  460. echo " <td colspan='2'>\n\r";
  461. echo "".TXT_WPSC_DISCOUNT.":";
  462. echo " </td>\n\r";
  463. echo " <td colspan='2' style='vertical-align: middle;'>\n\r";
  464. if ($discount > 0) {
  465. echo "" . nzshpcrt_currency_display($discount, 1) . "";
  466. } else {
  467. echo "<font color='red'>".TXT_WPSC_INVALID_COUPON."</font>";
  468. $_SESSION['coupon_num'] = '';
  469. }
  470. echo " </td>\n\r";
  471. echo "</tr>\n\r";
  472. }
  473. echo "<tr class='total_price'>\n\r";
  474. echo " <td colspan='2'>\n\r";
  475. echo "".TXT_WPSC_TOTALPRICE.":";
  476. echo " </td>\n\r";
  477. echo " <td colspan='2' id='checkout_total' style='vertical-align: middle;'>\n\r";
  478. echo nzshpcrt_overall_total_price($_SESSION['selected_country'],true,false,$total);
  479. echo " </td>\n\r";
  480. echo "</tr>\n\r";
  481. echo "</table>";
  482. if ($_POST['coupon_num']) {
  483. $_SESSION['nzshpcrt_totalprice'] = $total_after_discount;
  484. } else {
  485. $_SESSION['nzshpcrt_totalprice'] = $total;
  486. }
  487. if (get_option('payment_gateway') == 'google') {
  488. $google_cart = unserialize($_SESSION['google_shopping_cart']);
  489. if($_SESSION['coupon_num']){
  490. $overall_total = nzshpcrt_overall_total_price_numeric(null,true);
  491. $discount = $overall_total - nzshpcrt_apply_coupon($overall_total,$_SESSION['coupon_num']);
  492. $total_after_discount = $overall_total-$discount;
  493. $_SESSION['wpsc_discount']= $discount;
  494. } else {
  495. $_SESSION['wpsc_discount']= 0;
  496. }
  497. if ($_POST["quantity"]) {
  498. $pnp=$wpdb->get_var("SELECT SUM(pnp) FROM ".$wpdb->prefix."product_list WHERE id IN (".$cart_item->product_id.")");
  499. $local_shipping_price= nzshpcrt_determine_base_shipping(0, get_option('base_country'));
  500. $google_local_shipping = $local_shipping_price+$pnp*$_POST["quantity"];
  501. $pnp=$wpdb->get_var("SELECT SUM(international_pnp) FROM ".$wpdb->prefix."product_list WHERE id IN (".$cart_item->product_id.")");
  502. $international_shipping_price= nzshpcrt_determine_base_shipping(0, get_option('base_country')."-");
  503. $google_international_shipping = $international_shipping_price+$pnp*$_POST["quantity"];
  504. $google_cart->shipping_arr[0]->price=$google_local_shipping;
  505. $google_cart->shipping_arr[1]->price=$google_international_shipping;
  506. $google_cart->item_arr[$_POST["key"]]->quantity=$_POST["quantity"];
  507. }
  508. $state_name = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."region_tax WHERE country_id='136'",ARRAY_A);
  509. // echo "<pre>".print_r($tax_rate,1)."</pre>";
  510. foreach ($state_name as $state) {
  511. // $tax_rate = $wpdb->get_results("SELECT tax FROM ".$wpdb->prefix."region_tax WHERE id='".$state['id']."'",ARRAY_A);
  512. $tax_rule = new GoogleDefaultTaxRule($state['tax']/100);
  513. $tax_rule->SetStateAreas($state['code']);
  514. $google_cart->AddDefaultTaxRules($tax_rule);
  515. }
  516. if ($discount > 0) {
  517. $google_item = new GoogleItem(utf8_decode("Coupon Code: '".$_SESSION['coupon_num']."'"), // Item name
  518. utf8_decode("A coupon redeem"), // Item description
  519. 1, // Quantity
  520. -$discount); // Unit price
  521. //echo serialize($cart_item->product_variations);
  522. $google_item->SetMerchantPrivateItemData("Coupon Deduction");
  523. $google_cart->AddItem($google_item);
  524. }
  525. //exit("---><pre>".print_r($_SESSION,1)."</pre>");
  526. if (get_option('payment_gateway') == 'google') {
  527. if (get_option('google_button_size') == '0'){
  528. $google_button_size = 'BIG';
  529. } elseif(get_option('google_button_size') == '1') {
  530. $google_button_size = 'MEDIUM';
  531. } elseif(get_option('google_button_size') == '2') {
  532. $google_button_size = 'SMALL';
  533. }
  534. }
  535. echo "<br>".$google_cart->CheckoutButtonCode($google_button_size);
  536. } else {
  537. echo "<h2>".TXT_WPSC_ENTERDETAILS."</h2>";
  538. }
  539. include('checkout.php');
  540. } else {
  541. echo TXT_WPSC_NOITEMSINTHESHOPPINGCART;
  542. }
  543. ?>
  544. </div>