public static function getNewProducts($id_lang, $pageNumber = 0, $nbProducts = 10, $count = false, $orderBy = NULL, $orderWay = NULL, Context $context = null) { global $cookie; if ($context == null) { $context = Context::getContext(); } $agile_sql_parts = AgileSellerManager::getAdditionalSqlForProducts("p", true); if (Module::isInstalled('agilesellerlistoptions') && empty($orderby)) { $orderby = 'position2'; } if (empty($agile_sql_parts['joins']) or empty($agile_sql_parts['wheres'])) { parent::getNewProducts($id_lang, $pageNumber, $nbProducts, $count, $orderBy, $orderWay); } $front = true; if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) { $front = false; } if ($pageNumber < 0) { $pageNumber = 0; } if ($nbProducts < 1) { $nbProducts = 10; } if (empty($orderBy) || $orderBy == 'position') { $orderBy = 'date_add'; } if (empty($orderWay)) { $orderWay = 'DESC'; } if ($orderBy == 'id_product' or $orderBy == 'price' or $orderBy == 'date_add') { $orderByPrefix = 'p'; } elseif ($orderBy == 'name') { $orderByPrefix = 'pl'; } if (!Validate::isOrderBy($orderBy) or !Validate::isOrderWay($orderWay)) { die(Tools::displayError()); } $groups = FrontController::getCurrentCustomerGroups(); $sqlGroups = count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1'; if ($count) { $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' SELECT COUNT(p.`id_product`) AS nb FROM `' . _DB_PREFIX_ . 'product` p ' . Shop::addSqlAssociation('product', 'p') . ' ' . $agile_sql_parts['joins'] . ' WHERE product_shop.`active` = 1 AND DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL ' . (Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20) . ' DAY)) > 0 ' . $agile_sql_parts['wheres'] . ' ' . ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') . ' AND p.`id_product` IN ( SELECT cp.`id_product` FROM `' . _DB_PREFIX_ . 'category_group` cg LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_category` = cg.`id_category`) WHERE cg.`id_group` ' . $sqlGroups . ' )'); return (int) $result['nb']; } $sql = ' SELECT p.*, pl.`description`,pl.`country`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`, p.`upc`, i.`id_image`, il.`legend`, t.`rate`, m.`name` AS manufacturer_name, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL ' . (Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20) . ' DAY)) > 0 AS new, (p.`price` * ((100 + (t.`rate`))/100)) AS orderprice, pa.id_product_attribute ' . $agile_sql_parts['selects'] . ' FROM `' . _DB_PREFIX_ . 'product` p ' . Shop::addSqlAssociation('product', 'p') . ' ' . $agile_sql_parts['joins'] . ' LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . (int) $id_lang . ') LEFT OUTER JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND `default_on` = 1) LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ') LEFT JOIN `' . _DB_PREFIX_ . 'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = ' . (_PS_VERSION_ > '1.5' ? (int) Context::getContext()->country->id : (int) Country::getDefaultCountryId()) . ' AND tr.`id_state` = 0) LEFT JOIN `' . _DB_PREFIX_ . 'tax` t ON (t.`id_tax` = tr.`id_tax`) LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) WHERE product_shop.`active` = 1 ' . $agile_sql_parts['wheres'] . ' AND DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL ' . (Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20) . ' DAY)) > 0 ' . ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') . ' AND p.`id_product` IN ( SELECT cp.`id_product` FROM `' . _DB_PREFIX_ . 'category_group` cg LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_category` = cg.`id_category`) WHERE cg.`id_group` ' . $sqlGroups . ' ) ORDER BY ' . (isset($orderByPrefix) ? pSQL($orderByPrefix) . '.' : '') . '`' . pSQL($orderBy) . '` ' . pSQL($orderWay) . ' LIMIT ' . (int) ($pageNumber * $nbProducts) . ', ' . (int) $nbProducts; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql); if ($orderBy == 'price') { Tools::orderbyPrice($result, $orderWay); } if (!$result) { return false; } $productsIds = array(); foreach ($result as $row) { $productsIds[] = $row['id_product']; } $finalResults = Product::getProductsProperties((int) $id_lang, $result); $finalResults = AgileSellerManager::prepareSellerRattingInfo($finalResults); // die('<pre>' . print_r($finalResults, true)); /*foreach($finalResults as $k => $v) { $country = $v['country']; $flagId = Country::getIdByName(1, $country); $finalResults[$k]['img_exist'] = file_exists(_PS_ROOT_DIR_ . DS . 'flag' . DS . 'mini'. DS . $flagId . '.jpg')? 1 : 0; $finalResults[$k]['img_name'] = $flagId . '.jpg'; }*/ foreach ($finalResults as $key => $value) { $seller_id = $value['id_seller']; $flagIds = self::getFlagsId($seller_id); foreach ($flagIds as $k => $flgId) { $finalResults[$key]['img_exist'][$k] = file_exists(_PS_ROOT_DIR_ . DS . 'flag' . DS . 'mini' . DS . $flgId . '.jpg') ? 1 : 0; $finalResults[$key]['img_name'][$k] = $flgId . '.jpg'; } } return $finalResults; }