Пример #1
0
 /**
  * Add the collection to a template
  * @param   object
  * @param   array
  */
 public function addToTemplate(\Isotope\Template $objTemplate, array $arrConfig = array())
 {
     $arrGalleries = array();
     $arrItems = $this->addItemsToTemplate($objTemplate, $arrConfig['sorting']);
     $objTemplate->collection = $this;
     $objTemplate->config = $this->getRelated('config_id') || Isotope::getConfig();
     $objTemplate->surcharges = \Isotope\Frontend::formatSurcharges($this->getSurcharges());
     $objTemplate->subtotal = Isotope::formatPriceWithCurrency($this->getSubtotal());
     $objTemplate->total = Isotope::formatPriceWithCurrency($this->getTotal());
     $objTemplate->generateAttribute = function ($strAttribute, ProductCollectionItem $objItem) {
         if (!$objItem->hasProduct()) {
             return '';
         }
         $objAttribute = $GLOBALS['TL_DCA']['tl_iso_product']['attributes'][$strAttribute];
         if (!$objAttribute instanceof IsotopeAttribute) {
             throw new \InvalidArgumentException($strAttribute . ' is not a valid attribute');
         }
         return $objAttribute->generate($objItem->getProduct());
     };
     $objTemplate->getGallery = function ($strAttribute, ProductCollectionItem $objItem) use($arrConfig, &$arrGalleries) {
         if (!$objItem->hasProduct()) {
             return new \Isotope\Model\Gallery\Standard();
         }
         $strCacheKey = 'product' . $objItem->product_id . '_' . $strAttribute;
         $arrConfig['jumpTo'] = $objItem->getRelated('jumpTo');
         if (!isset($arrGalleries[$strCacheKey])) {
             $arrGalleries[$strCacheKey] = Gallery::createForProductAttribute($objItem->getProduct(), $strAttribute, $arrConfig);
         }
         return $arrGalleries[$strCacheKey];
     };
     // !HOOK: allow overriding of the template
     if (isset($GLOBALS['ISO_HOOKS']['addCollectionToTemplate']) && is_array($GLOBALS['ISO_HOOKS']['addCollectionToTemplate'])) {
         foreach ($GLOBALS['ISO_HOOKS']['addCollectionToTemplate'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             $objCallback->{$callback}[1]($objTemplate, $arrItems, $this);
         }
     }
 }
 public function addToTemplate($intProductType, Order $objOrder, \Template $objTemplate, array $arrConfig = array())
 {
     $arrGalleries = array();
     // FIX - call to custom function since addItemsToTemplate isn't static
     $arrItems = static::addItemsToTemplate($intProductType, $objOrder, $objTemplate, $arrConfig['sorting']);
     $objTemplate->id = $objOrder->id;
     $objTemplate->collection = $objOrder;
     $objTemplate->config = $objOrder->getRelated('config_id') || Isotope::getConfig();
     $objTemplate->surcharges = Frontend::formatSurcharges($objOrder->getSurcharges());
     $objTemplate->subtotal = Isotope::formatPriceWithCurrency($objOrder->getSubtotal());
     $objTemplate->total = Isotope::formatPriceWithCurrency($objOrder->getTotal());
     $objTemplate->tax_free_subtotal = Isotope::formatPriceWithCurrency($objOrder->getTaxFreeSubtotal());
     $objTemplate->tax_free_total = Isotope::formatPriceWithCurrency($objOrder->getTaxFreeTotal());
     $objTemplate->hasAttribute = function ($strAttribute, ProductCollectionItem $objItem) {
         if (!$objItem->hasProduct()) {
             return false;
         }
         $objProduct = $objItem->getProduct();
         return in_array($strAttribute, $objProduct->getAttributes()) || in_array($strAttribute, $objProduct->getVariantAttributes());
     };
     $objTemplate->generateAttribute = function ($strAttribute, ProductCollectionItem $objItem, array $arrOptions = array()) {
         if (!$objItem->hasProduct()) {
             return '';
         }
         $objAttribute = $GLOBALS['TL_DCA']['tl_iso_product']['attributes'][$strAttribute];
         if (!$objAttribute instanceof IsotopeAttribute) {
             throw new \InvalidArgumentException($strAttribute . ' is not a valid attribute');
         }
         return $objAttribute->generate($objItem->getProduct(), $arrOptions);
     };
     $objTemplate->getGallery = function ($strAttribute, ProductCollectionItem $objItem) use($arrConfig, &$arrGalleries) {
         if (!$objItem->hasProduct()) {
             return new Standard();
         }
         $strCacheKey = 'product' . $objItem->product_id . '_' . $strAttribute;
         $arrConfig['jumpTo'] = $objItem->getRelated('jumpTo');
         if (!isset($arrGalleries[$strCacheKey])) {
             $arrGalleries[$strCacheKey] = Gallery::createForProductAttribute($objItem->getProduct(), $strAttribute, $arrConfig);
         }
         return $arrGalleries[$strCacheKey];
     };
     // !HOOK: allow overriding of the template
     if (isset($GLOBALS['ISO_HOOKS']['addCollectionToTemplate']) && is_array($GLOBALS['ISO_HOOKS']['addCollectionToTemplate'])) {
         foreach ($GLOBALS['ISO_HOOKS']['addCollectionToTemplate'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             $objCallback->{$callback}[1]($objTemplate, $arrItems, $objOrder);
         }
     }
 }