/**
  * Split tax amount amongst collection products
  *
  * @param IsotopeProductCollection $objCollection
  * @param \Model                   $objSource
  */
 public function applySplittedTax(IsotopeProductCollection $objCollection, $objSource)
 {
     $this->tax_class = 0;
     $this->before_tax = true;
     $fltTotal = 0;
     if (!$objSource->isPercentage()) {
         $fltTotal = $objCollection->getTaxFreeSubtotal();
         if ($fltTotal == 0) {
             return;
         }
     }
     foreach ($objCollection->getItems() as $objItem) {
         if ($objSource->isPercentage()) {
             $fltProductPrice = $objItem->getTotalPrice() / 100 * $objSource->getPercentage();
         } else {
             $fltProductPrice = $this->total_price / 100 * (100 / $fltTotal * $objItem->getTaxFreeTotalPrice());
         }
         $fltProductPrice = $fltProductPrice > 0 ? floor($fltProductPrice * 100) / 100 : ceil($fltProductPrice * 100) / 100;
         $this->setAmountForCollectionItem($fltProductPrice, $objItem);
     }
 }
Пример #2
0
 /**
  * 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]};
     }
 }