The Commerce module version 7.x-1.11 contains a fix Remove the default product entity from the form state just prior to caching. A side effect of this update is, that the price on the Add to cart page is no longer updating, when changes are made in the form on that page.

The problematic bit of code introduced by that change:

 * After build callback for Add to Cart forms
*/
function commerce_cart_add_to_cart_form_after_build(&$form, &$form_state) {
  // Remove the default_product entity to mitigate cache_form bloat and performance issues.
  if (isset($form_state['default_product'])) {
    $form_state['default_product_id'] = $form_state['default_product']->product_id;
    unset($form_state['default_product']);
  }
  return $form;
}

...is in conflict with the submit function of the Commerce Pricing Attributes module:

function commerce_pricing_attributes_add_to_cart_submit($form, $form_state){
  if (isset($form_state['default_product'])) {
    $current_product = $form_state['default_product'];
  }
  elseif (isset($form_state['products'])) {
    $current_product = reset($form_state['products']);
  }
  else {
    return;
  }
 .............
}

So changing a value, or clicking the add to card button does not change the product price.

Comments

doidd created an issue. See original summary.

doidd’s picture

Issue summary: View changes
tedbow’s picture

Version: 7.x-1.0-beta4 » 7.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new1.17 KB

It seems that we need to load the product again from $form_state['default_product_id'].

I have attached a patch that does this in commerce_pricing_attributes_add_to_cart_submit and commerce_pricing_attributes_add_to_cart_form_attributes_refresh functions.

It seems to make it work with both the ajax callback and submitting the add to cart form.

ANDiTKO’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm that the patch from comment #3 works perfectly. Both ajax and submit work as expected after applying the patch.

webengr’s picture

WELL POOH, I was pulling my hair out recreating products trying to figure out what I did wrong for more than an hour
Should have read all the issues first.

THE PATCH WORKS FOR ME

PLEASE get this fixed for the next release, because it was critical for us, customer lost sales on gift card options because of it.

webengr’s picture

Priority: Normal » Major
alpinemedia’s picture

Patch #3 (7.x-1.x-dev) does not work for me.

The ajax price is changed on the display to the correct price, however the original price is added to the cart.

FranCarstens’s picture

This error actually prevented any of my options from being saved to the line-item. The patch fixed that. Thank you! Spent 2 days trying to figure out what was going on.

alpinemedia’s picture

On further tries the patch basically works on a clean Commerce Kickstart install, however I cannot get it to work on my site configuration even with extensive disabling of modules and swapping templates. Checked rules and views to see what might be different.

I did notice on the Kickstart install that the adding to cart pop up message does not reflect the selected option price and shows the original set price, by clicking continue shopping the top bar cart contents shows the non-option price too and it is only when you click the checkout link that the price does update in the checkout panel (and the top bar cart price) to the selected option price. This would not be very user friendly and cause confusion to shoppers.

alpinemedia’s picture

My issue on my own site configuration was due to the use of commerce file and license modules and using the inline_entity_form-commerce_license widget.

Changed the inline_entity_form-commerce_license widget from to select list in the line items fields configuration at admin/commerce/config/line-items/product/fields

iampuma’s picture

Status: Reviewed & tested by the community » Patch (to be ported)

This needs to be ported to a stable release, else this module is just not usable.

andrea.brogi’s picture

Hi, I have apply the patch #3.
Inside the product display page the price is correctly changed but when I add it to cart the price remain the original.
If I put again the object into the cart, the second time the price is update also into the cart. The first remain with the original price.
Into checkout instead the price is correct for all items.

Ps. If I reload the page the price is update correctly.

andrea.brogi’s picture

StatusFileSize
new111.69 KB
new103.32 KB
neograph734’s picture

Status: Patch (to be ported) » Reviewed & tested by the community

Since the patch is for the Drupal 7 version and this thread is for the Drupal 7 version of the module there is nothing to port. This patch is RTBC. But it would be nice to see it committed to the module.

yannisc’s picture

kurti’s picture

I´m using:

Product option 1.0-beta2
Products attributes 1.0-beta3

And Pricing attributes 1.0-beta4 width #3 path.

Inside the product display page the price is correctly changed, but when I add it to cart the price remain the original.

¿¿ Is there anything to change more ??

I´m desperated...

Many thanks!!

giorgosk’s picture

#3 works as expected applied to the latest version
using 7.x-1.0-beta4 since dev is 1 day older

should be committed

giorgosk’s picture

StatusFileSize
new56.76 KB

@Kurti you have to apply the patch from comment #3
read more here https://www.drupal.org/patch/apply

here is also a patched file if you want to just replace it in your installation (do it at your own risk)

rename the file from .module.txt to .module

AndreyMukha’s picture

patch 3 work for me, thanks

pradeepjha’s picture

patch #3 works for me.

brandonc503’s picture

so with patch im getting

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /system/ajax
StatusText: Service unavailable (with message)
ResponseText: Recoverable fatal error: Argument 2 passed to drupal_array_get_nested_value() must be of the type array, null given, called in /modules/field/field.default.inc on line 38 and defined in drupal_array_get_nested_value() (line 6932 of /includes/common.inc).

not on all pricing attributes instances. and some of the same option set with different pricing attribute fields work and some dont.

brandonc503’s picture

this is that line of code; for me .

function &drupal_array_get_nested_value(array &$array, array $parents, &$key_exists = NULL) {
$ref = &$array;
foreach ($parents as $parent) {
if (is_array($ref) && array_key_exists($parent, $ref)) {
$ref = &$ref[$parent];
}
else {
$key_exists = FALSE;
$null = NULL;
return $null;
}
}
$key_exists = TRUE;
return $ref;
}

shahidbscs’s picture

#3 patch worked for me, thank you

designate’s picture

Still facing the same behaviour as described by Kurti in #16, same module versions, commerce 7.x-1.13. The product display page shows the correct price when changing attributes, but when I add the product to the cart the price displayed within the cart block remains unchanged untill I visit the cart page itself. Using bartik theme with cart block in the left column.

emmanvazz’s picture

Patch #3 worked for me. Thanks.

anybody’s picture

Please please please create a new dev release containing this patch in #3. The current dev and stable are definitely broken without it.
Could someone find out why #16 appears on some pages? For me it didn't.

inweb’s picture

This patch #3 does not work.. Please, is there another fix for this? Such a shame..
Thanks

inweb’s picture

Just to mention again.. I have tried this patch

Commerce Version: 7.x-1.13
commerce_pricing_attributes Version: 7.x-1.0-beta4 (Only one available)

I've applied patch #3 with git

Everything functions as it should, except,

1. the price doesn't change in the cart
2. the changes are not captured in the final summary order
3. the changes are not captured in the final order confirmation

It would really be good if this could work, but I think i'm out of time and must move onto anther solutions.
I made a successful option for "colour options" that works as expected,, but using the taxonomy instead. However this in particular is't useful for my case when you have colour and size combinations needed..

Sorry guys, and thanks George, but this one doesn't work here.

ezoulou’s picture

+1 for patch #3 :-)

dtesenair’s picture

I'm having the same issue as #7, #12 & #16....

When I select the attribute on the product display/add to cart form, the displayed price on the node is updating properly from the AJAX call. However, when it is added to the cart, the cart initially displays the product with the original price. However, refreshing the cart view (either by a hard page refresh or visiting the cart page), causes the price in the cart to be corrected. Any thoughts or ideas on what might be causing this?

I am running the following module versions:

  • commerce_option: 7.x-1.0-beta2
  • commerce_product_attributes: 7.x-1.0-beta3
  • commerce_pricing_attributes: 7.x-1.0-beta4 (with the patch from comment #3 properly applied and verified).

I'm new to the Drupal Commerce platform but relatively familiar with Drupal module coding. I'll be happy to poke around in the code and (possibly) submit a patch if there's someone more experienced who can get me pointed in the right direction.

jayarex07’s picture

@tedbow
Thanks so much. I signed in just to say that.
I've been trying to figure out this solution for about a week for a website I'm working on for a client and immediately after patch #3 I've been able to stop ripping the little hairs I have left from stressing because my issue was magically solved for me.

Not sure I would have found the solution prior to deadline so..

THANK YOU AGAIN!!!

anybody’s picture

@Maintainer: Could we get a beta-5 with this patch included? That would be so wonderful! :) Open since years...

anybody’s picture

Still RTBC since years... any chance to get this in? Any active maintainer?

sano’s picture

Issue summary: View changes

making problem description more clear

anybody’s picture

The module has 6 maintainers, is anyone able to review and commit a major issue which is open since 2015? ;) ....

avpaderno’s picture

Issue tags: -Commerce (duplicate)

I am replacing the duplicate issue tags used in the past. I apologize for bumping this issue.