redpik of Axome
3/22/2017 - 9:35 AM

Récupérer la Catégorie de niveau 1

Récupérer la Catégorie de niveau 1

<?php

function ax_getParentCategory($id_category)
{
	$id_lang = Context::getContext()->language->id;
	$category = new Category($id_category, $id_lang);

	if (!empty($category->name)) {
		if ($category->level_depth > 2) {
			$parents = $category->getParentsCategories();

			if (!empty($parents)) {
				foreach ($parents as $p) {
					if ($p['level_depth'] == 2) {
						return array(
							'id' => $p['id_category'],
							'name' => $p['name']
						);
					}
				}
			}
		}

		return array(
			'id' => $category->id,
			'name' => $category->name
		);
	}

	return false;
}

//<h2 class="title_block">
//	{if isset($currentCategory)}
//	    {$parent_category = $currentCategory->id|ax_getParentCategory}
//
//		{if !empty($parent_category)}
//			{$parent_category.name|escape:'htmlall'}
//			<input type="hidden" id="ax_parent_category_id" value="{$parent_category.id}" />
//      {/if}
//	{else}
//		{l s='Categories' mod='blockcategories'}
//	{/if}
//</h2>