if ($oldsearch) { if ($this->ms['MODULES']['REGULAR_SEARCH_MODE'] == '%keyword') { // do normal indexed search $filter[] = "(" . $tbl . "products_name like '%" . addslashes($this->get['skeyword']) . "')"; } else { if ($this->ms['MODULES']['REGULAR_SEARCH_MODE'] == 'keyword%') { // do normal indexed search $filter[] = "(" . $tbl . "products_name like '" . addslashes($this->get['skeyword']) . "%')"; } else { // do normal indexed search $filter[] = "(" . $tbl . "products_name like '%" . addslashes($this->get['skeyword']) . "%')"; } } } else { // do fulltext search $tmpstr = addslashes(mslib_befe::ms_implode(', ', $array, '"', '+', true)); $select[] = "MATCH (" . $tbl . "products_name) AGAINST ('" . $tmpstr . "' in boolean mode) AS score"; $where[] = "MATCH (" . $tbl . "products_name) AGAINST ('" . $tmpstr . "' in boolean mode)"; $orderby[] = 'score desc'; } } else { $orderby[] = 'rand()'; } // filter by products name eof if ($this->ms['MODULES']['FLAT_DATABASE']) { $orderby[] = 'final_price_difference desc'; } else { $orderby[] = 'p.products_date_available desc'; } if ($this->ajax_content) { $limit = 4;
public function getProductRelativesBox($product, $type = 'relatives', $limit = 20) { $product['products_id'] = (int) $product['products_id']; $product['categories_id'] = (int) $product['categories_id']; $filter = array(); $having = array(); $match = array(); $orderby = array(); $where = array(); $select = array(); if ($this->ms['MODULES']['SHOW_PRODUCTS_WITH_IMAGE_FIRST']) { if (!$this->ms['MODULES']['FLAT_DATABASE']) { $prefix = 'p.'; } else { $prefix = 'pf.'; } $tmp_orderby = array(); $tmp_orderby[] = $prefix . 'contains_image desc'; $tmp_orderby = array_merge($tmp_orderby, $orderby); $orderby[] = $tmp_orderby; } switch ($type) { case 'customers_also_bought': $product_ids = array(); $orders = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('orders_id', 'tx_multishop_orders_products', "products_id = '" . $product['products_id'] . "'", 'orders_id'); foreach ($orders as $order) { $data = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('products_id', 'tx_multishop_orders_products', "orders_id = '" . $order['orders_id'] . "' and products_id !='" . $product['products_id'] . "'", '', '', $limit); if (is_array($data) && count($data)) { foreach ($data as $item) { $product_ids[] = $item['products_id']; if (count($product_ids) == $limit) { break; } } if (count($product_ids) == $limit) { break; } } } if (count($product_ids)) { $product_ids = array_unique($product_ids); } else { return false; } if (!$this->ms['MODULES']['FLAT_DATABASE']) { $prefix = 'p.'; } else { $prefix = ''; } $filter[] = $prefix . "products_id IN (" . implode(',', $product_ids) . ")"; break; case 'relatives': //$GLOBALS['TYPO3_DB']->store_lastBuiltQuery=1; if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('multishop_product_variations')) { $limit = ''; } $data = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('products_id,relative_product_id', 'tx_multishop_products_to_relative_products', "(products_id = '" . $product['products_id'] . "' or relative_product_id = '" . $product['products_id'] . "') and relation_types='cross-sell'", '', '', $limit); //echo $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery; //die(); $product_ids = array(); if (is_array($data) && count($data)) { foreach ($data as $item) { if ($product['products_id'] == $item['relative_product_id']) { $product_ids[] = $item['products_id']; } else { $product_ids[] = $item['relative_product_id']; } if (count($product_ids) == $limit) { break; } } } if (!count($product_ids)) { return false; } if (!$this->ms['MODULES']['FLAT_DATABASE']) { $prefix = 'p.'; } else { $prefix = ''; } $filter[] = $prefix . "products_id IN (" . implode(',', $product_ids) . ")"; break; case 'categories_id': if ($this->ms['MODULES']['FLAT_DATABASE']) { $filter[] = 'pf.categories_id=' . $product['categories_id']; } else { $filter[] = 'c.categories_id=' . $product['categories_id']; } break; case 'specials': if ($this->ms['MODULES']['FLAT_DATABASE']) { $filter[] = 'pf.sstatus=1'; } else { $filter[] = 's.status=1'; } break; case 'products_model': if (strlen($product['products_model']) > 2) { $array = explode(" ", $product['products_model']); $total = count($array); $oldsearch = 0; foreach ($array as $item) { if (strlen($item) < 2) { $oldsearch = 1; break; } } if ($this->ms['MODULES']['FLAT_DATABASE']) { $tbl = 'pf.'; } else { $tbl = 'p.'; } if ($oldsearch) { // do normal indexed search $filter[] = "(" . $tbl . "products_model like '" . addslashes($product['products_model']) . "%')"; } else { // do fulltext search $tmpstr = addslashes(mslib_befe::ms_implode(', ', $array, '"', '+', true)); $select[] = "MATCH (" . $tbl . "products_model) AGAINST ('" . $tmpstr . "' in boolean mode) AS score"; $where[] = "MATCH (" . $tbl . "products_model) AGAINST ('" . $tmpstr . "' in boolean mode)"; $orderby[] = 'score desc'; } } break; } if (is_numeric($this->get['manufacturers_id'])) { if ($this->ms['MODULES']['FLAT_DATABASE']) { $tbl = 'pf.'; } else { $tbl = 'p.'; } $filter[] = "(" . $tbl . "manufacturers_id='" . addslashes($this->get['manufacturers_id']) . "')"; } if ($this->ms['MODULES']['FLAT_DATABASE']) { $tbl = 'pf.'; if ($this->ms['MODULES']['FLAT_DATABASE_ORDER_PRODUCTS_BY_SORT_ORDER']) { $orderby[] = 'pf.sort_order'; } } else { $tbl = 'p.'; } $filter[] = "(" . $tbl . "products_id <> '" . $product['products_id'] . "')"; if ($this->ms['MODULES']['FLAT_DATABASE'] and count($having)) { $filter[] = $having[0]; unset($having); } $offset = 0; // custom hook that can be controlled by third-party plugin if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/scripts/front_pages/products_relatives.php']['productsRelativesQueryPreHook'])) { $params = array('filter' => &$filter, 'offset' => &$offset, 'limit' => &$limit, 'orderby' => &$orderby, 'having' => &$having, 'select' => &$select, 'where' => &$where); foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/scripts/front_pages/products_relatives.php']['productsRelativesQueryPreHook'] as $funcRef) { \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this); } } // custom hook that can be controlled by third-party plugin eof $pageset = mslib_fe::getProductsPageSet($filter, $offset, $limit, $orderby, $having, $select, $where, 0, array(), array(), 'products_relatives'); $products = $pageset['products']; if ($pageset['total_rows'] > 0) { $content = ''; if ($pageset['total_rows']) { if (!$this->ms['MODULES']['PRODUCTS_RELATIVES_TYPE']) { $this->ms['MODULES']['PRODUCTS_RELATIVES_TYPE'] = 'default'; } if (strstr($this->ms['MODULES']['PRODUCTS_RELATIVES_TYPE'], "..")) { die('error in PRODUCTS_RELATIVES_TYPE value'); } else { if (strstr($this->ms['MODULES']['PRODUCTS_RELATIVES_TYPE'], "/")) { require $this->DOCUMENT_ROOT . $this->ms['MODULES']['PRODUCTS_RELATIVES_TYPE'] . '.php'; } else { require \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('multishop') . 'scripts/front_pages/includes/products_relatives/' . $this->ms['MODULES']['PRODUCTS_RELATIVES_TYPE'] . '.php'; } } } } return $content; }