Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

get manufacture in products.php

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 10-25-2004, 08:38 AM
  jds580s's Avatar 
jds580s jds580s is offline
 

Advanced Member
  
Join Date: Oct 2004
Posts: 38
 

Default get manufacture in products.php

I'm trying to call the manufacture of a product in products.php so it is accessible in the smarty template customer/main/products.tpl
as {$products[product].manufacture} or something similar.

I've dead-ended 2 of my previous attempts to get this to work, has anyone done something similar before, or have any ideas on how to go about it?

x-cart 4.0.5
PHP 4.3.9
MySQL 4.0.20-standard
Linux

I really appreciate any advice

Justin
__________________
animator for hire
onthez.com
------------------------
x-cart v4.0.5 Linux
_________________
Reply With Quote
  #2  
Old 10-25-2004, 09:05 AM
 
pmstudios pmstudios is offline
 

Senior Member
  
Join Date: May 2004
Posts: 133
 

Default

You would have to merge two arrays or create one specifically for manufactures and just use it with the products array. And manufacturers have their own table, so you would need to use the manufactureid from the products table.

Something like this
Code:
foreach ($products as $k => $v) { $manufacturers = func_query("SELECT $sql_tbl[manufacturers].* FROM $sql_tbl[manufacturers]" WHERE manufactureid='".$products[$k]["manufacturerid"]'.""); } $smarty->assign("manufacturers", $manufacturers);

Example of use in products.tpl
Code:
{section name=product loop=$products} {$products[product].product} {if $products[product].manufacturerid eq $manufacturers[product].manufacturerid}owned by {$manufacturers[product].manufacturer}{/if} {/section}

Sorry for the rugged example. This should set you in the right direction at least, if it doesn't work.
__________________
X-Cart 4.0.5
MySQL: 3.23.58
PHP 4.3.2
Reply With Quote
  #3  
Old 10-25-2004, 10:09 AM
  jds580s's Avatar 
jds580s jds580s is offline
 

Advanced Member
  
Join Date: Oct 2004
Posts: 38
 

Default

I'll preface this by saying I'm no PHP expert, I can usually take care of the task at hand, but this x-cart install is my first venture into SQL, everything I've done before has been PHP with flat text files.

That said, I'm getting a parse error in products.php
It looks to me like it's a quotes issue after WHERE manufactureid=
My attempts resolve it continue to produce an error too, so perhaps I'm wrong about that. Does anythings stand out to you?

Quote:
Sorry for the rugged example. This should set you in the right direction at least, if it doesn't work.
Thanks very much, no sorry needed. The concept makes much better sense than what I was doing.
__________________
animator for hire
onthez.com
------------------------
x-cart v4.0.5 Linux
_________________
Reply With Quote
  #4  
Old 10-25-2004, 10:38 AM
 
pmstudios pmstudios is offline
 

Senior Member
  
Join Date: May 2004
Posts: 133
 

Default

You're right jds580s,

Here's the fixed query
Code:
$manufacturers = func_query("SELECT $sql_tbl[manufacturers].* FROM $sql_tbl[manufacturers]" WHERE manufacturerid='".$products[$k]["manufacturerid"]."'");
__________________
X-Cart 4.0.5
MySQL: 3.23.58
PHP 4.3.2
Reply With Quote
  #5  
Old 10-25-2004, 12:29 PM
  jds580s's Avatar 
jds580s jds580s is offline
 

Advanced Member
  
Join Date: Oct 2004
Posts: 38
 

Default

OK, I've almost got this working, it will correctly display the manufactures name of the first product in a catagory, but none of the subsiquent one.

for anyone else who references this I modified at least one or two things here in products.php
Code:
foreach ($products as $k => $v) { $manufactureid=$products[$k]["manufacturerid"]; $manufacturers = func_query ("SELECT $sql_tbl[manufacturers].* FROM $sql_tbl[manufacturers] WHERE manufacturerid='".$products[$k]["manufacturerid"]."'"); } $smarty->assign("manufacturers", $manufacturers);

and simplified the products_t.tpl code for my needs
Code:
{if $products[product].manufacturerid ne "0"}{$manufacturers[product].manufacturer}{/if}

Any ideas on why products after the first don't display?
The conditional statement in the .tpl file is correct, when I put some text in there it is "true" for all the products that have a manufacture set, it's just the $manufacturers[product].manufacturer that is only working on the first product.

Thanks!
__________________
animator for hire
onthez.com
------------------------
x-cart v4.0.5 Linux
_________________
Reply With Quote
  #6  
Old 10-25-2004, 12:39 PM
 
pmstudios pmstudios is offline
 

Senior Member
  
Join Date: May 2004
Posts: 133
 

Default

I thought that may happen..

Try adding a new section loop for the $manufacturers array.

Code:
{section name=id loop=$manufacturers} {section name=product loop=$products} // etc... {/section} {/section}
__________________
X-Cart 4.0.5
MySQL: 3.23.58
PHP 4.3.2
Reply With Quote
  #7  
Old 10-25-2004, 01:36 PM
  jds580s's Avatar 
jds580s jds580s is offline
 

Advanced Member
  
Join Date: Oct 2004
Posts: 38
 

Default

Ok, closer still... now it displays the manufacture for all the items that have the same manuf as the last item in the list.

this code also displays the manufacture id number "manid" to help me identify what id is with what product
Code:
{if $products[product].manufacturerid ne "0"} {assign var="manid" value=$products[product].manufacturerid} manid is {$manid} {section name=id loop=$manufacturers start="0"} {if $manid eq $manufacturers[id].manufacturerid} {$manufacturers[id].manufacturer} {/if} {/section} {/if}

you can see what this looks like http://www.yarnsmith.co.uk/xcart/home.php?cat=3

the first item's manufacture is Katia manid=6
__________________
animator for hire
onthez.com
------------------------
x-cart v4.0.5 Linux
_________________
Reply With Quote
  #8  
Old 10-25-2004, 02:08 PM
 
pmstudios pmstudios is offline
 

Senior Member
  
Join Date: May 2004
Posts: 133
 

Default

Ok, I just checked the method I use since I'm actually doing something similar - not with manufacturers but the idea is exactly same. Do away with everything else and try this...

Make a new function in func.php
Code:
function func_get_manufacturers($manufacturerid) { global $sql_tbl; return func_query("SELECT $sql_tbl[manufacturers].* FROM $sql_tbl[manufacturers] WHERE manufacturerid='$manufacturerid'"); }

In products.php
Code:
if ($products) { foreach ($products as $k => $v) $manufacturers[] = func_get_manufacturers($v["manufacturerid"]); } $smarty->assign("manufacturers", $manufacturers);

In products.tpl just use
Code:
{$manufacturers[product].manufacturer}


That should work. If not, I'll resign and bake donuts from now on
__________________
X-Cart 4.0.5
MySQL: 3.23.58
PHP 4.3.2
Reply With Quote
  #9  
Old 10-25-2004, 04:50 PM
  jds580s's Avatar 
jds580s jds580s is offline
 

Advanced Member
  
Join Date: Oct 2004
Posts: 38
 

Default

This seems a little more streamlined, and puts a manufacture at the top of each product... but it looks like the first product is manufacture1 second product is manufacture2 and so on.

http://www.yarnsmith.co.uk/xcart/home.php?cat=3 see example

looks like instead of checking the manufacture ID against the name it is taking the number of the foreach loop that it is on.
__________________
animator for hire
onthez.com
------------------------
x-cart v4.0.5 Linux
_________________
Reply With Quote
  #10  
Old 10-25-2004, 04:56 PM
 
pmstudios pmstudios is offline
 

Senior Member
  
Join Date: May 2004
Posts: 133
 

Default

Ok, then in the template add the if statement
Code:
{if $manufacturers[product].manufacturerid eq $products[product].manufacturerid} {$manufacturers[product].manufacturer} {/if}

should solve the problem...
__________________
X-Cart 4.0.5
MySQL: 3.23.58
PHP 4.3.2
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 02:59 PM.

   

 
X-Cart forums © 2001-2020