Ejemplo n.º 1
0
    /**
     * Makes the rendering for all articles for a given product
     * Renders different view, based on viewKind and number of articles
     *
     * @param string $viewKind Kind of view for choosing the right template
     * @param array $conf TSconfig for handling the articles
     * @param Tx_Commerce_Domain_Model_Product $product The parent product
     * @param array|string $templateMarkerArray Current template marker array
     * @param string $template Template text
     *
     * @return string the content for a single product
     */
    public function makeArticleView($viewKind, array $conf = array(), Tx_Commerce_Domain_Model_Product $product, $templateMarkerArray = '', $template = '')
    {
        $hookObjectsArr = array();
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/lib/class.tx_commerce_pibase.php']['articleview'])) {
            \TYPO3\CMS\Core\Utility\GeneralUtility::deprecationLog('
				hook
				$GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/lib/class.tx_commerce_pibase.php\'][\'articleview\']
				is deprecated since commerce 1.0.0, it will be removed in commerce 1.4.0, please use instead
				$GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/Classes/Controller/ListController.php\'][\'articleView\']
			');
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/lib/class.tx_commerce_pibase.php']['articleview'] as $classRef) {
                $hookObjectsArr[] = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef);
            }
        }
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/ListController.php']['articleView'])) {
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/ListController.php']['articleView'] as $classRef) {
                $hookObjectsArr[] = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef);
            }
        }
        $count = is_array($product->getArticleUids()) ? count($product->getArticleUids()) : FALSE;
        // do nothing if no articles, BE-user-error, should not happen
        if (strlen($template) < 1) {
            $template = $this->templateCode;
        }
        $templateMarker = array();
        $templateMarkerNostock = array();
        $templateMarkerMoreThanMax = array();
        if (is_array($templateMarkerArray)) {
            foreach ($templateMarkerArray as $v) {
                $templateMarker[] = '###' . strtoupper($v) . '###';
                $templateMarkerNostock[] = '###' . strtoupper($v) . '_NOSTOCK###';
                $templateMarkerMoreThanMax[] = '###' . strtoupper($v) . '_MORETHANMAX###';
            }
        } else {
            $templateMarker[] = '###' . strtoupper($this->conf['templateMarker.'][$viewKind . '_productArticleList']) . '###';
            $templateMarker[] = '###' . strtoupper($this->conf['templateMarker.'][$viewKind . '_productArticleList2']) . '###';
            $templateMarkerNostock[] = '###' . strtoupper($this->conf['templateMarker.'][$viewKind . '_productArticleList']) . '_NOSTOCK###';
            $templateMarkerNostock[] = '###' . strtoupper($this->conf['templateMarker.'][$viewKind . '_productArticleList2']) . '_NOSTOCK###';
        }
        $content = '';
        $markerArray = array();
        if ($product->getRenderMaxArticles() > $product->getArticlesCount()) {
            // Only if the number of articles is smaller than defined
            $templateAttrSelectorDropdown = $this->cObj->getSubpart($this->templateCode, '###' . strtoupper($this->conf['templateMarker.']['productAttributesSelectorDropdown']) . '###');
            $templateAttrSelectorDropdownItem = $this->cObj->getSubpart($templateAttrSelectorDropdown, '###' . strtoupper($this->conf['templateMarker.']['productAttributesSelectorDropdown']) . '_ITEM###');
            $templateAttrSelectorRadiobutton = $this->cObj->getSubpart($this->templateCode, '###' . strtoupper($this->conf['templateMarker.']['productAttributesSelectorRadiobutton']) . '###');
            $templateAttrSelectorRadiobuttonItem = $this->cObj->getSubpart($templateAttrSelectorRadiobutton, '###' . strtoupper($this->conf['templateMarker.']['productAttributesSelectorRadiobutton']) . '_ITEM###');
            $templateCount = count($templateMarker);
            $templateAttr = array();
            if (is_array($this->conf['templateMarker.'][$viewKind . '_selectAttributes.'])) {
                foreach ($this->conf['templateMarker.'][$viewKind . '_selectAttributes.'] as $oneMarker) {
                    $templateMarkerAttr = '###' . strtoupper($oneMarker) . '###';
                    $tCode = $this->cObj->getSubpart($this->templateCode, $templateMarkerAttr);
                    if ($tCode) {
                        $templateAttr[] = $tCode;
                    }
                }
            } elseif ($this->conf['templateMarker.'][$viewKind . '_selectAttributes']) {
                $templateMarkerAttr = '###' . strtoupper($this->conf['templateMarker.'][$viewKind . '_selectAttributes']) . '###';
                $templateAttr[] = $this->cObj->getSubpart($this->templateCode, $templateMarkerAttr);
            }
            $countTemplateInterations = count($templateAttr);
            if ($this->conf['showHiddenValues'] == 1) {
                $showHiddenValues = TRUE;
            } else {
                $showHiddenValues = FALSE;
            }
            // Parse piVars for values and names of selected attributes
            // define $arrAttSubmit for finding the right article later
            $arrAttSubmit = array();
            foreach ($this->piVars as $key => $val) {
                if (strstr($key, 'attsel_') && $val) {
                    // set only if it is the selected product - for listing mode
                    if ($this->piVars['changedProductUid'] == $product->getUid() || $this->piVars['showUid'] == $product->getUid()) {
                        $arrAttSubmit[(int) substr($key, 7)] = (int) $val;
                        if ($this->piVars['attList_' . $product->getUid() . '_changed'] == (int) substr($key, 7)) {
                            break;
                        }
                    }
                }
            }
            if (is_array($arrAttSubmit)) {
                $attributeMatrix = $product->getSelectAttributeValueMatrix($arrAttSubmit);
            } else {
                $attributeMatrix = $product->getSelectAttributeValueMatrix($arrAttSubmit);
            }
            if ($this->conf['allArticles'] || $count == 1) {
                for ($i = 0; $i < $count; $i++) {
                    $attributeArray = $product->getAttributeMatrix(array($product->getArticleUid($i)), $this->selectAttributes, $showHiddenValues);
                    $attCode = '';
                    if (is_array($attributeArray)) {
                        $ct = 0;
                        foreach ($attributeArray as $attributeUid => $myAttribute) {
                            /**
                             * Attribute
                             *
                             * @var Tx_Commerce_Domain_Model_Attribute $attributeObj
                             */
                            $attributeObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Commerce_Domain_Model_Attribute', $attributeUid, $this->getFrontendController()->tmpl->setup['config.']['sys_language_uid']);
                            $attributeObj->loadData();
                            $markerArray['###SELECT_ATTRIBUTES_TITLE###'] = $myAttribute['title'];
                            $markerArray['###SELECT_ATTRIBUTES_ICON###'] = $myAttribute['icon'];
                            // @todo check where the attribute values are
                            if (count($myAttribute['values'])) {
                                $v = current(array_splice(each($myAttribute['values']), 1, 1));
                                if (is_array($v) && isset($v['value']) && $v['value'] != '') {
                                    $v = $v['value'];
                                }
                            } else {
                                $v = '';
                            }
                            $markerArray['###SELECT_ATTRIBUTES_VALUE###'] = $v;
                            $markerArray['###SELECT_ATTRIBUTES_UNIT###'] = $myAttribute['unit'];
                            $numTemplate = $ct % $countTemplateInterations;
                            $attCode .= $this->cObj->substituteMarkerArray($templateAttr[$numTemplate], $markerArray);
                            $ct++;
                        }
                    }
                    $markerArray = (array) $this->getArticleMarker($product->getArticle($product->getArticleUid($i)));
                    $markerArray['SUBPART_ARTICLE_ATTRIBUTES'] = $this->cObj->stdWrap($this->makeArticleAttributList($product, array($product->getArticleUid($i))), $this->conf['singleView.']['articleAttributesList.']);
                    $markerArray['ARTICLE_SELECT_ATTRIBUTES'] = $this->cObj->stdWrap($attCode, $this->conf['singleView.']['articleAttributesSelectList.']);
                    foreach ($hookObjectsArr as $hookObj) {
                        if (method_exists($hookObj, 'additionalMarker')) {
                            $markerArray = (array) $hookObj->additionalMarker($markerArray, $this, $product->getArticle($product->getArticleUid($i)));
                        }
                    }
                    $templateAttributes = $this->cObj->getSubpart($template, $templateMarker[$i % $templateCount]);
                    /**
                     * Article
                     *
                     * @var Tx_Commerce_Domain_Model_Article $article
                     */
                    $article = $product->getArticle($product->getArticleUid($i));
                    if ($this->conf['useStockHandling'] == 1 and $article->getStock() <= 0) {
                        $tempTemplate = $this->cObj->getSubpart($template, $templateMarkerNostock[$i % $templateCount]);
                        if ($tempTemplate != '') {
                            $templateAttributes = $tempTemplate;
                        }
                    }
                    $content .= $this->cObj->substituteMarkerArray($templateAttributes, $markerArray, '###|###', 1);
                }
            } else {
                $sortedAttributeArray = array();
                $i = 0;
                foreach ($arrAttSubmit as $attrUid => $attrValUid) {
                    $sortedAttributeArray[$i]['AttributeUid'] = $attrUid;
                    $sortedAttributeArray[$i]['AttributeValue'] = $attrValUid;
                    $i++;
                }
                $artId = array_shift($product->getArticlesByAttributeArray($sortedAttributeArray));
                $attCode = '';
                if (is_array($attributeMatrix)) {
                    $getVarList = array('showUid', 'catUid', 'pointer');
                    $getVars = array();
                    foreach ($getVarList as $getVar) {
                        if (isset($this->piVars[$getVar])) {
                            $getVars[$this->prefixId . '[' . $getVar . ']'] = $this->piVars[$getVar];
                        }
                    }
                    // Makes pi1 a user int so form values are updated as one selects an attribute
                    $getVars['commerce_pi1_user_int'] = 1;
                    $actionUrl = $this->cObj->typoLink_URL(array('parameter' => $GLOBALS['TSFE']->id, 'additionalParams' => \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('', $getVars), 'useCacheHash' => 1, 'section' => 'attList_' . $product->getUid()));
                    $attCode = '<form name="attList_' . $product->getUid() . '" id="attList_' . $product->getUid() . '" action="' . $actionUrl . '"  method="post">' . '<input type="hidden" name="' . $this->prefixId . '[changedProductUid]" value="' . $product->getUid() . '" />' . '<input type="hidden" name="' . $this->prefixId . '[attList_' . $product->getUid() . '_changed]" id="attList_' . $product->getUid() . '_changed" value="1" />' . '<input type="hidden" name="tx_commerce_pi1[catUid]" value="' . $this->piVars['catUid'] . '" />';
                    $markerArray = array();
                    foreach ($attributeMatrix as $attrUid => $values) {
                        /**
                         * Attribute
                         *
                         * @var Tx_Commerce_Domain_Model_Attribute $attributeObj
                         */
                        $attributeObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Commerce_Domain_Model_Attribute', $attrUid, $this->getFrontendController()->tmpl->setup['config.']['sys_language_uid']);
                        $attributeObj->loadData();
                        // disable the icon mode by default
                        $iconMode = FALSE;
                        // if the icon mode is enabled in TS check if the iconMode is also enabled
                        // for this attribute
                        if ($this->conf[$this->handle . '.']['products.']['productAttributes.']['iconMode'] == '1') {
                            $iconMode = $attributeObj->isIconmode();
                        }
                        if ($iconMode) {
                            $templateAttrSelector = $templateAttrSelectorRadiobutton;
                            $templateAttrSelectorItem = $templateAttrSelectorRadiobuttonItem;
                        } else {
                            $templateAttrSelector = $templateAttrSelectorDropdown;
                            $templateAttrSelectorItem = $templateAttrSelectorDropdownItem;
                        }
                        $markerArray['###SELECT_ATTRIBUTES_TITLE###'] = $attributeObj->getTitle();
                        $markerArray['###SELECT_ATTRIBUTES_ON_CHANGE###'] = 'document.getElementById(\'attList_' . $product->getUid() . '_changed\').value = ' . $attrUid . ';document.getElementById(\'attList_' . $product->getUid() . '\').submit();';
                        $markerArray['###SELECT_ATTRIBUTES_HTML_ELEMENT_KEY###'] = $this->prefixId . '_' . $attrUid;
                        $markerArray['###SELECT_ATTRIBUTES_HTML_ELEMENT_NAME###'] = $this->prefixId . '[attsel_' . $attrUid . ']';
                        if (strpos($templateAttrSelector, '###SELECT_ATTRIBUTES_ITEM_TEXT_ALL###') !== FALSE) {
                            \TYPO3\CMS\Core\Utility\GeneralUtility::deprecationLog('
								marker ###SELECT_ATTRIBUTES_ITEM_TEXT_ALL### is deprecated since commerce 1.0.0,
								it will be removed in commerce 1.4.0
							');
                        }
                        $markerArray['###SELECT_ATTRIBUTES_ITEM_TEXT_ALL###'] = '';
                        $markerArray['###SELECT_ATTRIBUTES_UNIT###'] = $attributeObj->getUnit();
                        $itemsContent = '';
                        $i = 1;
                        $attributeValues = $attributeObj->getAllValues(TRUE, $product);
                        /**
                         * Attribute value
                         *
                         * @var Tx_Commerce_Domain_Model_AttributeValue $val
                         */
                        foreach ($attributeValues as $val) {
                            $markerArrayItem = $markerArray;
                            $markerArrayItem['###SELECT_ATTRIBUTES_VALUE_VALUE###'] = $val->getUid();
                            $markerArrayItem['###SELECT_ATTRIBUTES_VALUE_NAME###'] = $val->getValue();
                            $markerArrayItem['###SELECT_ATTRIBUTES_VALUE_ICON###'] = $this->renderValue($val->getIcon(), 'IMAGE', $this->conf[$this->handle . '.']['products.']['productAttributes.']['fields.']['icon.']);
                            if ($values[$val->getUid()] == 'selected') {
                                $attributeArray[$attrUid] = $val->getUid();
                                if ($iconMode) {
                                    $markerArrayItem['###SELECT_ATTRIBUTES_VALUE_STATUS###'] = 'checked="checked"';
                                } else {
                                    $markerArrayItem['###SELECT_ATTRIBUTES_VALUE_STATUS###'] = 'selected="selected"';
                                }
                                $i++;
                            } elseif ($values[$val->getUid()] == 'disabled') {
                                $markerArrayItem['###SELECT_ATTRIBUTES_VALUE_STATUS###'] = 'disabled="disabled"';
                            } else {
                                $markerArrayItem['###SELECT_ATTRIBUTES_VALUE_STATUS###'] = '';
                            }
                            if (strpos($templateAttrSelector, '###SELECT_ATTRIBUTES_ITEM_TEXT_ALL###') !== FALSE) {
                                \TYPO3\CMS\Core\Utility\GeneralUtility::deprecationLog('
									marker ###SELECT_ATTRIBUTES_VALUE_SELECTED### is deprecated since commerce 1.0.0,
									it will be removed in commerce 1.4.0, please use ###SELECT_ATTRIBUTES_VALUE_STATUS### instead
								');
                            }
                            $markerArrayItem['###SELECT_ATTRIBUTES_VALUE_SELECTED###'] = $markerArrayItem['###SELECT_ATTRIBUTES_VALUE_STATUS###'];
                            foreach ($hookObjectsArr as $hookObj) {
                                if (method_exists($hookObj, 'additionalAttributeMarker')) {
                                    $markerArrayItem = $hookObj->additionalAttributeMarker($markerArrayItem, $this, $val->getUid());
                                }
                            }
                            $itemsContent .= $this->cObj->substituteMarkerArray($templateAttrSelectorItem, $markerArrayItem);
                            $i++;
                        }
                        $attributeContent = $this->cObj->substituteMarkerArray($templateAttrSelector, $markerArray);
                        if ($iconMode) {
                            $attCode .= $this->cObj->substituteSubpart($attributeContent, '###' . strtoupper($this->conf['templateMarker.']['productAttributesSelectorRadiobutton']) . '_ITEM###', $itemsContent);
                        } else {
                            $attCode .= $this->cObj->substituteSubpart($attributeContent, '###' . strtoupper($this->conf['templateMarker.']['productAttributesSelectorDropdown']) . '_ITEM###', $itemsContent);
                        }
                    }
                    $attCode .= '</form>';
                }
                $markerArray = (array) $this->getArticleMarker($product->getArticle($artId));
                $markerArray['SUBPART_ARTICLE_ATTRIBUTES'] = $this->makeArticleAttributList($product, array($artId));
                $markerArray['ARTICLE_SELECT_ATTRIBUTES'] = $attCode;
                foreach ($hookObjectsArr as $hookObj) {
                    if (method_exists($hookObj, 'additionalMarker')) {
                        $markerArray = (array) $hookObj->additionalMarker($markerArray, $this, $product->getArticle($artId));
                    }
                }
                $templateAttributes = $this->cObj->getSubpart($template, $templateMarker[0]);
                /**
                 * Article
                 *
                 * @var Tx_Commerce_Domain_Model_Article $article
                 */
                $article = $product->getArticle($artId);
                if ($this->conf['useStockHandling'] == 1 and $article->getStock() <= 0) {
                    $tempTemplate = $this->cObj->getSubpart($template, $templateMarkerNostock[0]);
                    if ($tempTemplate != '') {
                        $templateAttributes = $tempTemplate;
                    }
                }
                $content .= $this->cObj->substituteMarkerArray($templateAttributes, $markerArray, '###|###', 1);
            }
        } else {
            // Special Marker and rendering when more articles are existing than
            // are allowed to render
            $localContent = $this->cObj->getSubpart($template, reset($templateMarkerMoreThanMax));
            $cat = $this->cat;
            $productCategories = $product->getParentCategories();
            if (!in_array($cat, $productCategories, FALSE)) {
                $cat = $productCategories[0];
            }
            /**
             * Generate TypoLink Configuration and ad to fields by addTypoLinkToTs
             */
            if ($this->conf['overridePid']) {
                $typoLinkConf['parameter'] = $this->conf['overridePid'];
            } else {
                $typoLinkConf['parameter'] = $this->pid;
            }
            $typoLinkConf['useCacheHash'] = 1;
            $typoLinkConf['additionalParams'] = $this->argSeparator . $this->prefixId . '[showUid]=' . $product->getUid();
            $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[catUid]=' . $cat;
            if ($this->basketHashValue) {
                $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[basketHashValue]=' . $this->basketHashValue;
            }
            $markerArray['LINKTOPRODUCT'] = $this->cObj->typoLink($this->pi_getLL('lang_toproduct'), $typoLinkConf);
            $content = $this->cObj->substituteMarkerArray($localContent, $markerArray, '###|###', 1);
            $markerArray = array();
            foreach ($hookObjectsArr as $hookObj) {
                if (method_exists($hookObj, 'additionalMarkerMakeArticleView')) {
                    $markerArray = (array) $hookObj->additionalMarkerMakeArticleView($markerArray, $product, $this);
                }
            }
        }
        $content = $this->cObj->substituteMarkerArray($content, $markerArray);
        return $content;
    }
Ejemplo n.º 2
0
 /**
  * Renders HTML output with list of attribute from a given product,
  * reduced for some articles
  * if article ids are givens
  * with possibility to
  * define a number of templates for interations.
  * when defining 2 templates you have an odd / even layout
  *
  * @param Tx_Commerce_Domain_Model_Product $product Current product
  * @param array $articleId ArticleIds for filtering attributss
  * @param array $subpartNameArray Suppart Names
  *
  * @return string Stringoutput for attributes
  */
 public function renderArticleAttributeList(Tx_Commerce_Domain_Model_Product &$product, array $articleId = array(), array $subpartNameArray = array())
 {
     $templateArray = array();
     foreach ($subpartNameArray as $oneSubpartName) {
         $tmpCode = $this->cObj->getSubpart($this->templateCode, $oneSubpartName);
         if (strlen($tmpCode) > 0) {
             $templateArray[] = $tmpCode;
         }
     }
     if ($this->conf['showHiddenValues'] == 1) {
         $showHiddenValues = TRUE;
     } else {
         $showHiddenValues = FALSE;
     }
     $this->can_attributes = $product->getAttributes(array(ATTRIB_CAN));
     $this->shall_attributes = $product->getAttributes(array(ATTRIB_SHAL));
     $matrix = $product->getAttributeMatrix($articleId, $this->shall_attributes, $showHiddenValues);
     $articleShallAttributesString = '';
     $i = 0;
     if (is_array($this->shall_attributes)) {
         foreach ($this->shall_attributes as $myAttributeUid) {
             if (!$matrix[$myAttributeUid]['values'][0] && $this->conf['hideEmptyShalAttr'] || !$matrix[$myAttributeUid]) {
                 continue;
             }
             if ($i == count($templateArray)) {
                 $i = 0;
             }
             $datas = array('title' => $matrix[$myAttributeUid]['title'], 'value' => $this->formatAttributeValue($matrix, $myAttributeUid), 'unit' => $matrix[$myAttributeUid]['unit'], 'icon' => $matrix[$myAttributeUid]['icon'], 'internal_title' => $matrix[$myAttributeUid]['internal_title']);
             $markerArray = $this->generateMarkerArray($datas, $this->conf['singleView.']['attributes.'], $prefix = 'ARTICLE_ATTRIBUTES_');
             $marker['ARTICLE_ATTRIBUTES_TITLE'] = $matrix[$myAttributeUid]['title'];
             $articleShallAttributesString .= $this->cObj->substituteMarkerArray($templateArray[$i], $markerArray, '###|###', 1);
             $i++;
         }
     }
     $articleShallAttributesString = $this->cObj->stdWrap($articleShallAttributesString, $this->conf['articleShalAttributsWrap.']);
     $matrix = $product->getAttributeMatrix($articleId, $this->can_attributes, $showHiddenValues);
     $articleCanAttributesString = '';
     $i = 0;
     if (is_array($this->can_attributes)) {
         foreach ($this->can_attributes as $myAttributeUid) {
             if (!$matrix[$myAttributeUid]['values'][0] && $this->conf['hideEmptyCanAttr'] || !$matrix[$myAttributeUid]) {
                 continue;
             }
             if ($i == count($templateArray)) {
                 $i = 0;
             }
             $datas = array('title' => $matrix[$myAttributeUid]['title'], 'value' => $this->formatAttributeValue($matrix, $myAttributeUid), 'unit' => $matrix[$myAttributeUid]['unit'], 'icon' => $matrix[$myAttributeUid]['icon'], 'internal_title' => $matrix[$myAttributeUid]['internal_title']);
             $markerArray = $this->generateMarkerArray($datas, $this->conf['singleView.']['attributes.'], $prefix = 'ARTICLE_ATTRIBUTES_');
             $marker['ARTICLE_ATTRIBUTES_TITLE'] = $matrix[$myAttributeUid]['title'];
             $articleCanAttributesString .= $this->cObj->substituteMarkerArray($templateArray[$i], $markerArray, '###|###', 1);
             $i++;
         }
     }
     $articleCanAttributesString = $this->cObj->stdWrap($articleCanAttributesString, $this->conf['articleCanAttributsWrap.']);
     $articleAttributesString = $this->cObj->stdWrap($articleShallAttributesString . $articleCanAttributesString, $this->conf['articleAttributsWrap.']);
     $articleAttributesString = $this->cObj->stdWrap($articleAttributesString, $this->conf['singleView.']['attributes.']['stdWrap.']);
     return $articleAttributesString . ' ';
 }