Example #1
0
 /**
  * This method renders a product to a template.
  *
  * @param Product $product Product
  * @param string $template TYPO3 Template
  * @param array $typoscript TypoScript
  * @param array $articleMarker Marker for the article description
  * @param string $articleSubpart Subpart
  *
  * @return string rendered HTML
  */
 public function renderProduct(Product $product, $template, array $typoscript, array $articleMarker, $articleSubpart = '')
 {
     if (!$product instanceof Product) {
         return '';
     }
     if (empty($articleMarker)) {
         return $this->error('renderProduct', __LINE__, 'No ArticleMarker defined in renderProduct ');
     }
     $hooks = HookFactory::getHooks('Controller/BaseController', 'renderProduct');
     $data = $product->returnAssocArray();
     // maybe this is a related product so category may be wrong
     $categoryUid = $this->category->getUid();
     $productCategories = $product->getParentCategories();
     if (!in_array($categoryUid, $productCategories, false)) {
         $categoryUid = $productCategories[0];
     }
     /*
      *  Build TS for Linking the Catergory Images
      */
     $localTs = $typoscript;
     $typoLinkConf = array('useCacheHash' => 1);
     /*
      * Generate TypoLink Configuration and ad to fields by addTypoLinkToTs
      */
     if ($this->conf['singlePid']) {
         $typoLinkConf['parameter'] = $this->conf['singlePid'];
     } elseif ($this->conf['overridePid']) {
         $typoLinkConf['parameter'] = $this->conf['overridePid'];
     } else {
         $typoLinkConf['parameter'] = $this->pid;
     }
     $typoLinkConf['additionalParams'] = $this->argSeparator . $this->prefixId . '[showUid]=' . $product->getUid();
     $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[catUid]=' . $categoryUid;
     if ($this->basketHashValue) {
         $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[basketHashValue]=' . $this->basketHashValue;
     }
     $localTs = $this->addTypoLinkToTypoScript($localTs, $typoLinkConf);
     $markerArray = $this->generateMarkerArray($data, $localTs, '', 'tx_commerce_products');
     $markerArrayUp = array();
     foreach ($markerArray as $k => $v) {
         $markerArrayUp[strtoupper($k)] = $v;
     }
     $markerArray = $this->cObj->fillInMarkerArray(array(), $markerArrayUp, implode(',', array_keys($markerArrayUp)), false, 'PRODUCT_');
     $this->can_attributes = $product->getAttributes(array(ATTRIB_CAN));
     $this->selectAttributes = $product->getAttributes(array(ATTRIB_SELECTOR));
     $this->shall_attributes = $product->getAttributes(array(ATTRIB_SHAL));
     $productAttributesSubpartArray = array();
     $productAttributesSubpartArray[] = '###' . strtoupper($this->conf['templateMarker.']['productAttributes']) . '###';
     $productAttributesSubpartArray[] = '###' . strtoupper($this->conf['templateMarker.']['productAttributes2']) . '###';
     $markerArray['###SUBPART_PRODUCT_ATTRIBUTES###'] = $this->cObj->stdWrap($this->renderProductAttributeList($product, $productAttributesSubpartArray, $typoscript['productAttributes.']['fields.']), $typoscript['productAttributes.']);
     $linkArray = array();
     $linkArray['catUid'] = (int) $categoryUid;
     if ($this->basketHashValue) {
         $linkArray['basketHashValue'] = $this->basketHashValue;
     }
     if (is_numeric($this->piVars['manufacturer'])) {
         $linkArray['manufacturer'] = $this->piVars['manufacturer'];
     }
     if (is_numeric($this->piVars['mDepth'])) {
         $linkArray['mDepth'] = $this->piVars['mDepth'];
     }
     foreach ($hooks as $hookObj) {
         if (method_exists($hookObj, 'postProcessLinkArray')) {
             $linkArray = $hookObj->postProcessLinkArray($linkArray, $product, $this);
         }
     }
     $wrapMarkerArray['###PRODUCT_LINK_DETAIL###'] = explode('|', $this->pi_list_linkSingle('|', $product->getUid(), true, $linkArray, false, $this->conf['overridePid']));
     $articleTemplate = $this->cObj->getSubpart($template, '###' . strtoupper($articleSubpart) . '###');
     if ($this->conf['useStockHandling'] == 1) {
         $product = \CommerceTeam\Commerce\Utility\GeneralUtility::removeNoStockArticles($product, $this->conf['articles.']['showWithNoStock']);
     }
     // Set RenderMaxArticles to TS value
     if (isset($localTs['maxArticles']) && (int) $localTs['maxArticles']) {
         $product->setRenderMaxArticles($localTs['maxArticles']);
     }
     $subpartArray = array();
     if ($this->conf['disableArticleViewForProductlist'] == 1 && !$this->piVars['showUid'] || $this->conf['disableArticleView'] == 1) {
         $subpartArray['###' . strtoupper($articleSubpart) . '###'] = '';
     } else {
         $subpartArray['###' . strtoupper($articleSubpart) . '###'] = $this->makeArticleView('list', array(), $product, $articleMarker, $articleTemplate);
     }
     /*
      * Get The Checapest Price
      */
     $cheapestArticleUid = $product->getCheapestArticle();
     /**
      * Cheapest Article.
      *
      * @var Article $cheapestArticle
      */
     $cheapestArticle = GeneralUtility::makeInstance('CommerceTeam\\Commerce\\Domain\\Model\\Article', $cheapestArticleUid);
     $cheapestArticle->loadData();
     $cheapestArticle->loadPrices();
     $markerArray['###PRODUCT_CHEAPEST_PRICE_GROSS###'] = Money::format($cheapestArticle->getPriceGross(), $this->currency);
     $cheapestArticleUid = $product->getCheapestArticle(1);
     /**
      * Cheapest Article.
      *
      * @var Article $cheapestArticle
      */
     $cheapestArticle = GeneralUtility::makeInstance('CommerceTeam\\Commerce\\Domain\\Model\\Article', $cheapestArticleUid);
     $cheapestArticle->loadData();
     $cheapestArticle->loadPrices();
     $markerArray['###PRODUCT_CHEAPEST_PRICE_NET###'] = Money::format($cheapestArticle->getPriceNet(), $this->currency);
     foreach ($hooks as $hookObj) {
         if (method_exists($hookObj, 'additionalMarkerProduct')) {
             $markerArray = $hookObj->additionalMarkerProduct($markerArray, $product, $this);
         }
     }
     foreach ($hooks as $hookObj) {
         if (method_exists($hookObj, 'additionalSubpartsProduct')) {
             $subpartArray = $hookObj->additionalSubpartsProduct($subpartArray, $product, $this);
         }
     }
     $content = $this->substituteMarkerArrayNoCached($template, $markerArray, $subpartArray, $wrapMarkerArray);
     if ($typoscript['editPanel'] == 1) {
         $content = $this->cObj->editPanel($content, $typoscript['editPanel.'], 'tx_commerce_products:' . $product->getUid());
     }
     foreach ($hooks as $hookObj) {
         if (method_exists($hookObj, 'modifyContentProduct')) {
             $content = $hookObj->modifyContentProduct($content, $product, $this);
         }
     }
     return $content;
 }