php - Display all categories on product page Prestashop -
php - Display all categories on product page Prestashop -
i need list of categories , ids on product page in prestashop (i using v 1.6.0.9).
i tried this:
$other_categories = $something->getcategories($this->context->language->id, 1, 100); foreach($other_categories something) { // if id of category isnt "1", display name of category if($category->id != "1") { $category->name } }
but, not working.
$category->name
gives me name of current open category, not name of each category in list. don't know set instead of something
? , works only, when utilize $category->getproducts
. here have shop (see "related products").
it 3rd shop , struggling problem 2 days.
in ps 1.6 there category
class, contains handy static methods usable in controller: getcategories(...)
, getnestedcategories(...)
, getsimplecategories
- these static (and public) sou phone call them category::funcname(...)
for purpose thing best alternative getnestedcategories()
has header:
public static function getnestedcategories( $root_category = null, $id_lang = false, $active = true, $groups = null, $use_shop_restriction = true, $sql_filter = '', $sql_sort = '', $sql_limit = '' )
in controller like:
$allcategories = category::getnestedcategories(null, $this->context->language->id); $this->context->smarty->assign( 'allcategories' , $allcategories );
then in template file like
{foreach from=$allcategories item=maincategory} <div class="categorybox"> <h2>{$maincategory.name}</h2> <p>{$maincategory.description}</p> </div> {foreach from=$maincategory.children item=subcategory} <div class="categorybox"> <h3>{$subcategory.name}</h3> <p>{$subcategory.description}</p> </div> {/foreach} {/foreach}
if have subcategories of home category, can utilize gethomecategories($id_lang, $active = true, $id_shop = false)
:
$allcategories = category::gethomecategories( $this->context->language->id );
also handy 1 static function getcategoryinformations($ids_category, $id_lang = null)
=> useful when have list of particular ids of categories want - pass them array - illustration of usage:
$mycustomcatids = array( 5 , 20 , 7); $mycustomcats = category::getcategoryinformations( $mycustomcatids );
php prestashop categories
Comments
Post a Comment