| ||||||||||
Shopping cart software Solutions for online shops and malls | ||||||||||
|
X-Cart Home | FAQ | Forum rules | Calendar | User manuals | Login |
Passing Smarty Variables to PHP? | ||||
|
|
Thread Tools | Search this Thread |
#11
|
|||||||
|
|||||||
You're right. I don't think I've adequately explained it. I have added a column to the xcart_products table for "Unit of Issue" (unit). I needed to be able to tell the customer at a glance whether the item was a set of 4, set of 12, a dozen in a bag, etc.
But the unit column itself only contains unit codes (ST4, ST12, BG, etc). The full descriptive unit names (ie, Set of 4) are stored in a separate table that I created. The ultimate goal is to add a line underneath the price of each product that says "Unit of issue: " and then insert the descriptive unit name, so that it reads something like "Unit of issue: Set of 4". So I created a php file that would take the productid (which products.tpl already is using), then query the xcart_products table to determine the unitcode, then query the unit table to determine the full unit name and display it as "Unit of issue: Set of 4". Seemed pretty easy to me. I figured I could just include that PHP file in the template right where I wanted it to appear, and that would be that. But since the PHP file can't use any Smarty variables, I'm stuck. Hope that clears things up a bit. I got confused just writing it |
|||||||
#12
|
|||||||
|
|||||||
...
Ok correct me if I'm wrong but could you add that into the array that products.php already creates, that is if the array doesn't already have it, and then in the tpl file use it by something like { $products[product].unit } ?
__________________
-tmx- |
|||||||
#13
|
|||||||
|
|||||||
Re: ...
Quote:
I guess what this may come down to is just finding a different way of storing the unit information in the db, but I'm once again having to do things differently just to cater to Smarty. Ugh. |
|||||||
#14
|
|||||||
|
|||||||
...
Ok so couldn't you set that other table up into an array in either another php file with just an include or just in products.php and use what $products[product].unit comes up to get the full unit name using the same basic method?
__________________
-tmx- |
|||||||
#15
|
|||||||
|
|||||||
variable passing
-tmx- described the exact process that I did. I had the same scenario where I added a new "leadtime" field to the products table. All that went into that field was a CODE that was translated from a new table ("leadtimes"). In the product.php code, I pulled the contents of the leadtimes table into an array. In the product.tpl, I then just referenced the matching entry in the array to the code in the product. That way I could change the "leadtimes" table at any time to change custom leadtimes based upon product characteristics without having to do a mass change in to all entries in the products table.
Let me know if you want an example of either the php or tpl files.
__________________
-Derrick FreeRangeMinds, LLC |
|||||||
#16
|
|||||||
|
|||||||
Re: variable passing
Quote:
|
|||||||
#17
|
|||||||
|
|||||||
passing variables/alternative approach
AJ,
I just pulled my code (it has been a little while). It looks like I did the "correlation" in the product.php program, and left the cross-referenced narrative (from the leadtimes table) in a single element array (could have just assigned to a variable) that is referenced in the product.tpl. Here is a snippet from the product.php (much hacked 3.1.1/3.1.2 version): Code:
Here is how I referenced it in product.tpl (once again from hacked 3.1.1 tpl file). Just a simple expression of the array. This was one of the first changes I made when I first started working with X-Cart, so I could have cleaned this up with just a single variable instead of an array, so you see the array index fixed to [0] Code:
Hope this helps. Let me know if I can provide any more details.
__________________
-Derrick FreeRangeMinds, LLC |
|||||||
#18
|
|||||||
|
|||||||
No dice. I tried something very similar to your code:
Code:
...and when I go to any product page, I get the "Access denied ! You are not allowed to access that resource!" message. I also thought about just trying to build my own query, based on the productid, but I can't even figure out how to get that variable. $products['productid'] doesn't work. I'm sure I'm nearing ten hours on this and I'm about to bug out. Once again, my client is going to have to suffer because Smarty is a pain in the ass. Thanks a bunch for the help so far, and if you've got any other ideas, I'm dying to hear them |
|||||||
#19
|
|||||||
|
|||||||
Can you send the tpl where you are accessing the variables?
Either in the forum our out, I can look at it later today. Can you also send the version you are working with?
__________________
-Derrick FreeRangeMinds, LLC |
|||||||
#20
|
|||||||
|
|||||||
more Smarty fun
AJ,
I did look through your posting again (actually read it closely this time) and think I see what the problem is. In my example, I was using the product (not products) table and therefore could do a simple lookup in the php code and pass the variable onto the tpl. In your case, you have an entire array of products. In your sample code (from the Forum), you are trying to do a select to populate the $unit_text array that is trying to match "code" to an entire array, not a single element. That is what is causing the access error. Just load the entire "units" table into the "$unit_text" array in the products.php program. Code:
Code:
Code:
Give it a try! If it still doesn't work, send me an email and I should be able to get my test site back on 3.2.2 tomorrow. Hope this helps.
__________________
-Derrick FreeRangeMinds, LLC |
|||||||
|
|||
X-Cart forums © 2001-2020
|