X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   get manufacture in products.php (https://forum.x-cart.com/showthread.php?t=10007)

jds580s 10-25-2004 08:38 AM

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

pmstudios 10-25-2004 09:05 AM

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.

jds580s 10-25-2004 10:09 AM

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.

pmstudios 10-25-2004 10:38 AM

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"]."'");

jds580s 10-25-2004 12:29 PM

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!

pmstudios 10-25-2004 12:39 PM

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}


jds580s 10-25-2004 01:36 PM

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

pmstudios 10-25-2004 02:08 PM

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 :lol:

jds580s 10-25-2004 04:50 PM

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.

pmstudios 10-25-2004 04:56 PM

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...


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.