Example #1
0
	/**
	* Calculates a price based on the chosen options for that price type and the product data
	*
	* @param array $options The price options
	* @param bool $convert Should the price be converted into the template's currency?
	* @return double The calculated price
	*/
	private function getPriceFromOptions($options, $convert = true)
	{
		switch ($options['selected_type']) {
			case 'CustomPrice':
				// no conversion necessary, assume it's already entered based on site currency
				return $options['price'];
			case 'ProductPrice':
				$productPrice = $this->getProductPrice();
			case 'PriceExtra':
				$productPrice = $this->getProductPrice();

				$modifierAmount = (double)$options['calculate_price'];
				if ($options['calculate_option'] == 'percent') {
					$modifierAmount = ($modifierAmount / 100) * $productPrice;
				}

				if ($options['calculate_operator'] == 'plus') {
					$productPrice += $modifierAmount;
				}
				else {
					$productPrice -= $modifierAmount;
				}
				break;
		}

		// convert our price from our currency to site's currency
		if ($convert) {
			return ConvertPriceToCurrency($productPrice, $this->getCurrency());
		}

		return $productPrice;
	}
Example #2
0
/**
 * Convert and format a price
 *
 * Function will convert and format a price. Function is a wrapper for FormatPrice and FormatCurrency
 *
 * @access public
 * @param float $price The price to convert and format
 * @param array $currency The currency record array. Default is the one stored within the currency session
 * @return string The converted and formatted price
 */
function CurrencyConvertFormatPrice($price, $currency=null, $exchangeRate=null, $includeCurrencyCode=false)
{
	$price = ConvertPriceToCurrency($price, $currency, $exchangeRate, null);
	return FormatPrice($price, false, true, false, $currency, $includeCurrencyCode);
}
	private function PurchaseGiftCertificate($errors = array())
	{

		// Coming back to this page with one or more errors?
		$GLOBALS['HideErrorMessage'] = 'none';
		if(is_array($errors)) {
			$errors = implode("<br />", $errors);
		}
		if($errors != "") {
			$GLOBALS['HideErrorMessage'] = '';
			$GLOBALS['ErrorMessage'] = $errors;
		}

		$editing = false;

		$GLOBALS['CartItemId'] = -1;

		$quote = getCustomerQuote();

		if(!$errors) {
			// Editing an existing cart item
			if(isset($_REQUEST['itemid'])) {
				$itemid = $_REQUEST['itemid'];
				if($quote->hasItem($itemid) &&
					$quote->getItemById($itemid)->getType() == PT_GIFTCERTIFICATE) {
						$item = $quote->getItemById($itemid);
						$_POST = array(
							'selected_amount' => $item->getPrice(),
							'certificate_amount' => convertPriceToCurrency($item->getPrice()),
							'to_name' => $item->getRecipientName(),
							'to_email' => $item->getRecipientEmail(),
							'from_name' => $item->getSenderName(),
							'from_email' => $item->getSenderEmail(),
							'message' => $item->getMessage(),
							'certificate_theme' => $item->getTheme()
						);
						$editing = true;
						$GLOBALS['CartItemId'] = $item->getId();
				}
			}
		}
		else {
			if(isset($_REQUEST['cartitemid'])) {
				$editing = true;
				$GLOBALS['CartItemId'] = isc_html_escape($_REQUEST['cartitemid']);
			}
		}

		if($editing == true) {
			$GLOBALS['SaveGiftCertificateButton'] = GetLang('UpdateCertificateCart');
			$GLOBALS['CertificateTitle'] = GetLang('UpdateGiftCertificate');
		}
		else {
			$GLOBALS['SaveGiftCertificateButton'] = GetLang('AddCertificateCart');
			$GLOBALS['CertificateTitle'] = GetLang('PurchaseAGiftCertificate');
		}

		if($editing == true || $errors) {
			$GLOBALS['AgreeChecked'] = "checked=\"checked\"";
		}

		// Can the user select from one or more predefined amounts?
		$GLOBALS['GiftCertificateAmountSelect'] = '';
		if(GetConfig('GiftCertificateCustomAmounts') == 0) {
			foreach(GetConfig('GiftCertificateAmounts') as $amount) {
				$displayAmount = CurrencyConvertFormatPrice($amount);
				$sel = '';
				if(isset($_POST['selected_amount']) && $_POST['selected_amount'] == $amount) {
					$sel = 'selected=\"selected\"';
				}
				$GLOBALS['GiftCertificateAmountSelect'] .= sprintf("<option value='%s' %s>%s</option>", $amount, $sel, $displayAmount);
			}
			$GLOBALS['HideGiftCertificateCustomAmount'] = "none";
		}

		// Can the user enter their own amount?
		else {
			if(isset($_POST['certificate_amount'])) {
				$GLOBALS['CustomCertificateAmount'] = isc_html_escape($_POST['certificate_amount']);
				$GLOBALS['CustomAmountChecked'] = 'checked="checked"';
			}

			$GLOBALS['HideGiftCertificateAmountSelect'] = "none";

			// Is there a minimum and maximum limit? Firstly convert them to our selected currency
			$GLOBALS['GiftCertificateMinimum'] = ConvertPriceToCurrency(GetConfig('GiftCertificateMinimum'));
			$GLOBALS['GiftCertificateMaximum'] = ConvertPriceToCurrency(GetConfig('GiftCertificateMaximum'));

			if(GetConfig('GiftCertificateMinimum') > 0 && GetConfig('GiftCertificateMaximum') > 0) {
				$GLOBALS['GiftCertificateRange'] = sprintf(GetLang('GiftCertificateValueBetween'), CurrencyConvertFormatPrice(GetConfig('GiftCertificateMinimum')), CurrencyConvertFormatPrice(GetConfig('GiftCertificateMaximum')));
			}
			else if(GetConfig('GiftCertificateMinimum')) {
				$GLOBALS['GiftCertificateRange'] = sprintf(GetLang('GiftCertificateValueGreaterThan'), CurrencyConvertFormatPrice(GetConfig('GiftCertificateMinimum')));
			}
			else if(GetConfig('GiftCertificateMaximum')) {
				$GLOBALS['GiftCertificateRange'] = sprintf(GetLang('GetCertificateValueLessThan'), CurrencyConvertFormatPrice(GetConfig('GiftCertificateMaximum')));
			}
		}

		// If there is an expiry date for gift certificates, we need to show it just so the user is aware
		if(GetConfig('GiftCertificateExpiry') > 0) {
			$days = GetConfig('GiftCertificateExpiry')/86400;
			if(($days % 365) == 0) {
				if(($days/365) == 1) {
					$GLOBALS['ExpiresAfter'] = "1 ".GetLang('YearLower');
				} else {
					$GLOBALS['ExpiresAfter'] = number_format($days/365)." ".GetLang('YearsLower');
				}
			}
			else if(($days % 30) == 0) {
				if($days/30 == 1) {
					$GLOBALS['ExpiresAfter'] = "1 ".GetLang('MonthLower');
				} else {
					$GLOBALS['ExpiresAfter'] = number_format($days/30)." ".GetLang('MonthsLower');
				}
			}
			else if(($days % 7) == 0) {
				if(($days/7) == 1) {
					$GLOBALS['ExpiresAfter'] = "1 ".GetLang('WeeksLower');
				} else {
					$GLOBALS['ExpiresAfter'] = number_format($days/7)." ".GetLang('WeeksLower');
				}
			}
			else {
				if($days == 1) {
					$GLOBALS['ExpiresAfter'] = "1 ".GetLang('DayLower');
				} else {
					$GLOBALS['ExpiresAfter'] = number_format($days)." ".GetLang('DaysLower');
				}
			}
		}

		if(isset($GLOBALS['ExpiresAfter'])) {
			$GLOBALS['GiftCertificateTerms'] = sprintf(GetLang('GiftCertificateTermsExpires'), $GLOBALS['ExpiresAfter']);
		}
		else {
			$GLOBALS['HideExpiryInfo'] = "none";
		}

		// Get a list of the gift certificate themes
		$themes = @scandir(APP_ROOT."/templates/__master/__gift_themes/");
		$enabledThemes = explode(",", GetConfig('GiftCertificateThemes'));

		$GLOBALS['GiftCertificateThemes'] = '';
		if(count($enabledThemes) == 1) {
			$GLOBALS['HideThemeSelect'] = "none";
		}
		foreach($enabledThemes as $theme) {
			// Just double check this theme still actually exists
			if(in_array($theme, $themes)) {
				$themeName = preg_replace('#\.html$#i', "", $theme);
				$sel = '';
				if((isset($_POST['certificate_theme']) && $_POST['certificate_theme'] == $theme) || count($enabledThemes) == 1) {
					$sel = 'checked="checked"';
					$GLOBALS['SelectedCertificateTheme'] = $theme;
				}
				$GLOBALS['GiftCertificateThemes'] .= sprintf('<label><input type="radio" class="themeCheck" name="certificate_theme" value="%s" %s /> %s</label><br />', $theme, $sel, $themeName);
			}
		}

		if(!GetConfig('GiftCertificateThemes')) {
			$GLOBALS['HideErrorMessage'] = '';
			$GLOBALS['ErrorMessage'] = GetLang('NoGiftCertificateThemes');
			$GLOBALS['HideGiftCertificateForm'] = "none";
		}

		// Do we need to pre-fill the to details with anything?
		if(isset($_POST['to_name'])) {
			$GLOBALS['CertificateTo'] = isc_html_escape($_POST['to_name']);
		}
		else {
			$GLOBALS['CertificateTo'] = '';
		}
		if(isset($_POST['to_email'])) {
			$GLOBALS['CertificateToEmail'] = isc_html_escape($_POST['to_email']);
		}
		else {
			$GLOBALS['CertifcateToEmail'] = '';
		}

		$customer = null;
		$GLOBALS['ISC_CLASS_CUSTOMER'] = GetClass('ISC_CUSTOMER');

		// From details
		if(isset($_POST['from_name'])) {
			$GLOBALS['CertificateFrom'] = isc_html_escape($_POST['from_name']);
		}
		else {
			$customer = $GLOBALS['ISC_CLASS_CUSTOMER']->GetCustomerInfo();
			if(is_array($customer)) {
				$GLOBALS['CertificateFrom'] = isc_html_escape($customer['custconfirstname'] . ' ' . $customer['custconlastname']);
			}
		}
		if(isset($_POST['from_email'])) {
			$GLOBALS['CertificateFromEmail'] = isc_html_escape($_POST['from_email']);
		}
		else {
			if($customer === null) {
				$customer = $GLOBALS['ISC_CLASS_CUSTOMER']->GetCustomerInfo();
			}
			if(is_array($customer)) {
				$GLOBALS['CertificateFromEmail'] = isc_html_escape($customer['custconemail']);
			}
		}

		if(isset($_POST['message'])) {
			$GLOBALS['CertificateMessage'] = isc_html_escape($_POST['message']);
		}

		$GLOBALS['GiftCertificatePreviewModalTitle'] = GetLang('GiftCertificatePreviewModalTitle');

		// Show the gift certificates main page
		$GLOBALS['ISC_CLASS_TEMPLATE']->SetPageTitle(sprintf("%s - %s", GetConfig('StoreName'), GetLang('GiftCertificates')));
		$GLOBALS['ISC_CLASS_TEMPLATE']->SetTemplate("giftcertificates");
		$GLOBALS['ISC_CLASS_TEMPLATE']->ParseTemplate();
	}
 private function EditCompanyGiftCertificate()
 {
     // Show the form to edit a news
     $cgcId = (int) $_GET['cgcid'];
     $GLOBALS['AmountReadOnly'] = 'readonly';
     $arrData = array();
     $sel_cats = array();
     if (GetConfig('CurrencyLocation') == 'right') {
         $GLOBALS['CurrencyTokenLeft'] = '';
         $GLOBALS['CurrencyTokenRight'] = GetConfig('CurrencyToken');
     } else {
         $GLOBALS['CurrencyTokenLeft'] = GetConfig('CurrencyToken');
         $GLOBALS['CurrencyTokenRight'] = '';
     }
     $GLOBALS['CurrencyToken'] = GetConfig('CurrencyToken');
     $this->_GetCGCData($cgcId, $arrData);
     if (count($arrData) > 0) {
         if ($arrData['cgcstatus'] == 2 || $arrData['cgcsended']) {
             $this->ManageGiftCertificates(GetLang('CompanyGiftCertificateCanNotEdit'), MSG_ERROR);
             return;
         }
         $GLOBALS['Title'] = GetLang('EditCompanyGiftCertificate');
         $GLOBALS['Intro'] = GetLang('EditCompanyGiftCertificateIntro');
         $GLOBALS['FormAction'] = "editCompanyGiftCertificate2";
         $GLOBALS['cgcCode'] = isc_html_escape($arrData['cgccode']);
         $GLOBALS['cgcName'] = isc_html_escape($arrData['cgcname']);
         //applies to
         if ($arrData['cgcappliesto'] == "categories") {
             // Show the categories list
             $GLOBALS['UsedForCat'] = 'checked="checked"';
             $GLOBALS['ToggleUsedFor'] = "ToggleUsedFor(0);";
             $sel_cats = explode(",", $arrData['cgcappliestovalues']);
             if ($arrData['cgcappliestovalues'] == "0") {
                 $GLOBALS['AllCategoriesSelected'] = "selected=\"selected\"";
             }
         } else {
             // Show the products textbox
             $GLOBALS['ToggleUsedFor'] = "ToggleUsedFor(1);";
             $GLOBALS['UsedForProd'] = 'checked="checked"';
             // Select a list of the products that this coupon is active for
             if ($arrData['cgcappliestovalues'] != "") {
                 $GLOBALS['SelectedProducts'] = '';
                 $GLOBALS['ProductIds'] = '';
                 $query = sprintf("SELECT productid, prodname FROM [|PREFIX|]products WHERE productid IN (%s) ORDER BY prodname ASC", $arrData['cgcappliestovalues']);
                 $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
                 while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
                     $GLOBALS['SelectedProducts'] .= sprintf("<option value='%d'>%s</option>", $row['productid'], $row['prodname']);
                     $GLOBALS['ProductIds'] .= $row['productid'] . ",";
                 }
                 $GLOBALS['ProductIds'] = isc_substr($GLOBALS['ProductIds'], 0, -1);
             }
         }
         $GLOBALS['ISC_CLASS_ADMIN_CATEGORY'] = GetClass('ISC_ADMIN_CATEGORY');
         $GLOBALS['CategoryList'] = $GLOBALS["ISC_CLASS_ADMIN_CATEGORY"]->GetCategoryOptions($sel_cats, "<option %s value='%d'>%s</option>", "selected=\"selected\"", "- ", false);
         if ($arrData['cgcminpurchase'] == 0) {
             $GLOBALS['MinPurchase'] = 0;
         } else {
             $GLOBALS['MinPurchase'] = CPrice($arrData['cgcminpurchase']);
         }
         if ($arrData['cgcexpirydate'] > 0) {
             $GLOBALS['ExpiryDate'] = isc_date("m/d/Y", $arrData['cgcexpirydate'], 0);
         }
         if ($arrData['cgcenabled'] == 1) {
             $GLOBALS['Enabled'] = 'checked="checked"';
         }
         if (isset($arrData['cgcamount'])) {
             $GLOBALS['Amount'] = CPrice($arrData['cgcamount']);
         }
         if (isset($arrData['cgcbalance'])) {
             $GLOBALS['Balance'] = CPrice($arrData['cgcbalance']);
         }
         if ($arrData['cgcto']) {
             $GLOBALS['to_name'] = $arrData['cgcto'];
         }
         if ($arrData['cgctoemail']) {
             $GLOBALS['to_email'] = $arrData['cgctoemail'];
         }
         $to_name = explode('$', $arrData['cgcto']);
         $to_email = explode('$', $arrData['cgctoemail']);
         $GLOBALS['recipientcount'] = count($to_name);
         if ($GLOBALS['recipientcount'] <= 0) {
             $GLOBALS['recipientcount'] = 1;
         }
         $GLOBALS['to_name_1'] = $to_name[0];
         $GLOBALS['to_email_1'] = $to_email[0];
         if (count($to_name) > 1) {
             for ($i = 1; $i < count($to_name); $i++) {
                 $GLOBALS['recipient_other'] .= "<p id=\"recipient_" . ($i + 1) . "\">Name:<input type=\"text\" class=\"Textbox Field200\" value=\"" . $to_name[$i] . "\" id=\"to_name_" . ($i + 1) . "\" name=\"to_name_" . ($i + 1) . "\" onkeyup=\"getCustomerNameandEmail('to_name_result_" . ($i + 1) . "', " . ($i + 1) . ", this.value)\" >&nbsp;&nbsp;Email:<input type=\"text\" class=\"Textbox Field200\" value=\"" . $to_email[$i] . "\" id=\"to_email_" . ($i + 1) . "\" name=\"to_email_" . ($i + 1) . "\">" . '<a href="#" onclick="deleteRecipient(' . ($i + 1) . ');return false;">delete</a>' . "<div id=\"to_name_result_" . ($i + 1) . "\" name=\"to_name_result_1" . ($i + 1) . "\" class=\"ProductSearchResults  returnname\" ></div></p>";
             }
         }
         $GLOBALS['CompanyGiftCertificateMessage'] = $arrData['cgcmessage'];
         //theme
         // Get a list of the gift certificate themes
         $themes = @scandir(dirname(__FILE__) . "/../../../templates/__gift_themes/");
         //$enabledThemes = explode(",", GetConfig('GiftCertificateThemes'));
         $enabledThemes = $this->getEnabledThemes();
         $GLOBALS['GiftCertificateThemes'] = '';
         if (count($enabledThemes) == 1) {
             $GLOBALS['HideThemeSelect'] = "none";
         }
         foreach ($enabledThemes as $theme) {
             // Just double check this theme still actually exists
             if (in_array($theme, $themes)) {
                 $themeName = preg_replace('#\\.html$#i', "", $theme);
                 $sel = '';
                 if (isset($arrData['cgctemplate']) && $arrData['cgctemplate'] == $theme || count($enabledThemes) == 1) {
                     $sel = 'checked="checked"';
                     $GLOBALS['SelectedCertificateTheme'] = $theme;
                 }
                 $GLOBALS['GiftCertificateThemes'] .= sprintf('<label><input type="radio" class="themeCheck" name="certificate_theme" value="%s" %s /> %s</label><br />', $theme, $sel, $themeName);
             }
         }
         if (!GetConfig('GiftCertificateThemes')) {
             $GLOBALS['HideErrorMessage'] = '';
             $GLOBALS['ErrorMessage'] = GetLang('NoGiftCertificateThemes');
             $GLOBALS['HideGiftCertificateForm'] = "none";
         }
         $GLOBALS['cgcId'] = (int) $arrData['cgcid'];
         // Add NI_20100901_Jack
         $GLOBALS['GiftCertificateMinimum'] = ConvertPriceToCurrency(GetConfig('CompanyGiftCertificateMinimum'));
         $GLOBALS['GiftCertificateMaximum'] = ConvertPriceToCurrency(GetConfig('CompanyGiftCertificateMaximum'));
         $GLOBALS["ISC_CLASS_TEMPLATE"]->SetTemplate("company.giftcertificates.form");
         $GLOBALS["ISC_CLASS_TEMPLATE"]->ParseTemplate();
     } else {
         // The coupon doesn't exist
         if ($GLOBALS["ISC_CLASS_ADMIN_AUTH"]->HasPermission(AUTH_Manage_Company_GiftCertificates)) {
             $this->ManageGiftCertificates(GetLang('CompanyGiftCertificateDoesntExist'), MSG_ERROR);
         } else {
             $GLOBALS['ISC_CLASS_ADMIN_ENGINE']->DoHomePage(GetLang('Unauthorized'), MSG_ERROR);
         }
     }
 }
	/**
	* Adds an Item element for the specified product and template into the supplied XML element
	*
	* @param SimpleXMLElement $xml The XML element to add the item to
	* @param array $product The array of product data
	* @param ISC_ADMIN_EBAY_TEMPLATE $template The template to use to add the product
	*/
	private static function addItemData(&$xml, $product, $template)
	{
		$template->setProductData($product);

		$productId = $product['productid'];

		$item = $xml->addChild('Item');

		$item->addChild('Site', $template->getSiteCode());

		// required details
		$item->addChild('Country', $template->getItemLocationCountry());
		$item->addChild('Currency', $template->getCurrencyCode());
		$item->addChild('ListingDuration', $template->getListingDuration());
		$item->addChild('ListingType', $template->getSellingMethod());

		$item->addChild('Location', $template->getItemLocationCityState());
		$item->addChild('PostalCode', $template->getItemLocationZip());

		$item->addChild('Title', isc_html_escape($product['prodname']));
		$item->addChild('Description', isc_html_escape($product['proddesc']));
		$item->addChild('SKU', isc_html_escape($product['prodcode']));

		$primaryOptions = $template->getPrimaryCategoryOptions();

		// are item specifics supported by the primary category?
		if (!empty($primaryOptions['item_specifics_supported'])) {
			$itemSpecifics = null;

			// brand name
			if (!empty($product['brandname'])) {
				$itemSpecifics = $item->addChild('ItemSpecifics');

				$specific = $itemSpecifics->addChild('NameValueList');
				$specific->addChild('Name', GetLang('Brand'));
				$specific->addChild('Value', $product['brandname']);
			}

			// do we have custom fields for the product?
			if (!empty($product['custom_fields'])) {
				if ($itemSpecifics == null) {
					$itemSpecifics = $item->addChild('ItemSpecifics');
				}

				foreach ($product['custom_fields'] as $customField) {
					$specific = $itemSpecifics->addChild('NameValueList');
					$specific->addChild('Name', $customField['fieldname']);
					$specific->addChild('Value', $customField['fieldvalue']);
				}
			}
		}

		// does this product have a upc? it can be used to pull in product information
		if (!empty($primaryOptions['catalog_enabled']) && !empty($product['upc'])) {
			$productListingDetails = $item->addChild('ProductListingDetails');
			$productListingDetails->addChild('UPC', $product['upc']);
		}

		// does the product have a variation?
		if ($product['prodvariationid']) {
			$variationId = $product['prodvariationid'];

			$variations = $item->addChild('Variations');
			$variationSpecificsSet = $variations->addChild('VariationSpecificsSet');

			$lastOptionName = '';
			$variationOptions = array();

			// add the variation options
			$res = Store_Variations::getOptions($variationId);
			while ($optionRow = $GLOBALS['ISC_CLASS_DB']->Fetch($res)) {
				if ($optionRow['voname'] != $lastOptionName) {
					$lastOptionName = $optionRow['voname'];

					$nameValueList = $variationSpecificsSet->addChild('NameValueList');
					$nameValueList->addChild('Name', $lastOptionName);
				}

				$nameValueList->addChild('Value', $optionRow['vovalue']);

				$variationOptions[$optionRow['voptionid']] = array($optionRow['voname'], $optionRow['vovalue']);
			}

			// add the combinations
			$res = Store_Variations::getCombinations($productId, $variationId);
			while ($comboRow = $GLOBALS['ISC_CLASS_DB']->Fetch($res)) {
				$variation = $variations->addChild('Variation');

				if ($comboRow['vcsku']) {
					$variation->addChild('SKU', $comboRow['vcsku']);
				}

				$variation->addChild('Quantity', $template->getQuantityToSell());

				$startPrice = $template->getStartPrice(false);
				$comboStartPrice = CalcProductVariationPrice($startPrice, $comboRow['vcpricediff'], $comboRow['vcprice']);
				$comboStartPrice = ConvertPriceToCurrency($comboStartPrice, $template->getCurrency());

				$variation->addChild('StartPrice', $comboStartPrice);

				// add the options for this combination
				$variationSpecifics = $variation->addChild('VariationSpecifics');

				$options = explode(',', $comboRow['vcoptionids']);
				foreach ($options as $optionId) {
					list($optionName, $optionValue) = $variationOptions[$optionId];

					$nameValueList = $variationSpecifics->addChild('NameValueList');
					$nameValueList->addChild('Name', $optionName);
					$nameValueList->addChild('Value', $optionValue);
				}
			}

			// add images
			$optionPictures = Store_Variations::getCombinationImagesForFirstOption($productId, $variationId);
			if (!empty($optionPictures)) {
				$pictures = $variations->addChild('Pictures');

				// we'll be adding images for the first option set
				list($optionName) = current($variationOptions);

				$pictures->addChild('VariationSpecificName', $optionName);

				foreach ($optionPictures as $optionName => $imageUrl) {
					$variationSpecificPictureSet = $pictures->addChild('VariationSpecificPictureSet');
					$variationSpecificPictureSet->addChild('VariationSpecificValue', $optionName);
					$variationSpecificPictureSet->addChild('PictureURL', $imageUrl);
				}
			}
		}

		// add quantity
		if (!$product['prodvariationid']) {
			$item->addChild('Quantity', $template->getTrueQuantityToSell());
		}

		$item->addChild('PrivateListing', (int)$template->isPrivateListing());

		// schedule date
		if ($template->getScheduleDate()) {
			$item->addChild('ScheduleTime', $template->getScheduleDate());
		}

		// condition
		if ($template->getItemCondition()) {
			$item->addChild('ConditionID', $template->getItemCondition());
		}

		// payment details
		foreach ($template->getPaymentMethods() as $paymentMethod) {
			$item->addChild('PaymentMethods', $paymentMethod);
		}

		if (in_array('PayPal', $template->getPaymentMethods())) {
			$item->addChild('PayPalEmailAddress', $template->getPayPalEmailAddress());
		}

		// add categories
		$item->addChild('PrimaryCategory')->addChild('CategoryID', $template->getPrimaryCategoryId());
		if ($template->getSecondaryCategoryId()) {
			$item->addChild('SecondaryCategory')->addChild('CategoryID', $template->getSecondaryCategoryId());
		}

		$item->addChild('CategoryMappingAllowed', (int)$template->getAllowCategoryMapping());

		// add store categories
		if ($template->getPrimaryStoreCategoryId()) {
			$storeFront = $item->addChild('Storefront');
			$storeFront->addChild('StoreCategoryID', $template->getPrimaryStoreCategoryId());

			if ($template->getSecondaryStoreCategoryId()) {
				$storeFront->addChild('StoreCategory2ID', $template->getSecondaryStoreCategoryId());
			}
		}

		// prices
		if ($template->getSellingMethod() == ISC_ADMIN_EBAY::CHINESE_AUCTION_LISTING) {
			$item->addChild('StartPrice', $template->getStartPrice());

			if ($template->getReservePrice() !== false) {
				$item->addChild('ReservePrice', $template->getReservePrice());
			}

			if ($template->getBuyItNowPrice() !== false) {
				$item->addChild('BuyItNowPrice', $template->getBuyItNowPrice());
			}
		}
		elseif (!$product['prodvariationid']) {
			$item->addChild('StartPrice', $template->getStartPrice());
		}

		// add return policy info
		$policy = $item->addChild('ReturnPolicy');
		$policy->addChild('ReturnsAcceptedOption', $template->getReturnsAcceptedOption());
		if ($template->getReturnsAccepted()) {
			if ($template->getAdditionalPolicyInfo()) {
				$policy->addChild('Description', isc_html_escape($template->getAdditionalPolicyInfo()));
			}
			if ($template->getReturnOfferedAs()) {
				$policy->addChild('RefundOption', $template->getReturnOfferedAs());
			}
			if ($template->getReturnsPeriod()) {
				$policy->addChild('ReturnsWithinOption', $template->getReturnsPeriod());
			}
			if ($template->getReturnCostPaidBy()) {
				$policy->addChild('ShippingCostPaidByOption', $template->getReturnCostPaidBy());
			}
		}

		// counter
		$item->addChild('HitCounter', $template->getCounterStyle());

		// gallery option
		$pictureDetails = $item->addChild('PictureDetails');
		$pictureDetails->addChild('GalleryType', $template->getGalleryType());
		if ($template->getGalleryType() == 'Featured') {
			$pictureDetails->addChild('GalleryDuration', $template->getFeaturedGalleryDuration());
		}

		if ($template->getItemPhoto()) {
			if ($template->getGalleryType() != 'None') {
				$pictureDetails->addChild('GalleryURL', $template->getItemPhoto());
			}

			$pictureDetails->addChild('PictureURL', $template->getItemPhoto());
		}

		// listing features
		foreach ($template->getListingFeatures() as $feature) {
			$item->addChild('ListingEnhancement', $feature);
		}

		// domestic shipping
		if ($template->getUseDomesticShipping()) {
			// add shipping details
			$shippingDetails = $item->addChild('ShippingDetails');
			// the actual shipping type - Flat or Calculated - where's our freight option gone?
			$shippingDetails->addChild('ShippingType', $template->getShippingType());

			//$insuranceDetails = $shippingDetails->addChild('InsuranceDetails');
			$shippingDetails->addChild('InsuranceOption', 'NotOffered');

			$calculatedRate = null;

			// add checkout instructions
			if ($template->getCheckoutInstructions()) {
				$shippingDetails->addChild('PaymentInstructions', $template->getCheckoutInstructions());
			}

			// add sales tax - US only
			if ($template->getUseSalesTax()) {
				$salesTax = $shippingDetails->addChild('SalesTax');
				$salesTax->addChild('SalesTaxState', $template->getSalesTaxState());
				$salesTax->addChild('SalesTaxPercent', $template->getSalesTaxPercent());
				$salesTax->addChild('ShippingIncludedInTax', $template->getShippingIncludedInTax());
			}


			$domesticServices = $template->getDomesticShippingServices();
			$domesticSettings = $template->getDomesticShippingSettings();

			if (empty($domesticSettings)) {
				throw new Exception('Missing domestic shipping settings');
			}

			// add a pickup service - can't get this to work gives error:  ShippingService is required if Insurance, SalesTax, or AutoPay is specified. (10019)
			if ($domesticSettings['offer_pickup']) {
				$domesticServices['Pickup'] = array(
					'additional_cost'	=> 0,
					'cost'				=> 0 //(double)$domesticServices['pickup_cost'] // where has this option gone?
				);
			}


			if (empty($domesticServices)) {
				throw new Exception('Missing domestic shipping services');
			}

			$domesticFeeShipping = (bool)$domesticSettings['is_free_shipping'];

			// add our domestic services
			self::addShippingServices($shippingDetails, $domesticSettings, $domesticServices, 'ShippingServiceOptions', $domesticFeeShipping);

			// buy it fast enabled?  domestic only
			if ($domesticSettings['get_it_fast']) {
				$item->addChild('GetItFast', true);
				$item->addChild('DispatchTimeMax', 1); // required for getitfast
			}
			else {
				// add handling time
				$item->addChild('DispatchTimeMax', $template->getHandlingTime());
			}

			if ($domesticSettings['cost_type'] == 'Calculated') {
				if ($calculatedRate == null) {
					$calculatedRate = self::addCalculatedDetails($shippingDetails, $template);
				}

				// handling cost
				if ($domesticSettings['handling_cost']) {
					$calculatedRate->addChild('PackagingHandlingCosts', $domesticSettings['handling_cost']);
				}
			}

			// international shipping - we can't supply international services if we don't specify domestic
			if ($template->getUseInternationalShipping()) {
				$internationalSettings = $template->getInternationalShippingSettings();
				$internationalServices = $template->getInternationalShippingServices();

				if (empty($internationalSettings)) {
					throw new Exception('Missing international shipping settings');
				}

				if (empty($internationalServices)) {
					throw new Exception('Missing international shipping services');
				}

				// add our international services
				self::addShippingServices($shippingDetails, $internationalSettings, $internationalServices, 'InternationalShippingServiceOption', false, true);


				if ($internationalSettings['cost_type'] == 'Calculated') {
					if ($calculatedRate == null) {
						$calculatedRate = self::addCalculatedDetails($shippingDetails, $template);
					}

					// handling cost
					if ($internationalSettings['handling_cost']) {
						$calculatedRate->addChild('InternationalPackagingHandlingCosts', $internationalSettings['handling_cost']);
					}
				}
			}
		}
		else {
			// domestic pickup only
			$item->addChild('ShipToLocations', 'None');
		}
	}