Пример #1
0
 /**
  * Get the shipping quote and display it in a form
  */
 public function TestQuoteResult()
 {
     $this->AddItem($_POST['weight']);
     $this->SetDestinationZip($_POST['destinationZip']);
     $this->SetDestinationCountry($_POST['destinationCountry']);
     if (isset($_POST['destinationState'])) {
         $this->SetDestinationState(GetStateById($_POST['destinationState']));
     }
     $quotes = $this->FetchQuotes();
     if (!is_array($quotes)) {
         $GLOBALS['Color'] = "red";
         $GLOBALS['Status'] = GetLang('StatusFailed');
         $GLOBALS['Label'] = GetLang('ShipErrorMessage');
         $GLOBALS['Message'] = implode('<br />', $this->GetErrors());
     } else {
         $GLOBALS['Color'] = "green";
         $GLOBALS['Status'] = GetLang('StatusSuccess');
         $GLOBALS['Label'] = GetLang('ShipQuotePrice');
         // Get each available shipping option and display it
         $GLOBALS['Message'] = '<ul style="margin-left: 0; padding-left: 0">';
         foreach ($quotes as $quote) {
             $GLOBALS['Message'] .= '<li style="color: green">' . $quote->GetDesc(false) . ' - ' . FormatPrice($quote->GetPrice()) . '</li>';
         }
         $GLOBALS['Message'] .= '</li>';
     }
     $GLOBALS['Image'] = $this->GetImage();
     $this->ParseTemplate("module.upsonline.testresult");
 }
Пример #2
0
	/**
	 * Actually save a new vendor in the database or update an existing one.
	 *
	 * @param array Array of data about the vendor to save.
	 * @param int The existing vendor ID to update, if we have one.
	 * @return boolean True if successful, false if not.
	 */
	private function CommitVendor($data, $vendorId=0)
	{
		$data['vendorcountry'] = GetCountryById((int)$data['vendorcountry']);

		if (isset($data['vendorstate']) && $data['vendorstate'] != "") {
			$data['vendorstate'] = GetStateById((int)$data['vendorstate']);
		}
		else {
			$data['vendorstate'] = $_POST['vendorstate1'];
		}

		$existingName = '';
		if($vendorId > 0) {
			$existingVendor = $this->GetVendorData($vendorId);
			$existingName = $existingVendor['vendorfriendlyname'];
		}

		if(!isset($data['vendororderemail'])) {
			$data['vendororderemail'] = '';
		}

		if(!isset($data['vendorshipping']) || $data['vendorshipping'] == 0) {
			$data['vendorshipping'] = 0;

			if($vendorId > 0) {
				$GLOBALS['ISC_CLASS_DB']->DeleteQuery('shipping_zones', "WHERE zonevendorid='".(int)$vendorId."'");
				$GLOBALS['ISC_CLASS_DB']->DeleteQuery('shipping_zone_locations', "WHERE locationvendorid='".(int)$vendorId."'");
				$GLOBALS['ISC_CLASS_DB']->DeleteQuery('shipping_methods', "WHERE methodvendorid='".(int)$vendorId."'");
				$GLOBALS['ISC_CLASS_DB']->DeleteQuery('shipping_vars', "WHERE varvendorid='".(int)$vendorId."'");
			}
		}
		else {
			if($vendorId > 0 && $existingVendor['vendorshipping'] == 0) {
				// Find the default zone for the store and copy it
				$query = "
					SELECT *
					FROM [|PREFIX|]shipping_zones
					WHERE zonedefault='1' AND zonevendorid='0'
				";
				$result = $GLOBALS['ISC_CLASS_DB']->Query($query);
				$masterZone = $GLOBALS['ISC_CLASS_DB']->Fetch($result);
				unset($masterZone['zoneid']);
				$masterZone['zonevendorid'] = $vendorId;
				$GLOBALS['ISC_CLASS_DB']->InsertQuery('shipping_zones', $masterZone);
			}
		}

		$vendorData = array(
			'vendorname' => $data['vendorname'],
			'vendorphone' => $data['vendorphone'],
			'vendorbio' => $data['vendorbio'],
			'vendoraddress' => $data['vendoraddress'],
			'vendorcity' => $data['vendorcity'],
			'vendorcountry' => $data['vendorcountry'],
			'vendorstate' => $data['vendorstate'],
			'vendorzip' => $data['vendorzip'],
			'vendorfriendlyname' => $this->GenerateVendorFriendlyName($data['vendorname'], $vendorId, $existingName),
			'vendororderemail' => $data['vendororderemail'],
			'vendorshipping' => (int)$data['vendorshipping'],
			'vendoremail' => $data['vendoremail'],
		);

		// If we have permission to, set the permissions for the vendor we're creating/editing
		if($GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId() == 0 || $vendorId == 0) {
			$vendorData['vendorprofitmargin'] = DefaultPriceFormat($data['vendorprofitmargin']);
			$vendorData['vendoraccesscats'] = '';
			if(!isset($data['vendorlimitcats']) && is_array($data['vendoraccesscats'])) {
				$data['vendoraccesscats'] = array_map('intval', $data['vendoraccesscats']);
				$vendorData['vendoraccesscats'] = implode(',', $data['vendoraccesscats']);
			}
		}

		if($vendorId == 0) {
			$vendorId = $GLOBALS['ISC_CLASS_DB']->InsertQuery('vendors', $vendorData);

			$updatedVendor = array();
			// If we chose to upload a logo for this vendor, save it too
			foreach(array(self::VENDOR_LOGO, self::VENDOR_PHOTO) as $image) {
				$vendorImage = $this->SaveVendorImage($vendorId, $image);
				if($vendorImage === false) {
					$GLOBALS['ISC_CLASS_DB']->DeleteQuery('vendors', "WHERE vendorid='".(int)$vendorId."'");
					return false;
				}
				else {
					$updatedVendor['vendor'.$image] = $vendorImage;
				}
			}

			if(!empty($updatedVendor)) {
				$GLOBALS['ISC_CLASS_DB']->UpdateQuery('vendors', $updatedVendor, "vendorid='".(int)$vendorId."'");
			}
		}
		else {
			// If we chose to upload a logo for this vendor, save it too
			foreach(array(self::VENDOR_LOGO, self::VENDOR_PHOTO) as $image) {
				// Did we choose to delete a logo?
				if(isset($data['deletevendor'.$image])) {
					$this->DeleteVendorImage($vendorId, $image);
					$vendorData['vendor'.$image] = '';
				}

				// Maybe we chose to upload an image?
				$vendorImage = $this->SaveVendorImage($vendorId, $image);
				if($vendorImage === false) {
					return false;
				}
				else if($vendorImage) {
					$vendorData['vendor'.$image] = $vendorImage;
				}
			}

			$GLOBALS['ISC_CLASS_DB']->UpdateQuery('vendors', $vendorData, "vendorid='".(int)$vendorId."'");
		}

		$GLOBALS['ISC_CLASS_DATA_STORE']->UpdateVendors();

		// Couldn't save? return an error message
		if($GLOBALS['ISC_CLASS_DB']->GetErrorMsg()) {
			return false;
		}

		return true;
	}
Пример #3
0
		public function BuildWhereFromVars($array)
		{
			$queryWhere = "";
			$queryJoin = "";
			$queryHaving = "";

			// Is this a custom search?
			if(!empty($array['searchId'])) {
				$this->_customSearch = $GLOBALS['ISC_CLASS_ADMIN_CUSTOMSEARCH']->LoadSearch($array['searchId']);
				$array = array_merge($array, (array)$this->_customSearch['searchvars']);
			}

			if (isset($array['searchQuery']) && $array['searchQuery'] != "") {
				// PostgreSQL is case sensitive for likes, so all matches are done in lower case
				$search_query = $GLOBALS['ISC_CLASS_DB']->Quote(trim($array['searchQuery']));
				$queryWhere .= "
					AND (
						customerid = '" . $search_query . "' OR
						custconfirstname LIKE '%" . $search_query . "%' OR
						custconlastname LIKE '%" . $search_query . "%' OR
						custconemail LIKE '%" . $search_query . "%' OR
						CONCAT(custconfirstname, ' ', custconlastname) LIKE '%" . $search_query . "%' OR
						custconcompany LIKE '%" . $search_query . "%'
					)";
			}

			if (isset($array['letter']) && $array['letter'] != '') {
				$letter = chr(ord($array['letter']));
				if ($array['letter'] == '0-9') {
					$queryWhere .= " AND custconlastname NOT REGEXP('^[a-zA-Z]')";
				}
				else if (isc_strlen($letter) == 1) {
					$queryWhere .= " AND custconlastname LIKE '".$GLOBALS['ISC_CLASS_DB']->Quote($letter)."%'";
				}
			}

			if (isset($array['phone']) && $array['phone'] != "") {
				$phone = $GLOBALS['ISC_CLASS_DB']->Quote(trim($array['phone']));
				$queryWhere .= sprintf(" AND custconphone LIKE '%%%s%%'", $phone);
			}

			if (isset($array['idFrom']) && $array['idFrom'] != "") {
				$id_from = $GLOBALS['ISC_CLASS_DB']->Quote((int)$array['idFrom']);
				$queryWhere .= sprintf(" AND customerid >= '%d'", $id_from);
			}
			if (isset($array['idTo']) && $array['idTo']) {
				$id_to = $GLOBALS['ISC_CLASS_DB']->Quote((int)$array['idTo']);
				$queryWhere .= sprintf(" AND customerid <= '%d'", $id_to);
			}

			// limit by number of orders
			if (!empty($array['ordersFrom'])) {
				$orders_from = $GLOBALS['ISC_CLASS_DB']->Quote((int)$array['ordersFrom']);
				$queryHaving .= sprintf(" AND numorders >= '%d'", $orders_from);
			}

			if (!empty($array['ordersTo'])) {
				$orders_to = $GLOBALS['ISC_CLASS_DB']->Quote((int)$array['ordersTo']);
				$queryHaving .= sprintf(" AND numorders <= '%d'", $orders_to);
			}

			if (isset($array['storeCreditFrom']) && $array['storeCreditFrom'] != "") {
				$credit_from = $GLOBALS['ISC_CLASS_DB']->Quote((int)$array['storeCreditFrom']);
				$queryWhere .= sprintf(" AND custstorecredit >= '%d'", $credit_from);
			}

			if (isset($array['storeCreditTo']) && $array['storeCreditTo'] != "") {
				$credit_to = $GLOBALS['ISC_CLASS_DB']->Quote((int)$array['storeCreditTo']);
				$queryWhere .= sprintf(" AND custstorecredit <= '%d'", $credit_to);
			}

			// Limit results to a particular join date range
			if (isset($array['dateRange']) && $array['dateRange'] != "") {
				$range = $array['dateRange'];
				switch($range) {
					// Registrations within the last day
					case "today":
						$from_stamp = mktime(0, 0, 0, isc_date("m"), isc_date("d"), isc_date("Y"));
						break;
					// Registrations received in the last 2 days
					case "yesterday":
						$from_stamp = mktime(0, 0, 0, isc_date("m"), date("d")-1, isc_date("Y"));
						$to_stamp = mktime(0, 0, 0, isc_date("m"), isc_date("d")-1, isc_date("Y"));
						break;
					// Registrations received in the last 24 hours
					case "day":
						$from_stamp = time()-60*60*24;
						break;
					// Registrations received in the last 7 days
					case "week":
						$from_stamp = time()-60*60*24*7;
						break;
					// Registrations received in the last 30 days
					case "month":
						$from_stamp = time()-60*60*24*30;
						break;
					// Registrations received this month
					case "this_month":
						$from_stamp = mktime(0, 0, 0, isc_date("m"), 1, isc_date("Y"));
						break;
					// Orders received this year
					case "this_year":
						$from_stamp = mktime(0, 0, 0, 1, 1, isc_date("Y"));
						break;
					// Custom date
					default:
						if (isset($array['fromDate']) && $array['fromDate'] != "") {
							$from_date = $array['fromDate'];
							$from_data = explode("/", $from_date);
							$from_stamp = mktime(0, 0, 0, $from_data[0], $from_data[1], $from_data[2]);
						}
						if (isset($array['toDate']) && $array['toDate'] != "") {
							$to_date = $array['toDate'];
							$to_data = explode("/", $to_date);
							$to_stamp = mktime(0, 0, 0, $to_data[0], $to_data[1], $to_data[2]);
						}
				}

				if (isset($from_stamp)) {
					$queryWhere .= sprintf(" AND custdatejoined >= '%d'", $from_stamp);
				}
				if (isset($to_stamp)) {
					$queryWhere .= sprintf(" AND custdatejoined <= '%d'", $to_stamp);
				}
			}

			if (isset($array['custGroupId']) && is_numeric($array['custGroupId'])) {
				$custGroupId = (int)$array['custGroupId'];

				// is this group the default group? we should then search for customers with a groupid of 0 as well
				$groupQuery = 'SELECT * FROM [|PREFIX|]customer_groups WHERE customergroupid = ' . $custGroupId . ' AND isdefault = 1';
				$groupRes = $this->db->Query($groupQuery);
				if ($this->db->CountResult($groupRes)) {
					$queryWhere .= ' AND (custgroupid = ' . $custGroupId . ' OR custgroupid = 0)';
				}
				else {
					$queryWhere .= ' AND custgroupid = ' . $custGroupId;
				}
			}

			// Search for users with a particular shipping country & state
			if (isset($array['country']) && $array['country'] != "") {
				$country = $GLOBALS['ISC_CLASS_DB']->Quote((int)$array['country']);

				$queryJoin .= " LEFT JOIN [|PREFIX|]shipping_addresses ON shipcustomerid = customerid";
				$queryWhere .= sprintf(" AND shipcountryid='%s'", $country);

				$state = '';
				if (isset($array['state']) && $array['state'] != "") {
					$state = GetStateById($array['state']);
				}
				else if (isset($array['state_1']) && $array['state_1'] != "") {
					$state = $array['state_1'];
				}

				// Searching by state too
				if ($state != '') {
					$queryWhere .= " AND shipstate='".$GLOBALS['ISC_CLASS_DB']->Quote($state)."'";
				}
			}

			return array("query" => $queryWhere, "join" => $queryJoin, "having" => $queryHaving);
		}
 public function BuildWhereFromVars($array)
 {
     $queryWhere = "";
     if (isset($array['searchQuery']) && $array['searchQuery'] != "") {
         // PostgreSQL is case sensitive for likes, so all matches are done in lower case
         $search_query = $GLOBALS['ISC_CLASS_DB']->Quote(trim(isc_strtolower($array['searchQuery'])));
         $queryWhere .= "\n\t\t\t\t\tAND (\n\t\t\t\t\t\tcustomerid = '" . $search_query . "' OR\n\t\t\t\t\t\tLOWER(custconfirstname) LIKE '%" . $search_query . "%' OR\n\t\t\t\t\t\tLOWER(custconlastname) LIKE '%" . $search_query . "%' OR\n\t\t\t\t\t\tLOWER(custconemail) LIKE '%" . $search_query . "%' OR\n\t\t\t\t\t\tLOWER(CONCAT(custconfirstname, ' ', custconlastname)) LIKE '%" . $search_query . "%' OR\n\t\t\t\t\t\tLOWER(custconcompany) LIKE '%" . $search_query . "%'\n\t\t\t\t\t)";
     }
     if (isset($array['letter']) && $array['letter'] != '') {
         $letter = chr(ord($array['letter']));
         if ($array['letter'] == '0-9') {
             $queryWhere .= " AND custconlastname NOT REGEXP('^[a-zA-Z]')";
         } else {
             if (isc_strlen($letter) == 1) {
                 $queryWhere .= " AND custconlastname LIKE '" . $GLOBALS['ISC_CLASS_DB']->Quote($letter) . "%'";
             }
         }
     }
     if (isset($array['phone']) && $array['phone'] != "") {
         $phone = $GLOBALS['ISC_CLASS_DB']->Quote(trim($array['phone']));
         $queryWhere .= sprintf(" AND custconphone LIKE '%%%s%%'", $phone);
     }
     if (isset($array['idFrom']) && $array['idFrom'] != "") {
         $id_from = $GLOBALS['ISC_CLASS_DB']->Quote((int) $array['idFrom']);
         $queryWhere .= sprintf(" AND customerid >= '%d'", $id_from);
     }
     if (isset($array['idTo']) && $array['idTo']) {
         $id_to = $GLOBALS['ISC_CLASS_DB']->Quote((int) $array['idTo']);
         $queryWhere .= sprintf(" AND customerid <= '%d'", $id_to);
     }
     if (isset($array['storeCreditFrom']) && $array['storeCreditFrom'] != "") {
         $credit_from = $GLOBALS['ISC_CLASS_DB']->Quote((int) $array['storeCreditFrom']);
         $queryWhere .= sprintf(" AND custstorecredit >= '%d'", $credit_from);
     }
     if (isset($array['storeCreditTo']) && $array['storeCreditTo'] != "") {
         $credit_to = $GLOBALS['ISC_CLASS_DB']->Quote((int) $array['storeCreditTo']);
         $queryWhere .= sprintf(" AND custstorecredit <= '%d'", $credit_to);
     }
     // Limit results to a particular join date range
     if (isset($array['dateRange']) && $array['dateRange'] != "") {
         $range = $array['dateRange'];
         switch ($range) {
             // Registrations within the last day
             case "today":
                 $from_stamp = mktime(0, 0, 0, isc_date("m"), isc_date("d"), isc_date("Y"));
                 break;
                 // Registrations received in the last 2 days
             // Registrations received in the last 2 days
             case "yesterday":
                 $from_stamp = mktime(0, 0, 0, isc_date("m"), date("d") - 1, isc_date("Y"));
                 $to_stamp = mktime(0, 0, 0, isc_date("m"), isc_date("d") - 1, isc_date("Y"));
                 break;
                 // Registrations received in the last 24 hours
             // Registrations received in the last 24 hours
             case "day":
                 $from_stamp = time() - 60 * 60 * 24;
                 break;
                 // Registrations received in the last 7 days
             // Registrations received in the last 7 days
             case "week":
                 $from_stamp = time() - 60 * 60 * 24 * 7;
                 break;
                 // Registrations received in the last 30 days
             // Registrations received in the last 30 days
             case "month":
                 $from_stamp = time() - 60 * 60 * 24 * 30;
                 break;
                 // Registrations received this month
             // Registrations received this month
             case "this_month":
                 $from_stamp = mktime(0, 0, 0, isc_date("m"), 1, isc_date("Y"));
                 break;
                 // Orders received this year
             // Orders received this year
             case "this_year":
                 $from_stamp = mktime(0, 0, 0, 1, 1, isc_date("Y"));
                 break;
                 // Custom date
             // Custom date
             default:
                 if (isset($array['fromDate']) && $array['fromDate'] != "") {
                     $from_date = $array['fromDate'];
                     $from_data = explode("/", $from_date);
                     $from_stamp = mktime(0, 0, 0, $from_data[0], $from_data[1], $from_data[2]);
                 }
                 if (isset($array['toDate']) && $array['toDate'] != "") {
                     $to_date = $array['toDate'];
                     $to_data = explode("/", $to_date);
                     $to_stamp = mktime(0, 0, 0, $to_data[0], $to_data[1], $to_data[2]);
                 }
         }
         if (isset($from_stamp)) {
             $queryWhere .= sprintf(" AND custdatejoined >= '%d'", $from_stamp);
         }
         if (isset($to_stamp)) {
             $queryWhere .= sprintf(" AND custdatejoined <= '%d'", $to_stamp);
         }
     }
     if (isset($array['custGroupId']) && is_numeric($array['custGroupId'])) {
         $custGroupId = (int) $array['custGroupId'];
         $queryWhere .= sprintf(" AND custgroupid='%d' ", $custGroupId);
     }
     $joinQuery = '';
     // Search for users with a particular shipping country & state
     if (isset($array['country']) && $array['country'] != "") {
         $country = $GLOBALS['ISC_CLASS_DB']->Quote((int) $array['country']);
         $joinQuery = sprintf(" LEFT JOIN [|PREFIX|]shipping_addresses ON (shipcustomerid=customerid)");
         $queryWhere .= sprintf(" AND shipcountryid='%s'", $country);
         $state = '';
         if (isset($array['state']) && $array['state'] != "") {
             $state = GetStateById($array['state']);
         } else {
             if (isset($array['state_1']) && $array['state_1'] != "") {
                 $state = $array['state_1'];
             }
         }
         // Searching by state too
         if ($state != '') {
             $queryWhere .= " AND LOWER(shipstate)='" . $GLOBALS['ISC_CLASS_DB']->Quote(isc_strtolower($state)) . "'";
         }
     }
     return array("query" => $queryWhere, "join" => $joinQuery);
 }
 /**
  * Set the shipping restrictions in the google filter module format for the default zone
  * so we can add it as part of the shipping rules
  *
  * @return void
  **/
 private function AddDefaultShippingRestrictions($zone)
 {
     switch ($zone['locationtype']) {
         case 'zip':
             foreach ($zone['locations'] as $location) {
                 $this->defaultZoneGFilter->AddExcludedPostalArea(GetCountryISO2ById($location['locationcountryid']));
             }
             return false;
             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
                     $this->defaultZoneGFilter->SetExcludedCountryArea('ALL');
                     break 2;
                 } elseif (empty($location['locationvalueid'])) {
                     continue;
                 }
                 if ($country == 'US' && $this->GetDefaultCurrencyCode() == 'USD') {
                     $this->defaultZoneGFilter->AddExcludedStateArea($state);
                 } else {
                     $this->defaultZoneGFilter->AddExcludedPostalArea($country, $state);
                 }
             }
             break;
         case 'country':
             foreach ($zone['locations'] as $location) {
                 $this->defaultZoneGFilter->AddExcludedPostalArea(GetCountryISO2ById($location['locationvalueid']));
             }
             break;
     }
 }
Пример #6
0
 /**
  * Calculate the tax based on the anonymised address information provided by google
  *
  * @param array $data The data representing the google request
  *
  * @return void
  **/
 private function RecalculateTax($data, $amount, $provider)
 {
     $root = 'merchant-calculation-callback';
     foreach ($data[$root]['calculate']['addresses'] as $data_address) {
         $address['shipcity'] = $data_address['city']['VALUE'];
         $address['shipzip'] = $data_address['postal-code']['VALUE'];
         $address['shipcountryid'] = GetCountryIdByISO2($data_address['country-code']['VALUE']);
         $address['shipcountry'] = GetCountryById($address['shipcountryid']);
         $address['shipstateid'] = GetStateByAbbrev($data_address['region']['VALUE'], $address['shipcountryid']);
         $address['shipstate'] = GetStateById($address['shipstateid']);
         $_SESSION['CHECKOUT']['SHIPPING'][0][0] = array("COST" => $amount, "PROVIDER" => $provider);
         $_SESSION['CHECKOUT']['SHIPPING_ADDRESS'] = $address;
         $_SESSION['CHECKOUT']['BILLING_ADDRESS'] = $address;
         $GLOBALS['ISC_CLASS_CHECKOUT'] = GetClass('ISC_CHECKOUT');
         $orderSummary = $GLOBALS['ISC_CLASS_CHECKOUT']->CalculateOrderSummary();
         return $orderSummary['taxCost'];
     }
 }
Пример #7
0
	/**
	 * Get the state ID
	 *
	 * Method will return the state ID if found
	 *
	 * @access protected
	 * @param string $stateName The state name / abbrevation
	 * @param int $countryId The country ID
	 * @param string $properStateName The referenced variable to set the proper state name if the record exists
	 * @return int The state ID on success, FALSE if not found
	 */
	protected function getStateId($stateName, $countryId, &$properStateName=null)
	{
		if (trim($stateName) == '' || !isId($countryId)) {
			return false;
		}

		$stateId = GetStateByName($stateName, $countryId);

		if (!isId($stateId)) {
			$stateId = GetStateByAbbrev($stateName, $countryId);
		}

		if (!isId($stateId)) {
			return false;
		}

		$properStateName = GetStateById($stateId);

		return $stateId;
	}
Пример #8
0
		/**
		* Get Express Checkout Details step
		* When customer come back from paypal after they select the payment method and shipping address in paypal,
		* This function takes the shipping address and redirect customer to choose shipping provider page.
		*/
		private function GetExpressCheckoutDetails()
		{
			if(isset($_SESSION['CHECKOUT']['FromCartPage'])) {
				unset($_COOKIE['SHOP_ORDER_TOKEN']);
			}
			$merchant = $this->GetMerchantSettings();
			if($merchant['testmode'] == 'YES') {
				$transactionURL = $this->_testTransactionURL;
				$transactionURI = $this->_testTransactionURI;
			}
			else {
				$transactionURL = $this->_liveTransactionURL;
				$transactionURI = $this->_liveTransactionURI;
			}

			$pp_array = array(
				'METHOD'	=> 'GetExpressCheckoutDetails',
				'USER'		=> $merchant['username'],
				'PWD'		=> $merchant['password'],
				'SIGNATURE'	=> $merchant['signature'],
				'VERSION'	=> '53.0',
				'PAYMENTACTION'	=> $merchant['transactionType'],
				'TOKEN'		=> $_REQUEST['token'],
				'NOTIFYURL'	=> $GLOBALS['ShopPath'].'/checkout.php?action=gateway_ping&provider='.$this->GetId(),

			);

			$paypal_query = '';
			foreach ($pp_array as $key => $value) {
				$paypal_query .= $key.'='.urlencode($value).'&';
			}
			$paypal_query = rtrim($paypal_query, '&');

			// get the customer details from paypal
			$result = $this->_ConnectToProvider($transactionURL, $transactionURI, $paypal_query);
			$nvpArray = $this->_DecodePaypalResult($result);

			if(strtolower($nvpArray['ACK']) == 'success') {

				$_SESSION['CHECKOUT']['PayPalExpressCheckout'] = $nvpArray;
				// if user started paypal express checkout at confirmation page, redirect user back to confirmation page
				if(isset($_COOKIE['SHOP_ORDER_TOKEN'])) {

					// Load the pending order
					$orders = LoadPendingOrdersByToken($_COOKIE['SHOP_ORDER_TOKEN']);
					if(!is_array($orders)) {
						@ob_end_clean();
						header("Location: ".$GLOBALS['ShopPath']."/checkout.php?action=confirm_order");
						die();
					}

					$this->SetOrderData($orders);

					$this->DoExpressCheckoutPayment();
					exit;
				}

				$countryID = GetCountryIdByISO2($nvpArray['SHIPTOCOUNTRYCODE']);
				$countryName = GetCountryById($countryID);

				$stateID = $this->GetStateId($countryID, $nvpArray['SHIPTOSTATE']);
				$stateName = GetStateById($stateID);

				$phone = '';
				if(isset($nvpArray['PHONENUM'])) {
					// phone will only be available if (see ISC-937)
					// 1. seller chooses "On (Required Field)" for contact telephone
					// 2. and, buyer ticks "Share this phone number with <store_name>"
					$phone = $nvpArray['PHONENUM'];
				}

				$shipaddress2 = '';
				if (isset($nvpArray['SHIPTOSTREET2'])) {
					$shipaddress2 = $nvpArray['SHIPTOSTREET2'];
				}

				$address = array(
					'shipfirstname'		=> $nvpArray['FIRSTNAME'],
					'shiplastname'		=> $nvpArray['LASTNAME'],
					'shipcompany'		=> '',
					'shipaddress1'		=> $nvpArray['SHIPTOSTREET'],
					'shipaddress2'		=> $shipaddress2,
					'shipcity'		=> $nvpArray['SHIPTOCITY'],
					'shipstate'		=> $stateName,
					'shipzip'		=> $nvpArray['SHIPTOZIP'],
					'shipcountry'		=> $countryName,
					'shipstateid'		=> $stateID,
					'shipcountryid'		=> $countryID,
					'shipdestination'	=> 'residential',
					'shipphone'		=> $phone
				);

				if(CustomerIsSignedIn()) {
					$GLOBALS['ISC_CLASS_CUSTOMER'] = GetClass('ISC_CUSTOMER');
					$customerID = $GLOBALS['ISC_CLASS_CUSTOMER']->GetCustomerId();
					$address['shipcustomerid'] = $customerID;

					// check if the customer's address we get back from paypal is already exist in the customer's ISC address book
					$addressid = $this->GetAddressID($address);

					if($addressid > 0) {
						//if address is already in ISC address book, set the ISC address id to session so it can be selected by default on the checkout page.
						$_SESSION['CHECKOUT']['SelectAddress'] = $addressid;
					} else {
						//if address isn't in ISC address book, add it to customer's address book.
						$_SESSION['CHECKOUT']['SelectAddress'] = $GLOBALS['ISC_CLASS_DB']->InsertQuery("shipping_addresses", $address, 1);
					}
				}
				$address['shipemail'] = $nvpArray['EMAIL'];
				$address['saveAddress'] = 0;

				$GLOBALS['ISC_CLASS_CHECKOUT'] = GetClass('ISC_CHECKOUT');
				//set the address to the session
				$GLOBALS['ISC_CLASS_CHECKOUT'] -> SetOrderBillingAddress($address);

				if($nvpArray['FIRSTNAME']." ".$nvpArray['LASTNAME'] != $nvpArray['SHIPTONAME']) {
					$_SESSION['CHECKOUT']['GoToCheckoutStep'] = "BillingAddress";
					$firstName = trim(preg_replace('/\s.*$/', '', $nvpArray['SHIPTONAME']));
					$lastName = trim(str_replace($firstName, '', $nvpArray['SHIPTONAME']));
					$address['shipfirstname'] = $firstName;
					$address['shiplastname'] = $lastName;
				} else {
					$_SESSION['CHECKOUT']['GoToCheckoutStep'] = "ShippingProvider";
				}
				$GLOBALS['ISC_CLASS_CHECKOUT'] -> SetOrderShippingAddress($address);


				// Only want to display paypal as the payment provider on order confirmation page, as customer has already selected the pay with paypal previously, so save paypal in provider list in session, so confirmation page will read from the session.
				$_SESSION['CHECKOUT']['ProviderListHTML'] = $this->ParseTemplate('paypalexpress.providerlist', true);

				// Skip choose a billing and shipping address step
				if(GetConfig('CheckoutType') == 'single') {
					$returnURL = $GLOBALS['ShopPath']."/checkout.php";
				} else {
					//set the address to the session
					$GLOBALS['ISC_CLASS_CHECKOUT']->SetOrderBillingAddress($address);
					$GLOBALS['ISC_CLASS_CHECKOUT']->SetOrderShippingAddress($address);
					$returnURL = $GLOBALS['ShopPath']."/checkout.php?action=choose_shipper";
				}

				header("Location: ".$returnURL);
			}
		}
Пример #9
0
 /**
  * Calculate the shipping cost for an array of products in the cart to the specified address.
  *
  * @param array The shipping address (shipcountryid, shipstateid, shipzip) to fetch the available methods/quotes for.
  * @param array Array containing the product information (generally from self::api::GetProductsInCart)
  * @param int The vendor ID that the shipping zone should be fetched from.
  * @return array An array of calculated shipping quotes.
  */
 public function GetAvailableShippingMethodsForProducts($address, $products, $vendorId = 0)
 {
     if (!is_array($address) || !is_array($products)) {
         return false;
     }
     // Fetch the shipping zone that this address belongs in
     $shippingZone = GetShippingZoneIdByAddress($address, $vendorId);
     $zone = GetShippingZoneById($shippingZone);
     $shippingQuotes = array();
     $shippableTotal = 0;
     $subTotal = 0;
     $fixedShippingCost = 0;
     $fixedShippingProducts = 0;
     $shippingQuoteProducts = array();
     $includesDigitalProducts = false;
     // Loop through the products and build an array of those that we can ship
     // also save the sub total so we can pass it to the shipping providers
     foreach ($products as $k => $product) {
         // Skip over any invalid products
         if (!isset($product['data'])) {
             continue;
         }
         $quantity = (int) $product['quantity'];
         // Determine the actual price of the product that this customer is paying
         if (isset($product['discount_price'])) {
             $price = $product['discount_price'];
         } else {
             if (isset($product['type']) && $product['type'] == "giftcertificate") {
                 $price = $product['giftamount'];
             } else {
                 $price = $product['original_price'];
             }
         }
         if (isset($product['wrapping']['wrapprice'])) {
             $price += $product['wrapping']['wrapprice'];
         }
         $subTotal += $quantity * $price;
         if ($product['data']['prodtype'] == PT_PHYSICAL && $product['data']['prodfixedshippingcost'] == 0) {
             $shippableTotal += $quantity * $price;
         }
         if ($product['data']['prodtype'] == PT_PHYSICAL && (!isset($product['data']['prodfreeshipping']) || $product['data']['prodfreeshipping'] != 1)) {
             if ($product['data']['prodfixedshippingcost'] > 0) {
                 $fixedShippingCost += $product['data']['prodfixedshippingcost'] * $quantity;
                 ++$fixedShippingProducts;
             } else {
                 $shippingQuoteProducts[$k] = $k;
             }
         } else {
             if ($product['data']['prodtype'] == PT_DIGITAL) {
                 $includesDigitalProducts = true;
             }
         }
     }
     // Now that we have all of the information we need, we can start calculating
     // shipping
     $zoneHandlingFee = 0;
     if ($zone['zonehandlingtype'] == 'global' && $zone['zonehandlingseparate']) {
         $zoneHandlingFee = $zone['zonehandlingfee'];
         if ($includesDigitalProducts) {
             $zoneHandlingFee += GetConfig('DigitalOrderHandlingFee');
         }
     }
     // Free shipping
     if ($zone['zonefreeshipping'] == 1 && $subTotal >= $zone['zonefreeshippingtotal'] || $this->api->GetCartFreeShipping(true)) {
         $adjustedPrice = $this->FactorInZoneHandling($shippingZone, 0, 0, $includesDigitalProducts);
         if ($adjustedPrice > 0) {
             $freeShippingName = GetConfig('StoreName');
         } else {
             $freeShippingName = GetLang('FreeShipping');
         }
         $shippingQuotes[] = array('description' => $freeShippingName, 'price' => $adjustedPrice, 'methodId' => -1, 'module' => '', 'handling' => $zoneHandlingFee);
     }
     // All products in the cart have a fixed shipping cost, just return that
     if ($fixedShippingProducts == count($products) || empty($shippingQuoteProducts)) {
         $adjustedPrice = $this->FactorInZoneHandling($shippingZone, $fixedShippingCost, 0, $includesDigitalProducts);
         if ($adjustedPrice > 0) {
             $shippingName = GetConfig('StoreName');
         } else {
             $shippingName = GetLang('FreeShipping');
         }
         $shippingQuotes = array();
         $shippingQuotes[] = array('description' => $shippingName, 'price' => $adjustedPrice, 'methodId' => -1, 'module' => '', 'handling' => $zoneHandlingFee);
         return $shippingQuotes;
     }
     // Get any shipping methods available for this module
     $query = "\n\t\t\t\tSELECT *\n\t\t\t\tFROM [|PREFIX|]shipping_methods\n\t\t\t\tWHERE zoneid='" . (int) $shippingZone . "' AND methodenabled='1' AND methodvendorid='" . (int) $zone['zonevendorid'] . "'\n\t\t\t";
     $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
     while ($method = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
         if ($zone['zonehandlingtype'] == 'module' && $zone['zonehandlingseparate']) {
             $methodHandling = $method['methodhandlingfee'];
             if ($includesDigitalProducts) {
                 $methodHandling += GetConfig('DigitalOrderHandlingFee');
             }
         } else {
             $methodHandling = $zoneHandlingFee;
         }
         // Set up the shipping module behind this method
         $shippingModule = null;
         GetModuleById('shipping', $shippingModule, $method['methodmodule']);
         if (!is_object($shippingModule)) {
             continue;
         }
         $shippingModule->SetMethodId($method['methodid']);
         // Add each item to the shipping quote
         foreach ($shippingQuoteProducts as $productId) {
             $cartProduct = $products[$productId];
             if (!isset($cartProduct['data'])) {
                 continue;
             }
             $shippingModule->AddItem($cartProduct['data']['prodweight'], $cartProduct['data']['proddepth'], $cartProduct['data']['prodwidth'], $cartProduct['data']['prodheight'], $cartProduct['quantity'], $cartProduct['data']['prodname']);
         }
         // Set the destination settings
         $shippingModule->SetDestinationCountry($address['shipcountryid']);
         if (!isset($address['shipstate'])) {
             $address['shipstate'] = GetStateById($address['shipstateid']);
         }
         $shippingModule->SetDestinationState($address['shipstate']);
         $shippingModule->SetDestinationZip($address['shipzip']);
         $shippingModule->SetDestinationType("RES");
         // Set the subtotal
         $shippingModule->SetSubTotal($shippableTotal);
         // Get the available services for this shipping method
         $moduleQuotes = array();
         if (method_exists($shippingModule, 'GetServiceQuotes')) {
             $methodQuotes = $shippingModule->GetServiceQuotes();
             // Can't ship by this method - nothing was returned
             if ($methodQuotes === false) {
                 continue;
             }
             if (!is_array($methodQuotes)) {
                 $methodQuotes = array($methodQuotes);
             }
             // For each of the returned quotes, add them to the quote stack
             foreach ($methodQuotes as $quote) {
                 if (!is_object($quote)) {
                     $quote = $quote[0];
                 }
                 $shippingQuotes[] = array('description' => $quote->GetDesc(true), 'price' => $this->FactorInZoneHandling($zone['zoneid'], $quote->GetPrice() + $fixedShippingCost, $method['methodhandlingfee'], $includesDigitalProducts), 'handling' => $methodHandling, 'module' => $method['methodmodule'], 'methodId' => $method['methodid']);
                 // Get the transit time
                 if ($quote->GetTransit() != '' && $quote->GetTransit() != -1) {
                     $shippingQuotes[count($shippingQuotes) - 1]['transit'] = $quote->GetTransit();
                 }
             }
         } else {
             $err = '';
             $quote = $shippingModule->GetQuote($err);
             // added for find the shippin cost if it is missing in the object. but it is available in variable for make a offer cart.
             /*$temp1 = $shippingModule->_shippingcost;
             $temp2 = $shippingModule->rules['cost'][0];
             $minamtforfreeship =  $shippingModule->rules['upper'][0];*/
             if ($quote !== false) {
                 /*if ($temp1 == 0 and $temp2  > 0  and $minamtforfreeship > $_SESSION['the_offered_price'])
                 					{
                 
                 						$shippingQuotes[] = array(
                 							'description' => $method['methodname'],
                 							'price' => $this->FactorInZoneHandling($shippingZone, $temp2 + $fixedShippingCost, $method['methodhandlingfee'], $includesDigitalProducts),
                 							'handling' => $methodHandling,
                 							'module' => $method['methodmodule'],
                 							'methodId' => $method['methodid']
                 						);
                 
                 					}
                 					else
                 						{*/
                 $shippingQuotes[] = array('description' => $method['methodname'], 'price' => $this->FactorInZoneHandling($shippingZone, $quote->GetPrice() + $fixedShippingCost, $method['methodhandlingfee'], $includesDigitalProducts), 'handling' => $methodHandling, 'module' => $method['methodmodule'], 'methodId' => $method['methodid']);
                 //}
             }
         }
     }
     // Order the shipping quotes from least expensive to most expensiv
     uasort($shippingQuotes, array($this, 'SortShippingQuotes'));
     // Now return what we've got
     return $shippingQuotes;
 }
Пример #10
0
	/**
	 * Save the updated store location settings.
	 */
	private function SaveUpdatedShippingSettings()
	{
		if(!$GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId() && !$GLOBALS['ISC_CLASS_ADMIN_AUTH']->HasPermission(AUTH_Manage_Settings)) {
			$GLOBALS['ISC_CLASS_ADMIN_ENGINE']->DoHomePage(GetLang('Unauthorized'), MSG_ERROR);
			return;
		}

		$companyCountry = GetCountryById((int)$_POST['companycountry']);
			if (isset($_POST['companystate']) && $_POST['companystate'] != "") {
			$companyState = GetStateById((int)$_POST['companystate']);
		}
		else {
			$companyState = $_POST['companystate1'];
		}

		$companyZip = $_POST['companyzip'];

		// Push everything to globals and save
		$GLOBALS['ISC_NEW_CFG']['CompanyName'] = $_POST['companyname'];
		$GLOBALS['ISC_NEW_CFG']['CompanyAddress'] = $_POST['companyaddress'];
		$GLOBALS['ISC_NEW_CFG']['CompanyCity'] = $_POST['companycity'];
		$GLOBALS['ISC_NEW_CFG']['CompanyCountry'] = $companyCountry;
		$GLOBALS['ISC_NEW_CFG']['CompanyState'] = $companyState;
		$GLOBALS['ISC_NEW_CFG']['CompanyZip'] = $companyZip;

		$settings = GetClass('ISC_ADMIN_SETTINGS');
		$messages = array();
		if ($settings->CommitSettings($messages)) {
			if (is_array($messages)) {
				foreach($messages as $message => $status) {
					FlashMessage($message, $status);
				}
			}
			$GLOBALS['ISC_CLASS_LOG']->LogAdminAction();

			$redirectUrl = 'index.php?ToDo=viewShippingSettings';
			if(!in_array('shippingOptions', GetConfig('GettingStartedCompleted'))) {
				$redirectUrl = 'index.php?ToDo=viewShippingSettings&currentTab=1';
			}
			FlashMessage(GetLang('ShippingSettingsSavedSuccessfully'), MSG_SUCCESS, $redirectUrl);
		}
		else {
			FlashMessage(GetLang('ShippingSettingsNotSaved'), MSG_ERROR, 'index.php?ToDo=viewShippingSettings&currentTab='.((int) $_POST['currentTab']));
		}
	}