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)
-   -   Manufacturer on Product List / Recommended (https://forum.x-cart.com/showthread.php?t=61592)

mhase 11-12-2011 11:52 PM

Manufacturer on Product List / Recommended
 
I searched through all of the previous topics mentioning this, but none of the solutions seem to have worked for me; I tried adding the following function to product.php:

Code:

//$thisManufactorer = $product_info["manufacturerid"]; 
//$manufacturer = func_query("SELECT manufacturer FROM manufacturers WHERE manufacturerid = $thisManufactorer"); 
//$smarty->assign("manufacturer", $manufacturer[0]); 


(without commenting them out of course), which all seemed pretty straightforward, but didn't seem to work. Also tried (again in product.php):

Code:

$product_info['manufacturer'] = func_query("SELECT manufacturer FROM xcart_manufacturers WHERE manufacturerid='" . $product_info[manufacturerid] . "'");

which again, the logic behind it seems pretty straightforward to me, but didn't work. For reference, here is the code I'm using on the products_t.tpl:

Code:

<div class="brand">{$product.manufacturer}</div>

Webmaster mode even shows manufacturer as a variable under the product arrays, but I just can't seem to access it. Any help appreciated before I slam my head against the wall! :D/

XCart4Life 11-13-2011 12:16 AM

Re: Manufacturer on Product List / Recommended
 
Check out the end of this thread. It looks like the same code but the smarty code they used to call the manufacturer was different. 7thdesire said this allowed him to see the manufacturer name on the products list.

Try changing (in your template products_t.tpl):

PHP Code:

<div class="brand">{$product.manufacturer}</div


To this:

PHP Code:

<div class="brand">{$manufacturer.manufacturer}</div


Edit: I forgot if you are using columns for your products list you want to edit products_t.tpl, if not edit product_list.tpl

mhase 11-13-2011 01:23 AM

Re: Manufacturer on Product List / Recommended
 
Quote:

Originally Posted by XCart4Life
Check out the end of this thread. It looks like the same code but the smarty code they used to call the manufacturer was different. 7thdesire said this allowed him to see the manufacturer name on the products list.

Try changing (in your template products_t.tpl):

PHP Code:

<div class="brand">{$product.manufacturer}</div


To this:

PHP Code:

<div class="brand">{$manufacturer.manufacturer}</div


Edit: I forgot if you are using columns for your products list you want to edit products_t.tpl, if not edit product_list.tpl


Thanks for the idea - one of the codes I was testing in the OP was modified from 7thdesire's. I just plugged in the original again to see if it worked, and tried a few different arrangements for the variable on products_t and none of them appear to display anything:
{$manufacturer.manufacturer}
{$product.manufacturer}
{$manufacturer.manufacturer}{$product.manufacturer } - this one works on the individual product pages, at least!

The <div class="brand"></div>s are showing up though, so at least I'm fairly certain that I'm using the correct .tpl file

XCart4Life 11-13-2011 04:28 PM

Re: Manufacturer on Product List / Recommended
 
Ok I almost slammed my head into a wall too trying to figure this one out. Okay so here's the solution for X-Cart 4.4.4.

FORGET ABOUT PRODUCT.PHP!!! All the other posts are saying to add to that file and it doesn't do anything.

Edit:
/products.php
<---- That's products.... with a 'S' on the end

Find this at the bottom of the file:

PHP Code:

$smarty->assign('cat_products',      isset($products) ? $products : array()); 


Add this magical rare code above that line:
PHP Code:

if ($products)
    foreach (
$products as $k => $v)
$products[$k]['manufacturer'] = func_query_first_cell("select manufacturer from $sql_tbl[manufacturers] where manufacturerid = '$v[manufacturerid]'"); 


Now edit:
/skin/your_skin/customer/main/products_list.tpl (if you are using single column)
/skin/your_skin/customer/main/products_t.tpl (if you are using multi column)

Add this code where you want the manufacturer name to appear:
PHP Code:

{if $product.manufacturer ne ""}
    <
div class="brand">Brand: {$product.manufacturer}</div>
{/if} 


That makes it work on the regular category pages. But if you want it to appear on the search pages read on.


Edit:
/search.php


Find this line all the way at the bottom:

PHP Code:

// Assign the current location line
$smarty->assign('location'$location); 


Add this code above:

PHP Code:

if ($products)
    foreach (
$products as $k => $v)
$products[$k]['manufacturer'] = func_query_first_cell("select  manufacturer from $sql_tbl[manufacturers] where manufacturerid =  '$v[manufacturerid]'"); 


And that's all. This mod is free! :mrgreen:

mhase 11-13-2011 06:15 PM

Re: Manufacturer on Product List / Recommended
 
It worked perfectly on both counts! Thank you so much.

Powertrain 03-23-2012 07:00 PM

Re: Manufacturer on Product List / Recommended
 
Could this be turned into array and display manufacturers on category page?

display only manufacturers that exist in products belonging to category you are viewing

Thanks.

Gennifer 01-03-2013 06:36 AM

Re: Manufacturer on Product List / Recommended
 
XCart4Life--thanks so much for your solution. I was able to get this to work on the homepage of my site, but for some reason, it doesn't work on category or manufacturer product listing pages. Any idea why that might be?

anandat 01-04-2013 07:33 AM

Re: Manufacturer on Product List / Recommended
 
Thanks XCart4Life

I confirm that your code works for 4.5.4 gold+ also :)

Now, I just need some help to display for featured products on home page....do you have any idea ?

anandat 01-05-2013 07:43 AM

Re: Manufacturer on Product List / Recommended
 
Ok I managed to show it for featured products also :D/

Open featured_products.php

Find this at the bottom of the file:
PHP Code:

$smarty->assign('f_products'$products); 


Add this code above that line:

PHP Code:

if ($products)
    foreach (
$products as $k => $v)
$products[$k]['manufacturer'] = func_query_first_cell("select manufacturer from $sql_tbl[manufacturers] where manufacturerid = '$v[manufacturerid]'"); 


Done...Now it should display on featured products also on home page :-)

cherie 01-05-2013 02:55 PM

Re: Manufacturer on Product List / Recommended
 
I recommend doing a single query rather than a separate query for each product. For example (untested):

PHP Code:

$mids = array();
foreach (
$products as $p)
  
$mids[] = $p['manufacturerid'];
if (!empty(
$mids)) {
  
$manufacturers func_query_hash("SELECT manufacturerid,manufacturer FROM $sql_tbl[manufacturers] WHERE manufacturerid IN(".implode(',',$mids).")",'manufacturerid',FALSE,TRUE);
  foreach (
$products as $k=>$p)
    
$products[$k]['manufacturer'] = $manufacturers[$p['manufacturerid']];


I'd rather loop through products twice and do a single query than a single loop with multiple queries.


All times are GMT -8. The time now is 08:33 AM.

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