Пример #1
0
 /**
  * Generate a product template
  *
  * @param array $arrConfig
  *
  * @return string
  */
 public function generate(array $arrConfig)
 {
     $this->strFormId = ($arrConfig['module'] instanceof \ContentElement ? 'cte' : 'fmd') . $arrConfig['module']->id . '_product_' . $this->getProductId();
     $objProduct = $this->validateVariant();
     // A variant has been loaded, generate the variant
     if ($objProduct->id != $this->id) {
         return $objProduct->generate($arrConfig);
     }
     $arrGalleries = array();
     /** @type Template|object $objTemplate */
     $objTemplate = new Template($arrConfig['template']);
     $objTemplate->setData($this->arrData);
     $objTemplate->product = $this;
     $objTemplate->config = $arrConfig;
     $objTemplate->generateAttribute = function ($strAttribute, array $arrOptions = array()) use($objProduct) {
         $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($objProduct, $arrOptions);
     };
     $objTemplate->generatePrice = function () use($objProduct) {
         $objPrice = $objProduct->getPrice();
         /** @type ProductType $objType */
         $objType = $objProduct->getRelated('type');
         if (null === $objPrice) {
             return '';
         }
         return $objPrice->generate($objType->showPriceTiers(), 1, $objProduct->getOptions());
     };
     $objTemplate->getGallery = function ($strAttribute) use($objProduct, $arrConfig, &$arrGalleries) {
         if (!isset($arrGalleries[$strAttribute])) {
             $arrGalleries[$strAttribute] = Gallery::createForProductAttribute($objProduct, $strAttribute, $arrConfig);
         }
         return $arrGalleries[$strAttribute];
     };
     $arrVariantOptions = array();
     $arrProductOptions = array();
     $arrAjaxOptions = array();
     foreach (array_unique(array_merge($this->getAttributes(), $this->getVariantAttributes())) as $attribute) {
         $arrData = $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$attribute];
         if ($arrData['attributes']['customer_defined'] || $arrData['attributes']['variant_option']) {
             $strWidget = $this->generateProductOptionWidget($attribute, $arrVariantOptions, $arrAjaxOptions);
             if ($strWidget != '') {
                 $arrProductOptions[$attribute] = array_merge($arrData, array('name' => $attribute, 'html' => $strWidget));
             }
         }
     }
     $arrButtons = array();
     // !HOOK: retrieve buttons
     if (isset($GLOBALS['ISO_HOOKS']['buttons']) && is_array($GLOBALS['ISO_HOOKS']['buttons'])) {
         foreach ($GLOBALS['ISO_HOOKS']['buttons'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             $arrButtons = $objCallback->{$callback}[1]($arrButtons);
         }
         $arrButtons = array_intersect_key($arrButtons, array_flip($arrConfig['buttons']));
     }
     if (\Input::post('FORM_SUBMIT') == $this->getFormId() && !$this->doNotSubmit) {
         foreach ($arrButtons as $button => $data) {
             if (isset($_POST[$button])) {
                 if (isset($data['callback'])) {
                     $objCallback = \System::importStatic($data['callback'][0]);
                     $objCallback->{$data['callback'][1]}($this, $arrConfig);
                 }
                 break;
             }
         }
     }
     RowClass::withKey('rowClass')->addCustom('product_option')->addFirstLast()->addEvenOdd()->applyTo($arrProductOptions);
     $objTemplate->buttons = $arrButtons;
     $objTemplate->useQuantity = $arrConfig['useQuantity'];
     $objTemplate->minimum_quantity = $this->getMinimumQuantity();
     $objTemplate->raw = $this->arrData;
     $objTemplate->raw_options = $this->getConfiguration();
     $objTemplate->configuration = $this->getConfiguration();
     $objTemplate->href = $this->generateUrl($arrConfig['jumpTo']);
     $objTemplate->label_detail = $GLOBALS['TL_LANG']['MSC']['detailLabel'];
     $objTemplate->options = $arrProductOptions;
     $objTemplate->hasOptions = !empty($arrProductOptions);
     $objTemplate->enctype = $this->hasUpload ? 'multipart/form-data' : 'application/x-www-form-urlencoded';
     $objTemplate->formId = $this->getFormId();
     $objTemplate->action = ampersand(\Environment::get('request'), true);
     $objTemplate->formSubmit = $this->getFormId();
     $objTemplate->product_id = $this->getProductId();
     $objTemplate->module_id = $arrConfig['module']->id;
     $GLOBALS['AJAX_PRODUCTS'][] = array('formId' => $this->getFormId(), 'attributes' => $arrAjaxOptions);
     // !HOOK: alter product data before output
     if (isset($GLOBALS['ISO_HOOKS']['generateProduct']) && is_array($GLOBALS['ISO_HOOKS']['generateProduct'])) {
         foreach ($GLOBALS['ISO_HOOKS']['generateProduct'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             $objCallback->{$callback}[1]($objTemplate, $this);
         }
     }
     return $objTemplate->parse();
 }
Пример #2
0
 /**
  * Generate template with given file
  * @param   object
  * @param   string
  * @param   array
  * @return  string
  */
 protected function addImageToTemplate(\Isotope\Template $objTemplate, $strType, array $arrFile)
 {
     $objTemplate->setData($this->arrData);
     $objTemplate->type = $strType;
     $objTemplate->product_id = $this->product_id;
     $objTemplate->file = $arrFile;
     $objTemplate->src = $arrFile[$strType];
     $objTemplate->size = $arrFile[$strType . '_size'];
     $objTemplate->alt = $arrFile['alt'];
     $objTemplate->title = $arrFile['desc'];
     $objTemplate->class = trim($this->arrData['class'] . ' ' . $arrFile['class']);
     switch ($this->anchor) {
         case 'reader':
             $objTemplate->hasLink = $this->href != '';
             $objTemplate->link = $this->href;
             break;
         case 'lightbox':
             list($link, $rel) = explode('|', $arrFile['link'], 2);
             $objTemplate->hasLink = true;
             $objTemplate->link = $link ?: $arrFile['lightbox'];
             $objTemplate->attributes = $link ? $rel ? ' data-lightbox="' . $rel . '"' : ' target="_blank"' : ' data-lightbox="product' . $this->product_id . '"';
             break;
         default:
             $objTemplate->hasLink = false;
             break;
     }
 }