/**
  * Flag product translations as deleted for productList.
  *
  * @param array $productList Product list
  *
  * @return void
  */
 protected function deleteProductTranslationsByProductList(array $productList)
 {
     $updateValues = array('tstamp' => $GLOBALS['EXEC_TIME'], 'deleted' => 1);
     $this->getDatabaseConnection()->exec_UPDATEquery('tx_commerce_products', 'l18n_parent IN (' . implode(',', $productList) . ')', $updateValues);
     $translatedArticles = array();
     foreach ($productList as $productId) {
         $articlesOfProduct = $this->belib->getArticlesOfProductAsUidList($productId);
         if (is_array($articlesOfProduct) && !empty($articlesOfProduct)) {
             $translatedArticles = array_merge($translatedArticles, $articlesOfProduct);
         }
     }
     $translatedArticles = array_unique($translatedArticles);
     if (!empty($translatedArticles)) {
         $this->deletePricesByArticleList($translatedArticles);
         $this->deleteArticlesByArticleList($translatedArticles);
     }
 }
 /**
  * Make query array.
  *
  * @param string $table Table
  * @param int $id Id
  * @param string $addWhere Additional where
  * @param string $fieldList Field list
  *
  * @return array
  */
 public function makeQueryArray($table, $id, $addWhere = '', $fieldList = '*')
 {
     $database = $this->getDatabaseConnection();
     $hookObjectsArr = array();
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list.inc']['makeQueryArray'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list.inc']['makeQueryArray'] as $classRef) {
             $hookObjectsArr[] = GeneralUtility::getUserObj($classRef);
         }
     }
     $tableControl = SettingsFactory::getInstance()->getTcaValue($table . '.ctrl');
     // Set ORDER BY:
     $orderBy = $tableControl['sortby'] ? 'ORDER BY ' . $table . '.' . $tableControl['sortby'] : $tableControl['default_sortby'];
     if ($this->sortField) {
         if (in_array($this->sortField, $this->makeFieldList($table, 1))) {
             $orderBy = 'ORDER BY ' . $table . '.' . $this->sortField;
             if ($this->sortRev) {
                 $orderBy .= ' DESC';
             }
         }
     }
     // Set LIMIT:
     $limit = '';
     if ($this->iLimit) {
         $limit = ($this->firstElementNumber ? $this->firstElementNumber . ',' : '') . ($this->iLimit + 1);
     }
     // Filtering on displayable pages (permissions):
     $pC = $table == 'pages' && $this->perms_clause ? ' AND ' . $this->perms_clause : '';
     if ($id > 0) {
         $pidWhere = ' AND tx_commerce_orders.pid = ' . $id;
     } else {
         \CommerceTeam\Commerce\Utility\FolderUtility::initFolders();
         // Find the right pid for the Ordersfolder
         $orderPid = current(array_unique(\CommerceTeam\Commerce\Domain\Repository\FolderRepository::initFolders('Orders', 'Commerce', 0, 'Commerce')));
         $orderFolders = \CommerceTeam\Commerce\Utility\BackendUtility::getOrderFolderSelector($orderPid, PHP_INT_MAX);
         $list = array();
         foreach ($orderFolders as $orderFolder) {
             $list[] = $orderFolder[1];
         }
         $pidWhere = ' AND tx_commerce_orders.pid in (' . implode(',', $list) . ')';
     }
     // Adding search constraints:
     $search = $this->makeSearchString($table);
     // specialhandling of search for joins
     if ($search) {
         $searchParts = GeneralUtility::trimExplode('OR', $search);
         foreach ($searchParts as &$part) {
             $part = str_replace('LOWER(', 'LOWER(' . $table . '.', $part);
             $part = str_replace('LOWER(' . $table . '.\'', 'LOWER(\'', $part);
         }
         $search = implode(' OR ', $searchParts);
     }
     $queryParts = array('SELECT' => 'DISTINCT tx_commerce_order_articles.order_id, delivery_table.order_id AS order_number,
             tx_commerce_order_articles.article_type_uid, tx_commerce_order_articles.title AS payment,
             delivery_table.title AS delivery, tx_commerce_orders.uid, tx_commerce_orders.pid,
             tx_commerce_orders.crdate, tx_commerce_orders.tstamp, tx_commerce_orders.order_id,
             tx_commerce_orders.sum_price_gross, tt_address.tx_commerce_address_type_id, tt_address.company,
             tt_address.name, tt_address.surname, tt_address.address, tt_address.zip, tt_address.city,
             tt_address.email, tt_address.phone AS phone_1, tt_address.mobile AS phone_2,
             tx_commerce_orders.cu_iso_3_uid, tx_commerce_orders.tstamp, tx_commerce_orders.uid AS articles,
             tx_commerce_orders.comment, tx_commerce_orders.internalcomment,
             tx_commerce_orders.order_type_uid AS order_type_uid_noName, static_currencies.cu_iso_3', 'FROM' => 'tx_commerce_orders, tt_address, tx_commerce_order_articles,
             tx_commerce_order_articles AS delivery_table, static_currencies', 'WHERE' => 'static_currencies.uid = tx_commerce_orders.cu_iso_3_uid
             AND delivery_table.order_id = tx_commerce_orders.order_id
             AND tx_commerce_order_articles.order_id = tx_commerce_orders.order_id
             AND tx_commerce_order_articles.article_type_uid = ' . PAYMENTARTICLETYPE . '
             AND delivery_table.article_type_uid = ' . DELIVERYARTICLETYPE . '
             AND tx_commerce_orders.deleted = 0
             AND tx_commerce_orders.cust_deliveryaddress = tt_address.uid ' . $pC . ' ' . $addWhere . $pidWhere . ' ' . $search, 'GROUPBY' => '', 'ORDERBY' => $database->stripOrderBy($orderBy), 'LIMIT' => $limit);
     // get Module TSConfig
     $moduleConfig = BackendUtility::getModTSconfig($id, 'mod.commerce_orders');
     $deliveryProductUid = $moduleConfig['properties']['deliveryProductUid'] ? $moduleConfig['properties']['deliveryProductUid'] : 0;
     if ($deliveryProductUid > 0) {
         $deliveryArticles = \CommerceTeam\Commerce\Utility\BackendUtility::getArticlesOfProductAsUidList($deliveryProductUid);
         if (!empty($deliveryArticles)) {
             $queryParts['WHERE'] .= ' AND delivery_table.article_uid IN (' . implode(',', $deliveryArticles) . ') ';
         }
     }
     $paymentProductUid = $moduleConfig['properties']['paymentProductUid'] ? $moduleConfig['properties']['paymentProductUid'] : 0;
     if ($paymentProductUid > 0) {
         $paymentArticles = \CommerceTeam\Commerce\Utility\BackendUtility::getArticlesOfProductAsUidList($paymentProductUid);
         if (!empty($paymentArticles)) {
             $queryParts['WHERE'] .= ' AND delivery_table.article_uid IN (' . implode(',', $paymentArticles) . ') ';
         }
     }
     // Apply hook as requested in http://bugs.typo3.org/view.php?id=4361
     foreach ($hookObjectsArr as $hookObj) {
         if (method_exists($hookObj, 'makeQueryArray_post')) {
             $parameter = array('orderBy' => $orderBy, 'limit' => $limit, 'pC' => $pC, 'search' => $search);
             $hookObj->makeQueryArray_post($queryParts, $this, $table, $id, $addWhere, $fieldList, $parameter);
         }
     }
     return $queryParts;
 }