示例#1
0
 /**
  * Init called by the constructor.
  *
  * @param int $uid Uid of category
  * @param int $languageUid Language_uid , default 0
  *
  * @return bool TRUE on success, FALSE if no $uid is submitted
  */
 public function init($uid, $languageUid = 0)
 {
     $uid = (int) $uid;
     $languageUid = (int) $languageUid;
     if ($uid > 0) {
         $this->uid = $uid;
         $this->lang_uid = $languageUid;
         $this->databaseConnection = GeneralUtility::makeInstance($this->databaseClass);
         $hooks = \CommerceTeam\Commerce\Factory\HookFactory::getHooks('Domain/Model/Category', 'init');
         foreach ($hooks as $hook) {
             if (method_exists($hook, 'postinit')) {
                 $hook->postinit($this);
             }
         }
         return true;
     }
     return false;
 }
示例#2
0
 /**
  * Overwrites a product record.
  *
  * @param int $uidFrom UID of the product we want to copy
  * @param int $uidTo UID of the product we want to overwrite
  * @param array $locale Languages
  *
  * @return bool
  */
 public static function overwriteProduct($uidFrom, $uidTo, array $locale = array())
 {
     $table = 'tx_commerce_products';
     // check params
     if (!is_numeric($uidFrom) || !is_numeric($uidTo) || $uidFrom == $uidTo) {
         if (TYPO3_DLOG) {
             GeneralUtility::devLog('overwriteProduct (belib) gets passed invalid parameters.', COMMERCE_EXTKEY, 3);
         }
         return false;
     }
     // check if we may actually copy the product (no permission check, only
     // check if we are not accidentally copying a placeholder or shadow or
     // deleted product)
     $recordFrom = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL($table, $uidFrom, '*', ' AND pid != -1 AND t3ver_state != 1 AND deleted = 0');
     if (!$recordFrom) {
         return false;
     }
     // check if we may actually overwrite the product (no permission check,
     // only check if we are not accidentaly overwriting a placeholder or
     // shadow or deleted product)
     $recordTo = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL($table, $uidTo, '*', ' AND pid != -1 AND t3ver_state != 1 AND deleted = 0');
     if (!$recordTo) {
         return false;
     }
     // check if we have the permissions to
     // copy and overwrite (check category rights)
     if (!self::checkProductPerms($uidFrom, 'copy') || !self::checkProductPerms($uidTo, 'editcontent')) {
         return false;
     }
     // First prepare user defined hooks
     $hooks = \CommerceTeam\Commerce\Factory\HookFactory::getHooks('Utility/BackendUtility', 'overwriteProduct');
     $data = self::getOverwriteData($table, $uidFrom, $uidTo);
     // do not overwrite uid, parent_categories, and create_date
     unset($data[$table][$uidTo]['uid'], $data[$table][$uidTo]['categories'], $data[$table][$uidTo]['crdate'], $data[$table][$uidTo]['cruser_id']);
     $datamap = $data;
     // execute
     /**
      * Data handler.
      *
      * @var \TYPO3\CMS\Core\DataHandling\DataHandler $tce
      */
     $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
     $tce->stripslashes_values = 0;
     $backendUser = self::getBackendUser();
     $tcaDefaultOverride = $backendUser->getTSConfigProp('TCAdefaults');
     if (is_array($tcaDefaultOverride)) {
         $tce->setDefaultsFromUserTS($tcaDefaultOverride);
     }
     // Hook: beforeOverwrite
     foreach ($hooks as $hookObj) {
         if (method_exists($hookObj, 'beforeOverwrite')) {
             $hookObj->beforeOverwrite($uidFrom, $uidTo, $datamap);
         }
     }
     $tce->start($datamap, array());
     $tce->process_datamap();
     // Hook: afterOverwrite
     foreach ($hooks as $hookObj) {
         if (method_exists($hookObj, 'beforeCopy')) {
             $hookObj->beforeCopy($uidFrom, $uidTo, $datamap, $tce);
         }
     }
     // Overwrite locales
     if (!empty($locale)) {
         foreach ($locale as $loc) {
             self::overwriteLocale($table, $uidFrom, $uidTo, $loc);
         }
     }
     // overwrite articles which are existing - do NOT delete articles
     // that are not in the overwritten product but in the overwriting one
     $articlesFrom = self::getArticlesOfProduct($uidFrom);
     if (is_array($articlesFrom)) {
         // the product has articles - check if they exist in the overwritten product
         $articlesTo = self::getArticlesOfProduct($uidTo);
         // simply copy if the overwritten product does not have articles
         if (false === $articlesTo || !is_array($articlesTo)) {
             self::copyArticlesByProduct($uidTo, $uidFrom, $locale);
         } else {
             // go through each article of the overwriting product
             // and check if it exists in the overwritten product
             $l = count($articlesFrom);
             $m = count($articlesTo);
             // walk the articles
             for ($i = 0; $i < $l; ++$i) {
                 $overwrite = false;
                 $uid = $articlesFrom[$i]['uid'];
                 // check if we need to overwrite
                 for ($j = 0; $j < $m; ++$j) {
                     if ($articlesFrom[$i]['ordernumber'] == $articlesTo[$j]['ordernumber']) {
                         $overwrite = true;
                         break;
                     }
                 }
                 if (!$overwrite) {
                     // copy if we do not need to overwrite
                     self::copyArticle($uid, $uidTo, $locale);
                 } else {
                     // overwrite if the article already exists
                     self::overwriteArticle($uid, $articlesTo[$j]['uid'], $locale);
                 }
             }
         }
     }
     return true;
 }
示例#3
0
 /**
  * Process Data when saving Order
  * Change the PID from this order via the new field newpid
  * As TYPO3 don't allows changing the PId directly.
  *
  * @param array $incomingFieldArray Incoming field array
  * @param string $table Table
  * @param int $id Id
  * @param DataHandler $pObj Parent object
  *
  * @return array
  */
 protected function preProcessOrder(array $incomingFieldArray, $table, $id, DataHandler &$pObj)
 {
     $incomingFieldArray['crdate'] = null;
     if (isset($incomingFieldArray['newpid'])) {
         $hooks = \CommerceTeam\Commerce\Factory\HookFactory::getHooks('Hook/DataMapHooks', 'preProcessOrder');
         $database = $this->getDatabaseConnection();
         // Add first the pid filled
         $incomingFieldArray['pid'] = $incomingFieldArray['newpid'];
         // Move Order articles
         $orders = $database->exec_SELECTquery('order_id, pid, uid, order_sys_language_uid', $table, 'uid = ' . (int) $id);
         if (!$database->sql_error()) {
             $order = $database->sql_fetch_assoc($orders);
             if ($order['pid'] != $incomingFieldArray['newpid']) {
                 // order_sys_language_uid is not always set in fieldArray so we overwrite
                 // it with our order data
                 if ($incomingFieldArray['order_sys_language_uid'] === null) {
                     $incomingFieldArray['order_sys_language_uid'] = $order['order_sys_language_uid'];
                 }
                 foreach ($hooks as $hookObj) {
                     if (method_exists($hookObj, 'moveOrders_preMoveOrder')) {
                         // @deprecated This method call gets removed in 5.0.0
                         $hookObj->moveOrders_preMoveOrder($order, $incomingFieldArray);
                     } elseif (method_exists($hookObj, 'moveOrdersPreMoveOrder')) {
                         $hookObj->moveOrdersPreMoveOrder($order, $incomingFieldArray);
                     }
                 }
                 $orderId = $order['order_id'];
                 $resultOrderArticles = $database->exec_SELECTquery('*', 'tx_commerce_order_articles', 'order_id = ' . $database->fullQuoteStr($orderId, 'tx_commerce_order_articles'));
                 if (!$database->sql_error()) {
                     // Run trough all articles from this order and move it to other storage folder
                     while ($orderArtikelRow = $database->sql_fetch_assoc($resultOrderArticles)) {
                         $orderArtikelRow['pid'] = $incomingFieldArray['newpid'];
                         $orderArtikelRow['tstamp'] = $GLOBALS['EXEC_TIME'];
                         $database->exec_UPDATEquery('tx_commerce_order_articles', 'uid = ' . $orderArtikelRow['uid'], $orderArtikelRow);
                     }
                 } else {
                     $pObj->log($table, $id, 2, 0, 2, 'SQL error: \'%s\' (%s)', 12, array($database->sql_error(), $table . ':' . $id));
                 }
                 $order['pid'] = $incomingFieldArray['newpid'];
                 $order['tstamp'] = $GLOBALS['EXEC_TIME'];
                 $database->exec_UPDATEquery('tx_commerce_orders', 'uid = ' . $order['uid'], $order);
                 foreach ($hooks as $hookObj) {
                     if (method_exists($hookObj, 'moveOrders_postMoveOrder')) {
                         // @deprecated This method call gets removed in 5.0.0
                         $hookObj->moveOrders_postMoveOrder($order, $incomingFieldArray);
                     } elseif (method_exists($hookObj, 'moveOrdersPostMoveOrder')) {
                         $hookObj->moveOrdersPostMoveOrder($order, $incomingFieldArray);
                     }
                 }
             }
         } else {
             $pObj->log($table, $id, 2, 0, 2, 'SQL error: \'%s\' (%s)', 12, array($database->sql_error(), $table . ':' . $id));
         }
     }
     return $incomingFieldArray;
 }
示例#4
0
 /**
  * Init Class.
  *
  * @param int $uid Attribute
  * @param int $languageUid Language uid, default 0
  *
  * @return void
  */
 public function init($uid, $languageUid = 0)
 {
     $this->uid = (int) $uid;
     $this->lang_uid = (int) $languageUid;
     $this->databaseConnection = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($this->databaseClass);
     $hooks = \CommerceTeam\Commerce\Factory\HookFactory::getHooks('Domain/Model/AttributeValue', 'init');
     foreach ($hooks as $hook) {
         if (method_exists($hook, 'postinit')) {
             $hook->postinit($this);
         }
     }
 }
示例#5
0
 /**
  * Init Method, called by constructor.
  *
  * @param int $uid         Uid of article
  * @param int $languageUid Language uid
  *
  * @return bool
  */
 public function init($uid, $languageUid = 0)
 {
     $this->uid = (int) $uid;
     $languageUid = (int) $languageUid;
     $return = false;
     if ($this->uid > 0) {
         $this->lang_uid = $languageUid;
         $this->databaseConnection = GeneralUtility::makeInstance($this->databaseClass);
         $hooks = HookFactory::getHooks('Domain/Model/Article', 'init');
         foreach ($hooks as $hook) {
             if (method_exists($hook, 'postinit')) {
                 $hook->postinit($this);
             }
         }
         $return = true;
     }
     return $return;
 }
示例#6
0
 /**
  * This method converts an sends mails.
  *
  * @param array $mailconf Mail configuration
  * @param array $orderdata Order data
  * @param string $template Template
  *
  * @return bool of \TYPO3\CMS\Core\Mail\MailMessage
  */
 protected function ordermoveSendMail(array $mailconf, array &$orderdata, &$template)
 {
     // First line is subject
     $parts = explode(chr(10), $mailconf['plain']['content'], 2);
     // add mail subject
     $mailconf['alternateSubject'] = trim($parts[0]);
     // replace plaintext content
     $mailconf['plain']['content'] = trim($parts[1]);
     /*
      * Convert Text to charset
      */
     $this->csConvObj->initCharset('utf-8');
     $this->csConvObj->initCharset('8bit');
     $mailconf['plain']['content'] = $this->csConvObj->conv($mailconf['plain']['content'], 'utf-8', 'utf-8');
     $mailconf['alternateSubject'] = $this->csConvObj->conv($mailconf['alternateSubject'], 'utf-8', 'utf-8');
     $hooks = \CommerceTeam\Commerce\Factory\HookFactory::getHooks('Hook/OrdermailHooks', 'ordermoveSendMail');
     foreach ($hooks as $hook) {
         if (method_exists($hook, 'postOrdermoveSendMail')) {
             $hook->postOrdermoveSendMail($mailconf, $orderdata, $template);
         }
     }
     return \CommerceTeam\Commerce\Utility\GeneralUtility::sendMail($mailconf);
 }
示例#7
0
 /**
  * Store basket data to database.
  *
  * @return void
  */
 protected function storeDataToDatabase()
 {
     $database = $this->getDatabaseConnection();
     $database->exec_DELETEquery('tx_commerce_baskets', 'sid = ' . $database->fullQuoteStr($this->getSessionId(), 'tx_commerce_baskets') . ' AND finished_time = 0');
     $hooks = HookFactory::getHooks('Domain/Model/Basket', 'storeDataToDatabase');
     // Get array keys from basket items to store correct position in basket
     $arBasketItemsKeys = array_keys($this->basketItems);
     // After getting the keys in a array, flip it to get the position of each item
     $arBasketItemsKeys = array_flip($arBasketItemsKeys);
     $oneuid = 0;
     /**
      * Basket item.
      *
      * @var \CommerceTeam\Commerce\Domain\Model\BasketItem $basketItem
      */
     foreach ($this->basketItems as $oneuid => $basketItem) {
         $insertData = array();
         $insertData['pid'] = $this->getBasketStoragePid();
         $insertData['pos'] = $arBasketItemsKeys[$oneuid];
         $insertData['sid'] = $this->sessionId;
         $insertData['article_id'] = $basketItem->getArticleUid();
         $insertData['price_id'] = $basketItem->getPriceUid();
         $insertData['price_net'] = $basketItem->getPriceNet();
         $insertData['price_gross'] = $basketItem->getPriceGross();
         $insertData['quantity'] = $basketItem->getQuantity();
         $insertData['readonly'] = $this->getReadOnly();
         $insertData['tstamp'] = $GLOBALS['EXEC_TIME'];
         if ($this->crdate > 0) {
             $insertData['crdate'] = $this->crdate;
         } else {
             $insertData['crdate'] = $insertData['tstamp'];
         }
         if (is_array($hooks)) {
             foreach ($hooks as $hookObj) {
                 if (method_exists($hookObj, 'storeDataToDatabase')) {
                     $insertData = $hookObj->storeDataToDatabase($basketItem, $insertData);
                 }
             }
         }
         $database->exec_INSERTquery('tx_commerce_baskets', $insertData);
     }
     $basketItem = $this->basketItems[$oneuid];
     if (is_object($basketItem)) {
         $basketItem->calculateNetSum();
         $basketItem->calculateGrossSum();
     }
 }
示例#8
0
 /**
  * Constructor class, basically calls init.
  *
  * @param int $uid Uid or attribute
  * @param int $languageUid Language uid, default 0
  *
  * @return bool
  */
 public function init($uid, $languageUid = 0)
 {
     $uid = (int) $uid;
     $this->fieldlist = array('title', 'unit', 'iconmode', 'has_valuelist', 'l18n_parent', 'parent');
     if ($uid > 0) {
         $this->uid = $uid;
         $this->lang_uid = (int) $languageUid;
         $this->databaseConnection = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($this->databaseClass);
         $hooks = \CommerceTeam\Commerce\Factory\HookFactory::getHooks('Domain/Model/Attribute', 'init');
         foreach ($hooks as $hook) {
             if (method_exists($hook, 'postinit')) {
                 $hook->postinit($this);
             }
         }
         return true;
     }
     return false;
 }
 /**
  * Commits the given command.
  *
  * @param int    $uidClip   Uid of clipboard item
  * @param int    $uidTarget Uid of target
  * @param string $command   Command
  */
 protected function commitCommand($uidClip, $uidTarget, $command)
 {
     // First prepare user defined hooks
     $hooks = \CommerceTeam\Commerce\Factory\HookFactory::getHooks('Utility/DataHandlerUtility', 'commitCommand');
     // Hook: beforeCommit
     foreach ($hooks as $hookObj) {
         if (method_exists($hookObj, 'beforeCommit')) {
             $hookObj->beforeCommit($uidClip, $uidTarget, $command);
         }
     }
     // we got all info we need - commit command
     switch ($command) {
         case 'overwrite':
             BackendUtility::overwriteProduct($uidClip, $uidTarget, $this->locales);
             break;
         case 'pasteProduct':
             BackendUtility::copyProduct($uidClip, $uidTarget, false, $this->locales, $this->sorting);
             break;
         case 'pasteCategory':
             BackendUtility::copyCategory($uidClip, $uidTarget, $this->locales, $this->sorting);
             break;
         default:
             die('unknown command');
     }
     // Hook: afterCommit
     foreach ($hooks as $hookObj) {
         if (method_exists($hookObj, 'afterCommit')) {
             $hookObj->afterCommit($uidClip, $uidTarget, $command);
         }
     }
     // Update page tree?
     if ($this->uPT && (isset($this->data['tx_commerce_categories']) || isset($this->cmd['tx_commerce_categories'])) && (isset($this->data['tx_commerce_products']) || isset($this->cmd['tx_commerce_products']))) {
         \TYPO3\CMS\Backend\Utility\BackendUtility::setUpdateSignal('updateFolderTree');
     }
 }
 /**
  * Get all addresses from the database that are assigned to the current user.
  *
  * @param int $userId      UID of the user
  * @param int $addressType Type of addresses to retrieve
  *
  * @return array Keys with UIDs and values with complete addresses data
  */
 public function getAddresses($userId, $addressType = 0)
 {
     $select = 'tx_commerce_fe_user_id = ' . (int) $userId . \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('tt_address');
     if ($addressType > 0) {
         $select .= ' AND tx_commerce_address_type_id=' . (int) $addressType;
     } elseif (isset($this->conf['selectAddressTypes'])) {
         $select .= ' AND tx_commerce_address_type_id IN (' . $this->conf['selectAddressTypes'] . ')';
     } else {
         $this->addresses = array();
         return array();
     }
     $select .= ' AND deleted=0 AND pid=' . $this->conf['addressPid'];
     /*
      * Hook for adding select statement
      */
     $hooks = HookFactory::getHooks('Controller/AddressesController', 'getAddresses');
     foreach ($hooks as $hook) {
         if (method_exists($hook, 'editSelectStatement')) {
             $select = $hook->editSelectStatement($select, $userId, $addressType, $this);
         }
     }
     $rows = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'tt_address', $select, '', 'tx_commerce_is_main_address desc');
     $result = array();
     foreach ($rows as $address) {
         $result[$address['uid']] = \CommerceTeam\Commerce\Utility\GeneralUtility::removeXSSStripTagsArray($address);
     }
     return $result;
 }
示例#11
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 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, Product $product, $templateMarkerArray = '', $template = '')
 {
     $hooks = HookFactory::getHooks('Controller/CheckoutController', 'makeArticleView');
     $count = is_array($product->getArticleUids()) ? count($product->getArticleUids()) : 0;
     // 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;
                     }
                 }
             }
         }
         // @todo wtf need to be reworked how it was ment to be
         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 \CommerceTeam\Commerce\Domain\Model\Attribute $attribute
                          */
                         $attribute = GeneralUtility::makeInstance('CommerceTeam\\Commerce\\Domain\\Model\\Attribute', $attributeUid, $this->getFrontendController()->sys_language_uid);
                         $attribute->loadData();
                         $markerArray['###SELECT_ATTRIBUTES_TITLE###'] = $myAttribute['title'];
                         // @todo check where the attribute values are
                         $attrIcon = '';
                         $attrValue = '';
                         if (!empty($myAttribute['values'])) {
                             $v = current(array_splice(each($myAttribute['values']), 1, 1));
                             if (is_array($v)) {
                                 if (isset($v['value']) && $v['value'] != '') {
                                     $attrValue = $v['value'];
                                 }
                                 if (isset($v['icon']) && $v['icon'] != '') {
                                     $handle = $this->handle . '.';
                                     $attrIcon = $this->renderValue($v['icon'], 'IMAGE', $this->conf[$handle]['products.']['productAttributes.']['fields.']['icon.']);
                                 }
                             }
                         }
                         $markerArray['###SELECT_ATTRIBUTES_ICON###'] = $attrIcon;
                         if (isset($myAttribute['valueformat']) && $myAttribute['valueformat']) {
                             $markerArray['###SELECT_ATTRIBUTES_VALUE###'] = sprintf($myAttribute['valueformat'], $attrValue);
                         } else {
                             $markerArray['###SELECT_ATTRIBUTES_VALUE###'] = $attrValue;
                         }
                         $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['ARTICLE_SELECT_ATTRIBUTES'] = $this->cObj->stdWrap($attCode, $this->conf['singleView.']['articleAttributesSelectList.']);
                 foreach ($hooks 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 \CommerceTeam\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;
                     }
                 }
                 if (!empty($markerArray)) {
                     $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('catUid', 'showUid', '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' => 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 \CommerceTeam\Commerce\Domain\Model\Attribute $attribute
                      */
                     $attribute = GeneralUtility::makeInstance('CommerceTeam\\Commerce\\Domain\\Model\\Attribute', $attrUid, $this->getFrontendController()->sys_language_uid);
                     $attribute->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 = $attribute->isIconmode();
                     }
                     if ($iconMode) {
                         $templateAttrSelector = $templateAttrSelectorRadiobutton;
                         $templateAttrSelectorItem = $templateAttrSelectorRadiobuttonItem;
                     } else {
                         $templateAttrSelector = $templateAttrSelectorDropdown;
                         $templateAttrSelectorItem = $templateAttrSelectorDropdownItem;
                     }
                     $markerArray['###SELECT_ATTRIBUTES_TITLE###'] = $attribute->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 . ']';
                     $markerArray['###SELECT_ATTRIBUTES_UNIT###'] = $attribute->getUnit();
                     $itemsContent = '';
                     $i = 1;
                     $attributeValues = $attribute->getAllValues(true, $product);
                     /**
                      * Attribute value.
                      *
                      * @var \CommerceTeam\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###'] = '';
                         }
                         foreach ($hooks 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['ARTICLE_SELECT_ATTRIBUTES'] = $attCode;
             foreach ($hooks 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 \CommerceTeam\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 ($hooks as $hookObj) {
             if (method_exists($hookObj, 'additionalMarkerMakeArticleView')) {
                 $markerArray = (array) $hookObj->additionalMarkerMakeArticleView($markerArray, $product, $this);
             }
         }
     }
     $content = $this->cObj->substituteMarkerArray($content, $markerArray);
     return $content;
 }
示例#12
0
 /**
  * Get price gross.
  *
  * @return int price gross
  */
 public function getPriceGross()
 {
     $hooks = \CommerceTeam\Commerce\Factory\HookFactory::getHooks('Domain/Model/Article', 'getPriceGross');
     foreach ($hooks as $hook) {
         if (method_exists($hook, 'postpricegross')) {
             $hook->postpricegross($this);
         }
     }
     return $this->price_gross;
 }
示例#13
0
 /**
  * Initializes the Records by the Mountpoints.
  *
  * @param int $index Index of the current leaf
  * @param array $indices Array with parent indices
  *
  * @return array Records-Array
  */
 protected function getRecordsByMountpoints($index, array &$indices)
 {
     if (!is_numeric($index) || !is_array($indices) || !is_array($this->mountIds) || empty($this->mountIds)) {
         if (TYPO3_DLOG) {
             \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('getRecordsByMountpoints (CommerceTeam\\Commerce\\Tree\\Leaf\\MasterData)
                  gets passed invalid parameters.', COMMERCE_EXTKEY, 3);
         }
         return null;
     }
     // First prepare hook objects
     $hooks = HookFactory::getHooks('Tree/Leaf/MasterData', 'getRecordsByMountpoints');
     $positions = $this->getPositionsByIndices($index, $indices);
     // Add the subquery - this makes sure that we not only read all
     // categories that are currently visible, but also their ("hidden") children
     if ($this->useMMTable) {
         $subquery = 'SELECT uid_local FROM ' . $this->mmTable . ' WHERE uid_foreign IN (' . implode(',', array_merge($positions, $this->mountIds)) . ') OR uid_local IN (' . implode(',', $this->mountIds) . ')';
         // uids of the items that are used as parents
         // this gets all the children from the parent items
         $this->where['uid_foreign'] = $subquery;
         // uids of the items that are the parents - this gets the mounts
         $this->where['uid_local'] = $subquery;
     } else {
         $subquery = 'SELECT uid FROM ' . $this->itemTable . ' WHERE ' . $this->itemParentField . ' IN (' . implode(',', array_merge($positions, $this->mountIds)) . ') OR uid IN (' . implode(',', $this->mountIds) . ')';
         $this->where[$this->itemParentField] = $subquery;
         $this->where['uid'] = $subquery;
     }
     // Hook: getRecordsByMountpoints_preLoadRecords
     foreach ($hooks as $hookObj) {
         if (method_exists($hookObj, 'getRecordsByMountpoints_preLoadRecords')) {
             // @deprecated This method call gets removed in 5.0.0
             $hookObj->getRecordsByMountpoints_preLoadRecords($positions, $this);
         } elseif (method_exists($hookObj, 'getRecordsByMountpointsPreLoadRecords')) {
             $hookObj->getRecordsByMountpointsPreLoadRecords($positions, $this);
         }
     }
     $records = $this->loadRecords();
     // Hook: getRecordsByMountpoints_postProcessRecords
     // useful especially if you are reading your tree items from an MM table and
     // have the mountpoint 0 - that mountpoint is not in the DB and thus you won't
     // see the correct tree if you belong to that group, use this mount to create
     // the relations in the MM table to the fictional root record
     foreach ($hooks as $hookObj) {
         if (method_exists($hookObj, 'getRecordsByMountpoints_postProcessRecords')) {
             // @deprecated This method call gets removed in 5.0.0
             $hookObj->getRecordsByMountpoints_postProcessRecords($records, $this);
         } elseif (method_exists($hookObj, 'getRecordsByMountpointsPostProcessRecords')) {
             $hookObj->getRecordsByMountpointsPostProcessRecords($records, $this);
         }
     }
     return $records;
 }
示例#14
0
 /**
  * Extracts the ID and the Title from which every item we have.
  *
  * @param string $itemFormElValue Item element (tx_commerce_article_42)
  *
  * @return array
  */
 public function processItemArrayForBrowseableTreeDefault($itemFormElValue)
 {
     $items = GeneralUtility::trimExplode(',', $itemFormElValue, true);
     $itemArray = array();
     // Walk the records we have.
     foreach ($items as $value) {
         // Get parts.
         $parts = GeneralUtility::trimExplode('_', $value, true);
         $uid = array_pop($parts);
         $table = implode('_', $parts);
         // Product
         if ('tx_commerce_products' == $table) {
             /**
              * Product.
              *
              * @var \CommerceTeam\Commerce\Domain\Model\Product $product
              */
             $product = GeneralUtility::makeInstance('CommerceTeam\\Commerce\\Domain\\Model\\Product', $uid);
             $product->loadData();
             $itemArray[] = $value . '|' . $product->getTitle();
         } elseif ('tx_commerce_articles' == $table) {
             /**
              * Article.
              *
              * @var \CommerceTeam\Commerce\Domain\Model\Article $article
              */
             $article = GeneralUtility::makeInstance('CommerceTeam\\Commerce\\Domain\\Model\\Article', $uid);
             $article->loadData();
             $itemArray[] = $value . '|' . $article->getTitle();
         } elseif ('tx_commerce_categories' == $table) {
             /**
              * Category.
              *
              * @var \CommerceTeam\Commerce\Domain\Model\Category $category
              */
             $category = GeneralUtility::makeInstance('CommerceTeam\\Commerce\\Domain\\Model\\Category', $uid);
             $category->loadData();
             $itemArray[] = $value . '|' . $category->getTitle();
         } else {
             // Hook:
             $hooks = \CommerceTeam\Commerce\Factory\HookFactory::getHooks('ViewHelpers/TreelibTceforms', 'processItemArrayForBrowseableTreeDefault');
             foreach ($hooks as $hook) {
                 if (method_exists($hook, 'processDefault')) {
                     $itemArray[] = $hook->processDefault($itemFormElValue, $table, $uid);
                 }
             }
         }
     }
     return $itemArray;
 }
 /**
  * Get an instance of DataHandler.
  *
  * @param int $pid Page id
  *
  * @return \TYPO3\CMS\Core\DataHandling\DataHandler
  */
 public function getInstanceOfTceMain($pid)
 {
     $hooks = HookFactory::getHooks('Controller/CheckoutController', 'getInstanceOfTceMain');
     foreach ($hooks as $hook) {
         if (method_exists($hook, 'postTcaInit')) {
             $hook->postTcaInit();
         }
     }
     $this->initializeBackendUser();
     $this->initializeLanguage();
     /**
      * Tce Main.
      *
      * @var \TYPO3\CMS\Core\DataHandling\DataHandler
      */
     $tceMain = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
     $tceMain->bypassWorkspaceRestrictions = true;
     $tceMain->recInsertAccessCache['tx_commerce_orders'][$pid] = 1;
     $tceMain->recInsertAccessCache['tx_commerce_order_articles'][$pid] = 1;
     return $tceMain;
 }
示例#16
0
 /**
  * Invokes the HTML mailing class
  * Example for $mailconf.
  *
  * $mailconf = array(
  *     'plain' => Array (
  *         'content'=> ''              // plain content as string
  *     ),
  *     'html' => Array (
  *         'content'=> '',             // html content as string
  *         'path' => '',
  *         'useHtml' => ''             // is set mail is send as multipart
  *     ),
  *     'defaultCharset' => 'utf-8',    // your chartset
  *     'encoding' => '8-bit',          // your encoding
  *     'attach' => Array (),           // your attachment as array
  *     'alternateSubject' => '',       // is subject empty will be ste alternateSubject
  *     'recipient' => '',              // comma seperate list of recipient
  *     'recipient_copy' => '',         // bcc
  *     'fromEmail' => '',              // fromMail
  *     'fromName' => '',               // fromName
  *     'replyTo' => '',                // replyTo
  *     'priority' => '3',              // priority of your Mail
  *                                         1 = highest,
  *                                         5 = lowest,
  *                                         3 = normal
  * );
  *
  * @param array $mailconf Configuration for the mailerengine
  *
  * @return bool
  */
 public static function sendMail(array $mailconf)
 {
     $hooks = \CommerceTeam\Commerce\Factory\HookFactory::getHooks('Utility/GeneralUtility', 'sendMail');
     $additionalData = array();
     if ($mailconf['additionalData']) {
         $additionalData = $mailconf['additionalData'];
     }
     foreach ($hooks as $hookObj) {
         // this is the current hook
         if (method_exists($hookObj, 'preProcessMail')) {
             $hookObj->preProcessMail($mailconf, $additionalData);
         }
     }
     foreach ($hooks as $hookObj) {
         if (method_exists($hookObj, 'ownMailRendering')) {
             return $hookObj->ownMailRendering($mailconf, $additionalData, $hooks);
         }
     }
     // validate e-mail addesses
     $mailconf['recipient'] = self::validEmailList($mailconf['recipient']);
     if ($mailconf['recipient']) {
         $parts = preg_split('/<title>|<\\/title>/i', $mailconf['html']['content'], 3);
         if (trim($parts[1])) {
             $subject = strip_tags(trim($parts[1]));
         } elseif ($mailconf['plain']['subject']) {
             $subject = $mailconf['plain']['subject'];
         } else {
             $subject = $mailconf['alternateSubject'];
         }
         /**
          * Mail message.
          *
          * @var \TYPO3\CMS\Core\Mail\MailMessage
          */
         $message = CoreGeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
         $message->setCharset($mailconf['defaultCharset']);
         if ($mailconf['encoding'] == 'base64') {
             $message->setEncoder(\Swift_Encoding::getBase64Encoding());
         } elseif ($mailconf['encoding'] == '8bit') {
             $message->setEncoder(\Swift_Encoding::get8BitEncoding());
         }
         $message->setSubject($subject);
         $message->setTo($mailconf['recipient']);
         $message->setFrom(self::validEmailList($mailconf['fromEmail']), implode(' ', CoreGeneralUtility::trimExplode(',', $mailconf['fromName'])));
         $replyAddress = $mailconf['replyTo'] ?: $mailconf['fromEmail'];
         $replyName = implode(' ', CoreGeneralUtility::trimExplode(',', $mailconf['replyTo'] ? '' : $mailconf['fromName']));
         $message->setReplyTo($replyAddress, $replyName);
         if (isset($mailconf['recipient_copy']) && $mailconf['recipient_copy'] != '') {
             if ($mailconf['recipient_copy'] != '') {
                 $message->setCc($mailconf['recipient_copy']);
             }
         }
         $message->setReturnPath($mailconf['fromEmail']);
         $message->setPriority((int) $mailconf['priority']);
         // add Html content
         if ($mailconf['html']['useHtml'] && trim($mailconf['html']['content'])) {
             $message->addPart($mailconf['html']['content'], 'text/html');
         }
         // add plain text content
         $message->addPart($mailconf['plain']['content']);
         // add attachment
         if (is_array($mailconf['attach'])) {
             foreach ($mailconf['attach'] as $file) {
                 if ($file && file_exists($file)) {
                     $message->attach(\Swift_Attachment::fromPath($file));
                 }
             }
         }
         foreach ($hooks as $hookObj) {
             if (method_exists($hookObj, 'postProcessMail')) {
                 $message = $hookObj->postProcessMail($message, $mailconf, $additionalData);
             }
         }
         return $message->send();
     }
     return false;
 }
示例#17
0
 /**
  * Renders the product list for the basket.
  *
  * @return string HTML Content
  */
 protected function makeProductList()
 {
     $content = '';
     $hooks = HookFactory::getHooks('Controller/BasketController', 'makeProductList');
     $hookObject = HookFactory::getHook('Controller/BasketController', 'alternativePrefixId');
     if (is_object($hookObject) && method_exists($hookObject, 'singleDisplayPrefixId')) {
         $altPrefixSingle = $hookObject->singleDisplayPrefixId();
     } else {
         $altPrefixSingle = $this->prefixId;
     }
     $list = array();
     $articleTypes = GeneralUtility::trimExplode(',', $this->conf['regularArticleTypes'], true);
     foreach ($articleTypes as $articleType) {
         $list = array_merge($list, $this->basket->getArticlesByArticleTypeUidAsUidlist($articleType));
     }
     // ###########    product list    ######################
     $templateMarker[] = '###' . strtoupper($this->conf['templateMarker.']['items_listview']) . '###';
     $templateMarker[] = '###' . strtoupper($this->conf['templateMarker.']['items_listview2']) . '###';
     $changerowcount = 0;
     foreach ($list as $basketItemId) {
         // Fill marker arrays with product/article values
         /**
          * Basket item.
          *
          * @var \CommerceTeam\Commerce\Domain\Model\BasketItem $basketItem
          */
         $basketItem = $this->basket->getBasketItem($basketItemId);
         // Check stock
         $stockOk = true;
         if ($this->conf['checkStock'] == 1) {
             if (!$basketItem->getArticle()->hasStock($basketItem->getQuantity())) {
                 $stockOk = false;
             }
         }
         // Check accessible
         $access = $basketItem->getProduct()->isAccessible() && $basketItem->getArticle()->isAccessible();
         // Only if Stock is ok and Access is ok (could have been changed since
         // the article was put into the basket
         if ($stockOk && $access) {
             $safePrefix = $this->prefixId;
             $typoLinkConf = array();
             $typoLinkConf['parameter'] = $this->conf['listPid'];
             $typoLinkConf['useCacheHash'] = 1;
             $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[catUid]=' . $basketItem->getProduct()->getMasterparentCategory();
             $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[showUid]=' . $basketItem->getProduct()->getUid();
             if ($this->basketHashValue) {
                 $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[basketHashValue]=' . $this->basketHashValue;
             }
             // @todo change link building to pure TypoScript, cObj->data usage required
             $lokalTsProduct = $this->addTypoLinkToTypoScript($this->conf['fields.']['products.'], $typoLinkConf);
             $lokalTsArticle = $this->addTypoLinkToTypoScript($this->conf['fields.']['articles.'], $typoLinkConf);
             $this->prefixId = $altPrefixSingle;
             $wrapMarkerArray['###PRODUCT_LINK_DETAIL###'] = explode('|', $this->pi_list_linkSingle('|', $basketItem->getProduct()->getUid(), 1, array('catUid' => (int) $basketItem->getProduct()->getMasterparentCategory()), false, $this->conf['listPid']));
             $this->prefixId = $safePrefix;
             $productMarkerArray = $this->generateMarkerArray($basketItem->getProductAssocArray(''), $lokalTsProduct, 'product_', 'tx_commerce_products');
             $articleMarkerArray = $this->generateMarkerArray($basketItem->getArticleAssocArray(''), $lokalTsArticle, 'article_', 'tx_commerce_articles');
             $this->selectAttributes = $basketItem->getProduct()->getAttributes(array(ATTRIB_SELECTOR));
             $productMarkerArray['PRODUCT_BASKET_FOR_LISTVIEW'] = $this->makeArticleView($basketItem->getArticle(), $basketItem->getProduct());
             $templateSelector = $changerowcount % 2;
             foreach ($hooks as $hookObj) {
                 if (method_exists($hookObj, 'changeProductTemplate')) {
                     $templateMarker = $hookObj->changeProductTemplate($templateMarker, $basketItem, $this);
                 }
             }
             $template = $this->cObj->getSubpart($this->getTemplateCode(), $templateMarker[$templateSelector]);
             ++$changerowcount;
             $template = $this->cObj->substituteSubpart($template, '###PRODUCT_BASKET_FORM_SMALL###', '');
             $markerArray = array_merge($productMarkerArray, $articleMarkerArray);
             foreach ($hooks as $hookObj) {
                 if (method_exists($hookObj, 'additionalMarkerProductList')) {
                     $markerArray = $hookObj->additionalMarkerProductList($markerArray, $basketItem, $this);
                 }
             }
             $tempContent = $this->cObj->substituteMarkerArray($template, $markerArray, '###|###', 1);
             $content .= $this->substituteMarkerArrayNoCached($tempContent, $this->languageMarker, array(), $wrapMarkerArray);
         } else {
             // Remove article from basket
             $this->basket->deleteArticle($basketItem->getArticle()->getUid());
             $this->basket->storeData();
         }
     }
     return $content;
 }
示例#18
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;
 }
示例#19
0
 /**
  * Loads the records of a given query and stores it.
  *
  * @return array Records array
  */
 public function loadRecords()
 {
     $hooks = \CommerceTeam\Commerce\Factory\HookFactory::getHooks('Tree/Leaf/Data', 'loadRecords');
     foreach ($hooks as $hook) {
         if (method_exists($hook, 'addExtendedFields')) {
             $this->extendedFields .= $hook->addExtendedFields($this->itemTable, $this->extendedFields);
         }
     }
     // Add the extended fields to the select statement
     if (is_string($this->extendedFields) && '' != $this->extendedFields) {
         $select = $this->defaultFields . ',' . $this->extendedFields;
     } else {
         $select = $this->defaultFields;
     }
     // add item parent
     $select .= ',' . $this->item_parent . ' AS item_parent';
     // add the item search
     $where = '';
     if ($this->useMMTable) {
         $where .= '' == $this->whereClause ? '' : ' AND ' . $this->whereClause;
         $where .= ' AND (uid_foreign IN (' . $this->where['uid_foreign'] . ') OR uid_local IN (' . $this->where['uid_local'] . '))';
     } else {
         $where = $this->whereClause;
         $where .= '' == $this->whereClause ? '' : ' AND ';
         $where .= '(' . $this->itemParentField . ' IN (' . $this->where[$this->itemParentField] . ') OR uid IN(' . $this->where['uid'] . '))';
     }
     $database = $this->getDatabaseConnection();
     // exec the query
     if ($this->useMMTable) {
         $res = $database->exec_SELECT_mm_query($select, $this->itemTable, $this->mmTable, '', $where, '', $this->order, $this->limit);
     } else {
         $res = $database->exec_SELECTquery($select, $this->itemTable, $where, '', $this->order, $this->limit);
     }
     if ($database->sql_error()) {
         if (TYPO3_DLOG) {
             GeneralUtility::devLog('loadRecords (CommerceTeam\\Commerce\\Tree\\Leaf\\Data) could not load records.
                     Possible sql error. Empty rows returned.', COMMERCE_EXTKEY, 3);
         }
         return array();
     }
     // Will hold a record to check rights against after this loop.
     $checkRightRow = false;
     $rows = array();
     while ($row = $database->sql_fetch_assoc($res)) {
         // get the version overlay if wanted
         // store parent item
         $parentItem = $row['item_parent'];
         // unset the pseudo-field (no pseudo-fields allowed for workspaceOL)
         unset($row['item_parent']);
         BackendUtility::workspaceOL($this->itemTable, $row);
         if (!is_array($row)) {
             GeneralUtility::devLog('There was an error overlaying a record with its workspace version.', COMMERCE_EXTKEY, 3);
             continue;
         } else {
             // write the pseudo field again
             $row['item_parent'] = $parentItem;
         }
         // the row will by default start with being the last node
         $row['lastNode'] = false;
         // Set the row in the 'uid' part
         $rows['uid'][$row['uid']] = $row;
         // Set the row in the 'pid' part
         if (!isset($rows['pid'][$row['item_parent']])) {
             $rows['pid'][$row['item_parent']] = array($row);
         } else {
             // store
             $rows['pid'][$row['item_parent']][] = $row;
         }
         $checkRightRow = $checkRightRow === false ? $row : $checkRightRow;
     }
     $database->sql_free_result($res);
     // Check perms on Commerce folders.
     if ($checkRightRow !== false && !$this->checkAccess($this->itemTable, $checkRightRow)) {
         if (TYPO3_DLOG) {
             GeneralUtility::devLog('loadRecords (CommerceTeam\\Commerce\\Tree\\Leaf\\Data) could not load records because it doesn\'t
                     have permissions on the commerce folder. Return empty array.', COMMERCE_EXTKEY, 3);
         }
         return array();
     }
     // Calculate the records which are last
     if (is_array($rows['pid'])) {
         $keys = array_keys($rows['pid']);
         $l = count($keys);
         $lastIndex = null;
         for ($i = 0; $i < $l; ++$i) {
             $lastIndex = end(array_keys($rows['pid'][$keys[$i]]));
             // Change last-attribute in 'uid' and 'pid' array
             // - this now holds under which pids the record is last
             $uidItem = $rows['uid'][$rows['pid'][$keys[$i]][$lastIndex]['uid']];
             $rows['uid'][$rows['pid'][$keys[$i]][$lastIndex]['uid']]['lastNode'] = $uidItem['lastNode'] !== false ? $uidItem['lastNode'] . ',' . $keys[$i] : $keys[$i];
             $rows['pid'][$keys[$i]][$lastIndex]['lastNode'] = $keys[$i];
         }
     }
     $this->records = $rows;
     return $this->records;
 }