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
Comment #2
doidd commentedComment #3
tedbowIt 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.
Comment #4
ANDiTKO commentedI can confirm that the patch from comment #3 works perfectly. Both ajax and submit work as expected after applying the patch.
Comment #5
webengr commentedWELL 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.
Comment #6
webengr commentedComment #7
alpinemedia commentedPatch #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.
Comment #8
FranCarstens commentedThis 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.
Comment #9
alpinemedia commentedOn 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.
Comment #10
alpinemedia commentedMy 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
Comment #11
iampumaThis needs to be ported to a stable release, else this module is just not usable.
Comment #12
andrea.brogi commentedHi, 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.
Comment #13
andrea.brogi commentedComment #14
neograph734Since 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.
Comment #15
yannisc commentedComment #16
kurti commentedI´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!!
Comment #17
giorgosk#3 works as expected applied to the latest version
using 7.x-1.0-beta4 since dev is 1 day older
should be committed
Comment #18
giorgosk@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
Comment #19
AndreyMukha commentedpatch 3 work for me, thanks
Comment #20
pradeepjha commentedpatch #3 works for me.
Comment #21
brandonc503 commentedso 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.
Comment #22
brandonc503 commentedthis 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;
}
Comment #23
shahidbscs commented#3 patch worked for me, thank you
Comment #24
designate commentedStill 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.
Comment #25
emmanvazz commentedPatch #3 worked for me. Thanks.
Comment #26
anybodyPlease 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.
Comment #27
inweb commentedThis patch #3 does not work.. Please, is there another fix for this? Such a shame..
Thanks
Comment #28
inweb commentedJust 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.
Comment #29
ezoulou commented+1 for patch #3 :-)
Comment #30
dtesenair commentedI'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:
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.
Comment #31
jayarex07 commented@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!!!
Comment #32
anybody@Maintainer: Could we get a beta-5 with this patch included? That would be so wonderful! :) Open since years...
Comment #33
anybodyStill RTBC since years... any chance to get this in? Any active maintainer?
Comment #34
sano commentedmaking problem description more clear
Comment #35
anybodyThe module has 6 maintainers, is anyone able to review and commit a major issue which is open since 2015? ;) ....
Comment #36
avpadernoI am replacing the duplicate issue tags used in the past. I apologize for bumping this issue.