/**
  * Gets all articles form database related to this product.
  *
  * @param int $uid Product uid
  *
  * @return array of Article UID
  */
 public function getArticles($uid)
 {
     $uid = (int) $uid;
     $articleUids = array();
     $return = false;
     if ($uid) {
         $localOrderField = $this->orderField;
         $hookObject = \CommerceTeam\Commerce\Factory\HookFactory::getHook('Domain/Repository/ProductRepository', 'getArticles');
         if (is_object($hookObject) && method_exists($hookObject, 'articleOrder')) {
             $localOrderField = $hookObject->articleOrder($this->orderField);
         }
         $where = 'uid_product = ' . $uid . $this->enableFields('tx_commerce_articles', $this->getFrontendController()->showHiddenRecords);
         $additionalWhere = '';
         if (is_object($hookObject) && method_exists($hookObject, 'additionalWhere')) {
             $additionalWhere = $hookObject->additionalWhere($where);
         }
         $database = $this->getDatabaseConnection();
         $result = $database->exec_SELECTquery('uid', 'tx_commerce_articles', $where . ' ' . $additionalWhere, '', $localOrderField);
         if ($database->sql_num_rows($result)) {
             while ($data = $database->sql_fetch_assoc($result)) {
                 $articleUids[] = $data['uid'];
             }
             $database->sql_free_result($result);
             $return = $articleUids;
         } else {
             $this->error('exec_SELECTquery("uid", "tx_commerce_articles", "uid_product = ' . $uid . '"); returns no Result');
         }
     }
     return $return;
 }
 /**
  * Gets all prices form database related to this product.
  *
  * @param int $uid Article uid
  * @param int $count Number of Articles for price_scale_amount, default 1
  * @param string $orderField Order field
  *
  * @return array of Price UID
  */
 public function getPrices($uid, $count = 1, $orderField = 'price_net')
 {
     $uid = (int) $uid;
     $count = (int) $count;
     $additionalWhere = '';
     $hookObject = \CommerceTeam\Commerce\Factory\HookFactory::getHook('Domain/Repository/ArticleRepository', 'getPrices');
     if (is_object($hookObject) && method_exists($hookObject, 'priceOrder')) {
         $orderField = $hookObject->priceOrder($orderField);
     }
     if (is_object($hookObject) && method_exists($hookObject, 'additionalPriceWhere')) {
         $additionalWhere = $hookObject->additionalPriceWhere($this, $uid);
     }
     if ($uid > 0) {
         $priceUidList = array();
         $proofSql = $this->enableFields('tx_commerce_article_prices', $this->getFrontendController()->showHiddenRecords);
         $database = $this->getDatabaseConnection();
         $result = $database->exec_SELECTquery('uid,fe_group', 'tx_commerce_article_prices', 'uid_article = ' . $uid . ' AND price_scale_amount_start <= ' . $count . ' AND price_scale_amount_end >= ' . $count . $proofSql . $additionalWhere, '', $orderField);
         if ($database->sql_num_rows($result)) {
             while ($data = $database->sql_fetch_assoc($result)) {
                 $feGroups = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $data['fe_group'], true);
                 if (!empty($feGroups)) {
                     foreach ($feGroups as $feGroup) {
                         $priceUidList[(string) $feGroup][] = $data['uid'];
                     }
                 } else {
                     $priceUidList[(string) $data['fe_group']][] = $data['uid'];
                 }
             }
             $database->sql_free_result($result);
             return $priceUidList;
         } else {
             $this->error('exec_SELECTquery(\'uid\', \'tx_commerce_article_prices\', \'uid_article = \' . ' . $uid . '); returns no Result');
             return false;
         }
     }
     return false;
 }
Beispiel #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;
 }
 /**
  * This Method generates a Mailcontent with $this->templatecode
  * as Mailtemplate. First Line in Template represents the Mailsubject.
  * The other required data can be queried from database by Parameters.
  *
  * @param string $orderUid The uid for the specified Order
  * @param array $orderData Contaning additional data like Customer UIDs.
  * @param string $templateCode Template code
  *
  * @return string The built Mailcontent
  */
 protected function generateMail($orderUid, array $orderData, $templateCode)
 {
     $database = $this->getDatabaseConnection();
     $markerArray = array('###ORDERID###' => $orderUid);
     $content = $this->cObj->getSubpart($templateCode, '###MAILCONTENT###');
     // Get The addresses
     $deliveryAdress = '';
     if ($orderData['cust_deliveryaddress']) {
         $data = $database->exec_SELECTgetSingleRow('*', 'tt_address', 'uid = ' . (int) $orderData['cust_deliveryaddress']);
         if (is_array($data)) {
             $deliveryAdress = $this->makeAdressView($data, '###DELIVERY_ADDRESS###', $content);
         }
     }
     $content = $this->cObj->substituteSubpart($content, '###DELIVERY_ADDRESS###', $deliveryAdress);
     $billingAdress = '';
     if ($orderData['cust_invoice']) {
         $data = $database->exec_SELECTgetSingleRow('*', 'tt_address', 'uid = ' . (int) $orderData['cust_invoice']);
         if (is_array($data)) {
             $billingAdress = $this->makeAdressView($data, '###BILLING_ADDRESS###', $content);
             $this->customermailadress = $data['email'];
         }
     }
     $content = $this->cObj->substituteSubpart($content, '###BILLING_ADDRESS###', $billingAdress);
     $content = $this->cObj->substituteSubpart($content, '###INVOICE_VIEW###', '');
     /*
      * Hook for processing Marker Array
      */
     $hookObject = \CommerceTeam\Commerce\Factory\HookFactory::getHook('Hook/OrdermailHooks', 'generateMail');
     if (is_object($hookObject) && method_exists($hookObject, 'processMarker')) {
         $markerArray = $hookObject->processMarker($markerArray, $this);
     }
     $content = $this->cObj->substituteMarkerArray($content, $markerArray);
     // Since The first line of the mail is the Subject, trim the template
     return ltrim($content);
 }
Beispiel #5
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;
 }
Beispiel #6
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;
 }
 /**
  * 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;
 }
Beispiel #8
0
 /**
  * Makes a set of  ItemMenu product list  of a category.
  *
  * @param int $pageUid Page uid
  * @param string $mainTable Main table
  * @param string $mmTable Relation table
  * @param int $categoryUid Category Uid
  * @param int $mDepth Depth
  * @param int $path Path
  * @param bool $manufacturerUid Manufacturer uid
  *
  * @return array array to be processed by HMENU
  */
 public function makeSubChildArrayPostRender($pageUid, $mainTable, $mmTable, $categoryUid, $mDepth = 1, $path = 0, $manufacturerUid = false)
 {
     $database = $this->getDatabaseConnection();
     $treeList = array();
     $sqlManufacturer = '';
     if (is_numeric($manufacturerUid)) {
         $sqlManufacturer = ' AND ' . $mainTable . '.manufacturer_uid = ' . (int) $manufacturerUid;
     }
     $sql = 'SELECT ' . $mmTable . '.* FROM ' . $mmTable . ',' . $mainTable . ' WHERE ' . $mainTable . '.deleted = 0 AND ' . $mainTable . '.uid = ' . $mmTable . '.uid_local AND ' . $mmTable . '.uid_local <> "" AND ' . $mmTable . '.uid_foreign = ' . (int) $categoryUid . $sqlManufacturer;
     $sorting = ' ORDER BY ' . $mainTable . '.sorting ';
     /*
      * Add some hooks for custom sorting
      */
     $hookObject = \CommerceTeam\Commerce\Factory\HookFactory::getHook('ViewHelpers/Navigation', 'makeSubChildArrayPostRender');
     if (is_object($hookObject) && method_exists($hookObject, 'sortingOrder')) {
         $sorting = $hookObject->sortingOrder($sorting, $categoryUid, $mainTable, $mmTable, $mDepth, $path, $this);
     }
     $sql .= $sorting;
     $res = $database->sql_query($sql);
     while ($row = $database->sql_fetch_assoc($res)) {
         $nodeArray = array();
         $dataRow = $this->getDataRow($row['uid_local'], $mainTable);
         if ($dataRow['deleted'] == '0') {
             $nodeArray['CommerceMenu'] = true;
             $nodeArray['pid'] = $dataRow['pid'];
             $nodeArray['uid'] = $pageUid;
             $nodeArray['parent_id'] = $categoryUid;
             $nodeArray['hidden'] = $dataRow['hidden'];
             $nodeArray['title'] = htmlspecialchars(strip_tags($dataRow['title']));
             $nodeArray['nav_title'] = htmlspecialchars(strip_tags($dataRow['navtitle']));
             // Add custom Fields to array
             foreach ($this->nodeArrayAdditionalFields as $field) {
                 $nodeArray[$field] = htmlspecialchars(strip_tags($dataRow[$field]));
             }
             /*
              * Add Pages Overlay to Array, if sys language uid set
              */
             if ($this->getFrontendController()->sys_language_uid) {
                 $nodeArray['_PAGES_OVERLAY'] = htmlspecialchars(strip_tags($dataRow['title']));
             }
             $nodeArray['depth'] = $mDepth;
             $nodeArray['leaf'] = 1;
             $nodeArray['table'] = $mainTable;
             if ($path != 0) {
                 $nodeArray['path'] = $dataRow['uid'] . ',' . $path;
             } else {
                 $nodeArray['path'] = $dataRow['uid'];
             }
             // Set default
             $nodeArray['ITEM_STATE'] = 'NO';
             if ($nodeArray['leaf'] == 1) {
                 $nodeArray['_ADD_GETVARS'] = $this->separator . $this->prefixId . '[catUid]=' . $categoryUid;
             } else {
                 $nodeArray['_ADD_GETVARS'] = $this->separator . $this->prefixId . '[catUid]=' . $row['uid_foreign'];
             }
             $nodeArray['_ADD_GETVARS'] .= $this->separator . $this->prefixId . '[showUid]=' . $dataRow['uid'];
             if ($this->useRootlineInformationToUrl == 1) {
                 $nodeArray['_ADD_GETVARS'] .= $this->separator . $this->prefixId . '[mDepth]=' . $mDepth . $this->separator . $this->prefixId . '[path]=' . $nodeArray['path'];
             }
             if ($this->gpVars['basketHashValue']) {
                 $nodeArray['_ADD_GETVARS'] .= $this->separator . $this->prefixId . '[basketHashValue]=' . $this->gpVars['basketHashValue'];
             }
             $nodeArray['_ADD_GETVARS'] .= $this->separator . 'cHash=' . $this->generateChash($nodeArray['_ADD_GETVARS'] . $this->getFrontendController()->linkVars);
             if ($this->gpVars['manufacturer']) {
                 $nodeArray['_ADD_GETVARS'] .= '&' . $this->prefixId . '[manufacturer]=' . $this->gpVars['manufacturer'];
             }
             // if this product is displayed set to CUR
             if ($mainTable == 'tx_commerce_products' && $dataRow['uid'] == $this->showUid) {
                 $nodeArray['ITEM_STATE'] = 'CUR';
             }
             $treeList[$row['uid_local']] = $nodeArray;
         }
     }
     return $treeList;
 }
 /**
  * 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;
 }
 /**
  * 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');
     }
 }
 /**
  * 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;
 }
Beispiel #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;
 }
Beispiel #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;
 }
 /**
  * Gets child products from this category.
  *
  * @param int $uid Product uid
  * @param int $languageUid Language uid
  *
  * @return array Array of child products UIDs
  */
 public function getChildProducts($uid, $languageUid = -1)
 {
     if (empty($uid) || !\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($uid)) {
         return array();
     }
     if ($languageUid == -1) {
         $languageUid = 0;
     }
     $this->uid = $uid;
     $frontend = $this->getFrontendController();
     if ($languageUid == 0 && $frontend->sys_language_uid) {
         $languageUid = $frontend->sys_language_uid;
     }
     $this->lang_uid = $languageUid;
     $localOrderField = $this->productOrderField;
     $hookObject = \CommerceTeam\Commerce\Factory\HookFactory::getHook('Domain/Repository/CategoryRepository', 'getChildProducts');
     if (is_object($hookObject) && method_exists($hookObject, 'productOrder')) {
         $localOrderField = $hookObject->productOrder($localOrderField, $this);
     }
     $whereClause = 'mm.uid_foreign = ' . (int) $uid;
     if (is_object($GLOBALS['TSFE']->sys_page)) {
         $whereClause .= $this->enableFields('tx_commerce_products', $GLOBALS['TSFE']->showHiddenRecords);
         $whereClause .= $this->enableFields('tx_commerce_articles', $GLOBALS['TSFE']->showHiddenRecords, 'a');
         $whereClause .= $this->enableFields('tx_commerce_article_prices', $GLOBALS['TSFE']->showHiddenRecords, 'ap');
     }
     // Versioning - no deleted or versioned records, nor live placeholders
     $whereClause .= ' AND tx_commerce_products.sys_language_uid = 0 AND tx_commerce_products.deleted = 0 AND tx_commerce_products.pid != -1 AND tx_commerce_products.t3ver_state != 1';
     $queryArray = array('SELECT' => 'DISTINCT(tx_commerce_products.uid)', 'FROM' => 'tx_commerce_products
          INNER JOIN tx_commerce_products_categories_mm AS mm ON tx_commerce_products.uid = mm.uid_local
          INNER JOIN tx_commerce_articles AS a ON tx_commerce_products.uid = a.uid_product
          INNER JOIN tx_commerce_article_prices AS ap ON a.uid = ap.uid_article', 'WHERE' => $whereClause, 'GROUPBY' => '', 'ORDERBY' => $localOrderField, 'LIMIT' => '');
     if (is_object($hookObject) && method_exists($hookObject, 'productQueryPreHook')) {
         $queryArray = $hookObject->productQueryPreHook($queryArray, $this);
     }
     $database = $this->getDatabaseConnection();
     $return = array();
     $result = $database->exec_SELECT_queryArray($queryArray);
     if ($result !== false) {
         while ($row = $database->sql_fetch_assoc($result)) {
             if ($languageUid == 0) {
                 $return[] = (int) $row['uid'];
             } else {
                 // Check if a localized product is available
                 // @todo Check if this is correct in multi tree sites
                 $lresult = $database->exec_SELECTquery('uid', 'tx_commerce_products', 'l18n_parent = ' . (int) $row['uid'] . ' AND sys_language_uid = ' . $this->lang_uid . $this->enableFields('tx_commerce_products', $frontend->showHiddenRecords));
                 if ($database->sql_num_rows($lresult)) {
                     $return[] = (int) $row['uid'];
                 }
             }
         }
         $database->sql_free_result($result);
         if (is_object($hookObject) && method_exists($hookObject, 'productQueryPostHook')) {
             $return = $hookObject->productQueryPostHook($return, $this);
         }
     }
     return $return;
 }
Beispiel #15
0
 /**
  * Calculates the Net deliverycost for this article
  * Called by $this->loadData().
  */
 public function calculateDeliveryCosts()
 {
     /*
      * Just one Hook as there is no sense for more than one delievery cost
      */
     $hookObject = HookFactory::getHook('Domain/Model/Article', 'calculateDeliveryCosts');
     if (is_object($hookObject) && method_exists($hookObject, 'calculateDeliveryCostNet')) {
         $hookObject->calculateDeliveryCostNet($this->deliveryCostNet, $this);
     }
     if (is_object($hookObject) && method_exists($hookObject, 'calculateDeliveryCostGross')) {
         $hookObject->calculateDeliveryCostGross($this->deliveryCostGross, $this);
     }
 }
 /**
  * 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);
         }
     }
 }
Beispiel #17
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;
 }
Beispiel #18
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();
     }
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * Creates an article in the database and all needed releations to attributes
  * and values. It also creates a new prices and assignes it to the new article.
  *
  * @param array $parameter Parameter
  * @param string $key The key in the POST var array
  *
  * @return int Returns the new articleUid if success
  */
 protected function createArticle(array $parameter, $key)
 {
     $database = $this->getDatabaseConnection();
     // get the create data
     $data = GeneralUtility::_GP('createData');
     $hash = '';
     if (is_array($data)) {
         $data = $data[$key];
         $hash = md5($data);
         $data = unserialize($data);
     }
     $database->debugOutput = 1;
     $database->store_lastBuiltQuery = true;
     // get the highest sorting
     $sorting = $database->exec_SELECTgetSingleRow('uid, sorting', 'tx_commerce_articles', 'uid_product = ' . $this->uid, '', 'sorting DESC', 1);
     $sorting = is_array($sorting) && isset($sorting['sorting']) ? $sorting['sorting'] + 20 : 0;
     // create article data array
     $articleData = array('pid' => $this->pid, 'crdate' => time(), 'title' => strip_tags($this->createArticleTitleFromAttributes($parameter, (array) $data)), 'uid_product' => (int) $this->uid, 'sorting' => $sorting, 'article_attributes' => count($this->attributes['rest']) + count($data), 'attribute_hash' => $hash, 'article_type_uid' => 1);
     $temp = CoreBackendUtility::getModTSconfig($this->pid, 'mod.commerce.category');
     if ($temp) {
         $moduleConfig = CoreBackendUtility::implodeTSParams($temp['properties']);
         $defaultTax = (int) $moduleConfig['defaultTaxValue'];
         if ($defaultTax > 0) {
             $articleData['tax'] = $defaultTax;
         }
     }
     $hookObject = \CommerceTeam\Commerce\Factory\HookFactory::getHook('Utility/ArticleCreatorUtility', 'createArticle');
     if (method_exists($hookObject, 'preinsert')) {
         $hookObject->preinsert($articleData);
     }
     // create the article
     $database->exec_INSERTquery('tx_commerce_articles', $articleData);
     $articleUid = $database->sql_insert_id();
     // create a new price that is assigned to the new article
     $database->exec_INSERTquery('tx_commerce_article_prices', array('pid' => $this->pid, 'crdate' => time(), 'tstamp' => time(), 'uid_article' => $articleUid));
     // now write all relations between article and attributes into the database
     $relationBaseData = array('uid_local' => $articleUid);
     $createdArticleRelations = array();
     $relationCreateData = $relationBaseData;
     $productsAttributesRes = $database->exec_SELECTquery('sorting, uid_local, uid_foreign', 'tx_commerce_products_attributes_mm', 'uid_local = ' . (int) $this->uid);
     $attributesSorting = array();
     while ($productsAttributes = $database->sql_fetch_assoc($productsAttributesRes)) {
         $attributesSorting[$productsAttributes['uid_foreign']] = $productsAttributes['sorting'];
     }
     if (is_array($data)) {
         foreach ($data as $selectAttributeUid => $selectAttributeValueUid) {
             $relationCreateData['uid_foreign'] = $selectAttributeUid;
             $relationCreateData['uid_valuelist'] = $selectAttributeValueUid;
             $relationCreateData['sorting'] = $attributesSorting[$selectAttributeUid];
             $createdArticleRelations[] = $relationCreateData;
             $database->exec_INSERTquery('tx_commerce_articles_article_attributes_mm', $relationCreateData);
         }
     }
     if (is_array($this->attributes['rest'])) {
         foreach ($this->attributes['rest'] as $attribute) {
             if (empty($attribute['attributeData']['uid'])) {
                 continue;
             }
             $relationCreateData = $relationBaseData;
             $relationCreateData['sorting'] = $attribute['sorting'];
             $relationCreateData['uid_foreign'] = $attribute['attributeData']['uid'];
             if ($attribute['uid_correlationtype'] == 4) {
                 $relationCreateData['uid_product'] = $this->uid;
             }
             $relationCreateData['default_value'] = '';
             $relationCreateData['value_char'] = '';
             $relationCreateData['uid_valuelist'] = $attribute['uid_valuelist'];
             if (!$this->belib->isNumber($attribute['default_value'])) {
                 $relationCreateData['default_value'] = $attribute['default_value'];
             } else {
                 $relationCreateData['value_char'] = $attribute['default_value'];
             }
             $createdArticleRelations[] = $relationCreateData;
             $database->exec_INSERTquery('tx_commerce_articles_article_attributes_mm', $relationCreateData);
         }
     }
     // update the article
     // we have to write the xml datastructure for this article. This is needed
     // to have the correct values inserted on first call of the article.
     $this->belib->updateArticleXML($createdArticleRelations, false, $articleUid);
     // Now check, if the parent Product is already lokalised, so creat Article in
     // the lokalised version Select from Database different localisations
     $resOricArticle = $database->exec_SELECTquery('*', 'tx_commerce_articles', 'uid = ' . (int) $articleUid . ' AND deleted = 0');
     $origArticle = $database->sql_fetch_assoc($resOricArticle);
     $result = $database->exec_SELECTquery('*', 'tx_commerce_products', 'l18n_parent = ' . (int) $this->uid . ' AND deleted = 0');
     if ($database->sql_num_rows($result)) {
         // Only if there are products
         while ($localizedProducts = $database->sql_fetch_assoc($result)) {
             // walk thru and create articles
             $destLanguage = $localizedProducts['sys_language_uid'];
             // get the highest sorting
             $langIsoCode = CoreBackendUtility::getRecord('sys_language', (int) $destLanguage, 'static_lang_isocode');
             $langIdent = CoreBackendUtility::getRecord('static_languages', (int) $langIsoCode['static_lang_isocode'], 'lg_typo3');
             $langIdent = strtoupper($langIdent['lg_typo3']);
             // create article data array
             $articleData = array('pid' => $this->pid, 'crdate' => time(), 'title' => $parameter['title'], 'uid_product' => $localizedProducts['uid'], 'sys_language_uid' => $localizedProducts['sys_language_uid'], 'l18n_parent' => $articleUid, 'sorting' => $sorting['sorting'] + 20, 'article_attributes' => count($this->attributes['rest']) + count($data), 'attribute_hash' => $hash, 'article_type_uid' => 1, 'attributesedit' => $this->belib->buildLocalisedAttributeValues($origArticle['attributesedit'], $langIdent));
             // create the article
             $database->exec_INSERTquery('tx_commerce_articles', $articleData);
             $localizedArticleUid = $database->sql_insert_id();
             // get all relations to attributes from the old article and copy them
             // to new article
             $res = $database->exec_SELECTquery('*', 'tx_commerce_articles_article_attributes_mm', 'uid_local = ' . (int) $origArticle['uid'] . ' AND uid_valuelist = 0');
             while ($origRelation = $database->sql_fetch_assoc($res)) {
                 $origRelation['uid_local'] = $localizedArticleUid;
                 $database->exec_INSERTquery('tx_commerce_articles_article_attributes_mm', $origRelation);
             }
             $this->belib->updateArticleXML($createdArticleRelations, false, $localizedArticleUid);
         }
     }
     return $articleUid;
 }