X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Display manufacturer list on category page (https://forum.x-cart.com/showthread.php?t=63034)

Powertrain 03-20-2012 04:10 PM

Display manufacturer list on category page
 
HI,

I have searched for this but only found posts for displaying manufacturer on product page.

I would like to display available manufacturers on category/subcategory page.

If any product in that category has manufacturer specified it would display a list of those manufacturers below or above product list.

Is there a post somewhere that has covered this, is it possible and how would I go about it?

Using X-Cart 4.4.2

Please point me in the right direction.

Thanks.

totaltec 03-20-2012 04:50 PM

Re: Display manufacturer list on category page
 
Use webmaster mode and look at the variables assigned on those pages. Here is a tut if you are not familiar with this method:http://forum.x-cart.com/showthread.php?p=335522 #2 on the list currently.

If you can see the variables, you should be good to go to write some Smarty code, if they are not assigned you will need to dive into the DB with PHP and assign them.

Kind of a generic response, but hopefully it will help.

Powertrain 03-20-2012 06:22 PM

Re: Display manufacturer list on category page
 
Thanks Mike, I'll try my best but not really sure what variables to look for, where will they be displayed?

I'm surprised that this is not default function in x-cart.

cflsystems 03-20-2012 06:59 PM

Re: Display manufacturer list on category page
 
Products shown on products list pages have manufacturerid specified for them in the product array but not the manufacturer name. If you want to show a list of manufacturers this will stillhas to be custom coded within php to assign the list to smarty with names

Powertrain 03-20-2012 09:16 PM

Re: Display manufacturer list on category page
 
Quote:

Originally Posted by cflsystems
Products shown on products list pages have manufacturerid specified for them in the product array but not the manufacturer name. If you want to show a list of manufacturers this will stillhas to be custom coded within php to assign the list to smarty with names


Hey Steve :)

Are there any examples on forums that you are aware of?

Thanks.

cflsystems 03-20-2012 09:32 PM

Re: Display manufacturer list on category page
 
Not aware of anything like this but there could be something in here. Try searching again. And you know my email if you need professional help with this

carlisleglass 03-21-2012 04:54 AM

Re: Display manufacturer list on category page
 
Try this ...

http://www.xcartmods.co.uk/x-cart-filter-by-manufacturer.html

cherie 03-21-2012 02:20 PM

Re: Display manufacturer list on category page
 
Depending on the skin, the list of Manufacturers should always show in the menu on the side on all pages. Also check that the box is checked in the Manufacturers settings.

Powertrain 03-23-2012 06:49 PM

Re: Display manufacturer list on category page
 
Quote:

Originally Posted by cherie
Depending on the skin, the list of Manufacturers should always show in the menu on the side on all pages. Also check that the box is checked in the Manufacturers settings.


They do but it always displays ALL manufacturers, i'd like to display only manufacturers that exist in products belonging to category you are viewing, if that makes sense.

Displaying all manufacturers on homepage is fine but once you click on category it should only display manufacturers from products in that category.

cherie 03-24-2012 07:02 AM

Re: Display manufacturer list on category page
 
You could do something like this on the product listing or subcategories tpl (untested):

PHP Code:

{foreach from=$products item=p}
  {foreach 
from=$manufacturers_menu item=m}
    {if 
$p.manufacturerid $m.manufacturerid}
      {
$p.product},
    {/if}
  {/foreach}
{/foreach} 


gb2world 03-24-2012 03:58 PM

Re: Display manufacturer list on category page
 
You will need to make an array of the manufacturers unique to that category. Try something like:
In products.php:
Code:

foreach ($products as $k => $v) {
  $manuf_this_cat[$products[$k]['manufacturerid']] = $manuf_this_cat[$products[$k]['manufacturerid']]+1;
}
$smarty->assign('manuf_this_cat',$manuf_this_cat);


Then in the template, probably subcategories.php, you can go through that array:
Code:

{if $manuf_this_cat}
<hr />
<ul>
{foreach from=$manuf_this_cat key=k item=v}
<li>
manufacturerid:{$k}<br />
number items this cat:{$v}<br />
name: {$manufacturers.$k.manufacturer}<br />
</li>
{/foreach}
</ul>
<hr />
{/if}


Powertrain 03-24-2012 10:38 PM

Re: Display manufacturer list on category page
 
Quote:

Originally Posted by gb2world
You will need to make an array of the manufacturers unique to that category. Try something like:
In products.php:
Code:

foreach ($products as $k => $v) {
  $manuf_this_cat[$products[$k]['manufacturerid']] = $manuf_this_cat[$products[$k]['manufacturerid']]+1;
}
$smarty->assign('manuf_this_cat',$manuf_this_cat);


Then in the template, probably subcategories.php, you can go through that array:
Code:

{if $manuf_this_cat}
<hr />
<ul>
{foreach from=$manuf_this_cat key=k item=v}
<li>
manufacturerid:{$k}<br />
number items this cat:{$v}<br />
name: {$manufacturers.$k.manufacturer}<br />
</li>
{/foreach}
</ul>
<hr />
{/if}



We are getting somewhere now O:)

That code display this list in array:
  • manufacturerid:4
    number items this cat:6
    name: Dodge
  • manufacturerid:5
    number items this cat:1
    name: Ford
Now we need to display those manufacturers as links with name as anchor text?

Thanks.

gb2world 03-25-2012 12:19 PM

Re: Display manufacturer list on category page
 
{if $manuf_this_cat}
<hr />
<ul>
{foreach from=$manuf_this_cat key=k item=v}
<li>
manufacturerid:{$k}<br />
number items this cat:{$v}<br />
name: {$manufacturers.$k.manufacturer}<br />
link: <a href="manufacturers.php?manufacturerid={$k}">{$man ufacturers.$k.manufacturer}</a>
</li>
{/foreach}
</ul>
<hr />
{/if}

---

Powertrain 03-25-2012 01:16 PM

Re: Display manufacturer list on category page
 
That does it :)

I did notice a bug tho, manufacturer name that is displayed is wrong.

What I noticed is that it pulls correct masnufacturer IDs but displays wrong name.

Is it in the products.php code?

Thanks.

gb2world 03-25-2012 01:57 PM

Re: Display manufacturer list on category page
 
Take care just when coping and pasting code from the forum - it looks like the forum software put an extra blank space in $manufacturers. I should have enclosed it in code tags

---

Powertrain 03-25-2012 04:58 PM

Re: Display manufacturer list on category page
 
Quote:

Originally Posted by gb2world
Take care just when coping and pasting code from the forum - it looks like the forum software put an extra blank space in $manufacturers. I should have enclosed it in code tags

---


I did caught that blank space and corrected it but still manufacturer name comes out wrong.

any idea?

Thanks.

gb2world 03-25-2012 07:34 PM

Re: Display manufacturer list on category page
 
Reviewing the code I provided, it is escaping me how the id could be right and the name be off. You could have something in your cart instance that I am not considering.

You can debug it by using webmastermode and looking at the contents of the $manufacturers array and the $manuf_this_cat array and seeing where the data is wrong, then correcting the code from there.

---

cherie 03-27-2012 01:04 PM

Re: Display manufacturer list on category page
 
It looks like the original array only stores id=count with no name.

The manufacturer name is already there in $manufacturers_menu as in my earlier code example.

gb2world 03-27-2012 02:24 PM

Re: Display manufacturer list on category page
 
I was thinking that $manufacturers used the actual id as the first key of the 2 dimensional array. But I did a quick check and the first key is just a counter - so my code needs to be fixed. No time to try this - syntax may be off, but something like this should do the trick:

In products.php:
Code:

foreach ($products as $k => $v) {
  $manufac_id = $products[$k]['manufacturerid'];
  $manuf_this_cat[$manufac_id] = func_query_first_cell ("SELECT manufacturer FROM $sql_tbl[manufacturers] WHERE $sql_tbl[manufacturers].manufacturerid='$manufac_id'");
}
$smarty->assign('manuf_this_cat',$manuf_this_cat);


Then in the template:
Code:

{if $manuf_this_cat}
<hr />
<ul>
{foreach from=$manuf_this_cat key=k item=v}
<li>
manufacturerid:{$k}<br />
name:{$v}<br />
link: <a href="manufacturers.php?manufacturerid={$k}">{$v}</a>
</li>
{/foreach}
</ul>
<hr />
{/if}


cherie 03-27-2012 03:01 PM

Re: Display manufacturer list on category page
 
Now on top of a new array there's an extra query for every product. I really don't recommend doing it like this. I would just use the data that is already there.

gb2world 03-27-2012 03:18 PM

Re: Display manufacturer list on category page
 
Good point - to avoid multiple queries you can go back to the original $products array and query for the manufacturer name as well as the id. But the array he is requesting is not already there. You can either add to the query in the php or cycle through the product and manufacturers arrays to get it.

---

gb2world 03-27-2012 09:20 PM

Re: Display manufacturer list on category page
 
Here is a way to do it by cycling through the existing product and manufacturer arrays in php and avoiding adding multiple queries. You can also do it in smarty as Cherie suggests, I just find php to be easier.
in products.php:
Code:

foreach ($products as $k => $v) {
  $manufac_id = $products[$k]['manufacturerid'];
  foreach ($manufacturers as $key => $value) {
    if ((!$manuf_this_cat[$manufac_id])&&($manufacturers[$key]['manufacturerid']==$manufac_id)) {$manuf_this_cat[$manufac_id]=$manufacturers[$key]['manufacturer'];}
  }}

$smarty->assign('manuf_this_cat',$manuf_this_cat);



In subcategories.tpl
Code:

{if $manuf_this_cat}
<hr />
<ul>
{foreach from=$manuf_this_cat key=k item=v}
<li>
manufacturerid:{$k}<br />
name:{$v}<br />
link: <a href="manufacturers.php?manufacturerid={$k}">{$v}</a>
</li>
{/foreach}
</ul>
<hr />
{/if}



The most efficient way would be to modify the original query for $products to include the manufacturers name by joining the manufacturers table, then you would not have to cycle through the manufacturers array to get the name. But that query is built in kind of a complex way and is used in many places, so, at least for me, it would take some effort to do it and test it.


---


---


All times are GMT -8. The time now is 09:57 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.