Example #1
0
	public function __construct($customerId = null)
	{
		// use the same settings as orders by default
		$this->setDoubleOptIn(GetConfig('EmailIntegrationOrderDoubleOptin'));
		$this->setSendWelcome(GetConfig('EmailIntegrationOrderSendWelcome'));

		if (!$customerId) {
			return;
		}

		$entity = new ISC_ENTITY_CUSTOMER();

		$data = $entity->get($customerId);
		if (!$data) {
			throw new Interspire_EmailIntegration_Subscription_Exception();
		}

		unset($data['custpassword']);

		$this->_data = $data;
		unset($data);

		$this->setSubscriptionIP($this->_data['custregipaddress']);

		// customer custom form fields

		/** @var ISC_FORM */
		$form = $GLOBALS["ISC_CLASS_FORM"];

		// populate empty form fields as a starting point -- this makes exports of imported customers work OK because they may not have a custformsessionid, or this ensures that export data is current with configured form fields even if the stored form fields are out of date
		$formFields = $form->getFormFields(FORMFIELDS_FORM_ACCOUNT);
		foreach ($formFields as /** @var ISC_FORMFIELD_BASE */$formField) {
			if ($formField->getFieldPrivateId()) {
				continue;
			}
			$this->_data[$formField->getFieldId()] = '';
		}

		// load saved data for this customer
		if (isId($this->_data['custformsessionid'])) {
			$customFields = $form->getSavedSessionData($this->_data['custformsessionid']);
			foreach ($customFields as $fieldId => $value) {
				$this->_data['FormField_' . $fieldId] = $value;
			}
		}

		// for email integration purposes, money values must be stored in an array as both numeric and formatted to allow for translation to both number fields and text fields, while maintaining currency information
		SetupCurrency();
		$moneyFields = array('custstorecredit');
		foreach ($moneyFields as $moneyFieldId) {
			$this->_data[$moneyFieldId] = array(
				'numeric' => $this->_data[$moneyFieldId],
				'formatted' => FormatPriceInCurrency($this->_data[$moneyFieldId]),
			);
		}

		unset($this->_data['addresses']); // the addresses provided by entity class are mixed billing/shipping addresses, can't be sure so discard them
		// find last used _billing_ address for this customer by non-deleted orders
		$order = $GLOBALS['ISC_CLASS_DB']->FetchRow("SELECT ordformsessionid, ordbillstreet1, ordbillstreet2, ordbillsuburb, ordbillstate, ordbillzip, ordbillcountryid FROM `[|PREFIX|]orders` WHERE ordcustid = " . (int)$customerId . " AND deleted = 0 ORDER BY orddate DESC LIMIT 1");
		if (is_array($order)) {
			// create fields specifically for email integration based on customer data

			if (isId($order['ordformsessionid'])) {
				$customFields = $form->getSavedSessionData($order['ordformsessionid']);
				foreach ($customFields as $fieldId => $value) {
					$this->_data['CustomerSubscription_Address_FormField_' . $fieldId] = $value;
				}
			}

			$this->_data['CustomerSubscription_Address'] = array(
				'addr1' => $order['ordbillstreet1'],
				'addr2' => $order['ordbillstreet2'],
				'city' => $order['ordbillsuburb'],
				'state' => $order['ordbillstate'],
				'zip' => $order['ordbillzip'],
				'country' => GetCountryById($order['ordbillcountryid']),
				'countryiso2' => GetCountryISO2ById($order['ordbillcountryid']),
				'countryiso3' => GetCountryISO3ById($order['ordbillcountryid']),
			);

			$this->_data['CustomerSubscription_Address_address1'] = $this->_data['CustomerSubscription_Address']['addr1'];
			$this->_data['CustomerSubscription_Address_address2'] = $this->_data['CustomerSubscription_Address']['addr2'];
			$this->_data['CustomerSubscription_Address_city'] = $this->_data['CustomerSubscription_Address']['city'];
			$this->_data['CustomerSubscription_Address_state'] = $this->_data['CustomerSubscription_Address']['state'];
			$this->_data['CustomerSubscription_Address_zip'] = $this->_data['CustomerSubscription_Address']['zip'];
			$this->_data['CustomerSubscription_Address_country'] = $this->_data['CustomerSubscription_Address']['country'];
			$this->_data['CustomerSubscription_Address_countryiso2'] = $this->_data['CustomerSubscription_Address']['countryiso2'];
			$this->_data['CustomerSubscription_Address_countryiso3'] = $this->_data['CustomerSubscription_Address']['countryiso3'];
		}

		// transform customer group data if available
		if ($this->_data['customergroup']) {
			$this->_data['customergroupid'] = $this->_data['customergroup']['customergroupid'];
			$this->_data['groupname'] = $this->_data['customergroup']['groupname'];
		}
		else
		{
			$this->_data['customergroupid'] = '';
			$this->_data['groupname'] = '';
		}
		unset($this->_data['customergroup']);
	}
Example #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;
	}
Example #3
0
 /**
  * Get the shipping quote and display it in a form
  */
 public function TestQuoteResult()
 {
     $api = "";
     $pounds = 0;
     $ounces = 0;
     // Add a single test item - no dimensions needed for UPS
     $this->additem($_POST['delivery_weight']);
     // Setup all of the shipping variables
     $this->_username = $this->GetValue("username");
     $this->_origincountry = GetConfig('CompanyCountry');
     $this->_originzip = GetConfig('CompanyZip');
     if ($_POST['destination_type'] == "domestic") {
         $this->_service = $_POST['delivery_type'];
         $this->_destcountry = GetConfig('CompanyCountry');
     } else {
         $this->_service = $_POST['intl_delivery_type'];
         $this->_destcountry = GetCountryById($_POST['delivery_country']);
     }
     $this->_destzip = $_POST['delivery_zip'];
     $this->_expressmailcontainertype = $_POST['shipping_usps_expressmailcontainertype'];
     $this->_expressmailpackagesize = $_POST['shipping_usps_expressmailpackagesize'];
     $this->_firstclasscontainertype = $_POST['shipping_usps_firstclasscontainertype'];
     $this->_firstclasspackagesize = $_POST['shipping_usps_firstclasspackagesize'];
     $this->_prioritycontainertype = $_POST['shipping_usps_prioritycontainertype'];
     $this->_prioritypackagesize = $_POST['shipping_usps_prioritypackagesize'];
     $this->_parcelpostmachpackagesize = $_POST['shipping_usps_parcelpostmachpackagesize'];
     $this->_bpmpackagesize = $_POST['shipping_usps_bpmpackagesize'];
     $this->_librarypackagesize = $_POST['shipping_usps_librarypackagesize'];
     $this->_mediapackagesize = $_POST['shipping_usps_mediapackagesize'];
     // Is this a priority large package?
     if (is_numeric($_POST['shipping_usps_prioritywidth']) && is_numeric($_POST['shipping_usps_prioritylength']) && is_numeric($_POST['shipping_usps_priorityheight'])) {
         $this->_prioritywidth = $_POST['shipping_usps_prioritywidth'];
         $this->_prioritylength = $_POST['shipping_usps_prioritylength'];
         $this->_priorityheight = $_POST['shipping_usps_priorityheight'];
         $this->_prioritygirth = $_POST['shipping_usps_prioritygirth'];
     }
     // Next actually retrieve the quote
     $err = "";
     $result = $this->GetQuote();
     if (!is_object($result) && !is_array($result)) {
         $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'] = "";
         if (!is_array($result)) {
             $result = array($result);
         }
         foreach ($result as $quote) {
             if (count($result) > 1) {
                 $GLOBALS['Message'] .= "<li>";
             }
             $GLOBALS['Message'] .= $quote->getdesc(false) . " - \$" . number_format($quote->getprice(), GetConfig('DecimalPlaces')) . " USD";
             if (count($result) > 1) {
                 $GLOBALS['Message'] .= "</li>";
             }
         }
     }
     $GLOBALS['Image'] = $this->_image;
     $this->ParseTemplate("module.usps.testresult");
 }
Example #4
0
 /**
  * Convert a google request format address to an ISC format address
  *
  * @param array $top The google formatted address array
  *
  * @return array The ISC format address
  **/
 public function GetAddressFromResponse($top)
 {
     include_once ISC_BASE_PATH . '/lib/shipping.php';
     $countryid = GetCountryIdByISO2($top['country-code']['VALUE']);
     $address = array('shipcity' => $top['city']['VALUE'], 'shipstate' => GetStateNameByAbbrev($top['region']['VALUE'], $countryid), 'shipzip' => $top['postal-code']['VALUE'], 'shipcountry' => GetCountryById($countryid), 'shipcountryid' => $countryid, 'shipstateid' => GetStateByAbbrev($top['region']['VALUE'], $countryid));
     // If we don't have the contact name then this is an anonymous request so we dont have any of the
     // other personally identifyable information
     if (isset($top['contact-name']['VALUE'])) {
         $name = $top['contact-name']['VALUE'];
         $name = explode(' ', $name, 2);
         $address['shipfirstname'] = $name[0];
         $address['shiplastname'] = $name[1];
         $address['shipaddress1'] = $top['address1']['VALUE'];
         $address['shipaddress2'] = $top['address2']['VALUE'];
         $address['shipcompany'] = $top['company-name']['VALUE'];
         $address['shipemail'] = $top['email']['VALUE'];
         $address['shipphone'] = $top['phone']['VALUE'];
     }
     return $address;
 }
Example #5
0
	/**
	 * Get the country ID
	 *
	 * Method will return the country ID if found
	 *
	 * @access protected
	 * @param string $countryName The country name / ISO3 name / ISO2 name
	 * @param string $properCountryName The referenced variable to set the proper country name if the record exists
	 * @return int The country ID on success, FALSE if not found
	 */
	protected function getCountryId($countryName, &$properCountryName=null)
	{
		if (trim($countryName) == '') {
			return false;
		}

		if (strlen($countryName) == 2) {
			$countryId = GetCountryIdByISO2($countryName);
		} else if (strlen($countryName) == 3) {
			$countryId = GetCountryIdByISO3($countryName);
		} else {
			$countryId = GetCountryIdByName($countryName);
		}

		if (!$countryId || trim($countryId) == '') {
			return false;
		}

		$properCountryName = GetCountryById($countryId);

		return (int)$countryId;
	}
Example #6
0
		/**
		* Get the shipping quote and display it in a form
		*/
		public function TestQuoteResult()
		{

			// Add a single test item - dimensions needed for Canada Post
			$this->AddItem($_POST['delivery_weight'], $_POST['delivery_length'], $_POST['delivery_width'], $_POST['delivery_height'], 1, "Item #1");

			$this->_merchantid = $this->GetValue("merchantid");
			$this->_destcountry = GetCountryById($_POST['delivery_country']);
			$this->_deststate = $_POST['delivery_state'];
			$this->_destzip = $_POST['delivery_zip'];
			$this->_readytoship = $this->GetValue("readytoship");
			// Next actually retrieve the quote
			$result = $this->GetQuote();

			if(!is_object($result) && !is_array($result)) {
				$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'] = "";

				if(!is_array($result)) {
					$result = array($result);
				}

				foreach($result as $quote) {
					if(count($result) > 1) {
						$GLOBALS['Message'] .= "<li>";
					}

					if($quote->GetTransit() != -1) {
						if($quote->GetTransit() == 0) {
							// Same day
							$transit = ", today";
						}
						else {
							$transit = ", " . $quote->GetTransit() . " day(s)";
						}
					}
					else {
						$transit = "";
					}

					$GLOBALS['Message'] .= $quote->GetDesc(false) . " - $" . $quote->GetPrice() . " CAD" . $transit;

					if(count($result) > 1) {
						$GLOBALS['Message'] .= "</li>";
					}
				}
			}

			$GLOBALS['Image'] = $this->_image;
			$this->ParseTemplate("module.canadapost.testresult");
		}
Example #7
0
	public function convert_shipping_to_zones()
	{
		// Truncate a few tables just incase we've got half way through here before and failed
		$GLOBALS['ISC_CLASS_DB']->Query("TRUNCATE [|PREFIX|]shipping_zone_locations");
		$GLOBALS['ISC_CLASS_DB']->Query("TRUNCATE [|PREFIX|]shipping_vars");
		$GLOBALS['ISC_CLASS_DB']->Query("TRUNCATE [|PREFIX|]shipping_methods");

		// Is free shipping enabled?
		$freeShipping = $freeShippingThreshold = 0;
		if(strpos(GetConfig('ShippingMethods'), 'shipping_freeshipping') !== false) {
			$GLOBALS['ISC_CLASS_LOG']->LogSystemDebug('general', 'Free Shipping on');
			$query = "SELECT variableval FROM [|PREFIX|]module_vars WHERE modulename='shipping_freeshipping' AND variablename='threshhold'";
			$freeShippingThreshold = $GLOBALS['ISC_CLASS_DB']->FetchOne($query);
			$GLOBALS['ISC_CLASS_LOG']->LogSystemDebug('general', 'Threshold '.$freeShippingThreshold);
			$freeShipping = 1;
		}

		// Handling?
		$handlingType = 'none';
		$handlingFee = $handlingSeparate = 0;
		if(GetConfig('HandlingFee') > 0) {
			$GLOBALS['ISC_CLASS_LOG']->LogSystemDebug('general', 'Handling Fee');
			$handlingType = 'global';
			$handlingFee = GetConfig('HandlingFee');
			$handlingSeparate = GetConfig('ShowHandlingFeeSeparately');
		}

		// Have a handling fee or shipping fee, update the default zone to also have this
		if($handlingFee || $freeShipping) {
			$GLOBALS['ISC_CLASS_LOG']->LogSystemDebug('general', 'ZZZZZ');

			$updatedZone = array(
				'zonefreeshipping' => $freeShipping,
				'zonefreeshippingtotal' => $freeShippingThreshold,
				'zonehandlingtype' => $handlingType,
				'zonehandlingfee' => $handlingFee,
				'zonehandlingseparate' => $handlingSeparate
			);
			$GLOBALS['ISC_CLASS_DB']->UpdateQuery('shipping_zones', $updatedZone, 'zoneid=1');
		}

		// If we have shipping per country on, we need to create multiple zones
		if(strpos(GetConfig('ShippingMethods'), 'shipping_percountry') !== false) {
			$GLOBALS['ISC_CLASS_LOG']->LogSystemDebug('general', 'Per Country');

			$query = "SELECT * FROM [|PREFIX|]module_vars WHERE modulename='shipping_percountry'";
			$result = $GLOBALS['ISC_CLASS_DB']->Query($query);
			while($country = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
				if(strpos($country['variablename'], 'flatrateforcountry') === false) {
					continue;
				}
				$countryId = str_replace('flatrateforcountry', '', $country['variablename']);
				$countryName = GetCountryById($countryId);
				$newZone = array(
					'zonename' => $countryName,
					'zonetype' => 'country',
					'zonefreeshipping' => $freeShipping,
					'zonefreeshippingtotal' => $freeShippingThreshold,
					'zonehandlingtype' => $handlingType,
					'zonehandlingfee' => $handlingFee,
					'zonehandlingseparate' => $handlingSeparate,
					'zoneenabled' => 1
				);
				$zoneId = $GLOBALS['ISC_CLASS_DB']->InsertQuery('shipping_zones', $newZone);

				// Insert the location
				$newLocation = array(
					'zoneid' => $zoneId,
					'locationtype' => 'country',
					'locationvalueid' => $countryId,
					'locationvalue' => $countryName
				);
				$GLOBALS['ISC_CLASS_DB']->InsertQuery('shipping_zone_locations', $newLocation);

				// Insert a shipping method
				$newMethod = array(
					'methodname' => 'Flat Rate Per Order',
					'methodmodule' => 'flatrate',
					'zoneid' => $zoneId,
					'methodenabled' => 1
				);

				$methodId = $GLOBALS['ISC_CLASS_DB']->InsertQuery('shipping_methods', $newMethod);

				// Now insert the value
				$newValue = array(
					'methodid' => $methodId,
					'zoneid' => $zoneId,
					'modulename' => 'flatrate',
					'variablename' => 'shippingcost',
					'variableval' => $country['variableval']
				);
				$GLOBALS['ISC_CLASS_DB']->InsertQuery('shipping_vars', $newValue);
			}
		}
		$GLOBALS['ISC_CLASS_LOG']->LogSystemDebug('general', 'Types'.GetConfig('ShippingMethods'));

		$shippingTypes = explode(',', GetConfig('ShippingMethods'));
		foreach($shippingTypes as $shipper) {
			// We've already dealt with these - don't bother us with them again
			if($shipper == 'shipping_percountry' || $shipper == 'shipping_freeshipping') {
				continue;
			}

			$GLOBALS['ISC_CLASS_LOG']->LogSystemDebug('general', 'Config for '.$shipper);


			// Oh now this is going to be fun - we need to instantiate the module to get the name
			GetModuleById('shipping', $objModule, $shipper);
			if(!is_object($objModule)) {
				$GLOBALS['ISC_CLASS_LOG']->LogSystemDebug('general', "Couldn't load ".$shipper);
				continue;
			}

			// Insert a record for this shipping method
			$newMethod = array(
				'methodname' => $objModule->GetName(),
				'methodmodule' => $shipper,
				'zoneid' => 1,
				'methodenabled' => 1
			);

			$methodId = $GLOBALS['ISC_CLASS_DB']->InsertQuery('shipping_methods', $newMethod);
			$GLOBALS['ISC_CLASS_LOG']->LogSystemDebug('general', 'Created method '.$methodId.' for '.$shipper);

			// Fetch out any configuration variables
			$query = "SELECT * FROM [|PREFIX|]module_vars WHERE modulename='".$shipper."'";
			$result = $GLOBALS['ISC_CLASS_DB']->Query($query);
			while($variable = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
				// Now insert the value
				$newValue = array(
					'methodid' => $methodId,
					'zoneid' => 1,
					'modulename' => $variable['modulename'],
					'variablename' => $variable['variablename'],
					'variableval' => $variable['variableval']
				);
				$GLOBALS['ISC_CLASS_DB']->InsertQuery('shipping_vars', $newValue);
			}
		}

		// If there was an error message, return false!
		if($GLOBALS['ISC_CLASS_DB']->GetErrorMsg()) {
			$this->SetError($GLOBALS['ISC_CLASS_DB']->GetErrorMsg());
			return false;
		}

		// If we're still here - delete all the old variables
		$GLOBALS['ISC_CLASS_DB']->DeleteQuery('module_vars', "WHERE modulename LIKE 'shipping_%'");

		return true;
	}
Example #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);
			}
		}
	/**
	 * 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']));
		}
	}