Anton_bcn Posted May 10, 2013 Share Posted May 10, 2013 (edited) In presta 1.5.3.1 i trying this and no succes: Please if some one who make a same can tell me somthing about if i use a right way to do this. Going to edit /controllers/front/SearchController.php there is a line of code i use when no one product found by search this found in public function initContent() .... else { $this->context->smarty->assign(array( 'products' => array(), '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'); ..... So as i can see i need here to get some category and products and pass them to smarty array for output in search.tpl or include there a product-list.php. my code get random products from random category: $categories = array(4,5,6); shuffle($cat_id); foreach ($cat_id as $id) { // create category object $categories = new Category($id); //get all active product in my case 316 $product_total = $categories->getProducts((Context::getContext()->language->id), 1, 9999,null,null,true,true); //no i try to randomize the start product number for getting product in next operation $num_prod = rand(1,($product_total-12)); //here as i thik it need $products = $categories->getProducts((Context::getContext()->language->id), $num_prod, 12); var_dump($products);die; //and array $products is empty.... } array $products sometimes return array of products but some times is empty.... what i do wrong? what i miss? is is another way to do this? -------------------- MOST IMPORTANT QUESTIONS -------------------------- is this correct way to get category like this for use this to get products? $categories = new Category(4); this is work $products = $categories->getProducts((Context::getContext()->language->id), 1, 12); but when i try to use different values like i need in randomize case this sometimes return empty array... $products = $categories->getProducts((Context::getContext()->language->id), RANDOM, 12); is this correct way to get products like this? $products = $categories->getProducts((Context::getContext()->language->id), 1, 12); Edited May 10, 2013 by anseme (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts