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 |
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) { Example of use in products.tpl Code:
{section name=product loop=$products} Sorry for the rugged example. This should set you in the right direction at least, if it doesn't work. |
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:
|
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"]."'"); |
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) { 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! |
I thought that may happen..
Try adding a new section loop for the $manufacturers array. Code:
{section name=id loop=$manufacturers} |
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"} 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 |
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) { In products.php Code:
if ($products) { In products.tpl just use Code:
{$manufacturers[product].manufacturer} That should work. If not, I'll resign and bake donuts from now on :lol: |
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. |
Ok, then in the template add the if statement
Code:
{if $manufacturers[product].manufacturerid eq $products[product].manufacturerid} should solve the problem... |
All times are GMT -8. The time now is 08:11 AM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.