nshox Posted February 15, 2016 Share Posted February 15, 2016 Somebody please lay out the code for SearchController and ManufacturerController 1 Link to comment Share on other sites More sharing options...
cmd.developer.team Posted February 24, 2016 Share Posted February 24, 2016 Hi everybody. I implemented the solution on Prestashop 1.6.1.1 and it works very well. The problem I have is that it doesn't show attributes when I use the page number to move or when I use "previous" - "next" or "show all". Further, attributes doesn't appear when I select an attribute with the layered navigation box. Can anybody help me solve this? Many thanks. Matteo Link to comment Share on other sites More sharing options...
cmd.developer.team Posted February 24, 2016 Share Posted February 24, 2016 Somebody please lay out the code for SearchController and ManufacturerController we have solved SearchController.php doing this modification: at the end of the public function init() (at raw 50) we added: public function getProductAttributeCombinations($products) { $combinations = array(); foreach ($products as $product) { // load product object $product = new Product ($product['id_product'], $this->context->language->id); // get the product combinations data // create array combinations with key = id_product $combinations[$product->id] = $product->getAttributeCombinations($this->context->language->id); } return $combinations; } Further to this we added few raws of code inside the public function initContent() - I'm copying all the code; the raws with comment //CMD has been added: public function initContent() { $original_query = Tools::getValue('q'); $query = Tools::replaceAccentedChars(urldecode($original_query)); if ($this->ajax_search) { $searchResults = Search::find((int)(Tools::getValue('id_lang')), $query, 1, 10, 'position', 'desc', true); if (is_array($searchResults)) { foreach ($searchResults as &$product) { $product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']); } Hook::exec('actionSearch', array('expr' => $query, 'total' => count($searchResults))); } $this->ajaxDie(Tools::jsonEncode($searchResults)); } //Only controller content initialization when the user use the normal search parent::initContent(); $product_per_page = isset($this->context->cookie->nb_item_per_page) ? (int)$this->context->cookie->nb_item_per_page : Configuration::get('PS_PRODUCTS_PER_PAGE'); if ($this->instant_search && !is_array($query)) { $this->productSort(); $this->n = abs((int)(Tools::getValue('n', $product_per_page))); $this->p = abs((int)(Tools::getValue('p', 1))); $search = Search::find($this->context->language->id, $query, 1, 10, 'position', 'desc'); Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); $combinations = $this->getProductAttributeCombinations($search['result']); // CMD $this->addColorsToProductList($search['result']); $this->context->smarty->assign(array( 'products' => $search['result'], // DEPRECATED (since to 1.4), not use this: conflict with block_cart module 'combinations' => $combinations, // CMD 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $original_query, 'instant_search' => $this->instant_search, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } elseif (($query = Tools::getValue('search_query', Tools::getValue('ref'))) && !is_array($query)) { $this->productSort(); $this->n = abs((int)(Tools::getValue('n', $product_per_page))); $this->p = abs((int)(Tools::getValue('p', 1))); $original_query = $query; $query = Tools::replaceAccentedChars(urldecode($query)); $search = Search::find($this->context->language->id, $query, $this->p, $this->n, $this->orderBy, $this->orderWay); if (is_array($search['result'])) { foreach ($search['result'] as &$product) { $product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&').'search_query='.urlencode($query).'&results='.(int)$search['total']; } } Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); $combinations = $this->getProductAttributeCombinations($search['result']); //CMD by the way does your shop shows attributes when moving through pages with "previous" - "next" or "show all" or when you select an attribute with the layered navigation box? Bye Matteo 1 Link to comment Share on other sites More sharing options...
Divyesh Prajapati Posted February 24, 2016 Share Posted February 24, 2016 Hello guys, Look at here. I have already told you in point#2 that you also have to assign combination of each controllers I have mentioned. If you are using Layered Navigation Module than also you need to assign combination there in layered navigation module file also. Link to comment Share on other sites More sharing options...
Divyesh Prajapati Posted February 24, 2016 Share Posted February 24, 2016 Hello Again , If you are using Layered Navigation module. You all find reference here what you all suppose to do. Hope this helps Link to comment Share on other sites More sharing options...
nshox Posted February 24, 2016 Share Posted February 24, 2016 we have solved SearchController.php doing this modification: at the end of the public function init() (at raw 50) we added: public function getProductAttributeCombinations($products) { $combinations = array(); foreach ($products as $product) { // load product object $product = new Product ($product['id_product'], $this->context->language->id); // get the product combinations data // create array combinations with key = id_product $combinations[$product->id] = $product->getAttributeCombinations($this->context->language->id); } return $combinations; } Further to this we added few raws of code inside the public function initContent() - I'm copying all the code; the raws with comment //CMD has been added: public function initContent() { $original_query = Tools::getValue('q'); $query = Tools::replaceAccentedChars(urldecode($original_query)); if ($this->ajax_search) { $searchResults = Search::find((int)(Tools::getValue('id_lang')), $query, 1, 10, 'position', 'desc', true); if (is_array($searchResults)) { foreach ($searchResults as &$product) { $product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']); } Hook::exec('actionSearch', array('expr' => $query, 'total' => count($searchResults))); } $this->ajaxDie(Tools::jsonEncode($searchResults)); } //Only controller content initialization when the user use the normal search parent::initContent(); $product_per_page = isset($this->context->cookie->nb_item_per_page) ? (int)$this->context->cookie->nb_item_per_page : Configuration::get('PS_PRODUCTS_PER_PAGE'); if ($this->instant_search && !is_array($query)) { $this->productSort(); $this->n = abs((int)(Tools::getValue('n', $product_per_page))); $this->p = abs((int)(Tools::getValue('p', 1))); $search = Search::find($this->context->language->id, $query, 1, 10, 'position', 'desc'); Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); $combinations = $this->getProductAttributeCombinations($search['result']); // CMD $this->addColorsToProductList($search['result']); $this->context->smarty->assign(array( 'products' => $search['result'], // DEPRECATED (since to 1.4), not use this: conflict with block_cart module 'combinations' => $combinations, // CMD 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $original_query, 'instant_search' => $this->instant_search, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } elseif (($query = Tools::getValue('search_query', Tools::getValue('ref'))) && !is_array($query)) { $this->productSort(); $this->n = abs((int)(Tools::getValue('n', $product_per_page))); $this->p = abs((int)(Tools::getValue('p', 1))); $original_query = $query; $query = Tools::replaceAccentedChars(urldecode($query)); $search = Search::find($this->context->language->id, $query, $this->p, $this->n, $this->orderBy, $this->orderWay); if (is_array($search['result'])) { foreach ($search['result'] as &$product) { $product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&').'search_query='.urlencode($query).'&results='.(int)$search['total']; } } Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); $combinations = $this->getProductAttributeCombinations($search['result']); //CMD by the way does your shop shows attributes when moving through pages with "previous" - "next" or "show all" or when you select an attribute with the layered navigation box? Bye Matteo Now work for me( Prestashop 1.6.1.4 Link to comment Share on other sites More sharing options...
cmd.developer.team Posted February 25, 2016 Share Posted February 25, 2016 Hello Again , If you are using Layered Navigation module. You all find reference here what you all suppose to do. Hope this helps Thank you very much! I solved the problem! Thanks a lot for sharing! Matteo Link to comment Share on other sites More sharing options...
polina_t Posted April 19, 2016 Share Posted April 19, 2016 Hi, Divyesh Prajapati! I did all your recommendations, but i don't understand how to change some code in ajax-cart and not delete all upgrades in my theme. May be you can show only different for working assing to cart with combinations, please Link to comment Share on other sites More sharing options...
luiskar Posted April 20, 2016 Share Posted April 20, 2016 (edited) Hello guys, Look at here. I have already told you in point#2 that you also have to assign combination of each controllers I have mentioned. If you are using Layered Navigation Module than also you need to assign combination there in layered navigation module file also. hi, can you tell me what controllers file i need to change to show the combinations in home page? Only need for popular products because its the only ones i show there. we have solved SearchController.php doing this modification: at the end of the public function init() (at raw 50) we added: public function getProductAttributeCombinations($products) { $combinations = array(); foreach ($products as $product) { // load product object $product = new Product ($product['id_product'], $this->context->language->id); // get the product combinations data // create array combinations with key = id_product $combinations[$product->id] = $product->getAttributeCombinations($this->context->language->id); } return $combinations; } Further to this we added few raws of code inside the public function initContent() - I'm copying all the code; the raws with comment //CMD has been added: public function initContent() { $original_query = Tools::getValue('q'); $query = Tools::replaceAccentedChars(urldecode($original_query)); if ($this->ajax_search) { $searchResults = Search::find((int)(Tools::getValue('id_lang')), $query, 1, 10, 'position', 'desc', true); if (is_array($searchResults)) { foreach ($searchResults as &$product) { $product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']); } Hook::exec('actionSearch', array('expr' => $query, 'total' => count($searchResults))); } $this->ajaxDie(Tools::jsonEncode($searchResults)); } //Only controller content initialization when the user use the normal search parent::initContent(); $product_per_page = isset($this->context->cookie->nb_item_per_page) ? (int)$this->context->cookie->nb_item_per_page : Configuration::get('PS_PRODUCTS_PER_PAGE'); if ($this->instant_search && !is_array($query)) { $this->productSort(); $this->n = abs((int)(Tools::getValue('n', $product_per_page))); $this->p = abs((int)(Tools::getValue('p', 1))); $search = Search::find($this->context->language->id, $query, 1, 10, 'position', 'desc'); Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); $combinations = $this->getProductAttributeCombinations($search['result']); // CMD $this->addColorsToProductList($search['result']); $this->context->smarty->assign(array( 'products' => $search['result'], // DEPRECATED (since to 1.4), not use this: conflict with block_cart module 'combinations' => $combinations, // CMD 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $original_query, 'instant_search' => $this->instant_search, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } elseif (($query = Tools::getValue('search_query', Tools::getValue('ref'))) && !is_array($query)) { $this->productSort(); $this->n = abs((int)(Tools::getValue('n', $product_per_page))); $this->p = abs((int)(Tools::getValue('p', 1))); $original_query = $query; $query = Tools::replaceAccentedChars(urldecode($query)); $search = Search::find($this->context->language->id, $query, $this->p, $this->n, $this->orderBy, $this->orderWay); if (is_array($search['result'])) { foreach ($search['result'] as &$product) { $product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&').'search_query='.urlencode($query).'&results='.(int)$search['total']; } } Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); $combinations = $this->getProductAttributeCombinations($search['result']); //CMD by the way does your shop shows attributes when moving through pages with "previous" - "next" or "show all" or when you select an attribute with the layered navigation box? Bye Matteo I've tried that in PS 1.6.1.5 and doesn't work Edited April 20, 2016 by luiskar (see edit history) Link to comment Share on other sites More sharing options...
samsonSVK Posted April 30, 2016 Share Posted April 30, 2016 we have solved SearchController.php doing this modification: at the end of the public function init() (at raw 50) we added: public function getProductAttributeCombinations($products) { $combinations = array(); foreach ($products as $product) { // load product object $product = new Product ($product['id_product'], $this->context->language->id); // get the product combinations data // create array combinations with key = id_product $combinations[$product->id] = $product->getAttributeCombinations($this->context->language->id); } return $combinations; } Further to this we added few raws of code inside the public function initContent() - I'm copying all the code; the raws with comment //CMD has been added: public function initContent() { $original_query = Tools::getValue('q'); $query = Tools::replaceAccentedChars(urldecode($original_query)); if ($this->ajax_search) { $searchResults = Search::find((int)(Tools::getValue('id_lang')), $query, 1, 10, 'position', 'desc', true); if (is_array($searchResults)) { foreach ($searchResults as &$product) { $product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']); } Hook::exec('actionSearch', array('expr' => $query, 'total' => count($searchResults))); } $this->ajaxDie(Tools::jsonEncode($searchResults)); } //Only controller content initialization when the user use the normal search parent::initContent(); $product_per_page = isset($this->context->cookie->nb_item_per_page) ? (int)$this->context->cookie->nb_item_per_page : Configuration::get('PS_PRODUCTS_PER_PAGE'); if ($this->instant_search && !is_array($query)) { $this->productSort(); $this->n = abs((int)(Tools::getValue('n', $product_per_page))); $this->p = abs((int)(Tools::getValue('p', 1))); $search = Search::find($this->context->language->id, $query, 1, 10, 'position', 'desc'); Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); $combinations = $this->getProductAttributeCombinations($search['result']); // CMD $this->addColorsToProductList($search['result']); $this->context->smarty->assign(array( 'products' => $search['result'], // DEPRECATED (since to 1.4), not use this: conflict with block_cart module 'combinations' => $combinations, // CMD 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $original_query, 'instant_search' => $this->instant_search, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } elseif (($query = Tools::getValue('search_query', Tools::getValue('ref'))) && !is_array($query)) { $this->productSort(); $this->n = abs((int)(Tools::getValue('n', $product_per_page))); $this->p = abs((int)(Tools::getValue('p', 1))); $original_query = $query; $query = Tools::replaceAccentedChars(urldecode($query)); $search = Search::find($this->context->language->id, $query, $this->p, $this->n, $this->orderBy, $this->orderWay); if (is_array($search['result'])) { foreach ($search['result'] as &$product) { $product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&').'search_query='.urlencode($query).'&results='.(int)$search['total']; } } Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); $combinations = $this->getProductAttributeCombinations($search['result']); //CMD by the way does your shop shows attributes when moving through pages with "previous" - "next" or "show all" or when you select an attribute with the layered navigation box? Bye Matteo Hi, I tried to do what you suggested but nothing happened. My code is here: public function getProductAttributeCombinations($products) { $combinations = array(); foreach ($products as $product) { // load product object $product = new Product ($product['id_product'], $this->context->language->id); // get the product combinations data // create array combinations with key = id_product $combinations[$product->id] = $product->getAttributeCombinations($this->context->language->id); } return $combinations; } /** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { $original_query = Tools::getValue('q'); $query = Tools::replaceAccentedChars(urldecode($original_query)); if ($this->ajax_search) { $searchResults = Search::find((int)(Tools::getValue('id_lang')), $query, 1, 10, 'position', 'desc', true); if (is_array($searchResults)) { foreach ($searchResults as &$product) { $product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']); } Hook::exec('actionSearch', array('expr' => $query, 'total' => count($searchResults))); } $this->ajaxDie(Tools::jsonEncode($searchResults)); } //Only controller content initialization when the user use the normal search parent::initContent(); $product_per_page = isset($this->context->cookie->nb_item_per_page) ? (int)$this->context->cookie->nb_item_per_page : Configuration::get('PS_PRODUCTS_PER_PAGE'); if ($this->instant_search && !is_array($query)) { $this->productSort(); $this->n = abs((int)(Tools::getValue('n', $product_per_page))); $this->p = abs((int)(Tools::getValue('p', 1))); $search = Search::find($this->context->language->id, $query, 1, 10, 'position', 'desc'); Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); $combinations = $this->getProductAttributeCombinations($search['result']); $this->addColorsToProductList($search['result']); $this->context->smarty->assign(array( 'nbProducts' => $search['total'], 'search_query' => $original_query, 'instant_search' => $this->instant_search, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } elseif (($query = Tools::getValue('search_query', Tools::getValue('ref'))) && !is_array($query)) { $this->productSort(); $this->n = abs((int)(Tools::getValue('n', $product_per_page))); $this->p = abs((int)(Tools::getValue('p', 1))); $original_query = $query; $query = Tools::replaceAccentedChars(urldecode($query)); $search = Search::find($this->context->language->id, $query, $this->p, $this->n, $this->orderBy, $this->orderWay); if (is_array($search['result'])) { foreach ($search['result'] as &$product) { $product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&').'search_query='.urlencode($query).'&results='.(int)$search['total']; } } Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); $combinations = $this->getProductAttributeCombinations($search['result']); $this->addColorsToProductList($search['result']); $this->context->smarty->assign(array( 'products' => $search['result'], // DEPRECATED (since to 1.4), not use this: conflict with block_cart module 'combinations' => $combinations, 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $original_query, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } elseif (($tag = urldecode(Tools::getValue('tag'))) && !is_array($tag)) { $nbProducts = (int)(Search::searchTag($this->context->language->id, $tag, true)); $this->pagination($nbProducts); $result = Search::searchTag($this->context->language->id, $tag, false, $this->p, $this->n, $this->orderBy, $this->orderWay); Hook::exec('actionSearch', array('expr' => $tag, 'total' => count($result))); $combinations = $this->getProductAttributeCombinations($search['result']); $this->addColorsToProductList($result); $this->context->smarty->assign(array( 'search_tag' => $tag, 'products' => $result, // DEPRECATED (since to 1.4), not use this: conflict with block_cart module 'combinations' => $combinations, 'search_products' => $result, 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } else { $this->context->smarty->assign(array( 'products' => array(), 'combinations' => $combinations, 'search_products' => array(), 'pages_nb' => 1, 'nbProducts' => 0)); } $this->context->smarty->assign(array('add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM'))); $this->setTemplate(_PS_THEME_DIR_.'search.tpl'); } I cannot see any change in my e-shop. Can you please tell me, where is the mistake? Link to comment Share on other sites More sharing options...
system_error86 Posted May 20, 2016 Share Posted May 20, 2016 Hello, I would like your help about something! How can I addapt these code to show the combinations like products? I want to get all product combinations in product-list with the images of each color for examle like a product! Check this example in this site . As you can see the product 1616100220 and 1616100230 are the same but different colors! If click on it you will see that inside has the two combinations! Is a way to do that with your code??? Thanks Link to comment Share on other sites More sharing options...
Keyosh Posted May 28, 2016 Share Posted May 28, 2016 <3 Thanks Divyesh Prajapati <3 ! Link to comment Share on other sites More sharing options...
Divyesh Prajapati Posted May 28, 2016 Share Posted May 28, 2016 Glad to know it worked for you guys 1 Link to comment Share on other sites More sharing options...
yomak84 Posted July 4, 2016 Share Posted July 4, 2016 Glad to know it worked for you guys Hello, i need help, i want to show just the colors ( combinations ) of my products on homepage, some of my clients doesn't know that the product has more colors, and they don't enter to product page. So i just want to show the colors, like that i'll be sure that the client will enter to product page. Thank you so much ! Link to comment Share on other sites More sharing options...
koc Posted August 22, 2016 Share Posted August 22, 2016 Hello, is this solution works correctly with Prestashop 1.6.1 (1.6.1.1), in my case, when I added products to the shopping cart price is unchanged, the same is when changing attribute - price stays default. In my case I only can choose the attribute from list and nothing else is changed Any sugestions with Prestashop 1.6.1 (1.6.1.1) and changing price when adding to cart? Link to comment Share on other sites More sharing options...
ZikmaSolutions Posted September 7, 2016 Share Posted September 7, 2016 Hi guys, Hi, thanks for your solutions with listing attributes on product list page. Can you help me with just displaying default attribute combination on product list for each product. I don't need to add to cart or anything else. Just to show what is default attribute. You know what i mean? I just want to show visitor when he browsing on product list page, what price is for what combination.Please look at attacment ! Thanks a lot ! Link to comment Share on other sites More sharing options...
shao_bee Posted October 4, 2016 Share Posted October 4, 2016 Hi, Is it possible to use some radio buttons instead of a dropdown list to select attribute ? Thanks ! Link to comment Share on other sites More sharing options...
PrestaShark Posted October 19, 2016 Share Posted October 19, 2016 Any ideas how to make it work in HomeTabs? Im using this modification to show data if product have desired attribute value id {foreach from=$product.combinations.values key=id_product_attribute item=combination} {if $combination.attributes_names == 50}Xtra Large SIZE!{/if} {/foreach} This works in category controller but how to make it work in home page and HomeFeatured modules? Thanks for informations ASAP! Link to comment Share on other sites More sharing options...
PrestaShark Posted October 20, 2016 Share Posted October 20, 2016 Bump bump. Which controller must be extended to show this modifications on HomeFeatured module in HomeTabs hook? Anybody? Link to comment Share on other sites More sharing options...
aymanbakir Posted October 29, 2016 Share Posted October 29, 2016 (edited) Hi All, I have tried to show attribute combinations on product listing page in prestashop 1.6.0.14 ( for defalut theme ) and adding products to cart from the same page it self and it worked for me ( See Attachment ). I am going to give brief steps here; Just follow the instruction given below. 1. First of all it is required to have list of combinations for all product and for that add following function in classes/Product.php file. public static function getProductAttributeCombinations($id_product) { $combinations = array(); $context = Context::getContext(); $product = new Product ($id_product, $context->language->id); $attributes_groups = $product->getAttributesGroups($context->language->id); $att_grps = ''; foreach ($attributes_groups as $k => $row) { $combinations[$row['id_product_attribute']]['attributes_values'][$row['id_attribute_group']] = $row['attribute_name']; $combinations[$row['id_product_attribute']]['attributes_group'][$row['id_attribute_group']] = $row['group_name']; $combinations[$row['id_product_attribute']]['attributes_groups'] = @implode(', ', $combinations[$row['id_product_attribute']]['attributes_group']); $att_grps = $combinations[$row['id_product_attribute']]['attributes_groups']; $combinations[$row['id_product_attribute']]['attributes_names'] = @implode(', ', $combinations[$row['id_product_attribute']]['attributes_values']); $combinations[$row['id_product_attribute']]['attributes'][] = (int)$row['id_attribute']; $combinations[$row['id_product_attribute']]['price'] = (float)$row['price']; // Call getPriceStatic in order to set $combination_specific_price if (!isset($combination_prices_set[(int)$row['id_product_attribute']])) { Product::getPriceStatic((int)$product->id, false, $row['id_product_attribute'], 6, null, false, true, 1, false, null, null, null, $combination_specific_price); $combination_prices_set[(int)$row['id_product_attribute']] = true; $combinations[$row['id_product_attribute']]['specific_price'] = $combination_specific_price; } $combinations[$row['id_product_attribute']]['ecotax'] = (float)$row['ecotax']; $combinations[$row['id_product_attribute']]['weight'] = (float)$row['weight']; $combinations[$row['id_product_attribute']]['quantity'] = (int)$row['quantity']; $combinations[$row['id_product_attribute']]['reference'] = $row['reference']; $combinations[$row['id_product_attribute']]['unit_impact'] = $row['unit_price_impact']; $combinations[$row['id_product_attribute']]['minimal_quantity'] = $row['minimal_quantity']; if ($row['available_date'] != '0000-00-00') { $combinations[$row['id_product_attribute']]['available_date'] = $row['available_date']; $combinations[$row['id_product_attribute']]['date_formatted'] = Tools::displayDate($row['available_date']); } else $combinations[$row['id_product_attribute']]['available_date'] = ''; foreach ($combinations as $id_product_attribute => $comb) { $attribute_list = ''; foreach ($comb['attributes'] as $id_attribute) $attribute_list .= '\''.(int)$id_attribute.'\','; $attribute_list = rtrim($attribute_list, ','); $combinations[$id_product_attribute]['list'] = $attribute_list; } } $comb = array( 'attribute_groups' => $att_grps, 'values' => $combinations ); return $comb; } 2. Now need to assign this combinations in controllers file like CategoryController.php, ManufacturerController.php, NewProductsController.php, PriceDropController.php, BestSalesController.php that is in controllers folder. I am showing you here only for category page and for that need to call function that we have made in step#1 in CategoryController.php Change function initContent() with following code public function initContent() { parent::initContent(); $this->setTemplate(_PS_THEME_DIR_.'category.tpl'); if (!$this->customer_access) return; if (isset($this->context->cookie->id_compare)) $this->context->smarty->assign('compareProducts', CompareProduct::getCompareProducts((int)$this->context->cookie->id_compare)); $this->productSort(); // Product sort must be called before assignProductList() $this->assignScenes(); $this->assignSubcategories(); $this->assignProductList(); $products = (isset($this->cat_products) && $this->cat_products) ? $this->cat_products : null; foreach($products as &$pro) { $pro['combinations'] = Product::getProductAttributeCombinations($pro['id_product']); } $this->context->smarty->assign(array( 'category' => $this->category, 'description_short' => Tools::truncateString($this->category->description, 350), 'products' => $products, 'combinations' => $combinations, 'id_category' => (int)$this->category->id, 'id_category_parent' => (int)$this->category->id_parent, 'return_category_name' => Tools::safeOutput($this->category->name), 'path' => Tools::getPath($this->category->id), 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'categorySize' => Image::getSize(ImageType::getFormatedName('category')), 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), 'thumbSceneSize' => Image::getSize(ImageType::getFormatedName('m_scene')), 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), 'allow_oosp' => (int)Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'comparator_max_item' => (int)Configuration::get('PS_COMPARATOR_MAX_ITEM'), 'suppliers' => Supplier::getSuppliers(), 'body_classes' => array($this->php_self.'-'.$this->category->id, $this->php_self.'-'.$this->category->link_rewrite) )); } 3. Replace code in your product-list.tpl ( in folder /themes/default-bootstrap/ ) file of default theme with code in product-list.tpl.txt file ( File attached ) 4. Replace code in your global.js ( in folder /themes/default-bootstrap/js ) file of default theme with code in global.js.txt file ( File attached ) 5. Add this in global.css ( in folder /themes/default-bootstrap/css ) .att_list{padding:10px;} .att_list .selector{margin: 0 auto;} 6. Replace code in your ajax-cart.js ( in folder /themes/default-bootstrap/modules/blockcart ) file of default theme with code in ajax-cart.js.txt file ( File attached ) That's It! Please note that this is only working in default theme for now if you want to use in custom theme you need to make changes in tpl files accordingly. Dear Divyesh, Thank you for the code it's very helpful and it seems a solution to my problem, but I have couple of questions to ask before I apply your code as I am not technically advanced (please excuse my shallow knowledge in this area). - if I upgraded prestashop after I applied code above, will I have to change the code again or it will remain there? - in case I upgraded the current theme I am using or changed the theme I have to change the code again, right? - Does this code above conflict / impact other modules? - Is code above applied to all categories with their relevant attributes I have or I have to apply for each category? example I have kids clothes and the attribute (AGE), Men Cloths attribute (SIZE) SaveSave Edited October 29, 2016 by aymanbakir (see edit history) Link to comment Share on other sites More sharing options...
MOnteAndr Posted November 11, 2016 Share Posted November 11, 2016 1. First of all it is required to have list of combinations for all product and for that add following function in classes/Product.php file. public static function getProductAttributeCombinations($id_product) { $combinations = array(); $context = Context::getContext(); $product = new Product ($id_product, $context->language->id); $attributes_groups = $product->getAttributesGroups($context->language->id); $att_grps = ''; foreach ($attributes_groups as $k => $row) { $combinations[$row['id_product_attribute']]['attributes_values'][$row['id_attribute_group']] = $row['attribute_name']; $combinations[$row['id_product_attribute']]['attributes_group'][$row['id_attribute_group']] = $row['group_name']; $combinations[$row['id_product_attribute']]['attributes_groups'] = @implode(', ', $combinations[$row['id_product_attribute']]['attributes_group']); $att_grps = $combinations[$row['id_product_attribute']]['attributes_groups']; $combinations[$row['id_product_attribute']]['attributes_names'] = @implode(', ', $combinations[$row['id_product_attribute']]['attributes_values']); $combinations[$row['id_product_attribute']]['attributes'][] = (int)$row['id_attribute']; $combinations[$row['id_product_attribute']]['price'] = (float)$row['price']; // Call getPriceStatic in order to set $combination_specific_price if (!isset($combination_prices_set[(int)$row['id_product_attribute']])) { Product::getPriceStatic((int)$product->id, false, $row['id_product_attribute'], 6, null, false, true, 1, false, null, null, null, $combination_specific_price); $combination_prices_set[(int)$row['id_product_attribute']] = true; $combinations[$row['id_product_attribute']]['specific_price'] = $combination_specific_price; } $combinations[$row['id_product_attribute']]['ecotax'] = (float)$row['ecotax']; $combinations[$row['id_product_attribute']]['weight'] = (float)$row['weight']; $combinations[$row['id_product_attribute']]['quantity'] = (int)$row['quantity']; $combinations[$row['id_product_attribute']]['reference'] = $row['reference']; $combinations[$row['id_product_attribute']]['unit_impact'] = $row['unit_price_impact']; $combinations[$row['id_product_attribute']]['minimal_quantity'] = $row['minimal_quantity']; if ($row['available_date'] != '0000-00-00') { $combinations[$row['id_product_attribute']]['available_date'] = $row['available_date']; $combinations[$row['id_product_attribute']]['date_formatted'] = Tools::displayDate($row['available_date']); } else $combinations[$row['id_product_attribute']]['available_date'] = ''; foreach ($combinations as $id_product_attribute => $comb) { $attribute_list = ''; foreach ($comb['attributes'] as $id_attribute) $attribute_list .= '\''.(int)$id_attribute.'\','; $attribute_list = rtrim($attribute_list, ','); $combinations[$id_product_attribute]['list'] = $attribute_list; } } $comb = array( 'attribute_groups' => $att_grps, 'values' => $combinations ); return $comb;} 2. Now need to assign this combinations in controllers file like CategoryController.php, ManufacturerController.php, NewProductsController.php, PriceDropController.php, BestSalesController.php that is in controllers folder. Good afternoon, everybody. I made all the changes, and then gives an error "HTTP ERROR 500". error falls once how I change product.php file. Tell me please. I just need to on a standard topic in the directory displayed attribute size. just in line. prestashop version 1.6.1.7. Help! ps Sorry for my bad english Link to comment Share on other sites More sharing options...
abdelkader2018 Posted November 27, 2016 Share Posted November 27, 2016 Hello MOnteAndr, Got the same error as you (error 500 ...)Did you find any solution ? I'll be very thankfull Link to comment Share on other sites More sharing options...
mizou125 Posted January 24, 2017 Share Posted January 24, 2017 Hello, Any solution for HomeFeatured, or another module ? Thank you Link to comment Share on other sites More sharing options...
Idiotic Posted March 7, 2017 Share Posted March 7, 2017 Cool, bless the founder ) saved my life man. Little tip for these who were fighting the searchcontroller and didnt solve it after all - should look like this (1.6.1.6): class SearchControllerCore extends FrontController { public $php_self = 'search'; public $instant_search; public $ajax_search; /** * Initialize search controller * @see FrontController::init() */ public function init() { parent::init(); $this->instant_search = Tools::getValue('instantSearch'); $this->ajax_search = Tools::getValue('ajaxSearch'); if ($this->instant_search || $this->ajax_search) { $this->display_header = false; $this->display_footer = false; } } /** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { $original_query = Tools::getValue('q'); $query = Tools::replaceAccentedChars(urldecode($original_query)); if ($this->ajax_search) { $searchResults = Search::find((int)(Tools::getValue('id_lang')), $query, 1, 10, 'position', 'desc', true); if (is_array($searchResults)) { foreach ($searchResults as &$product) { $product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']); } Hook::exec('actionSearch', array('expr' => $query, 'total' => count($searchResults))); } $this->ajaxDie(Tools::jsonEncode($searchResults)); } //Only controller content initialization when the user use the normal search parent::initContent(); $product_per_page = isset($this->context->cookie->nb_item_per_page) ? (int)$this->context->cookie->nb_item_per_page : Configuration::get('PS_PRODUCTS_PER_PAGE'); if ($this->instant_search && !is_array($query)) { $this->productSort(); $this->n = abs((int)(Tools::getValue('n', $product_per_page))); $this->p = abs((int)(Tools::getValue('p', 1))); $search = Search::find($this->context->language->id, $query, 1, 10, 'position', 'desc'); Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); $this->addColorsToProductList($search['result']); $products = $search['result']; foreach($products as &$pro) { $pro['combinations'] = Product::getProductAttributeCombinations($pro['id_product']); } $this->context->smarty->assign(array( 'products' => $search['result'], // DEPRECATED (since to 1.4), not use this: conflict with block_cart module 'combinations' => $combinations, 'search_products' => $products, 'nbProducts' => $search['total'], 'search_query' => $original_query, 'instant_search' => $this->instant_search, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } elseif (($query = Tools::getValue('search_query', Tools::getValue('ref'))) && !is_array($query)) { $this->productSort(); $this->n = abs((int)(Tools::getValue('n', $product_per_page))); $this->p = abs((int)(Tools::getValue('p', 1))); $original_query = $query; $query = Tools::replaceAccentedChars(urldecode($query)); $search = Search::find($this->context->language->id, $query, $this->p, $this->n, $this->orderBy, $this->orderWay); if (is_array($search['result'])) { foreach ($search['result'] as &$product) { $product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&').'search_query='.urlencode($query).'&results='.(int)$search['total']; } } Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); $this->addColorsToProductList($search['result']); $products = $search['result']; foreach($products as &$pro) { $pro['combinations'] = Product::getProductAttributeCombinations($pro['id_product']); } $this->context->smarty->assign(array( 'products' => $search['result'], // DEPRECATED (since to 1.4), not use this: conflict with block_cart module 'search_products' => $products, //'combinations' => $combinations, 'nbProducts' => $search['total'], 'search_query' => $original_query, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } elseif (($tag = urldecode(Tools::getValue('tag'))) && !is_array($tag)) { $nbProducts = (int)(Search::searchTag($this->context->language->id, $tag, true)); $this->pagination($nbProducts); $result = Search::searchTag($this->context->language->id, $tag, false, $this->p, $this->n, $this->orderBy, $this->orderWay); Hook::exec('actionSearch', array('expr' => $tag, 'total' => count($result))); $this->addColorsToProductList($result); $products = $result; foreach($products as &$pro) { $pro['combinations'] = Product::getProductAttributeCombinations($pro['id_product']); } $this->context->smarty->assign(array( 'search_tag' => $tag, 'products' => $result, // DEPRECATED (since to 1.4), not use this: conflict with block_cart module 'combinations' => $combinations, 'search_products' => $products, 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } else { $products = array(); foreach($products as &$pro) { $pro['combinations'] = Product::getProductAttributeCombinations($pro['id_product']); } $this->context->smarty->assign(array( 'products' => array(), 'combinations' => $combinations, 'search_products' => $products, 'pages_nb' => 1, 'nbProducts' => 0)); } $this->context->smarty->assign(array('add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM'))); $this->setTemplate(_PS_THEME_DIR_.'search.tpl'); } public function displayHeader($display = true) { if (!$this->instant_search && !$this->ajax_search) { parent::displayHeader(); } else { $this->context->smarty->assign('static_token', Tools::getToken(false)); } } public function displayFooter($display = true) { if (!$this->instant_search && !$this->ajax_search) { parent::displayFooter(); } } public function setMedia() { parent::setMedia(); if (!$this->instant_search && !$this->ajax_search) { $this->addCSS(_THEME_CSS_DIR_.'product_list.css'); } } } 1 Link to comment Share on other sites More sharing options...
lovemyseo Posted March 17, 2017 Share Posted March 17, 2017 i checked this code in my 1.5.6 demo store and works, make sure that you use correct code due to: is it possible to display product as list view ? Link to comment Share on other sites More sharing options...
arihadne Posted June 22, 2017 Share Posted June 22, 2017 Hi ! I'm trying to implement this code in my site, but I have two problems: 1. The view of products is in grid. How can I change to list view? 2.- The attributes change but not the final price of product, how can do it? thanks so muchs for your time ! http://www.milcolchones.com/56-colchones-muelles-viscoelasticos Link to comment Share on other sites More sharing options...
Aumanz Posted September 2, 2017 Share Posted September 2, 2017 Hi ! I'm trying to implement this code in my site, but I have two problems: 1. The view of products is in grid. How can I change to list view? 2.- The attributes change but not the final price of product, how can do it? thanks so muchs for your time ! http://www.milcolchones.com/56-colchones-muelles-viscoelasticos Hi there, how you solve it? Thanks for this great contribution! Link to comment Share on other sites More sharing options...
jordibv Posted July 9, 2019 Share Posted July 9, 2019 Hi, I'm trying to replicate the gonebdg option in Prestashop 1.7 but it does not show me any combination. ¿Could someone confirm if it also works for Prestashop 1.7? Thanks @gonebdg - webindoshop.com Link to comment Share on other sites More sharing options...
jordibabot Posted January 28, 2020 Share Posted January 28, 2020 (edited) On 3/7/2017 at 9:13 PM, Idiotic said: Cool, bless the founder ) saved my life man. Little tip for these who were fighting the searchcontroller and didnt solve it after all - should look like this (1.6.1.6): class SearchControllerCore extends FrontController { public $php_self = 'search'; public $instant_search; public $ajax_search; /** * Initialize search controller * @see FrontController::init() */ public function init() { parent::init(); $this->instant_search = Tools::getValue('instantSearch'); $this->ajax_search = Tools::getValue('ajaxSearch'); if ($this->instant_search || $this->ajax_search) { $this->display_header = false; $this->display_footer = false; } } /** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { $original_query = Tools::getValue('q'); $query = Tools::replaceAccentedChars(urldecode($original_query)); if ($this->ajax_search) { $searchResults = Search::find((int)(Tools::getValue('id_lang')), $query, 1, 10, 'position', 'desc', true); if (is_array($searchResults)) { foreach ($searchResults as &$product) { $product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']); } Hook::exec('actionSearch', array('expr' => $query, 'total' => count($searchResults))); } $this->ajaxDie(Tools::jsonEncode($searchResults)); } //Only controller content initialization when the user use the normal search parent::initContent(); $product_per_page = isset($this->context->cookie->nb_item_per_page) ? (int)$this->context->cookie->nb_item_per_page : Configuration::get('PS_PRODUCTS_PER_PAGE'); if ($this->instant_search && !is_array($query)) { $this->productSort(); $this->n = abs((int)(Tools::getValue('n', $product_per_page))); $this->p = abs((int)(Tools::getValue('p', 1))); $search = Search::find($this->context->language->id, $query, 1, 10, 'position', 'desc'); Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); $this->addColorsToProductList($search['result']); $products = $search['result']; foreach($products as &$pro) { $pro['combinations'] = Product::getProductAttributeCombinations($pro['id_product']); } $this->context->smarty->assign(array( 'products' => $search['result'], // DEPRECATED (since to 1.4), not use this: conflict with block_cart module 'combinations' => $combinations, 'search_products' => $products, 'nbProducts' => $search['total'], 'search_query' => $original_query, 'instant_search' => $this->instant_search, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } elseif (($query = Tools::getValue('search_query', Tools::getValue('ref'))) && !is_array($query)) { $this->productSort(); $this->n = abs((int)(Tools::getValue('n', $product_per_page))); $this->p = abs((int)(Tools::getValue('p', 1))); $original_query = $query; $query = Tools::replaceAccentedChars(urldecode($query)); $search = Search::find($this->context->language->id, $query, $this->p, $this->n, $this->orderBy, $this->orderWay); if (is_array($search['result'])) { foreach ($search['result'] as &$product) { $product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&').'search_query='.urlencode($query).'&results='.(int)$search['total']; } } Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); $this->addColorsToProductList($search['result']); $products = $search['result']; foreach($products as &$pro) { $pro['combinations'] = Product::getProductAttributeCombinations($pro['id_product']); } $this->context->smarty->assign(array( 'products' => $search['result'], // DEPRECATED (since to 1.4), not use this: conflict with block_cart module 'search_products' => $products, //'combinations' => $combinations, 'nbProducts' => $search['total'], 'search_query' => $original_query, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } elseif (($tag = urldecode(Tools::getValue('tag'))) && !is_array($tag)) { $nbProducts = (int)(Search::searchTag($this->context->language->id, $tag, true)); $this->pagination($nbProducts); $result = Search::searchTag($this->context->language->id, $tag, false, $this->p, $this->n, $this->orderBy, $this->orderWay); Hook::exec('actionSearch', array('expr' => $tag, 'total' => count($result))); $this->addColorsToProductList($result); $products = $result; foreach($products as &$pro) { $pro['combinations'] = Product::getProductAttributeCombinations($pro['id_product']); } $this->context->smarty->assign(array( 'search_tag' => $tag, 'products' => $result, // DEPRECATED (since to 1.4), not use this: conflict with block_cart module 'combinations' => $combinations, 'search_products' => $products, 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } else { $products = array(); foreach($products as &$pro) { $pro['combinations'] = Product::getProductAttributeCombinations($pro['id_product']); } $this->context->smarty->assign(array( 'products' => array(), 'combinations' => $combinations, 'search_products' => $products, 'pages_nb' => 1, 'nbProducts' => 0)); } $this->context->smarty->assign(array('add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM'))); $this->setTemplate(_PS_THEME_DIR_.'search.tpl'); } public function displayHeader($display = true) { if (!$this->instant_search && !$this->ajax_search) { parent::displayHeader(); } else { $this->context->smarty->assign('static_token', Tools::getToken(false)); } } public function displayFooter($display = true) { if (!$this->instant_search && !$this->ajax_search) { parent::displayFooter(); } } public function setMedia() { parent::setMedia(); if (!$this->instant_search && !$this->ajax_search) { $this->addCSS(_THEME_CSS_DIR_.'product_list.css'); } } } At last, this has worked for me, thanks! Edited January 28, 2020 by jordibabot grammar (see edit history) Link to comment Share on other sites More sharing options...
juanmlg Posted February 29, 2020 Share Posted February 29, 2020 On 4/22/2015 at 11:48 AM, Divyesh Prajapati said: May be you are using block layered navigation module. If yes than you need to add some short of code in blocklayered.php file. In blocklayered.php file there is a function ajaxCall() and in that just before $smarty->assign add below code. foreach($products as &$pro) { $pro['combinations'] = Product::getProductAttributeCombinations($pro['id_product']); } Hi Divyesh, Thanks to your post I discovered that the problem I have is due the blocklayered module OMG! Thanks god . I have the productcomments module modified to show the product rating in the product-list.tpl but when I am using the blocklayered module the ratings only appears on the first page... I have been reading you reply and I understand that I need to add a code at the blocklayered.php inside the ajaxCall() to load the rating on every ajax action but I have tried some code based in your reply without luck. Maybe you can help me: My working function in Productscomment.php is: Quote public function hookDisplayProductListReviews($params) { $id_product = (int) $params['product']['id_product']; if (!$this->isCached('productcomments_reviews.tpl', $this->getCacheId($id_product))) { require_once dirname(__FILE__).'/ProductComment.php'; $average = ProductComment::getAverageGrade($id_product); $this->smarty->assign(array( 'product' => $params['product'], 'averageTotal' => round($average['grade']), 'ratings' => ProductComment::getRatings($id_product), 'nbComments' => (int) ProductComment::getCommentNumber($id_product), )); } return $this->display(__FILE__, 'productcomments_reviews.tpl', $this->getCacheId($id_product)); } Could you say me what I need in the blocklayered.php to load the rating? Thanks so much! Link to comment Share on other sites More sharing options...
Divyesh Prajapati Posted May 29, 2020 Share Posted May 29, 2020 On 3/8/2017 at 1:43 AM, Idiotic said: Cool, bless the founder ) saved my life man. Little tip for these who were fighting the searchcontroller and didnt solve it after all - should look like this (1.6.1.6): class SearchControllerCore extends FrontController { public $php_self = 'search'; public $instant_search; public $ajax_search; /** * Initialize search controller * @see FrontController::init() */ public function init() { parent::init(); $this->instant_search = Tools::getValue('instantSearch'); $this->ajax_search = Tools::getValue('ajaxSearch'); if ($this->instant_search || $this->ajax_search) { $this->display_header = false; $this->display_footer = false; } } /** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { $original_query = Tools::getValue('q'); $query = Tools::replaceAccentedChars(urldecode($original_query)); if ($this->ajax_search) { $searchResults = Search::find((int)(Tools::getValue('id_lang')), $query, 1, 10, 'position', 'desc', true); if (is_array($searchResults)) { foreach ($searchResults as &$product) { $product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']); } Hook::exec('actionSearch', array('expr' => $query, 'total' => count($searchResults))); } $this->ajaxDie(Tools::jsonEncode($searchResults)); } //Only controller content initialization when the user use the normal search parent::initContent(); $product_per_page = isset($this->context->cookie->nb_item_per_page) ? (int)$this->context->cookie->nb_item_per_page : Configuration::get('PS_PRODUCTS_PER_PAGE'); if ($this->instant_search && !is_array($query)) { $this->productSort(); $this->n = abs((int)(Tools::getValue('n', $product_per_page))); $this->p = abs((int)(Tools::getValue('p', 1))); $search = Search::find($this->context->language->id, $query, 1, 10, 'position', 'desc'); Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); $this->addColorsToProductList($search['result']); $products = $search['result']; foreach($products as &$pro) { $pro['combinations'] = Product::getProductAttributeCombinations($pro['id_product']); } $this->context->smarty->assign(array( 'products' => $search['result'], // DEPRECATED (since to 1.4), not use this: conflict with block_cart module 'combinations' => $combinations, 'search_products' => $products, 'nbProducts' => $search['total'], 'search_query' => $original_query, 'instant_search' => $this->instant_search, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } elseif (($query = Tools::getValue('search_query', Tools::getValue('ref'))) && !is_array($query)) { $this->productSort(); $this->n = abs((int)(Tools::getValue('n', $product_per_page))); $this->p = abs((int)(Tools::getValue('p', 1))); $original_query = $query; $query = Tools::replaceAccentedChars(urldecode($query)); $search = Search::find($this->context->language->id, $query, $this->p, $this->n, $this->orderBy, $this->orderWay); if (is_array($search['result'])) { foreach ($search['result'] as &$product) { $product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&').'search_query='.urlencode($query).'&results='.(int)$search['total']; } } Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); $this->addColorsToProductList($search['result']); $products = $search['result']; foreach($products as &$pro) { $pro['combinations'] = Product::getProductAttributeCombinations($pro['id_product']); } $this->context->smarty->assign(array( 'products' => $search['result'], // DEPRECATED (since to 1.4), not use this: conflict with block_cart module 'search_products' => $products, //'combinations' => $combinations, 'nbProducts' => $search['total'], 'search_query' => $original_query, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } elseif (($tag = urldecode(Tools::getValue('tag'))) && !is_array($tag)) { $nbProducts = (int)(Search::searchTag($this->context->language->id, $tag, true)); $this->pagination($nbProducts); $result = Search::searchTag($this->context->language->id, $tag, false, $this->p, $this->n, $this->orderBy, $this->orderWay); Hook::exec('actionSearch', array('expr' => $tag, 'total' => count($result))); $this->addColorsToProductList($result); $products = $result; foreach($products as &$pro) { $pro['combinations'] = Product::getProductAttributeCombinations($pro['id_product']); } $this->context->smarty->assign(array( 'search_tag' => $tag, 'products' => $result, // DEPRECATED (since to 1.4), not use this: conflict with block_cart module 'combinations' => $combinations, 'search_products' => $products, 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); } else { $products = array(); foreach($products as &$pro) { $pro['combinations'] = Product::getProductAttributeCombinations($pro['id_product']); } $this->context->smarty->assign(array( 'products' => array(), 'combinations' => $combinations, 'search_products' => $products, 'pages_nb' => 1, 'nbProducts' => 0)); } $this->context->smarty->assign(array('add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM'))); $this->setTemplate(_PS_THEME_DIR_.'search.tpl'); } public function displayHeader($display = true) { if (!$this->instant_search && !$this->ajax_search) { parent::displayHeader(); } else { $this->context->smarty->assign('static_token', Tools::getToken(false)); } } public function displayFooter($display = true) { if (!$this->instant_search && !$this->ajax_search) { parent::displayFooter(); } } public function setMedia() { parent::setMedia(); if (!$this->instant_search && !$this->ajax_search) { $this->addCSS(_THEME_CSS_DIR_.'product_list.css'); } } } Thanks Link to comment Share on other sites More sharing options...
kugan80 Posted June 29, 2020 Share Posted June 29, 2020 How can we make it work in 1.7.6 ? does anyone has guide? Link to comment Share on other sites More sharing options...
laqmarc Posted October 1, 2020 Share Posted October 1, 2020 On 6/29/2020 at 2:53 PM, kugan80 said: How can we make it work in 1.7.6 ? does anyone has guide? Will be great if somebody have a guide how to do. Regards Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now