Beispiel #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']);
	}
 /**
  * Set the default group on all the customers
  *
  * Method will reset the default group on all the customers in the accounting world
  *
  * @access private
  */
 private function setDefaultCustomerGroup($customergroupid)
 {
     if (!isId($customergroupid)) {
         return false;
     }
     /**
      * Ok, now we have to set this customergroup on all the customers that have the default customer group
      */
     $customer = new ISC_ENTITY_CUSTOMER();
     $result = $GLOBALS['ISC_CLASS_DB']->Query("SELECT * FROM [|PREFIX|]customers WHERE custgroupid='0'");
     while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
         $input = $customer->get($row['customerid']);
         $this->createServiceRequest('customer', 'edit', $input, 'customer_edit');
     }
     return true;
 }
Beispiel #3
0
		protected function displayAddEditOrder($sessionId, $orderId = null)
		{
			$order = null;

			if ($orderId) {
				$order = new ISC_ENTITY_ORDER;
				$order = $order->get($orderId);
				if (!$order) {
					exit;
				}

				$forEditing = true;
				$this->template->assign('editingOrder', $orderId);
				$this->template->assign('addingOrder', false);

				// could be useful
				$this->template->assign('order', $order);
			} else {
				$forEditing = false;
				$this->template->assign('editingOrder', false);
				$this->template->assign('addingOrder', true);
			}

			/** @var ISC_QUOTE */
			$quote = $_SESSION['QUOTE_SESSIONS'][$sessionId];
			$this->template->assign('quote', $quote);

			if ($quote->getCustomerId()) {
				// verify the customer still exists
				$customer = new ISC_ENTITY_CUSTOMER;
				if (!$customer->get($quote->getCustomerId())) {
					FlashMessage(GetLang('OrderCustomerDoesNotExist'), MSG_ERROR);
					$quote->setCustomerId(0);
				}
			}

			$incTax = (getConfig('taxDefaultTaxDisplayCart') == TAX_PRICES_DISPLAY_INCLUSIVE);

			require ISC_BASE_PATH . '/lib/addressvalidation.php';

			$this->engine->printHeader();

			$this->template->assign('quoteSession', $sessionId);
			$this->template->assign('statusList', getOrderStatusList());

			$this->template->assign('subtotal', FormatPrice($quote->getSubTotal($incTax))); // would prefer this as {{ quote.subTotal|formatPrice }} but it relies on $incTax variable parameter

			$this->populateQuoteFormFields($quote);

			$shipItemsTo = 'billing';
			if ($forEditing) {
				if ($quote->getIsSplitShipping()) {
					$shipItemsTo = 'multiple';
				} else {
					$shipItemsTo = 'single';
				}
			}
			$this->template->assign('shipItemsTo', $shipItemsTo);

			$accountCustomerGroups = array();
			if(gzte11(ISC_MEDIUMPRINT)) {
				$query = "
					SELECT customergroupid, groupname
					FROM [|PREFIX|]customer_groups
					ORDER BY groupname
				";
				$result = $this->db->query($query);
				while($group = $this->db->fetch($result)) {
					$accountCustomerGroups[$group['customergroupid']] = $group['groupname'];
				}
				array_unshift($accountCustomerGroups, GetLang('CustomerGroupNotAssoc'));
			}
			$this->template->assign('accountCustomerGroups', $accountCustomerGroups);

			$this->template->assign('itemsTable', $this->generateEditOrderItemsTable($quote));

			if ($forEditing && $quote->getIsSplitShipping()) {
				$this->template->assign('multiShippingTable', $this->renderMultiShippingTable($quote));
			}

			$allowGiftCertificates = gzte11(ISC_LARGEPRINT);
			$this->template->assign('allowGiftCertificates', $allowGiftCertificates);

			$this->template->assign('paymentForm', $this->generateOrderPaymentForm($order));

			$this->template->display('order.form.tpl');
			$this->engine->printFooter();
		}
 /**
  * Get the order record
  *
  * Method will return the order record
  *
  * @access public
  * @param int $orderId The order ID
  * @return array The order array on success, NULL if no record could be found, FALSE on error
  */
 public function get($orderId)
 {
     if (!isId($orderId)) {
         return false;
     }
     $entity = array();
     $result = $GLOBALS['ISC_CLASS_DB']->Query("SELECT * FROM [|PREFIX|]orders WHERE orderid=" . (int) $orderId);
     if (!($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result))) {
         return null;
     }
     $entity = $row;
     $customer = new ISC_ENTITY_CUSTOMER();
     $entity['customer'] = $customer->get($entity['ordcustid']);
     $product = new ISC_ENTITY_PRODUCT();
     $entity['products'] = array();
     $result = $GLOBALS['ISC_CLASS_DB']->Query("SELECT * FROM [|PREFIX|]order_products WHERE orderorderid=" . (int) $orderId);
     while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
         $entity['products'][] = $product->get($row['ordprodid']);
         $key = count($entity['products']) - 1;
         $entity['products'][$key]['prodorderquantity'] = $row['ordprodqty'];
         $entity['products'][$key]['prodorderamount'] = $row['ordprodcost'];
     }
     return $entity;
 }
Beispiel #5
0
/**
 * Amongst other things, this class and ACCOUNTING_QUICKBOOKS_SERVICE_ORDERSYNC are the ones used to write orders from the shopping cart into QuickBooks.
 * The ones for the opposite direction (QB->ISC) are service.orderadd.php and ACCOUNTING_QUICKBOOKS_SERVICE_ORDERSYNC.
 * 
 */
	public function buildXML()
	{
		if (isc_strtolower($this->spool["service"]) == "edit" && is_array($this->spoolReferenceData)) {
			$this->writeEscapedElement("TxnID", $this->spoolReferenceData["TxnID"]);
			$this->writeEscapedElement("EditSequence", $this->spoolReferenceData["EditSequence"]);
		}

		if (isId($this->spoolNodeData["ordcustid"])) {
			$customerRef = $this->accounting->getReference("customer", '', '', $this->spoolNodeData["ordcustid"], false);
		} else {
			$searchData = array(
								"OrderID" => $this->spool["nodeId"],
								"FirstName" => $this->spoolNodeData["ordbillfirstname"],
								"LastName" => $this->spoolNodeData["ordbilllastname"]
			);

			$customerRef = $this->accounting->getReference("customerguest", $searchData, '', '', false);
		}

		/**
		 * If this is an edit service and there is no reference EVEN though there is a customer ID in the order record, then the
		 * customer must have been deleted. If this is the case then don't construct the CustomerRef (we can't really)
		 */
		$noCustomerRef = false;
		if (isc_strtolower($this->spool["service"]) == "edit" && isId($this->spoolNodeData["ordcustid"])) {
			$customerAPI = new ISC_ENTITY_CUSTOMER();

			if (!$customerAPI->get($this->spoolNodeData["ordcustid"])) {
				$noCustomerRef = true;
			}
		}

		if (!$noCustomerRef && (!is_array($customerRef) || !isset($customerRef["accountingrefexternalid"]) || trim($customerRef["accountingrefexternalid"]) == '')) {
			throw new QBException("Unable to find customer ListID for order ID: " . $this->spool["nodeId"], $this->spool);
		}

		$this->xmlWriter->startElement("CustomerRef");
		$this->writeEscapedElement("ListID", $customerRef["accountingrefexternalid"]);
		$this->xmlWriter->endElement();

		if (array_key_exists("orddate", $this->spoolNodeData)) {
			$this->writeEscapedElement("TxnDate", date("Y-m-d", $this->spoolNodeData["orddate"]));
		}

		$this->writeEscapedElement("RefNumber", $this->accounting->orderID2QBOrderRefNum($this->spool["nodeId"]));

		/**
		 * The addresses
		 */
		foreach (array("Bill", "Ship") as $addressType) {
			$addressMap = array(
							"firstname" => "firstname",
							"lastname" => "lastname",
							"address1" => "street1",
							"address2" => "street2",
							"city" => "suburb",
							"state" => "state",
							"zip" => "zip",
							"country" => "country"
			);

			$address = array();
			$addressField = "ord" . isc_strtolower($addressType);

			foreach ($addressMap as $ourField => $ordField) {
				/**
				 * JMW - Bandaid that fixes the problem for now. Need to do a cleanup of the city/suburb names throughout the module.
				 */
				if (!array_key_exists($addressField . $ordField, $this->spoolNodeData)) {
					if ($addressField . $ordField != 'ordshipsuburb') {
						continue;
					}
				}
				if ($addressField . $ordField != 'ordshipsuburb') {
					$address["ship" . $ourField] = $this->spoolNodeData[$addressField . $ordField];
				} else {
					$address["ship" . $ourField] = $this->spoolNodeData[$addressField . 'city'];
				}
			}

			if (empty($address)) {
				continue;
			}

			$this->buildAddressBlock($addressType . "Address", $address);
		}

		if (trim($this->spoolNodeData["ordnotes"]) !== '') {
			$this->writeEscapedElement("Memo", $this->spoolNodeData["ordnotes"]);
		}

		/**
		 * Now for the products
		 */
		if (!array_key_exists("products", $this->spoolNodeData) || !is_array($this->spoolNodeData["products"])) {
			throw new QBException("Unable to find products for order ID: " . $this->spool["nodeId"], $this->spool);
		}

		foreach ($this->spoolNodeData["products"] as $product) {

			if (isset($product["prodordvariationid"]) && isId($product["prodordvariationid"])) {
				$prodType = "productvariation";
				$prodId = $product["prodordvariationid"];
			} else {
				$prodType = "product";
				$prodId = $product["productid"];
			}

			$productRef = $this->accounting->getReference($prodType, '', '', $prodId, false);

			if (!is_array($productRef) || !isset($productRef["accountingrefexternalid"]) || trim($productRef["accountingrefexternalid"]) == '') {
				throw new QBException("Unable to find product ListID for order ID: " . $this->spool["nodeId"], array("order" => $this->spool, "product" => $product));
			}

			if ($this->accounting->getValue("orderoption") == "order") {
				$tagName = "SalesOrderLine";
			} else {
				$tagName = "SalesReceiptLine";
			}

			if (isc_strtolower(trim($this->spool["service"])) == "edit") {
				$this->xmlWriter->startElement($tagName . "Mod");
			} else {
				$this->xmlWriter->startElement($tagName . "Add");
			}

			/**
			 * If this is an edit then we need to check for the TxnLineID as well
			 */
			if (isc_strtolower(trim($this->spool["service"])) == "edit") {

				$searchData = array(
									"ListID" => $productRef["accountingrefexternalid"],
									"OrderID" => $this->spool["nodeId"]
				);

				$orderItemRef = $this->accounting->getReference("orderitem", $searchData, '', '', false);

				/**
				 * If there is a reference then it is an existing item, else it is a new one
				 */
				if (is_array($orderItemRef) && isset($orderItemRef["accountingrefexternalid"])) {
					$this->writeEscapedElement("TxnLineID", $orderItemRef["accountingrefexternalid"]);
				} else {
					$this->writeEscapedElement("TxnLineID", "-1");
				}
			}

			$this->xmlWriter->startElement("ItemRef");
			$this->writeEscapedElement("ListID", $productRef["accountingrefexternalid"]);
			$this->xmlWriter->endElement();

			$this->writeEscapedElement("Desc", isc_substr($product["prodname"], 0, 4000));
			$this->writeEscapedElement("Quantity", $product["prodorderquantity"]);
			$this->writeEscapedElement("Amount", number_format($product["prodorderamount"] * $product["prodorderquantity"], 2, ".", ""));

			$this->xmlWriter->endElement();
		}

		/**
		 * Now add in the shipping cost and tax if we have any (add it in regardless)
		 */
		$otherProductMap = array(
								"shipping" => "shipping_cost_ex_tax",
								"tax" => "total_tax",
								"discount" => "coupon_discount",
		);

		foreach ($otherProductMap as $refType => $columnName) {
			if (!array_key_exists($columnName, $this->spoolNodeData) || trim($this->spoolNodeData[$columnName]) == '') {
				$otherProductTotal = 0;
			} else {
				$otherProductTotal = (float)$this->spoolNodeData[$columnName];
				if($refType == 'shipping'){
					$otherProductTotal += (float)$this->spoolNodeData['handling_cost_ex_tax'];
					$otherProductTotal += (float)$this->spoolNodeData['wrapping_cost_ex_tax'];
				}elseif($refType == 'discount'){
					$otherProductTotal -= (float)$this->spoolNodeData['orddiscountamount'];
					$otherProductTotal -= (float)$this->spoolNodeData['coupon_discount'];
					$otherProductTotal -= (float)$this->spoolNodeData['coupon_discount'];
				}
			}

			/**
			 * If casting it to a float cleared it
			 */
			if (trim($otherProductTotal) == '') {
				$otherProductTotal = 0;
			}

			$otherProductListID = $this->accounting->getOtherProductListId($refType);

			if (trim($otherProductListID) == '') {
				throw new QBException("Unable to find " . $refType . " ListID for order ID: " . $this->spool["nodeId"], $this->spool);
			}

			if ($this->accounting->getValue("orderoption") == "order") {
				$tagName = "SalesOrderLine";
			} else {
				$tagName = "SalesReceiptLine";
			}

			if (isc_strtolower(trim($this->spool["service"])) == "edit") {
				$this->xmlWriter->startElement($tagName . "Mod");
			} else {
				$this->xmlWriter->startElement($tagName . "Add");
			}

			/**
			 * Same deal with the products where we have to find the TxnLineID aswell
			 */
			if (isc_strtolower(trim($this->spool["service"])) == "edit") {

				$searchData = array(
									"ListID" => $otherProductListID,
									"OrderID" => $this->spool["nodeId"],
									"Type" => $refType
				);

				$otherProductRef = $this->accounting->getReference("orderitem", $searchData, '', '', false);

				/**
				 * Is there a reference for it?
				 */
				if (is_array($otherProductRef) && isset($otherProductRef["accountingrefexternalid"])) {
					$this->writeEscapedElement("TxnLineID", $otherProductRef["accountingrefexternalid"]);
				} else {
					$this->writeEscapedElement("TxnLineID", "-1");
				}
			}

			$this->xmlWriter->startElement("ItemRef");
			$this->writeEscapedElement("ListID", $otherProductListID);
			$this->xmlWriter->endElement();

			$this->writeEscapedElement("Desc", isc_substr($otherProductRef["accountingrefvalue"]["Name"], 0, 4000));
			$this->writeEscapedElement("Quantity", 1);
			$this->writeEscapedElement("Amount", number_format($otherProductTotal, 2, ".", ""));

			$this->xmlWriter->endElement();
		}

		return $this->buildOutput();
	}
Beispiel #6
0
 /**
  *	Save the edited account details back to the database
  */
 public function SaveAccountDetails()
 {
     /**
      * Customer Details
      */
     $customerMap = array('EmailAddress' => 'account_email', 'Password' => 'account_password', 'ConfirmPassword' => 'account_password_confirm');
     $fields = $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_ACCOUNT, true);
     /**
      * Validate the field input. Unset the password and confirm password fields first
      */
     foreach (array_keys($fields) as $fieldId) {
         if (isc_strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'password' || isc_strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'confirmpassword') {
             $fields[$fieldId]->setRequired(false);
         }
     }
     $errmsg = '';
     if (!$this->validateFieldData($fields, $errmsg)) {
         return $this->EditAccount($errmsg, MSG_ERROR);
     }
     foreach (array_keys($fields) as $fieldId) {
         if (!array_key_exists($fields[$fieldId]->record['formfieldprivateid'], $customerMap)) {
             continue;
         }
         $_POST[$customerMap[$fields[$fieldId]->record['formfieldprivateid']]] = $fields[$fieldId]->GetValue();
     }
     $customer_id = $GLOBALS['ISC_CLASS_CUSTOMER']->GetCustomerId();
     $email_taken = false;
     $phone_invalid = false;
     $password_invalid = false;
     if (isset($_POST['account_firstname']) && isset($_POST['account_lastname']) && isset($_POST['account_companyname']) && isset($_POST['account_email']) && isset($_POST['account_phone']) && isset($_POST['account_password']) && isset($_POST['account_password_confirm'])) {
         // Are they updating their email address? If so is the new email address available?
         if ($GLOBALS['ISC_CLASS_CUSTOMER']->AccountWithEmailAlreadyExists($_POST['account_email'], $customer_id)) {
             $email_taken = true;
         }
         if (!$GLOBALS['ISC_CLASS_CUSTOMER']->ValidatePhoneNumber($_POST['account_phone'])) {
             $phone_invalid = true;
         }
         $pass1 = $_POST['account_password'];
         $pass2 = $_POST['account_password_confirm'];
         if ($pass1 . $pass2 !== '' && $pass1 !== $pass2) {
             $password_invalid = true;
         }
         if (!$email_taken && !$phone_invalid && !$password_invalid) {
             $UpdatedAccount = array("customerid" => $customer_id, "firstname" => $_POST['account_firstname'], "lastname" => $_POST['account_lastname'], "company" => $_POST['account_companyname'], "email" => $_POST['account_email'], "phone" => $_POST['account_phone']);
             // Do we need to update the password?
             if ($pass1 == $pass2 && $pass1 != "") {
                 $UpdatedAccount['password'] = $pass1;
             }
             $entity = new ISC_ENTITY_CUSTOMER();
             $existingCustomer = $entity->get($customer_id);
             /**
              * Create/Update our form session data
              */
             if (isId($existingCustomer['custformsessionid'])) {
                 $GLOBALS['ISC_CLASS_FORM']->saveFormSession(FORMFIELDS_FORM_ACCOUNT, true, $existingCustomer['custformsessionid']);
             } else {
                 $UpdatedAccount['custformsessionid'] = $GLOBALS['ISC_CLASS_FORM']->saveFormSession(FORMFIELDS_FORM_ACCOUNT);
             }
             if ($entity->edit($UpdatedAccount)) {
                 $this->EditAccount(GetLang('AccountDetailsUpdatedSuccess'), MSG_SUCCESS);
             } else {
                 $this->EditAccount(GetLang('AccountDetailsUpdatedFailed'), MSG_ERROR);
             }
         } else {
             if ($email_taken) {
                 // Email address is already taken
                 $this->EditAccount(sprintf(GetLang('AccountUpdateEmailTaken'), $_POST['account_email']), MSG_ERROR);
             } else {
                 if ($phone_invalid) {
                     // Phone number is invalid
                     $this->EditAccount(sprintf(GetLang('AccountUpdateValidPhone'), $_POST['account_phone']), MSG_ERROR);
                 } else {
                     if ($password_invalid) {
                         $this->EditAccount(GetLang('AccountPasswordsDontMatch'), MSG_ERROR);
                     }
                 }
             }
         }
     } else {
         ob_end_clean();
         header(sprintf("Location: %s/account.php", $GLOBALS['ShopPath']));
         die;
     }
 }