private function getCollectionTotalAsXML(IsotopeProductCollection $objCollection) { $intRebate = 0; $intRebateGross = 0; $strShippingName = ''; $intShippingPrice = 0; $intShippingPriceGross = 0; foreach ($objCollection->getSurcharges() as $objSurcharge) { if ($objSurcharge->total_price < 0) { $intRebate += round($objSurcharge->tax_free_total_price * 100); $intRebateGross += round($objSurcharge->total_price * 100); } elseif ($objSurcharge instanceof Shipping) { $strShippingName = $objSurcharge->label; $intShippingPrice += round($objSurcharge->tax_free_total_price * 100); $intShippingPriceGross += round($objSurcharge->total_price * 100); } } $xml = new \DOMDocument(); $total = $xml->createElement('total'); if ($intShippingPrice != 0 || $intShippingPriceGross != 0) { $shippingName = $xml->createAttribute('shippingname'); $shippingName->value = $strShippingName; $total->appendChild($shippingName); $shippingPrice = $xml->createAttribute('shippingprice'); $shippingPrice->value = $intShippingPrice; $total->appendChild($shippingPrice); $shippingPriceGross = $xml->createAttribute('shippingpricegross'); $shippingPriceGross->value = $intShippingPriceGross; $total->appendChild($shippingPriceGross); } if ($intRebate != 0 || $intRebateGross != 0) { $rebate = $xml->createAttribute('rebate'); $rebate->value = $intRebate; $total->appendChild($rebate); $rebateGross = $xml->createAttribute('rebategross'); $rebateGross->value = $intRebateGross; $total->appendChild($rebateGross); } $cartTotalPrice = $xml->createAttribute('carttotalprice'); $cartTotalPrice->value = round($objCollection->getTaxFreeTotal() * 100); $total->appendChild($cartTotalPrice); $cartTotalPriceGross = $xml->createAttribute('carttotalpricegross'); $cartTotalPriceGross->value = round($objCollection->getTotal() * 100); $total->appendChild($cartTotalPriceGross); $currency = $xml->createAttribute('currency'); $currency->value = $objCollection->currency; $total->appendChild($currency); $xml->appendChild($total); return $xml->saveXML($xml->documentElement); }
/** * Replace insert tag for a product collection. * * @param IsotopeProductCollection $collection * @param array $tokens * * @return string */ private function getValueForCollectionTag(IsotopeProductCollection $collection, array $tokens) { switch ($tokens[1]) { case 'items': return $collection->countItems(); case 'quantity': return $collection->sumItemsQuantity(); case 'items_label': $intCount = $collection->countItems(); if (!$intCount) { return ''; } if ($intCount == 1) { return '(' . $GLOBALS['TL_LANG']['MSC']['productSingle'] . ')'; } else { return sprintf('(' . $GLOBALS['TL_LANG']['MSC']['productMultiple'] . ')', $intCount); } break; case 'quantity_label': $intCount = $collection->sumItemsQuantity(); if (!$intCount) { return ''; } if ($intCount == 1) { return '(' . $GLOBALS['TL_LANG']['MSC']['productSingle'] . ')'; } else { return sprintf('(' . $GLOBALS['TL_LANG']['MSC']['productMultiple'] . ')', $intCount); } break; case 'subtotal': return Isotope::formatPriceWithCurrency($collection->getSubtotal()); case 'taxfree_subtotal': return Isotope::formatPriceWithCurrency($collection->getTaxFreeSubtotal()); case 'total': return Isotope::formatPriceWithCurrency($collection->getTotal()); case 'taxfree_total': return Isotope::formatPriceWithCurrency($collection->getTaxFreeTotal()); case 'billing_address': if (!$collection instanceof IsotopeOrderableCollection || ($address = $collection->getBillingAddress()) === null) { return ''; } return $this->getValueForAddressTag($address, $tokens[2]); case 'shipping_address': if (!$collection instanceof IsotopeOrderableCollection || !$collection->hasShipping() || ($address = $collection->getShippingAddress()) === null) { return ''; } return $this->getValueForAddressTag($address, $tokens[2]); default: return $collection->{$tokens[1]}; } }