This did work fine, but now when adding an item to the cart, I get the following notices and the 'sku' becomes empty.
Notice: Undefined index: default_product in _commerce_product_urls_build_query_string() (line 148 of /home/marvind/public_html/edsonintl/sites/all/modules/commerce_product_urls/commerce_product_urls.module).
Notice: Trying to get property of non-object in _commerce_product_urls_build_query_string() (line 148 of /home/marvind/public_html/edsonintl/sites/all/modules/commerce_product_urls/commerce_product_urls.module).
chain-and-wire-kit?sku=2S15B22
becomes
chain-and-wire-kit?sku
I am using Commerce Product URLs 7.x-1.2 with Commerce 7.x-1.11
I did some digging around and found that the first line in the notes for commerce 7.x- 1.11 is the removal of 'default_product' from the cache. The patch unsets the 'default_product'.
Here is part of their patch and I assume unset($form_state['default_product']); is the problem.
/**
+ * 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;
+}
How do we make this code in Commerce Product URLs compatible and not slow things down?
146 // Add back the current product's query string variable.
147 if (variable_get('commerce_product_urls_url_key', 'id') == 'sku') {
148 $parsed_url['query']['sku'] = $form_state['default_product']->sku;
149 }
150 else {
151 $parsed_url['query']['id'] = $form_state['default_product']->product_id;
152 }
Comment | File | Size | Author |
---|---|---|---|
#12 | commerce_product_urls-undefined_index_default_product-2448143-12.patch | 874 bytes | vasike |
#9 | commerce_product_urls-undefined_index_default_product-2448143-9.patch | 778 bytes | akosipax |
#7 | add_to_cart_triggers-2448143-7.patch | 774 bytes | joelpittet |
Comments
Comment #1
Marvin Daugherty CreditAttribution: Marvin Daugherty commentedComment #2
Marvin Daugherty CreditAttribution: Marvin Daugherty commentedComment #3
Marvin Daugherty CreditAttribution: Marvin Daugherty commentedComment #4
Alauddin CreditAttribution: Alauddin commentedSame issue here with Product URL module and Commerce 7.x-1.11
Temporary solution :
Disabling the checkbox
x Update page URL on attribute change
at module config /admin/commerce/config/product_urls
at least allows cart access, even though it throws the errors...otherwise I was getting 500 server errors.
Comment #5
IckZ CreditAttribution: IckZ commentedsubscribe!
Comment #6
IckZ CreditAttribution: IckZ commentedI'm just testing the following change in line ~160
from
to
in my dev-environment. Any remarks?
Comment #7
joelpittetHow about just exit early if that key doesn't exist?
Comment #8
Alauddin CreditAttribution: Alauddin commentedHi guys,
Tested #7 patch to fresh dev...did not stop the notices.
Tested #6 as well with fresh dev..no luck.
still getting the two notices in log each time I add an item to cart
Notice: Trying to get property of non-object in _commerce_product_urls_build_query_string() (line 157 of .../public_html/sites/all/modules/commerce_product_urls/commerce_product_urls.module).
Notice: Undefined index: default_product in _commerce_product_urls_build_query_string() (line 157 of .../public_html/sites/all/modules/commerce_product_urls/commerce_product_urls.module).
Comment #9
akosipax CreditAttribution: akosipax commentedI don't think #7 is the right solution -- this would remove the url query parameters that supposedly gets appended to the page url by the module.
#6 doesn't work for sites that are configured to use the SKU in the url's query parameters.
Here's a patch that I think would work for everyone.
Comment #10
rballou CreditAttribution: rballou commentedThe patch in #9 seems to be working for me. Thanks!
Comment #11
stuwat CreditAttribution: stuwat commentedYes, patch in #9 appears to be working great. Thank you for that.
Comment #12
vasikeIndeed i confirm the issue and also the #9 patch gets rid of the notices.
The issue:
Default product data does not exist after form is built.
It is unset within "commerce_cart_add_to_cart_form_after_build()".
And "_commerce_product_urls_build_query_string()" assumes that $form_state['default_product'] exists.
There is another patch that builds this value/data ($form_state['default_product']) within extra form submit handler - commerce_product_urls_commerce_cart_add_to_cart_form_submit().
Using the submitted data - $form_state['values']['product_id'].
I think this could be considered critical issue, as the notice is "very" public.
Comment #14
maciej.zgadzaj CreditAttribution: maciej.zgadzaj commentedMerged #12 - thanks vasike!