Exemple #1
0
	public static function getQuoteTotalRows(ISC_QUOTE $quote, $displayIncTax = null, $expandShipping = true)
	{
		if($displayIncTax === null) {
			$displayIncTax = false;
			if(getConfig('taxDefaultTaxDisplayCart') == TAX_PRICES_DISPLAY_INCLUSIVE) {
				$displayIncTax = true;
			}
		}

		$totalRows = array();

		// Subtotal
		$totalRows['subtotal'] = array(
			'label' => getLang('Subtotal'),
			'value' => $quote->getSubTotal($displayIncTax)
		);

		// Gift Wrapping
		$wrappingCost = $quote->getWrappingCost($displayIncTax);
		if($wrappingCost > 0) {
			$totalRows['giftWrapping'] = array(
				'label' => getLang('GiftWrapping'),
				'value' => $wrappingCost
			);
		}

		// Coupon codes
		$quote->reapplyCoupons();
		$coupons = $quote->getAppliedCoupons();
		$freeShippingCoupons = array();
		foreach($coupons as $coupon) {

			// Discard the coupon if it's already expired.
			if (isset ($coupon['expiresDate']) && $quote->isCouponExpired($coupon['expiresDate'])) {
				$quote->removeCoupon($coupon['code']);
				continue;
			}
			$couponRow = array(
				'type' => 'coupon',
				'label' => getLang('Coupon').' ('.$coupon['code'].')',
				'value' => $coupon['totalDiscount'] * -1,
				'id' => $coupon['id'],
			);

			if (getclass('ISC_COUPON')->isFreeShippingCoupon($coupon['discountType'])) {
				$freeShippingCoupons['coupon-'.$coupon['id']] = $couponRow;
				continue;
			}
			$totalRows['coupon-'.$coupon['id']] = $couponRow;
		}

		// Discount Amount
		$discountAmount = $quote->getDiscountAmount();
		if($discountAmount > 0){
			$totalRows['discount'] = array(
				'label' => getLang('Discount'),
				'value' => $discountAmount * -1,
			);
		}

		// Shipping & handling
		if(!$quote->isDigital()) {
			// show each shipping quote separately?
			if ($expandShipping) {
				$shippingAddresses = $quote->getShippingAddresses();
				foreach($shippingAddresses as $address) {
					if(!$address->hasShippingMethod()) {
						continue;
					}

					$totalRows['shipping-'.$address->getId()] = array(
						'label' => getLang('Shipping').' ('.$address->getShippingProvider().')',
						'value' => $address->getNonDiscountedShippingCost($displayIncTax)
					);
				}
			}
			else {
				$totalRows['shipping'] = array(
					'label' => getLang('Shipping'),
					'value' => $quote->getNonDiscountedShippingCost($displayIncTax),
				);
			}

			// Added the free shipping coupon display below shipping cost
			// Only if we have free shipping coupon applied
			if (!empty ($freeShippingCoupons)) {
				foreach ($freeShippingCoupons as $key=>$val) {
					$totalRows[$key] = $val;
				}
			}
		}

		$handlingCost = $quote->getHandlingCost($displayIncTax);
		if($handlingCost > 0) {
			$totalRows['handling'] = array(
				'label' => getLang('Handling'),
				'value' => $handlingCost
			);
		}

		// Taxes
		$taxes = array();
		$includedTaxes = array();
		$taxTotal = $quote->getTaxTotal();
		if($taxTotal) {
			$taxAppend = '';
			if(getConfig('taxDefaultTaxDisplayCart') == TAX_PRICES_DISPLAY_INCLUSIVE) {
				$taxAppend = ' '.getLang('IncludedInTotal');
			}

			// Show a single summary of applied tax
			if(getConfig('taxChargesInCartBreakdown') == TAX_BREAKDOWN_SUMMARY) {
				$taxes[] = array(
					'name'	=> getConfig('taxLabel').$taxAppend,
					'total'	=> $taxTotal,
				);
			}
			else {
				$taxSummary = $quote->getTaxRateSummary();
				foreach($taxSummary as $taxRateName => $taxRateAmount) {
					if($taxRateAmount == 0) {
						continue;
					}
					$taxes[] = array(
						'name' => $taxRateName.$taxAppend,
						'total' => $taxRateAmount,
					);
				}
			}

			if(getConfig('taxDefaultTaxDisplayCart') == TAX_PRICES_DISPLAY_INCLUSIVE) {
				$includedTaxes = $taxes;
				$taxes = array();
			}
		}

		foreach($taxes as $id => $taxRate) {
			$totalRows['tax-'.$id] = array(
				'label' => $taxRate['name'],
				'value' => $taxRate['total'],
			);
		}

		// Gift Certificates
		$giftCertificates = $quote->getAppliedGiftCertificates();
		foreach($giftCertificates as $giftCertificate) {
			$totalRows['giftcertificate-'.$giftCertificate['id']] = array(
				'type' => 'giftCertificate',
				'label' => getLang('GiftCertificate').' ('.$giftCertificate['code'].')',
				'value' => $giftCertificate['used'] * -1,
				'id' => $giftCertificate['id'],
			);
		}

		$totalRows['total'] = array(
			'label' => getLang('GrandTotal'),
			'value' => $quote->getGrandTotal($displayIncTax),
		);

		// Included taxes
		foreach($includedTaxes as $id => $taxRate) {
			$totalRows['tax-'.$id] = array(
				'label' => $taxRate['name'],
				'value' => $taxRate['total'],
			);
		}

		return $totalRows;
	}