/**
		 * Build the representation of the shopping cart using the google checkout objects
		 *
		 * @return void
		 **/
		private function BuildCart()
		{
			if ($this->cart === null) {
				include_once(dirname(__FILE__).'/library/googlecart.php');
				include_once(dirname(__FILE__).'/library/googleitem.php');

				$id = trim($this->GetValue('merchantid'));
				$key =trim($this->GetValue('merchanttoken'));

				$currency = $this->GetDefaultCurrencyCode();

				$this->cart = new GoogleCart($id, $key, $this->_server_type, $currency);
				$this->cart->SetMerchantPrivateData($_COOKIE['SHOP_SESSION_TOKEN']);
				$this->cart->SetEditCartUrl(GetConfig('ShopPath').'/cart.php');
				$this->cart->SetContinueShoppingUrl(GetConfig('ShopPath'));
				$this->cart->SetRequestBuyerPhone('true');

				// Add tax rules
				$this->AddTaxInformationToCart();

				// Add the analytics tracking to the cart
				$this->AddAnalyticsToCart();

				// Merchant calculations are only available for US based stores
				if ($this->GetDefaultCurrencyCode() == 'USD') {
					$this->cart->SetMerchantCalculations($this->xmlUrl, "true", "true", "true");
				} else {
					$this->cart->SetMerchantCalculations($this->xmlUrl, "false", "false", "false");
				}

				$coupon_discount = 0;
				$items_total = 0;

				$quote = getCustomerQuote();
				$items = $quote->getItems();

				foreach($items as $item) {
					$description = '';

					if(!$this->canSellItem($item))
					{
						$this->buttonVariant = false;
						return;
					}

					if($item->getVariationId() > 0) {
						$options = $item->getVariationOptions();
						foreach($options as $name => $value) {
							$description .= $name.': '.$value.', ';
						}
						$description = rtrim($description, ', ');
					}

					$googleItem = new GoogleItem(
						$item->getName(),
						$description,
						$item->getQuantity(),
						$item->getPrice(false),
						$item->getWeight()
					);

					if($item->getTaxClassId()) {
						$googleItem->setTaxTableSelector($item->getTaxClassId());
					}

					// If this item is a digital item or gift certificate then mark it as email delivery
					if($item->getType() == PT_DIGITAL || $item->getType() == PT_GIFTCERTIFICATE) {
						$googleItem->setEmailDigitalDelivery(true);
					}

					$this->cart->AddItem($googleItem);

					// does this item have gift wrapping? Add it as a line item
					$giftWrapping = $item->getGiftWrapping();
					if($giftWrapping) {
						$googleItem = new GoogleItem(
							'Gift Wrapping: '.$giftWrapping['wrapname'],
							$giftWrapping['wrapmessage'],
							$item->getQuantity(),
							$item->getWrappingCost()
						);
						$this->cart->AddItem($googleItem);
					}
				}

				// Send across any applied gift certificates from the store
				// Disabled - Gift certificate amounts need to be dynamic to
				// account for changes in tax, shipping and discounts which
				// can all change on the google check out page. This method
				// only allows us to send a static value. Gift certificates
				// must be re-applied on the google checkout page.
				/*
				$giftCertificates = $quote->getAppliedGiftCertificates();
				if(!empty($giftCertificates)) {
					foreach($giftCertificates as $giftCertificate) {
						$giftCertificateName = getLang('GiftCertificate').' ('.$giftCertificate['code'].')';
						$googleItem = new GoogleItem(
							$giftCertificateName, '', 1, $giftCertificate['used'] * -1
						);
						$googleItem->setEmailDigitalDelivery(true);
						$this->cart->addItem($googleItem);
					}
				}*/

				// send across applied coupons
				$coupons = $quote->getAppliedCoupons();
				if(!empty($coupons)) {
					foreach($coupons as $coupon) {
						$googleItem = new Googleitem(
							getLang('Coupon').' ('.$coupon['code'].')', '', 1,
							$coupon['totalDiscount'] * -1
						);

						// free or discounted shipping coupon, add a zero cost item
						// handle shipping rate adjustment via merchant callback later
						if ($coupon['discountType'] == 3 || $coupon['discountType'] == 4) {
							$desc = getLang('GoogleCheckoutDiscountShippingCoupon', $coupon);
							$googleItem = new Googleitem($desc, '', 1, 0);
						}

						$itemData = array(
							'type' => 'coupon',
							'code' => $coupon['code']);

						$googleItem->setMerchantPrivateItemData(json_encode($itemData));
						$this->cart->addItem($googleItem);
					}
				}

				// is there a subtotal discount? (discount rule. eg $X off for orders over $Y)
				if($quote->getDiscountAmount() > 0) {
					$googleItem = new GoogleItem(
						getLang('GoogleCheckoutDiscountOther'), '', 1,
						$quote->getDiscountAmount() * -1
					);
					$googleItem->setEmailDigitalDelivery(true);
					$this->cart->addItem($googleItem);
				}

				if(!$quote->isDigital()) {
					$this->AddShippingInformationToCart();
				}
				else {
					$this->AddDigitalShippingInformationToCart();
				}

				$this->DebugLog($this->cart->GetXML());
			}
		}