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

jds580s 10-26-2004 09:10 AM

For anyone else reading this I made one other small change and it is working like a charm

in products(_t).tpl I change the code to
Code:

{*** ########## Lines below to display manufacture name ########## ***}
{assign var="manid" value=$products[product].manufacturerid}
{if $manufacturers[$manid].manufacturerid ne "0"}
{$manufacturers[$manid].manufacturer}

{/if}
{*** ########## End display manufacture name ########## ***}


Before it was returning manufacture name based on the current loop number. And not it doesn't display anything if there is no manufacture set for a product.

Thanks pmstudios for all the help!

TheComputerGuy 10-27-2004 06:31 AM

Ok, i'm also interested to display the Manufacture, but instead of the Products (customer/main/products.tpl) I want to display it on the actual Product Page (customer/main/product.tpl).

All I want to do is have is something as simple as:

Manufacture: Sony

Can some please help with what code to insert into the template file?

Thank you...

pmstudios 10-27-2004 07:10 AM

Quote:

Originally Posted by TheComputerGuy
Ok, i'm also interested to display the Manufacture, but instead of the Products (customer/main/products.tpl) I want to display it on the actual Product Page (customer/main/product.tpl).


In product.php, near the bottom (add lines marked with +)
Code:

$smarty->assign("product",$product_info);

+ $manufacturer = func_query_first("SELECT manufacturer FROM $sql_tbl[manufacturers] WHERE manufacturerid='$product_info[manufacturerid]'");
+ $smarty->assign("manufacturer", $manufacturer);


In customer/product.tpl, use {$manufacturer.manufacturer} to display it...

TheComputerGuy 10-27-2004 11:33 PM

thank you very much! Works a charm

i just don't understand why that option wasn't standard.

genekurtz 10-29-2004 10:37 AM

In customer/product.tpl, use {$manufacturer.manufacturer} to display it...


Where do I place {$manufacturer.manufacturer} within the code of the customer/main/product.tpl page? Do I need to put it within any other code?

jds580s 10-29-2004 10:42 AM

That shouldn't need to go any place in particular.

Typically it would be between the {capture} and {/capture} near the top and bottom of the file

pmstudios 10-29-2004 10:48 AM

Quote:

Originally Posted by genekurtz
Where do I place {$manufacturer.manufacturer} within the code of the customer/main/product.tpl page? Do I need to put it within any other code?


You can put it anywhere. The product info page is product specific, so the script selects the manufacturer of that product.

genekurtz 10-29-2004 10:51 AM

OK

You have to place it within the template at the spot on the page where you want it to show up. If you place it at the bottom of product.tpl it will show up after all of the other tables on the page.

It works great!

Thanks

dalmuti 10-29-2004 11:04 AM

That did work great. Just what I wanted.....except.. I would like to also add the SKU in the same place...product.tpl.

Can anyone give me the code to add?

Thanks,

Dalmuti

pmstudios 10-29-2004 11:20 AM

Quote:

Originally Posted by dalmuti
That did work great. Just what I wanted.....except.. I would like to also add the SKU in the same place...product.tpl.

Can anyone give me the code to add?

Thanks,

Dalmuti


You should be able to reference it by just using {$product.productcode} as it's already included in the select product query.

dalmuti 10-29-2004 11:41 AM

Perfect! Got it done. Appreciate the help!

Dalmuti

august 11-11-2004 12:06 AM

Quote:

$smarty->assign("product",$product_info);

+ $manufacturer = func_query_first("SELECT manufacturer FROM $sql_tbl[manufacturers] WHERE manufacturerid='$product_info[manufacturerid]'");
+ $smarty->assign("manufacturer", $manufacturer);

Could anybody post the variant that instead of saying
Manufacturer:Timex
It will show the brandlogo, something like
Timex.gif (brand logo)
else
Timex (text)

To me the customer recognize faster the logo than the name
.

Also, how can I change the manufacturer.php so it will put the brandlogos and names in several columns, instead of one column name.
With an output like this: http://www.makeitfast.com/default.php?manufacturers_id=11

vortexonline 02-07-2005 10:34 AM

Manufacturer logo?
 
How about a manufacturer logo?
How can I place the manufacturer's logo above the product tile?

I am kind of envious of newegg.com

I like how the manufacturer logo appears with the products.

Thanks in advance.

pmstudios 02-07-2005 11:39 AM

Re: Manufacturer logo?
 
Quote:

Originally Posted by vortexonline
How about a manufacturer logo?
How can I place the manufacturer's logo above the product tile?

I am kind of envious of newegg.com

I like how the manufacturer logo appears with the products.

Thanks in advance.



Basically the same exact method, but instead use {$manufacturer.image}

Make sure you have image included in the SELECT query too.

mpj 02-07-2005 04:09 PM

Quote:

Make sure you have image included in the SELECT query too.

Sorry, how do you go about doing this ?

Here is the MySQL table fields:

Full Texts manufacturerid manufacturer url image image_type descr orderby provider avail





Thanks for a great mod !

pmstudios 02-07-2005 07:21 PM

Quote:

Originally Posted by mpj
Sorry, how do you go about doing this ?


Modify the code added in product.php so the query looks like this:
Code:

$manufacturer = func_query_first("SELECT manufacturer,image FROM $sql_tbl[manufacturers] WHERE manufacturerid='$product_info[manufacturerid]'");

Quote:

Originally Posted by mpj
Thanks for a great mod !


And you're welcome :)

mpj 02-08-2005 08:24 AM

great work pmstudios!

I've just started out on PHP so please forgive my noobness

As for
Code:

{manufacturer.image}
this would output the blob in raw GIF89 code.


Here's what I've done for displaying manufacturer's image:

in products.tpl

to display image:
Code:

[img]mlogo.php?manufacturerid={$manufacturerid.manufacturerid}[/img]

to display the manufacturer name and a link that display other products by the manufacturer:
Code:

Manuacturer: {$manufacturer.manufacturer}


in product.php
Code:

$manufacturer = func_query_first("SELECT manufacturer,image,image_type,manufacturerid FROM $sql_tbl[manufacturers] WHERE manufacturerid='$product_info[manufacturerid]'");
$smarty->assign("manufacturer", $manufacturer);


$manufacturerid = func_query_first("SELECT manufacturerid FROM $sql_tbl[products] WHERE manufacturerid='$product_info[manufacturerid]'");
$smarty->assign("manufacturerid", $manufacturerid);



Thanks again pmstudios for an excellent code!

RQJay 05-10-2005 09:34 PM

I am sorry to ask, but i am having no luck on getting this to work for me, I have to be missing somthing....

In my Product.php file I added this code :
Code:

# Manufacturers Logo In Products
$smarty->assign("product",$product_info);

$manufacturer = func_query_first("SELECT manufacturer,image FROM $sql_tbl[manufacturers] WHERE manufacturerid='$product_info[manufacturerid]'");
#end logo in Products


And added this to my Product.Tpl file :
Code:

[img]mlogo.php?manufacturerid={$manufacturerid.manufacturerid}[/img]

Pretty much as directed. But still no luck. My product template does display the Xcart image place holder but not the manufacturers Logo.

Any help is greatly appreciated.
Jason

august 05-11-2005 11:02 PM

Hey MPJ, it is in products.tpl or product.tpl
In the other post they are talking about product.tpl

Hey Vortex, can you post your code, is exactly what I want to do, put the logo at the top, and the text under the image product.

RQJay 05-14-2005 09:22 PM

Bump-o-

august 05-15-2005 12:56 PM

Ok I got it:
instead of

Quote:

[img]mlogo.php?manufacturerid={$manufacturerid.manufact urerid}[/img]

It should be:

Quote:

[img]{$xcart_web_dir}/mlogo.php?manufacturerid={$product.manufacturerid} [/img]


dmr8448 05-15-2005 04:59 PM

Manfacturer Name and Link in Products List
 
I am trying to get the manfucturer name to display on the products listing page. I have done the following:

==========================================

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:
{*** ########## Lines below to display manufacture name ########## ***}
{assign var="manid" value=$products[product].manufacturerid}
{if $manufacturers[$manid].manufacturerid ne "0"}
<FONT class="ItemsList">{$manufacturers[$manid].manufacturer}</FONT>

{/if}
{*** ########## End display manufacture name ########## ***}

==========================================

The problem I am having is the the link shows the incorrect manufacturer name, but when I click on the link it takes me to the correct manufacturer page.

Thanks
David

X-Cart version 4.0.12
PHP 4.3.10
MySQL server 4.0.23-nt-max
MySQL client 3.23.49
Web server Microsoft-IIS/6.0
Operation system Windows
XML parser (expat) 1.95.6

august 05-15-2005 07:36 PM

This is the way it works for me:

In product.php before the smarty assigns

Quote:

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


In product.tpl you have to play different positions that you'll like to see it display
You can use this one:
Quote:

<tr><TD align="left" valign="top">
Producer:

</td>
<TD align="left" valign="top">
{$manufacturer}
<font size=1 face=Arial>(click to get all products from this brand)</font>

</td>
</tr>


or you can use yours.

Forget about the func.php

davros 05-16-2005 07:08 AM

Hello
I've been working my way through this thread and managed to get the manufacturer displaying items on the product page (product.tpl) and the product list (products.tpl) - thanks very much to pmstudios and jds580s for that. You've helped me get my head round xcart quite a bit with your posts.

However, I can only get the manufacturer to display per product. In fact I want to display all the products for a manufacturer. I think this might need to be done in products_t.tpl but I can't really work out what's going on in there.

In fact I really want the manufacturer to be a subcategory but that doesn't seem to be an option. Any help with this would be greatly appreciated.

Davros

august 05-16-2005 09:12 AM

You mean:
http://www.your-domain.com/manufacturers.php

davros 05-16-2005 09:54 AM

No - manufacturers.php just gives a list of _all_ manufacturers. I want to list the items by manufacturer for each category.
So when I go to home.php?cat=1
I want
Category 1
Manufacturer 1
item 1
item 3
Manufacturer 2
item 2
item 4
item 5
etc

At the moment I get
Category 1
item 1 - manufacturer 1
item 2 - manufacturer 2
item 3 - manufacturer 1
item 4 - manufacturer 2
item 5 - manufacturer 2

Does that make sense?

august 05-17-2005 01:06 PM

You can do that manually, you create the category, your subcategories will be the name of the manufacturers or brands, and then you assign the products to each one, also you can put a logo to each of the subcategories(brands). Also you can use one of the mod's that handle subcategories for your products presentation.
Hope this help.

finestshops 05-25-2005 07:39 AM

Re: Manfacturer Name and Link in Products List
 
Quote:

Originally Posted by dmr8448
The problem I am having is the the link shows the incorrect manufacturer name, but when I click on the link it takes me to the correct manufacturer page.


Just a summary of things we did to show manufacturer name in the list of products (thanks to pmstudios and jds580s)

add to include/func.php

Code:

#
# Function to get manufacturers into product list
#
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

before this line:

Code:

$smarty->assign("products",$products);

add

Code:

#
# Get products manufacturers
#
if ($products) {
foreach ($products as $k => $v)
$manufacturers[] = func_get_manufacturers($v["manufacturerid"]);
}
$smarty->assign("manufacturers", $manufacturers);
#
# Get products manufacturers



in customer/main/products.tpl or customer/main/products_t.tpl:

after

Code:

<FONT class="ProductTitle">{$products[product].product}</FONT></A>

add

Code:

{* show Manufacturer name *}


<FONT class="sitesmall">Manufacturer:
{assign var="manid" value=$products[product].manufacturerid}
{if $manufacturers[$manid].manufacturerid ne "0"}
{$manufacturers[$manid].manufacturer}
{/if}
{* show Manufacturer name *}


Example is here:

http://www.reach4life.com/store/home.php?cat=554

august 05-26-2005 01:35 PM

Hey 27stars, I'm glad that you convinced them to change to x-cart. I used to have their old shopping cart too.

btomasie 06-26-2005 06:15 PM

I cannot get this code to work for me. I have followed all the different variations that many of you have placed in this thread, but can't any of them to work.

Here is my thread, any help would be appreciated!
http://forum.x-cart.com/viewtopic.php?t=20524

Brian


All times are GMT -8. The time now is 06:23 AM.

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