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)
-   -   What is the Smarty variable for Provider company name? (https://forum.x-cart.com/showthread.php?t=62041)

jake8804 12-15-2011 11:35 PM

What is the Smarty variable for Provider company name?
 
I am trying to display the Provider's company name on the product details page. My current code is:

<tr>
<td class="property-name">{$lng.lbl_company}</td>
<td class="property-value" colspan="2">{$userinfo.company}</td>
</tr>

Obviously $userinfo is wrong (I got that from the provider account page in admin) but I can't see anything in the debugging console that would work. So can someone tell me what is the correct smarty variable?

Thank you!

jake8804 12-15-2011 11:43 PM

Re: What is the Smarty variable for Provider company name?
 
I see a $product.provider but that would just give me the Provider's # instead of name...

totaltec 12-15-2011 11:57 PM

Re: What is the Smarty variable for Provider company name?
 
Unfortunately, I don't think you can accomplish this from within Smarty or a template.

Your going to have to add the provider name to the product array, or initialize a separate variable containing the name. You've got the number, just query the db for the name associated with it and add it to the array or assign it to a new variable.

Hope that helps,
-Mike

jake8804 12-16-2011 12:40 AM

Re: What is the Smarty variable for Provider company name?
 
I am making some progress on understanding this system of web design :-). I COULD run an SQL query directly from the template right now and get the info that way but that is undesirable, yes?

The query will be something like:

SELECT customers.company
FROM customers
JOIN products
ON customers.provider = products.provider;

And then the Smarty assign is:

$smarty->assign('company',$product);

How do I put them together?
Also, I have been trying to figure out which .php file to use to assign variables to $product...which one is it? I am more of a database guy than a web designer lol

totaltec 12-16-2011 12:55 AM

Re: What is the Smarty variable for Provider company name?
 
You are right, no queries from the template. Definitely a bad practice.

But that doesn't look like the right way to assign to smarty. What you have there looks like it will assign whatever value $product has to a new smarty variable called company.

It is not going to assign anything to the product array like that.

I have to admit that I am also confused by your query. Join on customers.provider. There is no such column name that I am aware of.

Bear in mind that I have much less experience with x-cart pro than I do with gold. That may be my confusion.

-Mike

jake8804 12-16-2011 01:34 AM

Re: What is the Smarty variable for Provider company name?
 
My knowledge of Smarty a few hours ago was zero and it has risen very little so far. You're right about that query not making sense...I should get some sleep haha.

There is a customers.company and products.provider but no way to join the tables. I can't see any table that connects provider to customers.id or customers.company. Maybe I'm too tired...I'll try again tomorrow.

totaltec 12-16-2011 01:45 AM

Re: What is the Smarty variable for Provider company name?
 
Sleep helps...sometimes. :)

{$provider_info} is the variable that is usually initialized with an array containing the provider info:

Array (5)
id => "1"
login => "mike@babymonkeystudios.com"
title => "Mr."
firstname => "Michael"
lastname => "White"

I can't give you a crash course on Smarty, but if you know php, smarty will come naturally over time. It is even easier for me than php itself. I like writing eq or ne instead of == or !=. It truly is a "smart" language- pun intended. :_)

Let me know when you get stuck. Post real code examples and I will help where I can. If you need more than just volunteer support, I can help out professionally as well.

-Mike

cflsystems 12-16-2011 06:40 AM

Re: What is the Smarty variable for Provider company name?
 
Quote:

Originally Posted by jake8804
I am making some progress on understanding this system of web design :-). I COULD run an SQL query directly from the template right now and get the info that way but that is undesirable, yes?

The query will be something like:

SELECT customers.company
FROM customers
JOIN products
ON customers.provider = products.provider;

And then the Smarty assign is:

$smarty->assign('company',$product);

How do I put them together?
Also, I have been trying to figure out which .php file to use to assign variables to $product...which one is it? I am more of a database guy than a web designer lol


Don't run php code from within the templates - bad practice and slows down everything. You need to find the function that puts the product info together in include/func/func.product.php and modify the query that gets all product info together (or add new one) to include provider's name. No need for other changes or smarty assigns - everythign is done for you by the function and the info will just add to $product array and eventually to $products array on products list pages

jake8804 12-16-2011 03:46 PM

Re: What is the Smarty variable for Provider company name?
 
This is from func.product.php:

$product = func_query_first("SELECT $sql_tbl[products].*, $sql_tbl[products].avail-$in_cart AS avail, MIN($sql_tbl[pricing].price) as price $add_fields FROM $sql_tbl[pricing] INNER JOIN $sql_tbl[products] ON $sql_tbl[pricing].productid = $sql_tbl[products].productid AND $sql_tbl[products].productid='$id' $join WHERE 1 ".$login_condition.$p_membershipid_condition.$pric e_condition." GROUP BY $sql_tbl[products].productid");

The problem is that, the way X-Cart is set up, there is no way to join the customers table (where the provider information is also stored) to the products table (where the only reference to the provider is an auto-increment in column products.provider). X-Cart should have put providers in a separate table; then you could easily have a connection between providers and products without creating a many-to-many relationship. Will I have to create an association class/table to eliminate the many-to-many relationship?

jake8804 12-17-2011 12:44 PM

Re: What is the Smarty variable for Provider company name?
 
I decided to just take the easy way out and create an extra field for every vendor/provider with a default value being their company name. Not ideal, but it works since I'll only have 10 to 20 vendors. I also created a "Shop by Vendor" category with the "Vendor" Extra Field linking to each vendor's page. I also made that extra field show up on the product list page. Good 'nuf. :p


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

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