/** * 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]}; } }