Esempio n. 1
0
	public function SetPanelSettings()
	{
		$GLOBALS['SNIPPETS']['SideCartItems'] = '';

		// We check $_SESSION['QUOTE'] directly here as to not
		// instantiate the quote if it doesn't already exist.
		if(!isset($_SESSION['QUOTE']) && getCustomerQuote()->getNumItems() == 0) {
			$this->DontDisplay = true;
			return;
		}

		$incTax = false;
		if(getConfig('taxDefaultTaxDisplayCart') != TAX_PRICES_DISPLAY_EXCLUSIVE) {
			$incTax = true;
		}

		$quote = getCustomerQuote();
		$items = $quote->getItems();
		foreach($items as $item) {
			if($item->getProductId()) {
				$GLOBALS['ProductName'] = "<a href=\"".ProdLink($item->getName())."\">".isc_html_escape($item->getName())."</a>";
			}
			else {
				$GLOBALS['ProductName'] = isc_html_escape($item->getName());
			}

			// Is this product a variation?
			$GLOBALS['ProductOptions'] = '';
			$options = $item->getVariationOptions();
			if(!empty($options)) {
				$GLOBALS['ProductOptions'] .= "<br /><small>(";
				$comma = '';
				foreach($options as $name => $value) {
					if(!trim($name) || !trim($value)) {
						continue;
					}
					$GLOBALS['ProductOptions'] .= $comma.isc_html_escape($name).": ".isc_html_escape($value);
					$comma = ', ';
				}
				$GLOBALS['ProductOptions'] .= ")</small>";
			}

			$GLOBALS['ProductPrice'] = currencyConvertFormatPrice($item->getTotal($incTax));
			$GLOBALS['ProductQuantity'] = $item->getQuantity();
			$GLOBALS['SNIPPETS']['SideCartItems'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("SideCartItem");
		}

		$numItems = $quote->getNumItems();
		if($numItems == 1) {
			$GLOBALS['SideCartItemCount'] = GetLang('SideCartYouHave1Item');
		} else {
			$GLOBALS['SideCartItemCount'] = sprintf(GetLang('SideCartYouHaveXItems'), $numItems);
		}

		$total = $quote->getSubTotal($incTax);
		$GLOBALS['ISC_LANG']['SideCartTotalCost'] = sprintf(GetLang('SideCartTotalCost'), CurrencyConvertFormatPrice($total));

		// Go through all the checkout modules looking for one with a GetSidePanelCheckoutButton function defined
		$GLOBALS['AdditionalCheckoutButtons'] = '';
		$HideCheckout = false;
		foreach (GetAvailableModules('checkout', true, true) as $module) {
			if (method_exists($module['object'], 'GetSidePanelCheckoutButton')) {
				$GLOBALS['AdditionalCheckoutButtons'] .= $module['object']->GetSidePanelCheckoutButton();
			}

			if ($module['object']->disableNonCartCheckoutButtons) {
				$HideCheckout = true;
			}

		}

		if ($HideCheckout) {
			$GLOBALS['SNIPPETS']['SideCartContentsCheckoutLink'] = '';
		} else {
			require_once ISC_BASE_PATH.'/includes/display/CartHeader.php';

			$cartPanel = getClass('ISC_CARTHEADER_PANEL');
			$cartPanel -> insertOptimizerLinkScript();
			$GLOBALS['SNIPPETS']['SideCartContentsCheckoutLink'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet('SideCartContentsCheckoutLink');
		}

	}
Esempio n. 2
0
	/**
	 * Set up the list of coupon codes that have been applied to the shopping
	 * cart.
	 */
	public function setUpAppliedCouponsList()
	{
		$GLOBALS['SNIPPETS']['Coupons'] = '';
		$coupons = $this->quote->getAppliedCoupons();
		if(empty($coupons)) {
			return;
		}

		$GLOBALS['SNIPPETS']['FreeShippingCoupons'] = '';
		$GLOBALS['SNIPPETS']['NormalCoupons'] = '';
		$freeShippingTypesIds = array(4,3);
		foreach ($coupons as $coupon) {
			$GLOBALS['CouponId'] = $coupon['id'];
			$GLOBALS['CouponCode'] = $coupon['code'];
			$GLOBALS['CouponDiscount'] = currencyConvertFormatPrice($coupon['totalDiscount'] * -1);
			$GLOBALS['SNIPPETS']['Coupons'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CartCoupon");

			if (!empty ($coupon['discountType']) && getclass('ISC_COUPON')->isFreeShippingCoupon($coupon['discountType'])) {
				$GLOBALS['SNIPPETS']['FreeShippingCoupons'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CartCoupon");
			} else {
				$GLOBALS['SNIPPETS']['NormalCoupons'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CartCoupon");
			}
		}
	}
Esempio n. 3
0
		/**
		*	Show the details of an order and allow them to print an invoice
		*/
		private function ViewOrderDetails()
		{
			$GLOBALS['SNIPPETS']['AccountOrderItemRow'] = "";
			$count = 0;

			if (!isset($_GET['order_id']) || !is_numeric($_GET['order_id'])) {
				redirect('account.php?action=view_orders');
			}

			$GLOBALS['FlassMessage'] = GetFlashMessageBoxes();

			// Retrieve the completed order that matches the customers user id
			$orderId = (int)$_GET['order_id'];
			$GLOBALS['OrderId'] = $orderId;

			$customerId = getClass('ISC_CUSTOMER')->getcustomerId();
			$query = "
				SELECT *, (
						SELECT CONCAT(custconfirstname, ' ', custconlastname)
						FROM [|PREFIX|]customers
						WHERE customerid=ordcustid
					) AS custname, (
						SELECT statusdesc
						FROM [|PREFIX|]order_status
						WHERE statusid=ordstatus
					) AS ordstatustext
				FROM [|PREFIX|]orders
				WHERE ordcustid='".(int)$customerId."' AND orderid='".(int)$orderId."' AND deleted = 0
			";
			$result = $GLOBALS['ISC_CLASS_DB']->query($query);
			$row = $GLOBALS['ISC_CLASS_DB']->fetch($result);
			if(!$row) {
				redirect('account.php?action=view_orders');
			}

			$GLOBALS['DisableReturnButton'] = "";
			if (!gzte11(ISC_LARGEPRINT)) {
				$GLBOALS['DisableReturnButton'] = "none";
			}

			$order = $row;

			// Fetch the shipping addresses for this order
			$addresses = array();
			$query = "
				SELECT *
				FROM [|PREFIX|]order_addresses
				WHERE order_id='".$order['orderid']."'
			";
			$result = $GLOBALS['ISC_CLASS_DB']->query($query);
			while($address = $GLOBALS['ISC_CLASS_DB']->fetch($result)) {
				$addresses[$address['id']] = $address;
			}

			// Fetch the shipping details for the order
			$query = "
				SELECT *
				FROM [|PREFIX|]order_shipping
				WHERE order_id=".$order['orderid'];
			$result = $GLOBALS['ISC_CLASS_DB']->query($query);
			while($shipping = $GLOBALS['ISC_CLASS_DB']->fetch($result)) {
				$addresses[$shipping['order_address_id']]['shipping'] = $shipping;
			}

			$GLOBALS['OrderComments'] = '';
			if($row['ordcustmessage'] != '') {
				$GLOBALS['OrderComments'] = nl2br(isc_html_escape($row['ordcustmessage']));
			}
			else {
				$GLOBALS['HideOrderComments'] = 'display: none';
			}

			if(OrderIsComplete($row['ordstatus'])) {
				if (!gzte11(ISC_LARGEPRINT)) {
					$GLOBALS['DisableReturnButton'] = "none";
				}

				if ($row['ordstatus'] == 4 || GetConfig('EnableReturns') == 0) {
					$GLOBALS['DisableReturnButton'] = "none";
				}

				$GLOBALS['HideOrderStatus'] = "none";
				$orderComplete = true;
			}
			else {
				$GLOBALS['HideOrderStatus'] = '';
				$GLOBALS['OrderStatus'] = $row['ordstatustext'];
				$GLOBALS['DisableReturnButton'] = "none";
				$orderComplete = false;
			}

			// Hide print order invoive if it's a incomplete order
			$GLOBALS['ShowOrderActions'] = '';
			if(!$row['ordstatus']) {
				$GLOBALS['ShowOrderActions'] = 'display:none';
			}

			$GLOBALS['OrderDate'] = isc_date(GetConfig('ExtendedDisplayDateFormat'), $row['orddate']);

			$GLOBALS['OrderTotal'] = CurrencyConvertFormatPrice($row['total_inc_tax'], $row['ordcurrencyid'], $row['ordcurrencyexchangerate'], true);

			// Format the billing address
			$GLOBALS['ShipFullName'] = isc_html_escape($row['ordbillfirstname'].' '.$row['ordbilllastname']);
			$GLOBALS['ShipCompany'] = '';
			if($row['ordbillcompany']) {
				$GLOBALS['ShipCompany'] = '<br />'.isc_html_escape($row['ordbillcompany']);
			}

			$GLOBALS['ShipAddressLines'] = isc_html_escape($row['ordbillstreet1']);

			if ($row['ordbillstreet2'] != "") {
				$GLOBALS['ShipAddressLines'] .= '<br />' . isc_html_escape($row['ordbillstreet2']);
			}

			$GLOBALS['ShipSuburb'] = isc_html_escape($row['ordbillsuburb']);
			$GLOBALS['ShipState'] = isc_html_escape($row['ordbillstate']);
			$GLOBALS['ShipZip'] = isc_html_escape($row['ordbillzip']);
			$GLOBALS['ShipCountry'] = isc_html_escape($row['ordbillcountry']);
			$GLOBALS['ShipPhone'] = "";
			$GLOBALS['BillingAddress'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("AddressLabel");

			// Is there a shipping address, or is it a digital download?
			if ($order['ordisdigital']) {
				$GLOBALS['HideSingleShippingAddress'] = 'display: none';
			}
			else if ($order['shipping_address_count'] > 1) {
				$GLOBALS['ShippingAddress'] = GetLang('OrderWillBeShippedToMultipleAddresses');
				$GLOBALS['HideItemDetailsHeader'] = 'display:none;';
			}
			else {
				$shippingAddress = current($addresses);
				$GLOBALS['ShipFullName'] = isc_html_escape($shippingAddress['first_name'].' '.$shippingAddress['last_name']);

				$GLOBALS['ShipCompany'] = '';
				if($shippingAddress['company']) {
					$GLOBALS['ShipCompany'] = '<br />'.isc_html_escape($shippingAddress['company']);
				}

				$GLOBALS['ShipAddressLines'] = isc_html_escape($shippingAddress['address_1']);

				if ($shippingAddress['address_2'] != "") {
					$GLOBALS['ShipAddressLines'] .= '<br />' . isc_html_escape($shippingAddress['address_2']);
				}

				$GLOBALS['ShipSuburb'] = isc_html_escape($shippingAddress['city']);
				$GLOBALS['ShipState'] = isc_html_escape($shippingAddress['state']);
				$GLOBALS['ShipZip'] = isc_html_escape($shippingAddress['zip']);
				$GLOBALS['ShipCountry'] = isc_html_escape($shippingAddress['country']);

				$GLOBALS['ShipPhone'] = "";
				$GLOBALS['ShippingAddress'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("AddressLabel");
			}

			$itemTotalColumn = 'total_ex_tax';
			if(getConfig('taxDefaultTaxDisplayOrders') == TAX_PRICES_DISPLAY_INCLUSIVE) {
				$itemTotalColumn = 'total_inc_tax';
			}

			$GLOBALS['OrderTotalRows'] = '';
			$totalRows = getOrderTotalRows($order);
			foreach($totalRows as $id => $totalRow) {
				$GLOBALS['ISC_CLASS_TEMPLATE']->assign('label', $totalRow['label']);
				$GLOBALS['ISC_CLASS_TEMPLATE']->assign('classNameAppend', ucfirst($id));
				$value = currencyConvertFormatPrice(
					$totalRow['value'],
					$row['ordcurrencyid'],
					$row['ordcurrencyexchangerate']
				);
				$GLOBALS['ISC_CLASS_TEMPLATE']->assign('value', $value);
				$GLOBALS['OrderTotalRows'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->getSnippet('AccountOrderTotalRow');
			}

			$OrderProducts = array();
			$ProductIds = array();
			// Load up the items in this order
			$query = "
				SELECT
					o.*,
					op.*,
					oa.address_1,
					oa.address_2,
					oa.city,
					oa.zip,
					oa.country,
					oa.state,
					p.productid,
					p.prodpreorder,
					p.prodreleasedate,
					p.prodpreordermessage
				FROM
					[|PREFIX|]orders o
					LEFT JOIN [|PREFIX|]order_products op ON op.orderorderid
					LEFT JOIN [|PREFIX|]products p ON p.productid = op.ordprodid
					LEFT JOIN [|PREFIX|]order_addresses oa ON oa.`id` = op.order_address_id
				WHERE
					orderorderid = " . (int)$order['orderid'] ."
				ORDER BY
					op.order_address_id";
			$result = $GLOBALS['ISC_CLASS_DB']->Query($query);

			//check if products are reorderable
			while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
				$OrderProducts[$row['orderprodid']] = $row;
				$ProductIds[] = $row['ordprodid'];
			}

			$UnreorderableProducts = $this->GetUnreorderableProducts($OrderProducts, $ProductIds);

			// for grouping of shipping addresses in template output
			$previousAddressId = null;
			$destinationCounter = 0;

			foreach ($OrderProducts as $row) {
				if ($count++ % 2 != 0) {
					$GLOBALS['ItemClass'] = "OrderItem2";
				} else {
					$GLOBALS['ItemClass'] = "OrderItem1";
				}

				$GLOBALS['OrderProductId'] = $row['orderprodid'];
				$GLOBALS['DisableReorder'] = '';

				$GLOBALS['ReorderMessage'] = "";
				$GLOBALS['HideItemMessage'] = 'display:none;';
				if(isset($UnreorderableProducts[$row['orderprodid']])) {
					$GLOBALS['DisableReorder'] = 'Disabled';
					$GLOBALS['ReorderMessage'] = $UnreorderableProducts[$row['orderprodid']];
					if(isset($_REQUEST['reorder']) && $_REQUEST['reorder']==1) {
						$GLOBALS['HideItemMessage'] = '';
					}
				}

				$GLOBALS['Qty'] = (int) $row['ordprodqty'];
				$GLOBALS['Name'] = isc_html_escape($row['ordprodname']);
				$GLOBALS['EventDate'] = '';

				if ($row['ordprodeventdate'] != 0) {
					$GLOBALS['EventDate'] = $row['ordprodeventname'] . ': '. isc_date('M jS Y', $row['ordprodeventdate']);
				}

				// Does the product still exist or has it been deleted?
				$prod_name = GetProdNameById($row['ordprodid']);

				if ($prod_name == "" && $row['ordprodtype'] == 'giftcertificate') {
					$GLOBALS['Link'] = "javascript:product_giftcertificate()";
					$GLOBALS['Target'] = "";
				}else if ($prod_name == "") {
					$GLOBALS['Link'] = "javascript:product_removed()";
					$GLOBALS['Target'] = "";
				}
				else {
					$GLOBALS['Link'] = ProdLink(GetProdNameById($row['ordprodid']));
					$GLOBALS['Target'] = "_blank";
				}

				$GLOBALS['DownloadsLink'] = '';
				if ($row['ordprodtype'] == "digital" && $orderComplete) {
					$GLOBALS['DownloadItemEncrypted'] = $this->EncryptDownloadKey($row['orderprodid'], $row['ordprodid'], $row['orderorderid'], $row['ordtoken']);
					$GLOBALS['DownloadsLink'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("AccountOrderItemDownloadLink");
				}

				$GLOBALS['Refunded'] = '';
				$GLOBALS['StrikeEnd'] = '';
				$GLOBALS['StrikeStart'] = '';

				if ($row['ordprodrefunded'] > 0) {
					if ($row['ordprodrefunded'] == $row['ordprodqty']) {
						$GLOBALS['StrikeStart'] = "<s>";
						$GLOBALS['StrikeEnd'] = "</s>";
						$GLOBALS['Refunded'] = '<span class="Refunded">'.GetLang('OrderProductRefunded').'</span>';
					}
					else {
						$GLOBALS['Refunded'] = '<span class="Refunded">'.sprintf(GetLang('OrderProductsRefundedX'), $row['ordprodrefunded']).'</span>';
					}
				}

				$GLOBALS['Price'] = CurrencyConvertFormatPrice(
					$row[$itemTotalColumn],
					$order['ordcurrencyid'],
					$order['ordcurrencyexchangerate']
				);

				// Were there one or more options selected?
				$GLOBALS['ProductOptions'] = '';
				if($row['ordprodoptions'] != '') {
					$options = @unserialize($row['ordprodoptions']);
					if(!empty($options)) {
						$GLOBALS['ProductOptions'] = "<br /><small class='OrderItemOptions'>(";
						$comma = '';
						foreach($options as $name => $value) {
							$GLOBALS['ProductOptions'] .= $comma.isc_html_escape($name).": ".isc_html_escape($value);
							$comma = ', ';
						}
						$GLOBALS['ProductOptions'] .= ")</small>";
					}
				}

				if($row['ordprodwrapname']) {
					$GLOBALS['GiftWrappingName'] = isc_html_escape($row['ordprodwrapname']);
					$GLOBALS['HideWrappingOptions'] = '';
				}
				else {
					$GLOBALS['GiftWrappingName'] = '';
					$GLOBALS['HideWrappingOptions'] = 'display: none';
				}

				$GLOBALS['HideExpectedReleaseDate'] = 'display:none;';
				$GLOBALS['ExpectedReleaseDate'] = '';

				if ($row['prodpreorder']) {
					if ($row['prodreleasedate']) {
						$message = $row['prodpreordermessage'];
						if (!$message) {
							$message = GetConfig('DefaultPreOrderMessage');
						}
						$GLOBALS['ExpectedReleaseDate'] = '(' . str_replace('%%DATE%%', isc_date(GetConfig('DisplayDateFormat'), $row['prodreleasedate']), $message) . ')';
					} else {
						$GLOBALS['ExpectedReleaseDate'] = '(' . GetLang('PreOrderProduct') . ')';
					}
					$GLOBALS['HideExpectedReleaseDate'] = '';
				}

				$GLOBALS['ItemShippingRow'] = '';
				if ($order['shipping_address_count'] > 1 && ($previousAddressId != $row['order_address_id'])) {
					$destinationCounter++;

					$GLOBALS['Destination_Number'] = GetLang('Destination_Number', array('number' => $destinationCounter));

					$addressLine = array_filter(array(
						$row['address_1'],
						$row['address_2'],
						$row['city'],
						$row['state'],
						$row['zip'],
						$row['country'],
					));

					$GLOBALS['ItemShippingRow_AddressLine'] = Store_String::rightTruncate(implode(', ', $addressLine), 60);

					$GLOBALS['ItemShippingRow'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet('AccountOrderItemShippingRow');
				}

				$GLOBALS['SNIPPETS']['AccountOrderItemRow'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("AccountOrderItemRow");
				$previousAddressId = $row['order_address_id'];
			}

			$GLOBALS['ISC_CLASS_TEMPLATE']->SetPageTitle(sprintf("%s - %s%d", GetConfig('StoreName'), GetLang('OrderIdHash'), $orderId));
			$GLOBALS['ISC_CLASS_TEMPLATE']->SetTemplate("account_order");
			$GLOBALS['ISC_CLASS_TEMPLATE']->ParseTemplate();
		}
Esempio n. 4
0
	/**
	 * Build the contents for the order confirmation page. This function sets up everything to be used by
	 * the order confirmation on the express checkout page as well as the ConfirmOrder page when using a
	 * multi step checkout.
	 */
	public function BuildOrderConfirmation()
	{
		$GLOBALS['ISC_CLASS_CUSTOMER'] = GetClass('ISC_CUSTOMER');
		if(!GetConfig('ShowMailingListInvite')) {
			$GLOBALS['HideMailingListInvite'] = 'none';
		}

		// Do we need to show the special offers & discounts checkbox and should they
		// either of the newsletter checkboxes be ticked by default?
		if (GetConfig('MailAutomaticallyTickNewsletterBox')) {
			$GLOBALS['NewsletterBoxIsTicked'] = 'checked="checked"';
		}

		if (ISC_EMAILINTEGRATION::doOrderAddRulesExist()) {
			if (GetConfig('MailAutomaticallyTickOrderBox')) {
				$GLOBALS['OrderBoxIsTicked'] = 'checked="checked"';
			}
		}
		else {
			$GLOBALS['HideOrderCheckBox'] = "none";
		}

		if(isset($_REQUEST['ordercomments'])) {
			$GLOBALS['OrderComments'] = $_REQUEST['ordercomments'];
		}

		// Now we check if we have an incoming coupon or gift certificate code to apply
		if (isset($_REQUEST['couponcode']) && $_REQUEST['couponcode'] != '') {
			$code = trim($_REQUEST['couponcode']);

			// Were we passed a gift certificate code?
			if (self::isCertificateCode($code)) {
				try {
					$this->getQuote()->applyGiftCertificate($code);

					// If successful show a message
					$GLOBALS['CheckoutSuccessMsg'] = GetLang('GiftCertificateAppliedToCart');
				}
				catch(ISC_QUOTE_EXCEPTION $e) {
					$GLOBALS['CheckoutErrorMsg'] = $e->getMessage();
				}
			}
			// Otherwise, it must be a coupon code
			else {
				try {
					$this->getQuote()->applyCoupon($code);

					// Coupon code applied successfully
					$GLOBALS['CheckoutSuccessMsg'] = GetLang('CouponAppliedToCart');
				}
				catch(ISC_QUOTE_EXCEPTION $e) {
					$GLOBALS['CheckoutErrorMsg'] = $e->getMessage();
				}
			}
		}

		$GLOBALS['ISC_CLASS_ACCOUNT'] = GetClass('ISC_ACCOUNT');

		// Determine what we'll be showing for the redeem gift certificate/coupon code box
		if (gzte11(ISC_LARGEPRINT)) {
			$GLOBALS['RedeemTitle'] = GetLang('RedeemGiftCertificateOrCoupon');
			$GLOBALS['RedeemIntro'] = GetLang('RedeemGiftCertificateorCouponIntro');
		}
		else {
			$GLOBALS['RedeemTitle'] = GetLang('RedeemCouponCode');
			$GLOBALS['RedeemIntro'] = GetLang('RedeemCouponCodeIntro');
		}

		$GLOBALS['HideCheckoutError'] = "none";
		$GLOBALS['HidePaymentOptions'] = "";
		$GLOBALS['HideUseCoupon'] = '';
		$checkoutProviders = array();

		// if the provider list html is set in session then use it as the payment provider options.
		// it's normally set in payment modules when it's required.
		if(isset($_SESSION['CHECKOUT']['ProviderListHTML'])) {
			$GLOBALS['HidePaymentProviderList'] = "";
			$GLOBALS['HidePaymentOptions'] = "";
			$GLOBALS['PaymentProviders'] = $_SESSION['CHECKOUT']['ProviderListHTML'];
			$GLOBALS['StoreCreditPaymentProviders'] = $_SESSION['CHECKOUT']['ProviderListHTML'];
			$GLOBALS['CheckoutWith'] = "";
		} else {
			// Get a list of checkout providers
			$checkoutProviders = GetCheckoutModulesThatCustomerHasAccessTo(true);


			// If no checkout providers are set up, send an email to the store owner and show an error message
			if (empty($checkoutProviders)) {
				$GLOBALS['HideConfirmOrderPage'] = "none";
				$GLOBALS['HideCheckoutError'] = '';
				$GLOBALS['HideTopPaymentButton'] = "none";
				$GLOBALS['HidePaymentProviderList'] = "none";
				$GLOBALS['CheckoutErrorMsg'] = GetLang('NoCheckoutProviders');
				$GLOBALS['NoCheckoutProvidersError'] = sprintf(GetLang("NoCheckoutProvidersErrorLong"), $GLOBALS['ShopPath']);

				$GLOBALS['EmailHeader'] = GetLang("NoCheckoutProvidersSubject");
				$GLOBALS['EmailMessage'] = sprintf(GetLang("NoCheckoutProvidersErrorLong"), $GLOBALS['ShopPath']);

				$emailTemplate = FetchEmailTemplateParser();
				$emailTemplate->SetTemplate("general_email");
				$message = $emailTemplate->ParseTemplate(true);

				require_once(ISC_BASE_PATH . "/lib/email.php");
				$obj_email = GetEmailClass();
				$obj_email->Set('CharSet', GetConfig('CharacterSet'));
				$obj_email->From(GetConfig('OrderEmail'), GetConfig('StoreName'));
				$obj_email->Set("Subject", GetLang("NoCheckoutProvidersSubject"));
				$obj_email->AddBody("html", $message);
				$obj_email->AddRecipient(GetConfig('AdminEmail'), "", "h");
				$email_result = $obj_email->Send();
			}

			// We have more than one payment provider, hide the top button and build a list
			else if (count($checkoutProviders) > 1) {
				$GLOBALS['HideTopPaymentButton'] = "none";
				$GLOBALS['HideCheckoutError'] = "none";
			}

			// There's only one payment provider - hide the list
			else {
				$GLOBALS['HidePaymentProviderList'] = "none";
				$GLOBALS['HideCheckoutError'] = "none";
				$GLOBALS['HidePaymentOptions'] = "none";
				list(,$provider) = each($checkoutProviders);
				if(method_exists($provider['object'], 'ShowPaymentForm') && !isset($_SESSION['CHECKOUT']['ProviderListHTML'])) {
					$GLOBALS['ExpressCheckoutLoadPaymentForm'] = 'ExpressCheckout.ShowSingleMethodPaymentForm();';
				}
				if ($provider['object']->GetPaymentType() == PAYMENT_PROVIDER_OFFLINE) {
					$GLOBALS['PaymentButtonSwitch'] = "ShowContinueButton();";
				}
				$GLOBALS['CheckoutWith'] = $provider['object']->GetDisplayName();
			}

			// Build the list of payment provider options
			$GLOBALS['PaymentProviders'] = $GLOBALS['StoreCreditPaymentProviders'] =  "";
			foreach ($checkoutProviders as $provider) {
				$GLOBALS['ProviderChecked'] = '';
				if(count($checkoutProviders) == 1) {
					$GLOBALS['ProviderChecked'] = 'checked="checked"';
				}
				$GLOBALS['ProviderId'] = $provider['object']->GetId();
				$GLOBALS['ProviderName'] = isc_html_escape($provider['object']->GetDisplayName());
				$GLOBALS['ProviderType'] = $provider['object']->GetPaymentType("text");
				if(method_exists($provider['object'], 'ShowPaymentForm')) {
					$GLOBALS['ProviderPaymentFormClass'] = 'ProviderHasPaymentForm';
				}
				else {
					$GLOBALS['ProviderPaymentFormClass'] = '';
				}
				$GLOBALS['PaymentFieldPrefix'] = '';
				$GLOBALS['PaymentProviders'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CheckoutProviderOption");
				$GLOBALS['PaymentFieldPrefix'] = 'credit_';
				$GLOBALS['StoreCreditPaymentProviders'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CheckoutProviderOption");
			}

		}

		// Are we coming back to this page for a particular reason?
		if (isset($_SESSION['REDIRECT_TO_CONFIRMATION_MSG'])) {
			$GLOBALS['HideCheckoutError'] = '';
			$GLOBALS['CheckoutErrorMsg'] = $_SESSION['REDIRECT_TO_CONFIRMATION_MSG'];
			unset($_SESSION['REDIRECT_TO_CONFIRMATION_MSG']);
		}

		$displayIncludingTax = false;
		if(getConfig('taxDefaultTaxDisplayCart') != TAX_PRICES_DISPLAY_EXCLUSIVE) {
			$displayIncludingTax = true;
		}

		$items = $this->getQuote()->getItems();

		// Start building the summary of all of the items in the order
		$GLOBALS['SNIPPETS']['CartItems'] = '';
		foreach ($items as $item) {
			$GLOBALS['ProductQuantity'] = $item->getQuantity();

			$price = $item->getPrice($displayIncludingTax);
			$total = $item->getTotal($displayIncludingTax);
			$GLOBALS['ProductPrice'] = currencyConvertFormatPrice($price);
			$GLOBALS['ProductTotal'] = currencyConvertFormatPrice($total);

			if($item instanceof ISC_QUOTE_ITEM_GIFTCERTIFICATE) {
				$GLOBALS['GiftCertificateName'] = isc_html_escape($item->getName());
				$GLOBALS['GiftCertificateTo'] = isc_html_escape($item->getRecipientName());
				$GLOBALS['SNIPPETS']['CartItems'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CheckoutCartItemGiftCertificate");
				continue;
			}

			$GLOBALS['ProductAvailability'] = $item->getAvailability();
			$GLOBALS['ItemId'] = $item->getProductId();

			// Is this product a variation?
			$GLOBALS['ProductOptions'] = '';
			$options = $item->getVariationOptions();
			if(!empty($options)) {
				$GLOBALS['ProductOptions'] .= "<br /><small>(";
				$comma = '';
				foreach($options as $name => $value) {
					if(!trim($name) || !trim($value)) {
						continue;
					}
					$GLOBALS['ProductOptions'] .= $comma.isc_html_escape($name).": ".isc_html_escape($value);
					$comma = ', ';
				}
				$GLOBALS['ProductOptions'] .= ")</small>";
			}
			$GLOBALS['EventDate'] = '';
			$eventDate = $item->getEventDate(true);
			if(!empty($eventDate)) {
				$GLOBALS['EventDate'] = '
					<div style="font-style: italic; font-size:10px; color:gray">(' .
						$item->getEventName() . ': ' . isc_date('M jS Y', $eventDate) .
					')</div>';
			}

			$GLOBALS['HideGiftWrapping'] = 'display: none';
			$GLOBALS['GiftWrappingName'] = '';
			$GLOBALS['GiftMessagePreview'] = '';
			$GLOBALS['HideGiftMessagePreview'] = 'display: none';

			$wrapping = $item->getGiftWrapping();
			if($wrapping !== false) {
				$GLOBALS['HideGiftWrapping'] = '';
				$GLOBALS['GiftWrappingName'] = isc_html_escape($wrapping['wrapname']);
				if(!empty($wrapping['wrapmessage'])) {
					if(isc_strlen($wrapping['wrapmessage']) > 30) {
						$wrapping['wrapmessage'] = substr($wrapping['wrapmessage'], 0, 27).'...';
					}
					$GLOBALS['GiftMessagePreview'] = isc_html_escape($wrapping['wrapmessage']);
					$GLOBALS['HideGiftMessagePreview'] = '';
				}
			}

			//create configurable product fields on order confirmation page with the data posted from add to cart page
			$GLOBALS['CartProductFields'] = '';
			$configuration = $item->getConfiguration();
			if (!empty($configuration)) {
				require_once ISC_BASE_PATH.'/includes/display/CartContent.php';
				ISC_CARTCONTENT_PANEL::GetProductFieldDetails($configuration, $item->getId());
			}

			$GLOBALS['ProductName'] = isc_html_escape($item->getName());
			$GLOBALS['ProductImage'] = imageThumb($item->getThumbnail(), prodLink($item->getName()));

			$GLOBALS['HideExpectedReleaseDate'] = 'display: none;';
			if($item->isPreOrder()) {
				$GLOBALS['ProductExpectedReleaseDate'] = $item->getPreOrderMessage();
				$GLOBALS['HideExpectedReleaseDate'] = '';
			}

			$GLOBALS['SNIPPETS']['CartItems'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CheckoutCartItem");
		}

		// Do we have a shipping price to show?
		if(!$this->getQuote()->isDigital()) {
			$shippingAddresses = $this->getQuote()->getShippingAddresses();
			$numShippingAddresses = count($shippingAddresses);
			if($numShippingAddresses == 1) {
				$shippingAddress = $this->getQuote()->getShippingAddress();
				$GLOBALS['ShippingAddress'] = $GLOBALS['ISC_CLASS_ACCOUNT']->FormatShippingAddress($shippingAddress->getAsArray());
			}
			else {
				$GLOBALS['ShippingAddress'] = '<em>(Order will be shipped to multiple addresses)</em>';
			}

			// Show the shipping details
			$GLOBALS['HideShippingDetails'] = '';
		}
		// This is a digital order - no shipping applies
		else {
			$GLOBALS['HideShippingDetails'] = 'display: none';
			$GLOBALS['HideShoppingCartShippingCost'] = 'none';
			$GLOBALS['ShippingAddress'] = GetLang('NotRequiredForDigitalDownloads');
			$GLOBALS['ShippingMethod'] = GetLang('ShippingImmediateDownload');
		}

		$billingAddress = $this->getQuote()->getBillingAddress();
		$GLOBALS['BillingAddress'] = getClass('ISC_ACCOUNT')
			->formatShippingAddress($billingAddress->getAsArray());

		$totalRows = self::getQuoteTotalRows($this->getQuote());
		$templateTotalRows = '';
		foreach($totalRows as $id => $totalRow) {
			$GLOBALS['ISC_CLASS_TEMPLATE']->assign('label', $totalRow['label']);
			$GLOBALS['ISC_CLASS_TEMPLATE']->assign('classNameAppend', ucfirst($id));
			$value = currencyConvertFormatPrice($totalRow['value']);
			$GLOBALS['ISC_CLASS_TEMPLATE']->assign('value', $value);
			$templateTotalRows .= $GLOBALS['ISC_CLASS_TEMPLATE']->getSnippet('CheckoutCartTotal');
		}
		$GLOBALS['ISC_CLASS_TEMPLATE']->assign('totals', $templateTotalRows);

		$grandTotal = $this->getQuote()->getGrandTotal();
		$GLOBALS['GrandTotal'] = formatPrice($grandTotal);
		if($grandTotal == 0) {
			$GLOBALS['HidePaymentOptions'] = "none";
			$GLOBALS['HideUseCoupon'] = 'none';
			$GLOBALS['HidePaymentProviderList'] = "none";
			$GLOBALS['PaymentButtonSwitch'] = "ShowContinueButton(); ExpressCheckout.UncheckPaymentProvider();";
		}

		// Does the customer have any store credit they can use?
		$GLOBALS['HideUseStoreCredit'] = "none";
		$GLOBALS['HideRemainingStoreCredit'] = "none";
		$customer = $GLOBALS['ISC_CLASS_CUSTOMER']->GetCustomerDataByToken();
		if ($customer['custstorecredit'] > 0) {
			$GLOBALS['HidePaymentOptions'] = "";
			$GLOBALS['StoreCredit'] = CurrencyConvertFormatPrice($customer['custstorecredit']);
			$GLOBALS['HideUseStoreCredit'] = "";
			$GLOBALS['HidePaymentProviderList'] = "none";
			// The customer has enough store credit to pay for the entirity of this order
			if ($customer['custstorecredit'] >= $grandTotal) {
				$GLOBALS['PaymentButtonSwitch'] = "ShowContinueButton();";
				$GLOBALS['HideLimitedCreditWarning'] = "none";
				$GLOBALS['HideLimitedCreditPaymentOption'] = "none";
				$GLOBALS['HideCreditPaymentMethods'] = "none";
				$GLOBALS['RemainingCredit'] = $customer['custstorecredit'] - $grandTotal;
				if ($GLOBALS['RemainingCredit'] > 0) {
					$GLOBALS['HideRemainingStoreCredit'] = '';
					$GLOBALS['RemainingCredit'] = CurrencyConvertFormatPrice($GLOBALS['RemainingCredit']);
				}
			}
			// Customer doesn't have enough store credit to pay for the order
			else {
				$GLOBALS['Remaining'] = CurrencyConvertFormatPrice($grandTotal-$customer['custstorecredit']);

				if(count($checkoutProviders) == 1) {
					$GLOBALS['CheckoutStoreCreditWarning'] = sprintf(GetLang('CheckoutStoreCreditWarning2'), $GLOBALS['Remaining'], $GLOBALS['CheckoutWith']);
					$GLOBALS['HideLimitedCreditPaymentOption'] = "none";
				}
				else {
					$GLOBALS['CheckoutStoreCreditWarning'] = GetLang('CheckoutStoreCreditWarning');
				}
				$GLOBALS['ISC_LANG']['CreditPaymentMethod'] = sprintf(GetLang('CreditPaymentMethod'), $GLOBALS['Remaining']);
			}

			if (count($checkoutProviders) > 1) {
				$GLOBALS['CreditAlt'] = GetLang('CheckoutCreditAlt');
			}
			else if (count($checkoutProviders) <= 1 && isset($GLOBALS['CheckoutWith'])) {
				$GLOBALS['CreditAlt'] = sprintf(GetLang('CheckoutCreditAltOneMethod'), $GLOBALS['CheckoutWith']);
			}
			else {
				if ($customer['custstorecredit'] >= $grandTotal) {
					$GLOBALS['HideCreditAltOptionList'] = "none";
					$GLOBALS['HideConfirmOrderPage'] = "";
					$GLOBALS['HideTopPaymentButton'] = "none";
					$GLOBALS['HideCheckoutError'] = "none";
					$GLOBALS['CheckoutErrorMsg'] = '';
				}
			}
		}

		// Customer has hit this page before. Delete the existing pending order
		// The reason we do a delete is if they're hitting this page again, something
		// has changed with their order or something has become invalid with it along the way.
		if (isset($_COOKIE['SHOP_ORDER_TOKEN']) && IsValidPendingOrderToken($_COOKIE['SHOP_ORDER_TOKEN'])) {
			$query = "
				SELECT orderid
				FROM [|PREFIX|]orders
				WHERE ordtoken='".$GLOBALS['ISC_CLASS_DB']->Quote($_COOKIE['SHOP_ORDER_TOKEN'])."' AND ordstatus=0
			";
			$result = $GLOBALS['ISC_CLASS_DB']->Query($query);
			while($order = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
				$entity = new ISC_ENTITY_ORDER();
				/** @todo ISC-1141 check to see if this needs changing to ->purge() */
				/** @todo ISC-860 this is relying on another bugfix, I'm leaving this as ->delete() for now so that orders remain in the db somewhere at least -gwilym */
				if ($entity->delete($order['orderid'], true)) {
					$GLOBALS['ISC_CLASS_LOG']->LogSystemNotice('general', GetLang('OrderDeletedAutomatically', array('order' => $order['orderid'])));
				}
			}
		}

		// Are we showing an error message?
		if (isset($GLOBALS['CheckoutErrorMsg']) && $GLOBALS['CheckoutErrorMsg'] != '') {
			$GLOBALS['HideCheckoutError'] = '';
		}
		else {
			$GLOBALS['HideCheckoutError'] = "none";
		}

		// Is there a success message to show?
		if (isset($GLOBALS['CheckoutSuccessMsg']) && $GLOBALS['CheckoutSuccessMsg'] != '') {
			$GLOBALS['HideCheckoutSuccess'] = '';
		}
		else {
			$GLOBALS['HideCheckoutSuccess'] = "none";
		}

		if(GetConfig('EnableOrderComments') == 1) {
			$GLOBALS['HideOrderComments'] = "";
		} else {
			$GLOBALS['HideOrderComments'] = "none";
		}

		if(GetConfig('EnableOrderTermsAndConditions') == 1) {

			$GLOBALS['HideOrderTermsAndConditions'] = "";

			if(GetConfig('OrderTermsAndConditionsType') == "link") {
				$GLOBALS['AgreeTermsAndConditions'] = GetLang('YesIAgree');

				$GLOBALS['TermsAndConditionsLink'] = "<a href='".GetConfig('OrderTermsAndConditionsLink')."' target='_BLANK'>".strtolower(GetLang('TermsAndConditions'))."</a>.";

				$GLOBALS['HideTermsAndConditionsTextarea'] = "display:none;";

			} else {
				$GLOBALS['HideTermsAndConditionsTextarea']= '';
				$GLOBALS['OrderTermsAndConditions'] = GetConfig('OrderTermsAndConditions');
				$GLOBALS['AgreeTermsAndConditions'] = GetLang('AgreeTermsAndConditions');
				$GLOBALS['TermsAndConditionsLink'] = '';
			}
		} else {
			$GLOBALS['HideOrderTermsAndConditions'] = "display:none;";
		}

		// BCSIXBETA-372 - mail format preferences removed/disabled for now
		// %%SNIPPET_CheckoutMailFormatPreference%% references also need to be added back into the checkout panels/snippets to re-enable this if needed
//		$GLOBALS['MailFormatPreferenceOptions'] = $this->GenerateMailFormatPreferenceOptions();
//		$GLOBALS['SNIPPETS']['CheckoutMailFormatPreference'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet('CheckoutMailFormatPreference');
	}
Esempio n. 5
0
/**
 * Generate a single printable invoice.
 * @param int
 * @return strong The generated printable invoice (HTML)
 */
function generatePrintableInvoice($orderId)
{
	$db = $GLOBALS['ISC_CLASS_DB'];

	$template = TEMPLATE::GetInstance();
	$template->assign('StoreAddressFormatted', nl2br(getConfig('StoreAddress')));

	// allow access to deleted orders if printing from within control panel
	$isAdmin = (defined('ISC_ADMIN_CP') && ISC_ADMIN_CP);

	$query = "
		SELECT o.*, CONCAT(c.custconfirstname, ' ', c.custconlastname) AS ordcustname, c.custconemail AS ordcustemail, c.custconphone AS ordcustphone
		FROM [|PREFIX|]orders o
		LEFT JOIN [|PREFIX|]customers c ON o.ordcustid = c.customerid
		WHERE o.orderid = '".(int)$orderId."'
	";

	if (!$isAdmin) {
		$query .= " AND o.deleted = 0 ";
	}

	$result = $db->Query($query);
	$row = $db->Fetch($result);
	$order = $row;

	if(!$row) {
		return false;
	}

	$template->assign('OrderId', $row['orderid']);
	$template->assign('OrderDate', cDate($row['orddate']));

	if($row['ordcustmessage']) {
		$template->assign('Comments', nl2br(isc_html_escape($row['ordcustmessage'])));
		$template->assign('HideComments', '');
	}
	else {
		$template->assign('Comments', '');
		$template->assign('HideComments', 'display: none');
	}

	$template->assign('InvoiceTitle', sprintf(getLang('InvoiceTitle'), $orderId));

	$showShipping = true;
	$template->assign('totalRowColspan', 4);
	$template->assign('hideAddressColumn', 'display: none');

	if($row['shipping_address_count'] > 1) {
		$showShipping = false;
		$template->assign('totalRowColspan', 5);
		$template->assign('hideAddressColumn', '');
		$template->assign('hideInvoiceShippingDetails', 'display: none');
	}
	else if($row['ordisdigital']) {
		$template->assign('hideInvoiceShippingDetails', 'display: none');
		$showShipping = false;
	}

	$totalRows = getOrderTotalRows($row, $showShipping);
	$templateTotalRows = '';
	foreach($totalRows as $id => $totalRow) {
		$template->assign('label', $totalRow['label']);
		$template->assign('classNameAppend', ucfirst($id));
		$value = currencyConvertFormatPrice(
			$totalRow['value'],
			$row['ordcurrencyid'],
			$row['ordcurrencyexchangerate'],
			true
		);
		$template->assign('value', $value);
		$templateTotalRows .= $template->getSnippet('PrintableInvoiceTotalRow');
	}

	$template->assign('totals', $templateTotalRows);

	// Fetch shipping addresses in this order
	$addresses = array();
	$query = "
		SELECT *
		FROM [|PREFIX|]order_addresses
		WHERE order_id='".(int)$orderId."'
		ORDER BY `id`
	";
	$result = $db->query($query);
	while($address = $db->fetch($result)) {
		$addresses[$address['id']] = $address;
	}

	// Fetch shippng details
	$query = "
		SELECT *
		FROM [|PREFIX|]order_shipping
		WHERE order_id='".(int)$orderId."'
		ORDER BY order_address_id
	";
	$result = $db->query($query);
	while($shipping = $db->fetch($result)) {
		$addresses[$shipping['order_address_id']]['shipping'] = $shipping;
	}

	// Order has a single shipping address
	if($row['shipping_address_count'] == 1) {
		$address = current($addresses);
		$template->assign('ShippingAddress', getInvoiceShippingAddressBlock($address));
		$template->assign('ShippingEmail', isc_html_escape($address['email']));
		if(!$address['email']) {
			$template->assign('HideShippingEmail', 'display: none');
		}
		$template->assign('ShippingMethod', isc_html_escape($address['shipping']['method']));
	}

	// Format the customer details
	if($row['ordcustid'] == 0) {
		$template->assign('HideCustomerDetails', 'display: none');
	}
	$template->assign('CustomerId', $row['ordcustid']);
	$template->assign('CustomerName', isc_html_escape($row['ordcustname']));
	$template->assign('CustomerEmail', $row['ordcustemail']);
	$template->assign('CustomerPhone', $row['ordcustphone']);

	// Format the billing address
	$template->assign('ShipFullName', isc_html_escape($row['ordbillfirstname'].' '.$row['ordbilllastname']));

	if($row['ordbillcompany']) {
		$template->assign('ShipCompany', '<br />'.isc_html_escape($row['ordbillcompany']));
	}
	else {
		$template->assign('ShipCompany', '');
	}

	$addressLine = isc_html_escape($row['ordbillstreet1']);
	if ($row['ordbillstreet2'] != "") {
		$addressLine .=  '<br />' . isc_html_escape($row['ordbillstreet2']);
	}
	$template->assign('ShipAddressLines', $addressLine);

	$template->assign('ShipSuburb', isc_html_escape($row['ordbillsuburb']));
	$template->assign('ShipState', isc_html_escape($row['ordbillstate']));
	$template->assign('ShipZip', isc_html_escape($row['ordbillzip']));
	$template->assign('ShipCountry', isc_html_escape($row['ordbillcountry']));
	$template->assign('BillingAddress', $template->getSnippet('AddressLabel'));
	$template->assign('BillingPhone', isc_html_escape($row['ordbillphone']));
	if(!$row['ordbillphone']) {
		$template->assign('HideBillingPhone', 'display: none');
	}
	$template->assign('BillingEmail', isc_html_escape($row['ordbillemail']));
	if(!$row['ordbillemail']) {
		$template->assign('HideBillingEmail', 'display: none');
	}

	// Set the payment method
	$paymentMethod = $row['orderpaymentmethod'];
	if($row['orderpaymentmethod'] == '') {
		$paymentMethod = getLang('NA');
	}

	if($row['orderpaymentmethod'] != 'storecredit' && $row['orderpaymentmethod'] != 'giftcertificate') {
		$paymentMethod .= " (". formatPriceInCurrency($row['total_inc_tax'], $row['orddefaultcurrencyid']).")";
	}

	$template->assign('PaymentMethod', $paymentMethod);

	// Get the products in the order
	$fieldsArray = array();
	$query = "
		SELECT o.*
		FROM [|PREFIX|]order_configurable_fields o
		JOIN [|PREFIX|]product_configurable_fields p ON o.fieldid = p.productfieldid
		WHERE o.orderid=".(int)$orderId."
		ORDER BY p.fieldsortorder ASC
	";
	$result = $db->Query($query);
	$fields = array();
	while ($row = $db->Fetch($result)) {
		$fieldsArray[$row['ordprodid']][] = $row;
	}

	$query = "
		SELECT
			op.*,
			p.productid,
			p.prodpreorder,
			p.prodreleasedate,
			p.prodpreordermessage
		FROM
			[|PREFIX|]order_products op
			LEFT JOIN [|PREFIX|]products p ON p.productid = op.ordprodid
		WHERE
			op.orderorderid='".(int)$orderId."'
		ORDER BY op.order_address_id
	";
	$result = $db->query($query);

	$productsTable = '';
	$lastAddressId = -1;

	$shippingCostColumn = 'cost_ex_tax';
	$itemPriceColumn = 'price_ex_tax';
	$itemTotalColumn = 'total_ex_tax';

	if(getConfig('taxDefaultTaxDisplayOrders') == TAX_PRICES_DISPLAY_INCLUSIVE) {
		$shippingCostColumn = 'cost_inc_tax';
		$itemPriceColumn = 'price_inc_tax';
		$itemTotalColumn = 'total_inc_tax';
	}

	$addressProducts = array();
	while($product = $db->fetch($result)) {
		if(!isset($addressProducts[$product['order_address_id']])) {
			$addressProducts[$product['order_address_id']] = array();
		}

		$addressProducts[$product['order_address_id']][] = $product;
	}

	foreach($addressProducts as $addressId => $products) {
		$numProducts = count($products);
		if(!isset($addresses[$addressId])) {
			$template->assign('productShippingAddress', getLang('NA'));
		}
		else {
			$address = $addresses[$addressId];
			$template->assign('productShippingAddress', getInvoiceShippingAddressBlock($address));
		}
		$template->assign('addressColumnRowSpan', $numProducts);
		if($order['shipping_address_count'] > 1) {
			$template->assign('hideAddressColumn', '');
			$template->assign('invoiceItemClass', 'InvoiceItemDivider');
		}

		foreach($products as $product) {
			$template->assign('ProductName', isc_html_escape($product['ordprodname']));
			if($product['ordprodsku']) {
				$template->assign('ProductSku', isc_html_escape($product['ordprodsku']));
			}
			else {
				$template->assign('ProductSku', getLang('NA'));
			}
			$template->assign('ProductQuantity', $product['ordprodqty']);

			$pOptions = '';
			if($product['ordprodoptions'] != '') {
				$options = @unserialize($product['ordprodoptions']);
				if(!empty($options)) {
					foreach($options as $name => $value) {
						$template->assign('FieldName', isc_html_escape($name));
						$template->assign('FieldValue', isc_html_escape($value));
						$pOptions .= $template->GetSnippet('PrintableInvoiceItemConfigurableField');
					}
				}
			}

			if($pOptions) {
				$template->assign('ProductOptions', $pOptions);
				$template->assign('HideVariationOptions', '');
			}
			else {
				$template->assign('HideVariationOptions', 'display: none');
			}

			$productFields = '';
			if(!empty($fieldsArray[$product['orderprodid']])) {
				$fields = $fieldsArray[$product['orderprodid']];
				foreach($fields as $field) {
					if(empty($field['textcontents']) && empty($field['filename'])) {
						continue;
					}

					$fieldValue = '-';
					$template->assign('FieldName', isc_html_escape($field['fieldname']));

					if($field['fieldtype'] == 'file') {
						$fieldValue = '<a href="'.GetConfig('ShopPath').'/'.GetConfig('ImageDirectory').'/configured_products/'.urlencode($field['originalfilename']).'">'.isc_html_escape($field['originalfilename']).'</a>';
					}
					else {
						$fieldValue = isc_html_escape($field['textcontents']);
					}

					$template->assign('FieldValue', $fieldValue);
					$productFields .= $template->getSnippet('PrintableInvoiceItemConfigurableField');
				}
			}
			$template->assign('ProductConfigurableFields', $productFields);
			if(!$productFields) {
				$template->assign('HideConfigurableFields', 'display: none');
			}
			else {
				$template->assign('HideConfigurableFields', '');
			}

			$template->assign('ProductCost', currencyConvertFormatPrice(
				$product[$itemPriceColumn],
				$order['ordcurrencyid'],
				$order['ordcurrencyexchangerate'],
				true)
			);

			$template->assign('ProductTotalCost', currencyConvertFormatPrice(
				$product[$itemTotalColumn],
				$order['ordcurrencyid'],
				$order['ordcurrencyexchangerate'],
				true)
			);

			if($product['ordprodwrapname']) {
				$template->assign('FieldName', getLang('GiftWrapping'));
				$template->assign('FieldValue', isc_html_escape($product['ordprodwrapname']));
				$template->assign('ProductGiftWrapping', $template->getSnippet('PrintableInvoiceItemConfigurableField'));
				$template->assign('HideGiftWrapping', '');
			}
			else {
				$template->assign('ProductGiftWrapping', '');
				$template->assign('HideGiftWrapping', 'display: none');
			}

			if($product['ordprodeventdate']) {
				$template->assign('FieldName', isc_html_escape($product['ordprodeventname']));
				$template->assign('FieldValue', isc_date('dS M Y', $product['ordprodeventdate']));
				$template->assign('ProductEventDate', $template->getSnippet('PrintableInvoiceItemConfigurableField'));
				$template->assign('HideEventDate', '');
			}
			else {
				$template->assign('ProductEventDate', '');
				$template->assign('HideEventDate', 'display: none');
			}

			// determine preorder status
			$template->Assign('HidePreOrder', '');
			$template->Assign('ProductPreOrder', '');

			if ($product['productid'] && $product['prodpreorder']) {
				// product is pre-order because it exists in current db with preorder status
				if ($product['prodreleasedate']) {
					$message = $product['prodpreordermessage'];
					if (!$message) {
						$message = GetConfig('DefaultPreOrderMessage');
					}
					$message = str_replace('%%DATE%%', isc_date(GetConfig('DisplayDateFormat'), $product['prodreleasedate']), $message);
				} else {
					$message = GetLang('PreOrderProduct');
				}
				$template->Assign('ProductPreOrder', $message);
			} else {
				$template->Assign('HidePreOrder', 'display:none;');
			}

			$productsTable .= $template->GetSnippet('PrintableInvoiceItem');

			$template->assign('hideAddressColumn', 'display: none');
			$template->assign('productShippingAddress', '');
			$template->assign('addressColumnRowSpan', 1);
			$template->assign('invoiceItemClass', '');
		}
	}

	if($order['shipping_address_count'] > 1) {
		$template->assign('hideAddressColumn', '');
	}

	$template->assign('ProductsTable', $productsTable);

	return $template->GetSnippet('PrintableInvoice');
}
Esempio n. 6
0
	public function UpdateGiftCertificateInCart($itemid, $certificateData)
	{
		$name = currencyConvertFormatPrice($certificateData['amount']) . ' ' . GetLang('GiftCertificate');
		$quote = getCustomerQuote();
		if(!$quote->hasItem($itemid) ||
			$quote->getItemById($itemid)->getType() != PT_GIFTCERTIFICATE) {
				return false;
		}

		$item = $quote->getItemById($itemid);
		$item
			->setName($name)
			->setBasePrice($certificateData['amount'], true)
			->setQuantity(1)
			->setRecipientName($certificateData['to_name'])
			->setRecipientEmail($certificateData['to_email'])
			->setSenderName($certificateData['from_name'])
			->setSenderEmail($certificateData['from_email'])
			->setMessage($certificateData['message'])
			->setTheme($certificateData['theme']);
		return true;
	}
	public function setPanelSettings()
	{
		$output = "";
		$lastend = 0;

		$categoryId = $GLOBALS['ISC_CLASS_CATEGORY']->getId();
		$categoryName = $GLOBALS['ISC_CLASS_CATEGORY']->getName();
		$categorySql = $GLOBALS['ISC_CLASS_CATEGORY']->getCategoryAssociationSQL();

		// Prices entered without tax and shown without tax, so we don't need to join special tables
		if(getConfig('taxDefaultTaxDisplayCatalog') == TAX_PRICES_DISPLAY_EXCLUSIVE &&
			getConfig('taxEnteredWithPrices') == TAX_PRICES_ENTERED_EXCLUSIVE) {
				$query = "
					SELECT
						MIN(prodcalculatedprice) AS pmin,
						MAX(prodcalculatedprice) AS pmax
					FROM [|PREFIX|]products p
					WHERE p.prodvisible='1' AND p.prodhideprice=0 " . $categorySql . "
					ORDER BY p.productid DESC
				";
		}
		else {
			// Showing prices ex tax, so the tax zone ID = 0
			if(getConfig('taxDefaultTaxDisplayCatalog') == TAX_PRICES_DISPLAY_EXCLUSIVE) {
				$taxZone = 0;
			}
			// Showing prices inc tax, so we need to fetch the applicable tax zone
			else {
				$taxZone = getClass('ISC_TAX')->determineTaxZone();
			}

			$query = "
				SELECT
					MIN(tp.calculated_price) AS pmin,
					MAX(tp.calculated_price) AS pmax
				FROM [|PREFIX|]products p
				JOIN [|PREFIX|]product_tax_pricing tp ON (
					tp.price_reference=p.prodcalculatedprice AND
					tp.tax_zone_id=".$taxZone." AND
					tp.tax_class_id=p.tax_class_id
				)
				WHERE p.prodvisible='1' AND p.prodhideprice=0 " . $categorySql . "
				ORDER BY p.productid DESC
			";
		}

		$result = $GLOBALS['ISC_CLASS_DB']->query($query);
		$row = $GLOBALS['ISC_CLASS_DB']->fetch($result);
		if(!$row) {
			$this->DontDisplay = true;
			return;
		}

		$min = ceil($row['pmin']);
		$max = ceil($row['pmax']);

		// Is there enough of a variation to show a shop by price panel?
		if ($max - $min <= $min) {
			$this->DontDisplay = true;
			return;
		}

		$diff = (($max - $min) / 5);

		if($diff == 0) {
			$diff = 1;
		}

		for ($i = 0; $i < 5; $i++) {
			if ($lastend == 0) {
				$start = $min + ($diff * $i);
			} else {
				$start = $lastend;
			}

			$end = $start + $diff;

			if($end == $lastend) {
				break;
			}

			if ($lastend == 0) {
				$start = 0;
			}

			$lastend = $end;

			$start = round($start);
			$end = round($end);

			$GLOBALS['PriceLow'] = currencyConvertFormatPrice($start);
			$GLOBALS['PriceHigh'] = currencyConvertFormatPrice($end);
			$GLOBALS['PriceLink'] = isc_html_escape(catLink($categoryId, $categoryName, false, array(
				'price_min' => $start,
				'price_max' => $end,
				'sort' => $GLOBALS['ISC_CLASS_CATEGORY']->getSort()
			)));
			$output .= $GLOBALS['ISC_CLASS_TEMPLATE']->getSnippet("ShopByPriceItem");
		}
		$GLOBALS['SNIPPETS']['SideCategoryShopByPrice'] = $output;
	}
Esempio n. 8
0
		public function saveExpressCheckoutShippingProvider()
		{
			$quote = getCustomerQuote();
			if($quote->isDigital()) {
				exit;
			}

			// If the shipping provider couldn't be saved with the order show an error message
			// For each shipping address in the order, the shipping provider now needs to be saved
			$success = true;
			$shippingAddresses = getClass('ISC_CHECKOUT')->getQuote()->getShippingAddresses();
			foreach($shippingAddresses as $shippingAddress) {
				$shippingAddressId = $shippingAddress->getId();
				if(!isset($_POST['selectedShippingMethod'][$shippingAddressId])) {
					$success = false;
					break;
				}

				$id = $_POST['selectedShippingMethod'][$shippingAddressId];
				$cachedShippingMethod = $shippingAddress->getCachedShippingMethod($id);
				if(empty($cachedShippingMethod)) {
					$success = false;
					break;
				}

				$shippingAddress->setShippingMethod(
					$cachedShippingMethod['price'],
					$cachedShippingMethod['description'],
					$cachedShippingMethod['module']
				);
				$shippingAddress->setHandlingCost($cachedShippingMethod['handling']);
			}

			if(!$success) {
				$response = array(
					'success' => 0,
					'changeStep' => 'ShippingProvider',
					'errorMessage' => getLang('UnableSaveOrderShippingMethod'),
				);
				echo isc_json_encode($response);
				exit;
			}

			$completedSteps = array(
				array(
					'id' => 'ShippingProvider',
					'message' =>
						$shippingAddress->getShippingProvider() . ' ' .
						getLang('ExpressCheckoutFor') . ' ' .
						currencyConvertFormatPrice($shippingAddress->getShippingCost())
				)
			);
			$this->getExpressCheckoutConfirmation($completedSteps);
		}
	public function applyRule(ISC_QUOTE $quote)
	{
		if($quote->getBaseSubTotal() < $this->amount) {
			return false;
		}

		$runningTotal = $this->amount_off;
		$items = $quote->getItems();
		foreach ($items as $item) {
			$discountedBase = $item->getDiscountedBaseTotal();
			if($discountedBase - $runningTotal < 0) {
				$item->addDiscount($this->getDbId(), $discountedBase);
				$runningTotal -= $discountedBase;
			}
			else {
				$item->addDiscount($this->getDbId(), $runningTotal);
				$runningTotal -= $runningTotal;
			}

			if($runningTotal <= 0) {
				break;
			}
		}

		$quote->addDiscount($this->getDbId(), $this->amount_off);

		$amountOff = currencyConvertFormatPrice($this->amount_off);
		$amount = currencyConvertFormatPrice($this->amount);
		$this->banners[] = sprintf(getLang($this->getName().'DiscountMessage'), $amountOff, $amount);
		return true;
	}
	public function applyRule(ISC_QUOTE $quote)
	{
		$customerId = getClass('ISC_CUSTOMER')->getCustomerId();
		$query = "
			SELECT COUNT(*)
			FROM [|PREFIX|]orders
			WHERE ordcustid='".$customerId."' AND ordstatus > 0 AND deleted = 0
			LIMIT 1
		";
		$orderCount = $GLOBALS['ISC_CLASS_DB']->fetchOne($query);

		// Discount does not apply
		if($orderCount <= $this->orders) {
			return false;
		}

		$runningTotal = $this->amount;
		$appliedAmount = 0;
		$items = $quote->getItems();
		foreach ($items as $item) {
			$discountedBase = $item->getDiscountedBaseTotal();
			if($discountedBase - $runningTotal < 0) {
				$item->addDiscount($this->getDbId(), $discountedBase);
				$appliedAmount += $discountedBase;
				$runningTotal -= $discountedBase;
			}
			else {
				$item->addDiscount($this->getDbId(), $runningTotal);
				$appliedAmount += $runningTotal;
				$runningTotal -= $runningTotal;
			}

			if($runningTotal <= 0) {
				break;
			}
		}

		$quote->addDiscount($this->getDbId(), $appliedAmount);

		$amount = currencyConvertFormatPrice($appliedAmount);
		$this->banners[] = sprintf(getLang($this->getName().'DiscountMessage'), $amount);
		return true;
	}