/**
  * 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;
 }
 /**
  * Formates the attribute value
  * concerning the sprinf formating if value is a number.
  *
  * @param array $matrix AttributeMatrix
  * @param int $attributeUid Uid of attribute
  *
  * @return string Formated Value
  */
 public function formatAttributeValue(array $matrix, $attributeUid)
 {
     $return = '';
     /*
      * Return if empty
      */
     if (!is_array($matrix)) {
         return $return;
     }
     $hookObject = HookFactory::getHook('Controller/BaseController', 'formatAttributeValue');
     $i = 0;
     $attributeValues = count($matrix[$attributeUid]['values']);
     foreach ((array) $matrix[$attributeUid]['values'] as $key => $value) {
         // Sometimes $value is the whole database array
         if (is_array($value) && isset($value['value']) && $value['value'] != '') {
             $value = $value['value'];
         }
         $return2 = $value;
         if (is_numeric($value)) {
             if ($matrix[$attributeUid]['valueformat']) {
                 $return2 = sprintf($matrix[$attributeUid]['valueformat'], $value);
             }
         }
         if (is_object($hookObject) && method_exists($hookObject, 'formatAttributeValue')) {
             $return2 = $hookObject->formatAttributeValue($key, $attributeUid, $matrix[$attributeUid]['valueuidlist'][$key], $return2, $this);
         }
         if ($attributeValues > 1) {
             $return2 = $this->cObj->stdWrap($return2, $this->conf['mutipleAttributeValueWrap.']);
         }
         if ($i > 0) {
             $return .= $this->conf['attributeLinebreakChars'];
         }
         $return .= $return2;
         ++$i;
     }
     if ($attributeValues > 1) {
         $return = $this->cObj->stdWrap($return, $this->conf['mutipleAttributeValueSetWrap.']);
     }
     return $return;
 }
Exemple #4
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;
 }
 /**
  * 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);
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
Exemple #8
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);
     }
 }
 /**
  * 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;
 }