Jump to content

[SOLVED] List manufacturers under category page.


mytheory.

Recommended Posts

Hello,

I've been setting up my shop for the past couple of months using prestashop, and due to an abundant amount of information on these forums (through alot of searching) I haven't had the need to post a question until now. Now that my shop is getting closer to it's relaunch there are a couple of things that I am trying to resolve... which leads to my first question:

How would I add a list of manufacturers (within that specific category & subcats) under the category.php page? For example when you click on a main category it shows you the list of products under that category as well as the subcategories (given they exist). How would I list all the manufacturers under that category under the "subcategory" list (in the same format... shows a thumbnail image and the name below it).

I have been messing around with the category.tpl under themes.. and was able to get a header (that reads "Manufacturer") and a couple links, but these links seem fairly random including its title. I can't seem to get past this point.

I hope this makes sense. And thank you in advance.

  • Like 1
Link to comment
Share on other sites

Ok... to ask a more specific question with some relation to the topic.

What is the code to call out the manufacturer of a product under a subcategory? From what I have looked through $product->id_manufacturer calls the id of the manufacturer for a specific product. However, how would I find all and only the products under a specific category or subcategory, so that from that "product list" I can call the manufacturers? ($product->id_manufacturer works on the product page or any category page with products, but my category pages that have subcategories ususally do not have products under the main category. So my question relates to calling these items from the category page with no products.)

To explain a bit further, from the home page I click on say "Category 1" which opens the next page listing the 3 subcategories under "Category 1"... Now I need to compile a "list" of all the products that are only under each of the 3 subcategories (and category as a whole).

Thanks.

Link to comment
Share on other sites

Are you trying to filter categories by manufacturer or just list the manufacturers relevant to the current category? Or to put it another way, when you click on a manufacturer on the category page, do you want only products that are both from that manufacturer and in that category or do you want to list all products by that manufacturer? The former is quite difficult. There are filter modules available, but I'm not aware of any free ones. The latter is easier, since you just have to go through all the $products and get all the unique $product.id_manufacturer values, then create a list similar to the subcategories that link directly to those manufacturer pages.

Link to comment
Share on other sites

rocky,

First, thanks for you reply.

If I understood correctly, I believe I am trying to do something along the lines of the latter (easier method as you put it). I am trying to "list the manufacturers relevant to the current category/subcategory" in the category page.

Most of my category pages on my shop are divided into subcategories, which then contain products. So, off the homepage from the category block if I click on a category it takes me to a page that lists only subcategories, and if I click on one of the subcategories it lists the products. What I am trying to do is under the category page that lists only the subcategories, below it I want to list the manufacturers that are unique to only products of the subcategories under that specifc category page.

Per my last post, I was able to kind of narrow down what I think I need to do. However, the obstacle I am facing is: if there are products under a page I can get all the unique $product.id_manufacturer values as you said, but the problem is how would I get those values from the category page that ONLY has subcategories? Essentially, how would I tell the code to identify each of the subcategories on that page, then for each subcat get the $product.id_manufacturer w/o duplicates? That way once I can get those values I can output it on the category page under the subcat listings. I am open to any suggestions.

Thanks!

Link to comment
Share on other sites

Add the following to category.php after line 59 ($cat_products = ...):

$manufacturers = array();

if ($cat_products)
   foreach ($cat_products as $product)
   {
       $manufacturers[$product['id_manufacturer']] = new Manufacturer(intval($product['id_manufacturer']), intval($cookie->id_lang));
       $manufacturer_images[$product['id_manufacturer']] = (!file_exists(_PS_MANU_IMG_DIR_.'/'.$product['id_manufacturer'].'-medium.jpg')) ? 
Language::getIsoById(intval($cookie->id_lang)).'-default' :    $product['id_manufacturer'];
   }



then add the following to the $smarty->assign on line 71:

'manufacturers' => $manufacturers,
'manufacturer_images' => $manufacturer_images,



then add the following to category.tpl in your theme's directory wherever you want the manufacturer list to appear:

{if isset($manufacturers)}
<!-- Manufacturers -->

{l s='Manufacturers'}

   {foreach from=$manufacturers item=manufacturer}

           <a href="{$link->getManufacturerLink($manufacturer->id_manufacturer, $manufacturer->link_rewrite)|escape:'htmlall':'UTF-8'}" title="{$manufacturer->name|escape:'htmlall':'UTF-8'}">
           {foreach from=$manufacturer_images key=id_manufacturer item=manufacturer_image}
               {if $id_manufacturer == $manufacturer->id_manufacturer}
               <img src="{$img_manu_dir}{$manufacturer_image|escape:'htmlall':'UTF-8'}-medium.jpg" alt="" />
               {/if}
           {/foreach}



           <a href="{$link->getManufacturerLink($manufacturer->id_manufacturer, $manufacturer->link_rewrite)|escape:'htmlall':'UTF-8'}">{$manufacturer->name|escape:'htmlall':'UTF-8'}

   {/foreach}




{/if}

Link to comment
Share on other sites

rocky,

you are a genius! Thank you for this code, it brings everything one step closer.

I have 2 issues:

1) Manufacturers are successfully listed in a subcategory (with products), but it only lists the manufacturers on that pagination. When I go to the next page it lists only the manufacturers on that page... Is there any way to display the manufacturers of all the products in the subcategory and not just the pages alone?

2) So, when somebody clicks on a category from the homepage it takes them to another page that lists out the subcategories (and if they click on a subcat. they are taken to the products, which aside from issue #1 works). Usually on these pages there are no products, and consequently there are no manufacturers that are listing. I think it has something to do with there being no products on these "category" (subcategory) pages, thus no id_manufacturers are being arrayed. Is there anyway to parse the manufacturers of all the subcategories on this page?

Thanks!

PS. For the above code,

$manufacturers = array();

if ($cat_products)
   foreach ($cat_products as $product)
   {
       $manufacturers[$product['id_manufacturer']] = new Manufacturer(intval($product['id_manufacturer']), intval($cookie->id_lang));
       $manufacturer_images[$product['id_manufacturer']] = (!file_exists(_PS_MANU_IMG_DIR_.'/'.$product['id_manufacturer'].'-medium.jpg')) ? 
Language::getIsoById(intval($cookie->id_lang)).'-default' :    $product['id_manufacturer'];
   } 



you need to add:

$manufacturer_images = array();

under

$manufacturers = array();

to display thumbnails without error.

Cheer!

Link to comment
Share on other sites

Try the following code instead of the above code in category.php after line 59:

$manufacturer_fields = getManufacturers($category->id_category);
$manufacturers = $manufacturer_fields['object'];
$manufacturer_images = $manufacturer_fields['image'];



And add this function on line 77 (before the $smarty->assign):

function getManufacturers($id_category)
{
   global $cookie;

   $manufacturers = array();
   $category = new Category($id_category);
   $products = $category->getProducts(intval($cookie->id_lang), 1, 1000000);

   if ($products)
       foreach ($products as $product)
       {
           $manufacturers['object'][$product['id_manufacturer']] = new Manufacturer(intval($product['id_manufacturer']), intval($cookie->id_lang));
           $manufacturers['image'][$product['id_manufacturer']] = (!file_exists(_PS_MANU_IMG_DIR_.'/'.$product['id_manufacturer'].'-medium.jpg')) ? 
   Language::getIsoById(intval($cookie->id_lang)).'-default' :    $product['id_manufacturer'];
       }

   $subcategories = $category->getSubcategories(intval($cookie->id_lang));

   if ($subcategories)
       foreach ($subcategories as $subcategory)
           $manufacturers = array_merge($manufacturers, getManufacturers($subcategory['id_category']));

   return $manufacturers;
}



This function will recursively get all the unique manufacturers in the current category and its subcategories. I added the parameters "page" = 1 and "number of products per page" = 1000000, since I can't see any option to get all the products in a category. I doubt you'll have more than 1000000 products in a category, so it should work.

  • Thanks 1
Link to comment
Share on other sites

rocky,

You are the man! The above codes worked perfectly! I can't thank you enough for you help. I made some minor formatting changes on the .tpl file but other than that the function of what I was trying to achieve is right on.

Thanks again!

Link to comment
Share on other sites

  • 1 month later...

This is a minor problem I just recently noticed, but since I like to pay attention to the details... Is there anyway to sort the manufacturers alphabetically? I think the current code is sorting them according to the manufacturer ID.

If there is an easy fix that would be great, if not I can live with it.

Thanks again!

Link to comment
Share on other sites

Hi.

First, thanks for the code.

I'm starting with prestashop and I made some probes with this final code, but doesn´t work well, because only shows the manufacturers of the last subcategory, and doesn´t show the manufacturers of the principal category, nor of the firsts subcategories.

I think that, perhaps, mytheory has the same manufacturers inside the differents subcategories and so, the manufacturers shows well.

Is possible any change in the code for a correct operation?.

Thanks again.

Link to comment
Share on other sites

Nihplod,

After taking a closer look at my shop and the functioning of the above code... I am having the same (or similar) problem. I didn't notice it earlier because I modified the code to output a small thumbnail of the manufacturer instead of any text, and seeing as how I have not been able to input an image for all the manufacturers yet I presumed that I was just missing the image for a particular manufacturer under a category/subcat.

From my experience, I think each of the subcategories are working. However, in the main category (parent) the manufacturers that are being listed is from the same list as the last subcategory under that parent category.

I'm going to try and mess around with it, but seeing as how I am not a programmer I think we could use some help.

Thanks!

Link to comment
Share on other sites

Hello.

I'm newbie, but I made some changes in the code, and now seems to work well, although I am trying to do that clicking over the manufacturer, only shows the items that this manufacturer has in the category, and not all the items that has in store, but I need help. ;)

The modified function:

function getManufacturers($id_category)
{
   global $cookie;

   $manufacturers = array();
   $catmanufacturers = array();
   $allmanufacturers = array();
   $category = new Category($id_category);
   $products = $category->getProducts(intval($cookie->id_lang), 1, 1000000);

   if ($products)
       foreach ($products as $product)
       {
           $manufacturers['object'][$product['id_manufacturer']] = new Manufacturer(intval($product['id_manufacturer']), intval($cookie->id_lang));
           $manufacturers['image'][$product['id_manufacturer']] = (!file_exists(_PS_MANU_IMG_DIR_.'/'.$product['id_manufacturer'].'-medium.jpg')) ? Language::getIsoById(intval($cookie->id_lang)).'-default' :    $product['id_manufacturer'];
       }

   $subcategories = $category->getSubcategories(intval($cookie->id_lang));

   if ($subcategories)
       foreach ($subcategories as $subcategory)
       {
           $category = new Category($subcategory);
           $products = $category->getProducts(intval($cookie->id_lang), 1, 1000000);
           if ($products)
               foreach ($products as $product)
               {
                   $catmanufacturers['object'][$product['id_manufacturer']] = new Manufacturer(intval($product['id_manufacturer']), intval($cookie->id_lang));
                   $catmanufacturers['image'][$product['id_manufacturer']] = (!file_exists(_PS_MANU_IMG_DIR_.'/'.$product['id_manufacturer'].'-medium.jpg')) ? Language::getIsoById(intval($cookie->id_lang)).'-default' :    $product['id_manufacturer'];
               }
       }

   $allmanufacturers = array_merge($manufacturers, $catmanufacturers);

   return $allmanufacturers;
} 

Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...
  • 2 months later...
  • 2 months later...
  • 1 month later...

Hi, after reading this topic, and using rocky's hints I have managed to add a dropdown menu just above sort options with the manufacturers only in this category/subcategory. Works on v1.3.7.0

So here it is:
In classes/Category.php find public function getProducts and modify it as follows:

public function getProducts($id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $random = false, $randomNumberProducts = 1,[b] $id_manufacturer = NULL[/b])
   {
       global $cookie;

       if ($p < 1) $p = 1;

       if (empty($orderBy))
           $orderBy = 'position';
       else
           /* Fix for all modules which are now using lowercase values for 'orderBy' parameter */
           $orderBy = strtolower($orderBy);


       if (empty($orderWay))
           $orderWay = 'ASC';
       if ($orderBy == 'id_product' OR    $orderBy == 'date_add')
           $orderByPrefix = 'p';
       elseif ($orderBy == 'name')
           $orderByPrefix = 'pl';
       elseif ($orderBy == 'manufacturer')
       {
           $orderByPrefix = 'm';
           $orderBy = 'name';
       }
       elseif ($orderBy == 'position')
           $orderByPrefix = 'cp';

       if ($orderBy == 'price')
           $orderBy = 'orderprice';

       if (!Validate::isBool($active) OR !Validate::isOrderBy($orderBy) OR !Validate::isOrderWay($orderWay))
           die (Tools::displayError());

       $id_supplier = intval(Tools::getValue('id_supplier'));

       /* Return only the number of products */
       if ($getTotal)
       {
           $result = Db::getInstance()->getRow('
           SELECT COUNT(cp.`id_product`) AS total
           FROM `'._DB_PREFIX_.'product` p
           LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product`
           WHERE cp.`id_category` = '.intval($this->id).($active ? ' AND p.`active` = 1' : '').'
          [b] '.($id_manufacturer ? 'AND p.id_manufacturer = '.$id_manufacturer : '').'[/b]
           '.($id_supplier ? 'AND p.id_supplier = '.intval($id_supplier) : ''));
           return isset($result) ? $result['total'] : 0;
       }

       $sql = '
       SELECT p.*, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`, cl.`name` AS category_default, 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` * IF(t.`rate`,((100 + (t.`rate`))/100),1) - IF((DATEDIFF(`reduction_from`, CURDATE()) <= 0 AND DATEDIFF(`reduction_to`, CURDATE()) >=0) OR `reduction_from` = `reduction_to`, IF(`reduction_price` > 0, `reduction_price`, (p.`price` * IF(t.`rate`,((100 + (t.`rate`))/100),1) * `reduction_percent` / 100)),0)) AS orderprice 
       FROM `'._DB_PREFIX_.'category_product` cp
       LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product`
       LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1)
       LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.intval($id_lang).')
       LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.intval($id_lang).')
       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` = '.intval($id_lang).')
       LEFT JOIN `'._DB_PREFIX_.'tax` t ON t.`id_tax` = p.`id_tax`
       LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.intval($id_lang).')
       LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
       WHERE cp.`id_category` = '.intval($this->id).($active ? ' AND p.`active` = 1' : '').'
      [b] '.($id_manufacturer ? 'AND p.id_manufacturer = '.$id_manufacturer : '').'[/b]
       '.($id_supplier ? 'AND p.id_supplier = '.$id_supplier : '');

       if ($random === true)
       {
           $sql .= ' ORDER BY RAND()';
           $sql .= ' LIMIT 0, '.intval($randomNumberProducts);
       }
       else
       {
           $sql .= ' ORDER BY '.(isset($orderByPrefix) ? $orderByPrefix.'.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay).'
           LIMIT '.((intval($p) - 1) * intval($n)).','.intval($n);
       }

       $result = Db::getInstance()->ExecuteS($sql);

       if ($orderBy == 'orderprice')
       {
           Tools::orderbyPrice($result, $orderWay);
       }
       if (!$result)
           return false;

       /* Modify SQL result */
       return Product::getProductsProperties($id_lang, $result);
   }


Added one more parameter for the function - $id_manufacturer defaults to NULL
in the SQL addded the WHERE clause id_manufacturer if id_manufacturer is not NULL

Link to comment
Share on other sites

NEXT In the root directory of Prestashop file category.php
Somewhere around line 58 find

$nbProducts = $category->getProducts(NULL, NULL, .............


and replace with

$nbProducts = $category->getProducts(NULL, NULL, NULL, $orderBy, $orderWay, true, TRUE, FALSE, 1,[b] intval(Tools::getValue('id_manufacturer'))[/b]);



Three rows down find

$cat_products = $category->getProducts(intval($cookie->id_lang), intval($p)......


and replace with

$cat_products = $category->getProducts(intval($cookie->id_lang), intval($p), intval($n), $orderBy, $orderWay, FALSE, TRUE, FALSE, 1, intval(Tools::getValue('id_manufacturer')));


just after that add

$manufacturers = getManufacturers($category->id_category);



So it looks like that:

if ($category->id != 1)
       {
           $nbProducts = $category->getProducts(NULL, NULL, NULL, $orderBy, $orderWay, true, TRUE, FALSE, 1, intval(Tools::getValue('id_manufacturer')));
           include(dirname(__FILE__).'/pagination.php');
           $smarty->assign('nb_products', $nbProducts);
           $cat_products = $category->getProducts(intval($cookie->id_lang), intval($p), intval($n), $orderBy, $orderWay, FALSE, TRUE, FALSE, 1, intval(Tools::getValue('id_manufacturer')));
           $manufacturers = getManufacturers($category->id_category);
       }


After that in the $smarty->asign add

'manufacturers' => $manufacturers,


$smarty->assign(array(
           'products' => (isset($cat_products) AND $cat_products) ? $cat_products : NULL,
           'manufacturers' => $manufacturers,
           'id_category' => intval($category->id),
           'id_category_parent' => intval($category->id_parent),
           'return_category_name' => Tools::safeOutput(Category::hideCategoryPosition($category->name)),
           'path' => Tools::getPath(intval($category->id), $category->name),
           'homeSize' => Image::getSize('home')
       ));



After the end of the IF clause (two rows after the end of $smarty->asign) add the following function

function getManufacturers($id_category)
{
   global $cookie;

   $manufacturers = array();
   $category = new Category($id_category);
   $products = $category->getProducts(intval($cookie->id_lang), 1, 1000000, NULL, NULL, FALSE, TRUE, FALSE, 1);
   if ($products)
       foreach ($products as $product)
       {
           $manufacturers[$product['id_manufacturer']] = Manufacturer::getNameById($product['id_manufacturer']);
       }

   $subcategories = $category->getSubcategories(intval($cookie->id_lang));

   if ($subcategories)
       foreach ($subcategories as $subcategory)
           $manufacturers = array_merge($manufacturers, getManufacturers($subcategory['id_category']));

   return $manufacturers;
}


This is rocky's function a little bit modified. So starting from line 56 -

if ($category->id != 1)

the file looks like that:

if ($category->id != 1)
       {
           $nbProducts = $category->getProducts(NULL, NULL, NULL, $orderBy, $orderWay, true, TRUE, FALSE, 1, intval(Tools::getValue('id_manufacturer')));
           include(dirname(__FILE__).'/pagination.php');
           $smarty->assign('nb_products', $nbProducts);
           $cat_products = $category->getProducts(intval($cookie->id_lang), intval($p), intval($n), $orderBy, $orderWay, FALSE, TRUE, FALSE, 1, intval(Tools::getValue('id_manufacturer')));
           $manufacturers = getManufacturers($category->id_category);
       }
       $smarty->assign(array(
           'products' => (isset($cat_products) AND $cat_products) ? $cat_products : NULL,
           'manufacturers' => $manufacturers,
           'id_category' => intval($category->id),
           'id_category_parent' => intval($category->id_parent),
           'return_category_name' => Tools::safeOutput(Category::hideCategoryPosition($category->name)),
           'path' => Tools::getPath(intval($category->id), $category->name),
           'homeSize' => Image::getSize('home')
       ));
   }
}
function getManufacturers($id_category)
{
   global $cookie;

   $manufacturers = array();
   $category = new Category($id_category);
   $products = $category->getProducts(intval($cookie->id_lang), 1, 1000000, NULL, NULL, FALSE, TRUE, FALSE, 1);
   //print_r($products);
   if ($products)
       foreach ($products as $product)
       {
           $manufacturers[$product['id_manufacturer']] = Manufacturer::getNameById($product['id_manufacturer']);
       }

   $subcategories = $category->getSubcategories(intval($cookie->id_lang));

   if ($subcategories)
       foreach ($subcategories as $subcategory)
           $manufacturers = array_merge($manufacturers, getManufacturers($subcategory['id_category']));

   return $manufacturers;
}
$smarty->assign(array(
   'allow_oosp' => intval(Configuration::get('PS_ORDER_OUT_OF_STOCK')),
   'suppliers' => Supplier::getSuppliers(),
   'errors' => $errors));

if (isset($subCategories))
   $smarty->assign(array(
       'subcategories_nb_total' => sizeof($subCategories),
       'subcategories_nb_half' => ceil(sizeof($subCategories) / 2)));

$smarty->display(_PS_THEME_DIR_.'category.tpl');

include(dirname(__FILE__).'/footer.php');

?>

Link to comment
Share on other sites

And finally the in themes/theme001/product-sort.tpl

{if isset($orderby) AND isset($orderway)}
<!-- Sort products -->
{if $smarty.get.id_category|intval}
   {assign var='request' value=$link->getPaginationLink('category', $category, false, true)}
{elseif $smarty.get.id_manufacturer|intval}
   {assign var='request' value=$link->getPaginationLink('manufacturer', $manufacturer, false, true)}
{elseif $smarty.get.id_supplier|intval}
   {assign var='request' value=$link->getPaginationLink('supplier', $supplier, false, true)}
{else}
   {assign var='request' value=$link->getPaginationLink(false, false, false, true)}
{/if}
<form id="productsSortForm" action="{$request}">
   {if !strstr($request, 'search.php')}



{l s='--'}
       {foreach from=$manufacturers key=mkey item=manufacturer name=manufacturers}
{$manufacturer}
       {/foreach}

{l s='Manufacturer'}

   {/if}



{l s='--'}
{l s='price: lowest first'}
{l s='price: highest first'}
{l s='name: A to Z'}
{l s='name: Z to A'}
{l s='in-stock first'}

{l s='sort by'}

</form>
<!-- /Sort products -->
{/if}



if you compare the original file with that on you will find the diff:

{if !strstr($request, 'search.php')}



{l s='--'}
       {foreach from=$manufacturers key=mkey item=manufacturer name=manufacturers}
{$manufacturer}
       {/foreach}

{l s='Manufacturer'}

   {/if}




I think that this is it. Sorry if I have forgotten something. Hope it will work on your stores. I have only tested it on Prestashop v1.3.7.0. Dunno if it will work on other versions.

Link to comment
Share on other sites

I just realized I don't need this code in function getManufacturers

if ($subcategories)
       foreach ($subcategories as $subcategory)
           $manufacturers = array_merge($manufacturers, getManufacturers($subcategory['id_category']));



It is to get manufacturers when you are on category page that has subcategories. But since I don display manufacturers there, I don't need this code.

Link to comment
Share on other sites

That code works also on Prestashop v1.4.0.17 but you have to do some modifications on the code in category.php since the code is in controllers/CategoryController.php. You have to make the function getManufacturers member of the class CategoryControllerCore. change some of the properties like $category->getProducts into $this->category->getProducts;
intval(Tools::getValue('id_manufacturer')) into (int)(Tools::getValue('id_manufacturer')). The function getProducts is modified and has one more parameter, so you should add it when calling the function. When I have some more time, I will post the code for v.1.4.0.17

Link to comment
Share on other sites

  • 1 month later...
  • 9 months later...
  • 2 weeks later...

Hello,

 

Apologies if this is an off-topic but I need just the opposite. I would like to get the categories sold by a manufacturer. I mean, when I click on a manufacturer, I need to get all categories that this manufacturer sells.

 

Is there any module for this?

 

 

Regards.

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 months later...
  • 1 year later...
  • 8 months later...

Try the following code instead of the above code in category.php after line 59:

 

$manufacturer_fields = getManufacturers($category->id_category);$manufacturers = $manufacturer_fields['object'];$manufacturer_images = $manufacturer_fields['image'];

And add this function on line 77 (before the $smarty->assign):

 

function getManufacturers($id_category){    global $cookie;        $manufacturers = array();    $category = new Category($id_category);    $products = $category->getProducts(intval($cookie->id_lang), 1, 1000000);        if ($products)        foreach ($products as $product)        {            $manufacturers['object'][$product['id_manufacturer']] = new Manufacturer(intval($product['id_manufacturer']), intval($cookie->id_lang));            $manufacturers['image'][$product['id_manufacturer']] = (!file_exists(_PS_MANU_IMG_DIR_.'/'.$product['id_manufacturer'].'-medium.jpg')) ?     Language::getIsoById(intval($cookie->id_lang)).'-default' :    $product['id_manufacturer'];        }        $subcategories = $category->getSubcategories(intval($cookie->id_lang));        if ($subcategories)        foreach ($subcategories as $subcategory)            $manufacturers = array_merge($manufacturers, getManufacturers($subcategory['id_category']));            return $manufacturers;}

This function will recursively get all the unique manufacturers in the current category and its subcategories. I added the parameters "page" = 1 and "number of products per page" = 1000000, since I can't see any option to get all the products in a category. I doubt you'll have more than 1000000 products in a category, so it should work.

 

any updated version for 1.6 Rocky?

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
  • 2 weeks later...
  • 3 months later...
  • 1 month later...
  • 9 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...