![]() |
Product options on products.tpl
Has anyone or can anyone figure out how to get product options to display while viewing multiple products? :?:
I already have an the add to cart and quantity showing on this page but am totally stumped for getting options to show. :? Any help would be greatly appreciated!! :!: |
This requires quite a bit of backend PHP modifications for such to exist. If you wish you can submit a request to me via the link in my signature and I can provide you quote for such modifications. ;)
|
Boomer
This is quite an interesting one to solve - just did it myself for a client. 8) |
Almost finished my own version...
If anyone wants to clue me into how you chose to write your javascript validation and exceptions code to work on multiple products on the same page, I'd love to hear it. I don't need the code, just the logic. I've resorted to using a preg_replace to parse out the function names and give them numbers. Was this part of your solutions or did you find a more elegant approach?
I've got the code working on my test server (though I still need to add the quantity select menu to the products.tpl) with only one minor problem left to solve (one of my Javascript functions is being incorrectly numbered because I'm using the wrong increment variable). Post UPdate: I think I've finally conquered this one. It was definitely a brain teaser and I still haven't tested it with the validation exceptions, but now my script displays product options (but not quantity) on the products.tpl page. It ain't pretty and I had to stoop so low as to grab some php array values by numeric index rather than by associative index and do some lame preg_replace-ing, but it seems to work for me. I'll post the results of my hair-pulling session in a bit. |
Solution to product options on products.tpl
Well it was harder than it should have been and this may not be the best way, but here's the code to do it in xcart 3.3.1.
You will need to modify the following files: customer/products.php skindirectory/customer/main/products.tpl And you'll need to create the following file: skindirectory/Modules/Product_Options/customer_options_productspage.tpl I am pasting the code below with no warranty whatsoever. I have left extensive comments in the customer_options_productspage.tpl where certain functionality remains unfinished because I don't need it yet. It is also there to give other programmers a possible starting point for finishing this script. Note: among the unimplemented functionality is price modification based on chosen options. In other words, if you have options that modify the price of your product, this code will not work as is. Othewise, you should be okay using this code, but I don't guarantee it. Here's the code: customer/products.php Code:
<? skindirectory/customer/main/products.tpl Code:
{* $Id: products.tpl,v 1.21.2.1 2003/01/20 12:57:59 svowl Exp $ *} skindirectory/modules/Product_Options/customer_options_productspage.tpl Code:
{* $Id: customer_options.tpl,v 1.6 2002/10/22 10:27:05 olga Exp $ *} The above code really needs some cleaning up and there's still some code in there for my own custom mods that you may not have. I'll come back later and clean it up if anyone wants me to. Enjoy. |
Thanks
Thanks minorgod for posting this. It is Greatly Appreciated! :D
I haven't tried it out yet but I will take a look through it right away. I do need prices to change based on different options but I will see if I can figure that out and post it back here. If you get that figured first I'd love to see it. Thanks again, Marty |
Just pay attention to all the code I commented out. It would probably be easier for you to just delete all that extra code and start writing your own price modifier from scratch or based on the original product options code. If you need any explanation of what's happening in my code, just let me know. It's still working great for me, but it's only tested in my version of x-cart which is heavily modified already (so much so that I will probably never be upgrading). Good luck, and please do post your results if you figure it out.
|
Not working properly
I tried the code but am getting just the empty text field instead of the options. For some reason the product_options array isn't loading in. I don't quite understand where you got the index array #4 from. Maybe it needs to be different for me since it isn't an associative array. That's all I can think of right now that might not be making it work properly.
If you could explain your code a bit, that might help me. :? Thanks, Marty :) |
You should modify your xcartdir/smarty.php file. Change the line that reads
Code:
$smarty->debug_tpl="file:debug_templates.tpl"; Code:
$smarty->debug_tpl="file:debug.tpl"; Now launch your store in webmaster mode...open a new customer window and browse to a product category where the options should be displaying. In the debug window you will see a full list of all assigned PHP variables and their values. In my PHP code, I used the numeric index [4] because I didn't see an associative index containing my options as a string (which needs to be parsed by the func_parse_options() function). Look for an index in the $products[i][product_options] array that contains your options as such and replace the index [4] with whatever that index turns out to be. This might fix things for you. The original product options code was designed to work with only a single product and therefore the old code produces a $product_options array which only holds options for the specific product being viewed on the detail page. Since our new script must keep track of options for more than one product, I've simply extended the $products array which is already generated by x-cart, to include product_options with each product. So my code essentially loops through the $products array, and creates a sub array in each product called "product_options". Oh...and your empty text field showing up, means that the code is nearly working...it just can't find the parsed options. The options code is designed to default to an empty text field if you haven't specified any options (such as blue\n,yellow\n,red\n,etc.) when setting up your options for that product in the admin interface. So it seems you are on the right track. I think if you fix that array index to point to a valid index, it should work for you. Let me know if you have any luck. |
Got the box to fill
I figured out the associative array and now the option box is populating properly. Instead of putting the number 4 in you just have to put 'options' in. For some reason the hyperlink to the detail page isn't working properly for me with your template code. I am going to have to look in to that now and then I will try to figure out the pricing issues.
Thanks for your help. The modified debugging window really helps. I didn't know about that one. Thanks, Marty :D |
Hey, thanks for figuring out the array index I needed. Let me know if you figure out the price modification code or if you see any other flaws in my code. I may be generating more dynamic javascript functions than are necessarry to make the options work...haven't yet tried to optimize the code in any way.
|
Price changing
Minorgod,
The price modification is working for me with the code that you gave me. I haven't made any changes besides the array change. I am however using a different products.tpl file than you. I don't think this would really affect anything. I can post my code if you want. Just let me know. :D Marty |
Sweet...I hadn't even tried using the price modification part of the product options, but that actually makes sense now that I think about it, since the original product options code is what still gets run by all the other areas of the site. Since the prices on the products.tpl output aren't javascript-accessible in their current form, it would be a serious pain in the ass to have to modify the price display directly on the products.tpl page based on what options are chosen. Anyway, this makes me happy. Thanks for the info!
|
Thanks for working with me too!
I appreciate the collaboration! :D |
updated products.php page...
Below is an update to my modified customer/products.php page for displaying options on the products.tpl page.
Code:
<? |
Possibly a faster way to do this...
After I created the mod above, I noticed that my site was running slower and I suspected it was because the code above was looping through the products and doing a separate query for each product options and then lopping through the products again and doing a separate query for each product javascript options.
I rewrote the script so that it only does two queries, one to get all the options, and one to get all the javascript. I then loop through the products and and options and javascripts to associate the proper options and javascript with each product without doing any more MySQL queries. In the end, I'm not sure if this way is faster since I'm now forced to loop through all the options for each product to associate them, and then loop through all the javascripts for each product to associate the correct javascript with each product. So ultimately, there's a lot more loops happening and I can't tell if I've made it faster or not. At any rate, here's the code...it still works with the modified templates posted above. Code:
<? If anyone knows if this is faster than the previous method, let me know please. Thanks...and...uh...you're welcome. |
Thanks Brett :)
If you do any more optimization, can you please keep this thread updated. Appreciated. |
How can we add options to the featured products page?
|
Can't you just use the above example? I haven't looked at it yet, but I'll need to modify my featured products page at some point. If I do the modifications I'll post them here.
|
I used the code above, but it didn't work for the featured products.
|
Any thoughts anybody? This is important for me. Thanks.
|
Did you modify the template as well? You need to modify both the PHP source code and the template code to display the options properly.
|
Yes I modified both, and it works well for the category listings. However it doesnt' work for featured products.
|
SQL error in version 4.0.12
I've tried to adapt this code for my 4.0.12 x-cart store, but keep getting this error:
Quote:
The error occurs with any product (any productid) regardless of whether or not it has product options. I'm pretty sure the error is in the products.php file in this section: Code:
// first we build a query to get all the product options with a single query I know this is an old thread, but if anyone has adapted this code for 4.x.x of x-cart, I'd be grateful for any insight. Many thanks, Joe |
It looks like you have no value for $sql_tbl[product_options]. Make sure this is defined properly. They may have changed the name of the table in the newer version of x-cart, so just go into your config file or look at your xcart database and make sure you are usnig the correct key name in your $sql_tbl array to specify the product_options table.
|
SQL Error gone, but options still not shown on products.tpl
minorgod,
Thanks so much. You were right on the money that the SQL values were not properly defined. I went into config.php and added: Code:
"product_options" => "xcart_product_options_ex", to the SQL Table aliases (there is also "xcart_product_options_lng" which I have not figured out yet how it works with "xcart_product_options_ex"). I noticed that in the SQL table for xcart_product_options_ex there was no productid field and that now it was called optionid. As such I edited your mod in products.php to reflect this: Code:
$query="SELECT * from $sql_tbl[product_options] WHERE "; This removed the SQL errors, however the products.tpl does not display the product options. In fact, the product pages display as if no changes have been made. Obviously I am missing something (not surprising as I feel I am in over my head with this mod). Any suggestions on where to look next would be most appreciated. Joe |
product options on products page
Did you ever get this figured out for 4.0.x?
I am looking for a solution |
Re: product options on products page
Quote:
I never did find a solution for this. As I needed this for only a couple of products, I ended up making a workaround in which I formatted my product.tpl to resemble my products.tpl and then linked directly via the Categories list to individual products. Joe |
All times are GMT -8. The time now is 06:29 AM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.