Update price when attributes are selected

Posts: 17
Joined: 08/07/2007

When attributes hold different prices - You'll see the exstra amount after the attribute in the "select option"-menu...

I would like it not to show (which I managed) but instead update the display_price/sell_price on the node, so it gets visible to customers how much the full price is of the product with a chosen attribute. (Before they add it to the cart.)

I was trying to use jquery, but can't figure out how/ where to use it.

Any help is very welcome.

Lots of other webshops have this behavior, other Übercart-users must need this too... (?) Did anyone succed in doing this?

Thanks a lot for help/advices/solution/comments Smiling

Posts: 17
Joined: 08/07/2007

It seems that http://frames.texasexes.org did almost what we want... Except they have a preview-button to make the update...

Does anyone know how they achieved their solution?

(I'll write them one of the following days if nobody have a suggestion.)

Thanks again. Smiling

Posts: 3898
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

I thought megg or Phoenix or someone was working on this before the crash... we'll have to search around to see if we can find it in the Google cache. A quick search only turned up a few requests for that functionality and a little bit of discussion about it. No results or who it was workin' on it.

I really dig the way the Texas Exes have done their frame previews. That's pretty incredible!

Posts: 95
Joined: 08/08/2007
Getting busy with the Ubercode.Internationalizationizer

that _would_ be cool functionality... i was more trying to affect the layout of the form, adding notes between the selects, etc. it's still on my list of things to do.

this thread seems to be aiming for something kind of similar, though:
http://www.ubercart.org/forum/support/26/jquery_help

Posts: 83
Joined: 08/07/2007
Bug FinderGetting busy with the Ubercode.

I believe the way to approach issues of this kind is to look into adding some functionality to the attribute system. I would like the ability to push the configuration to an ahah handler, which would reply with some of the key items(price, image change, or additional options based on the the option chosen).

As far as how we should do this, there was some discussion before 'the crash' about performing image changes and the product attributes schema as a whole.

I am interested in taking a look at this, but I have 3-4 other items on my list first.

Posts: 3898
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Ahh, that's right... it was CpILL/mike. Sorry, megg. Eye-wink

Anyways, I've reposted that thread of CpILL's here:
http://www.ubercart.org/forum/development/78/images_attached_product_atr...

Posts: 17
Joined: 08/07/2007

I really need this behavior in my shop... and must admit I'm to confused over the drupal/übercart structure (hooks - scripts - templates). I would love to understand and make a solution the drupal-way with either a new (extension-)module or perhaps a new attributes module... But I'll proberbly end up with some kind of hack. Sad

On one of my other sites (with a simple handmade cms) I implemented a feature pretty much doing just that... very simple with the help of prototype... How come this is so difficult to obtain in drupal/übercart?

After all it's just a javascript-thing updating a div-field/value based on a html-select option.

Is it just me... goofing to much around in the code confusing myself? or is this simple thing really so complicated in drupal/übercart?

Please help. Smiling

---

@ mikejoconnor

Thanks a lot for your links.

Those 3-4 items are they big?

In other words... when do you think you'll have time to look at this?

As mentioned above, I really need this feature/behavior - and think it's relatively simple...

So any help you can give makes me very happy. Thanks. Smiling

Posts: 17
Joined: 08/07/2007

@ megg

Ooops, sorry didn't follow your link at the time - saw it earlier, without answers... Now it actually looks like that could be a solution...

But again, a hack. Why is it so difficult to do it "nicely"?

Posts: 461
Joined: 08/13/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer

Why not just made it with jquery ?

you create a .js file in which you get the attribute price when you select an attribute in the dropdown menu.

in a file like node-product.tpl.php, you just put an drupal_add_js('my_js_file.js');

If, one day, the functionnality is in ubercart core, you can just remove the attached .js file you made.

Posts: 17
Joined: 08/07/2007

Well, that's actually what I tried, but unfortunately did not succed with...
Please look at this thread... http://www.ubercart.org/forum/support/26/jquery_help

As you can see, I'm having trouble using a js-file in node-product.tpl.php - as I'm showing many products on the same /taxonimy/term list.

Any idea or solution are very welcome.

Posts: 275
Joined: 11/19/2007
Bug FinderGetting busy with the Ubercode.

I wrote a module that I believe will do what you were looking for here. There are some restrictions on how it works and also it is a first pass, but give it a try if you'd like and give me some feedback.

http://www.ubercart.org/contrib/2010

Posts: 1896
Joined: 08/07/2007
AdministratoreLiTe!

Sweet action. This is awesome, and I'm glad I didn't have to figure out how to do it. Evil

A few things I want to point out:
In _calculate_price(), use {uc_product_options} WHERE nid = %d AND oid = %d. You can change the price of an option on a per-product basis.

Use uc_currency_format() instead of number_format() so the $ sign isn't hard-coded.

Do you know why there are so many AJAX requests for every selection that's made? It seems excessive, but I haven't dug deep enough yet to find out why it's happening.

Great job.

Posts: 275
Joined: 11/19/2007
Bug FinderGetting busy with the Ubercode.

Thanks for taking a look at it and thank you for the quick feedback. I'll make those adjustments you suggested.

As far as excessive AJAX requests, it is doing them onChange of any attributes that exist...so I guess if you are looking at a page with a bunch of products each having a bunch of attributes it is going to make a separate AJAX call for every attribute during the initial page load. I might be able to alter it so that on initial load it only makes one call per product or so that an adjusted price is calculated right off the bat without AJAX calls.

I'll need to set up a larger sample cart to get a feel for what is practical.

Posts: 1896
Joined: 08/07/2007
AdministratoreLiTe!

No, I was looking at a product with only two attributes. That shouldn't be the problem.

I just looked at it again today, and I noticed that the number of POST requests doubled every time I changed an option. That explains why I couldn't get rid of the failure messages last night.

Posts: 275
Joined: 11/19/2007
Bug FinderGetting busy with the Ubercode.

Ahh....that was silly. I had it adding another $(this).change(function) each time it looped back through to do the evaluation. I took the assignment of the change functions out to an initialize function to fix it. I'll upload all the updates a little later. Thanks again for the troubleshooting.

Posts: 275
Joined: 11/19/2007
Bug FinderGetting busy with the Ubercode.

I accidentally deleted the contrib while trying to delete the file attachment and upload a new one. The changes are now uploaded at...
http://www.ubercart.org/contrib/2010

Posts: 2
Joined: 03/07/2008

Just what I needed. You guys are awsome!