Spinoff from #1376724: Refactor _uc_attribute_alter_form(). Selecting an option on the add to cart form should update product fields as well as the display of attribute prices.

Comments

wodenx’s picture

Status: Active » Needs work
StatusFileSize
new11.22 KB

Here is a patch as a starting point. It updates the prices of attribute options when they are displayed as 'total price' to be accurate even if there are more than one priced attribute associated with a product. The second part of the patch turns off this functionality for checkboxes, because that seemed confusing.

Responses to longwave's comments from the parent issue:

I want to see more Ajax used in the Ubercart front end but found the price updates a bit confusing/disconcerting when in "total" mode. I think we should hold off implementing this until we can also update the sell price and display price fields via Ajax at the same time (and perhaps the weight too), effectively bringing uc_aac into core - and preferably let's break this out into a separate issue, here I was only trying to refactor existing code rather than add new functionality.

Did you find this confusing with select/radio options as well as checkboxes? I totally agree about checkboxes, but the other makes sense to me because the price next to each option is always the correct total with that option selected.

Do you think both the sell price and the display price should be updated? Or perhaps only the display price (and the weight)?

uc_aac (which I hadn't even known existed...) also provides an option to modify the price adjustments so they're always relative to the display price - do you agree with this approach? (as I recall, that's how places like Dell and Lenovo handle configurable systems - once you select an option, cheaper ones are listed with a negative value).

marking as "needs work" because I think we want additional functionality.

wodenx’s picture

By the way - updating the other product fields should be very easy to do once #1301430: Inclusive tax implementation is not flexible (attribute options) goes in.

artatum’s picture

This is a great news that this feature is about to be moved on D7.
I've tried to edit the module,( manually) with the patch above. The spining icon is there when I click on an option but my price remains unchanged.
Could you put the whole uc_attribute.module file please ? Or maybe I missed smthing...
thx a lot for this long awaited work...

wodenx’s picture

As longwave said in the other thread, this is still a work in progress (hence the "needs work" status) - I don't think this will be completed until #1301430: Inclusive tax implementation is not flexible (attribute options) lands.

artatum’s picture

As you were talking of 'total price', and my attributes are displaying the difference for now, I looked for editing my attributes display but could not find the menu item for that. Could you tell me where it can be edited please ?

wodenx’s picture

You specify how option prices are displayed at admin/store/settings/products - is that what you're looking for?

artatum’s picture

Bingo!
Gee I looked for it 100 times there, yet. Shame on me.
But THX a LOT.:-)

wodenx’s picture

Assigned: Unassigned » wodenx

Patch at #1 no longer applies.

wodenx’s picture

Status: Needs work » Needs review
StatusFileSize
new19.19 KB

Completely reworked this - attached patch provides a generic mechanism for any module which adds fields to the "add-to-cart" form to cause node display to update based on customer input. It then uses this mechanism to update display-price, cost and weight when attribute options change.

The mechanism is controlled by a store-wide product setting.

Definitely need some tests to go with this...

Status: Needs review » Needs work

The last submitted patch, 1380772-attribute-ajax-9.patch, failed testing.

jarrodirwin’s picture

Hey this is a great addition and is almost exactly what I would say a lot of people are asking after (including myself).

One question I do have is does this provide the ability to update the initial product price on the node? I would like to use the 'Display price adjustment' option but have it also update the overall price depending on what attribute is chosen.

Do I need to add a particular id/class to the theme of the product price or anything like that or is that out of scope of this patch?

wodenx’s picture

Status: Needs work » Needs review
StatusFileSize
new19.1 KB

Tests were failing because they assumed the attribute prices would be included. Changed the default behavior - but I still need to write some tests for this.

@jarrodirwin: This updates the "display_price" of the node - not the "sell_price". I don't update the sell_price because I think it will be usefulto have both the unmodified and modified prices available for display. No you don't need to add any css.

wodenx’s picture

Status: Needs review » Needs work

The method used to determine which divs to replace on the node display is theme dependent and needs to be changed.

longwave’s picture

benitezv1ang’s picture

Status: Needs work » Needs review

#12: 1380772-attribute-ajax-12.patch queued for re-testing.

wodenx’s picture

Status: Needs review » Needs work

Status is "needs work" because of #13.

tr’s picture

Now that 3.0 is out I'd like to make an effort to get this finished!

wodenx’s picture

I'm swamped at the moment, but I think this is just waiting for #629048: By default, product (node) elements are undistinguishable in a multi-product display. Once that (or something like it) gets in, it should be pretty easy to fix the issue in #13.

combait’s picture

What is the status of this feature ? Can i implement 1 of the patches or do i need to wait for a fix ?

longwave’s picture

You can try out the patch in #12 and see if it works for you. Please post back with your results; whether it works or not may depend on your theme as noted above.

combait’s picture

What dependencies are required for this to work ?

wodenx’s picture

StatusFileSize
new18.63 KB

Rebased this to the current DEV. I think it's really only being held up by the issue mentioned in #18

general975’s picture

I couldn't get the patch to work (im using tortise svn and it rejected all the changes, even when I remove the a/ and b/ folder paths)

I did, however, make all the changes manually. Like post #21 are there dependencies for this to work? Everything works as normal so to me that says that I got all of the php code right., but no update of the prices.

update: to clarify, I am showing the Display price, and hiding both the Sell price and List price

wodenx’s picture

Status: Needs work » Needs review
StatusFileSize
new18.63 KB

The patch applies with some offsets - here is a rebased version. Also, assuming your by-hand changes are complete, you need to enable this feature at admin/store/settings/products by checking the box labelled "Update product display based on customer selections".

general975’s picture

Thanks wodenx!

It works great for me using a modified version of bluesmaster. My only complaint is that the ajax, and thus the spinning update icon, is used for attributes that have a $0 price adjustment. I'll probably dive into the code to see where I can put in a condition to check for this.

ComputerWolf’s picture

#24: 1380772-24-attribute-ajax.patch queued for re-testing.

general975’s picture

Has this been tested with the newest ubercart update?

Also, I have been unable to get the patch to work either with tortoisesvn or cygwin.

jarrodirwin’s picture

I can confirm it applies cleanly and works as expected with 7.x-3.1

Poieo’s picture

Working well with 7.x-3.1.

However, I second @general975 in that there should be a check to see if the attribute has a price adjustment before calling the ajax function. The current patch attempts to update the price regardless of whether or not the attribute actually has a price adjustment.

benitezv1ang’s picture

how can i apply the patch on my site
Can you please help me
Thanks

stewart.adam’s picture

Details on how to do so are available in the Drupal documentation: http://drupal.org/patch/apply

jarrodirwin’s picture

Anyone using this having any issues with speed? It takes an age for the total to update on my site.

http://www.pwnpcs.co.uk/?q=laptops/sager-n6175-clevo-w170er-high-perform... (click Configure tab)

Any ideas on how to speed this up?

chertzog’s picture

Cross posting from #1691666: Unexpected behavior with other ajax modules.

The patch in #24 applies clean, and seems to work. But when used in conjunction with UC Dropdown Attributes stuff breaks. I cant tell if the problem is because if this patch or the other module, because they both work perfectly when used independently.

benitezv1ang’s picture

i tried the patch on my site with no luck can some one post a zip file as module.
I want to test it and work on the module too.

benitezv1ang’s picture

Can you please send me a copy of theAjax-ify attribute option price selection
as module not a patch
I try patch and does not work for me
Thanks

longwave’s picture

@benitezv1ang: We do not supply pre-patched modules, please use http://drupal.org/patch/apply to learn how to apply patches, or explain why you had "no luck" and someone might be able to help.

digital fire’s picture

Just tested on UC 7.x-3.1. Ajax icon spins like its doing something but it doesn't modify the Display price.

digital fire’s picture

If I can get in contact with any of the maintainers. I'm willing to run tests with very quick turn around responses on the tests. Would love to help with the issue that the display price isn't changing.

longwave’s picture

@Digital Fire: That is perhaps related to the problem described in #13 - what theme are you using? If you change your theme to Bartik, does the Ajax update work?

digital fire’s picture

Just ran that test and it did not work. I am using the whitebull theme which is a pretty simple/basic theme.

digital fire’s picture

Let me know if there is anything else I can try.

longwave’s picture

@Digital Fire: The patch works for me in both Bartik and Whitebull, after patching, clearing cache and enabling the checkbox. Perhaps this has the same cause in your setup as #1669796: Items won't add to cart?

There are some minor code style issues in this patch which I will try to clean up soon, otherwise it looks good to me. I don't see why we have to wait for #629048: By default, product (node) elements are undistinguishable in a multi-product display to get this into -dev.

longwave’s picture

StatusFileSize
new24.23 KB

Updated patch with coding standards and documentation fixes. Code is otherwise identical to #24.

digital fire’s picture

Well in that particular issue. I was dealing with an old site. Thats the reason i'm using the whitebull theme. I created a new site from scratch since the old one was hacked to hell from previous devs. ATM I don't have any caching enabled since i'm still in dev with this one. I will go over the patch one more time and make sure I did everything correctly (I'm manually patching).

digital fire’s picture

It might have something to do with the particular way I have my products set up. Right now the products have a 0$ price. You pick an attribute and that is what is supposed to be the final product price. I will try adding a base price for the product and the attribute should just add to the final price. Maybe it has something to do with it being a base line 0$. Will review my patch, test this theory and report back.

digital fire’s picture

Below you will find pastebins of my patched code for review and in case anyone needs to manually patch the code like I did. I don't think I missed anything so the next step I will take is listed any additional modules I have that may be interfering with this. If there are any particular modules that you KNOW will conflict. Please let me know.

longwave’s picture

There is nothing I know of that should conflict with this, although obviously I don't know every single module out there. So the Ajax spinner spins, but the page never updates? Does the spinner eventually stop? The next thing I would try is debugging with Firebug to see what, if anything, comes back in the Ajax update. If your site is publically available, posting a link will let other people help debug - or contact me privately if you don't want to post the link here.

digital fire’s picture

I sent you a message with the link. Indeed the AJAX spinner comes up for about a second or two and then goes away. I tried using firebug, but could not find any changes (Probably due to my inexperience with Firebug as I prefer to use the inspect tool).

digital fire’s picture

I tried using Firebug and I did see ajax doing SOMETHING but it appeared as if it never touched the display price.

longwave’s picture

The Ajax is working, your product node div id is missing, which means your problem is #629048: By default, product (node) elements are undistinguishable in a multi-product display. I sent more details by email.

longwave’s picture

StatusFileSize
new28.41 KB

This patch adds classes to the replaced elements, working around #629048: By default, product (node) elements are undistinguishable in a multi-product display for many cases. Doesn't work with product kits or where the same node is displayed twice on the page. To solve this I think we need a more complex solution using drupal_html_id(), but perhaps this is good enough for now.

digital fire’s picture

It works! Thank you so much! Will be posting and linking to this on the SE. If there is any additional testing I can help with on this or any other issue. Feel free to message me and I will assist where/when ever possible.

longwave’s picture

Status: Needs review » Fixed

Committed #51. Bug reports about this feature, or followups for the issues I mentioned above, should be posted as new issues.

digital fire’s picture

Good Morning. Any idea when the product kits will be integrated with the ajax price change?

maen’s picture

I have exactly the same issue like Digital Fire. It's sending something but it seems there's no result. @ Digital Fire: Could you please explain how to theme in Ubercart 3 Drupal 7 the divs to achieve the goal?
I don't believe that I'm the only one who stucks here...
Do I only have to create a node--product.tpl.php and render some divs with nid? Is there a special theme to use for attributes? Would be awesome to read about!

THX in advance

maen

benitezv1ang’s picture

is now included in Ubercart 7.x-3.x-dev and will be in 7.x-3.2 when it is released. Enable the feature by checking "Update product display based on customer selections" at /admin/store/settings/products.

Posted by longwave on August 8, 2012 at 4:40pm

maen’s picture

Thx a lot, very good!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

benitezv1ang’s picture

I nedd some help
it works ok with out custom node but
I need to update Total Price in custom node. node--product.tpl

Help me please
Thanks

<p><?php print render($content['add_to_cart']); ?></p>
                         
<p>List Price:<?php print uc_currency_format($node->list_price); ?></p>
<p>Sell Price:<?php print uc_currency_format($node->sell_price); ?></p>
benitezv1ang’s picture

ubercart 3 update price

Here is the the code to update price in custom page after selection. node--product.tpl

<p><?php print $title ?></p>

<div class="uc_product_image"> <?php print render($content['uc_product_image']);?> </div>

<div class="uc_product_body"> <?php print render($content['body']);?> </div>


 <p><?php print render($content['add_to_cart']); ?></p>
               
<p>Total: <span class="uc-price product-info display-price uc-product-<?php $nid = $node->nid; print $nid; ?>"> <?php print uc_currency_format($node->sell_price); ?> </span></p>
hockey2112’s picture

Can this feature be used on product grids created with Views? I have the Display Price set to be shown in the view, but the attribute selection does not change the price dynamically (even though the little blue circle spins when making a selection).

xl_cheese’s picture

Does anyone have a solution to also update the SKU? The D6 aac module used to update the price and the sku, but this only seems to update the price.

Thanks for any help!

RAWDESK’s picture

Issue summary: View changes

Hi everybody,
I would like to attach this comment i've posted on an issue related to (no)price update after product attribute selection :
https://www.drupal.org/node/2171129#comment-9303073

My currently installed Ubercart version has the 'Update product display based on customer selections' enabled and it works smoothly, except in 1 small 'ifty' case :
If the attribute selection occurs the first time with an anonymous user, the price is not updated.
On chrome and firefox the Ajax icon is visibly running, so i am assuming this issue is not related to ajax directly, although in some other thread, i've read that an ajax 'cache: false' setting might solve some browser caching issues related to ajax.
All subsequent attribute selections then again do perform the price update correctly.

Somebody also experienced this symptom ?

RAWDESK’s picture

StatusFileSize
new437.99 KB

@benitezv1ang
Thanks for the code snippet in #60.
I was even able to use it in combination with the dropdown attributes module resulting in a price update on every option change.

What i still would like to achieve is also an update in my cart item total price.
As illustrated in attached screenshot, i would like to show 156€ (total price including options), instead of 61€ (price without options)

You know in which module i have to include the sell price instead of product price ?
Thanks

*EDIT*
This was related to AURA theme customization, as reported here to support :
http://support.diamondlayers.org/questions/aura-premium-drupal-7-theme/u...