Conversation
orange_ecom_starter.theme
Outdated
| */ | ||
| function orange_ecom_starter_commerce_checkout_pane_info_alter(&$checkout_panes) { | ||
| if($checkout_panes['shipping_information']) { return false; } | ||
| } No newline at end of file |
There was a problem hiding this comment.
The file doesn't end with a newline. That's required by the code standard. This is easier if you set PhpStorm to always add it automatically (in Settings > Editor > General, select "Ensure line feed at file end on Save").
orange_ecom_starter.theme
Outdated
| * Implements hook_commerce_checkout_pane_info_alter(&$checkout_panes). | ||
| */ | ||
| function orange_ecom_starter_commerce_checkout_pane_info_alter(&$checkout_panes) { | ||
| if($checkout_panes['shipping_information']) { return false; } |
There was a problem hiding this comment.
What's the purpose of this? I don't think it has any effect unless you change something in $checkout_panes.
There's two code standards issues:
if(should beif (.- The body of this block and the
}should each be on new lines.
If this does do something, please add a comment for what it does and why we need to do it that way - I'm sure I wouldn't be the only one confused by it.
There was a problem hiding this comment.
This has been removed completely since it didn't actually do anything.
| console.log('blur!'); | ||
| $('input[id^=edit-shipping-information-recalculate-shipping]').mousedown(); | ||
| }); | ||
| } |
There was a problem hiding this comment.
I'm sure this hack isn't the solution we want (it may not work the same on sites that have been customized and it doesn't help other users of commerce_shipping who could use the same feature), but I'm not really sure what the proper solution is. See https://www.drupal.org/project/commerce_shipping/issues/2898118. Bojan described this as "not easy" but maybe changes to Commerce in the last few months have made things better.
It would be a good idea to get some direction from Bojan in the commerce channel of Drupal Slack (https://www.drupal.org/slack) about how to implement what we want (fixing it upstream in commerce or commerce_shipping rather than just in Drupal Orange).
9f98513 to
8868b68
Compare
…d selection on cart form
We can't seem to add ajax listeners after the fact using #after_build, so the js listener is going back in as our best bet - we might be able to avoid clicking the button though and instead trigger an event durpal- side.
| 'class' => array('hidden'), | ||
| ]; | ||
| } | ||
| // edit-shipping-information-shipping-profile-address-0-address-postal-code |
There was a problem hiding this comment.
What's this comment about? Is this something that should be removed?
There was a problem hiding this comment.
That was a note to myself about where something was located and I forgot about, removed.
orange_ecom_starter.theme
Outdated
| * Ajax callback for refreshing the order shipping method, this will eventually | ||
| * be moved to the commerce shipping module instead. | ||
| */ | ||
| function ajaxRefreshSummary(array $form, FormStateInterface $form_state) { |
There was a problem hiding this comment.
This function name must be snake case (ajax_refresh_summary) not camel case (ajaxRefreshSummary). In the Drupal standard functions use underscores and class methods use camel case.
The name must also be prefixed with the module or theme name: orange_ecom_starter_ajax_refresh_summary instead of ajax_request_summary.
orange_ecom_starter.theme
Outdated
|
|
||
| /** | ||
| * Ajax callback for refreshing the order shipping method, this will eventually | ||
| * be moved to the commerce shipping module instead. |
There was a problem hiding this comment.
The first line of a documentation block must be its own paragraph under 80 characters. Further text would be another paragraph.
/**
* Ajax callback for refreshing the order shipping method.
*
* Something about how this should be accomplished by commerce_shipping and a
* link to the relevant Drupal.org issue.
*/
js/custom/script.js
Outdated
| // Mousedown on hidden button to trigger price recalculation when postal code input is out of focus, because | ||
| // we can't override it in our theme hooks. | ||
| if($('#edit-shipping-information-recalculate-shipping').length) { | ||
| $('body').on('blur', 'input.postal-code', function () { |
There was a problem hiding this comment.
Since we're using blur, this doesn't activate until I've entered my postal code and then try to do something else. You could end up trying to put in your payment information and having your available shipping methods change, which is weird since we've moved past that, or probably more likely, have these weird issues selecting
Filling out the address, there are no shipping methods, just in-store. It looks like the only option, so if I want it shipped I'm now confused. Or, I settle for in-store pickup and go to payment information, and now the methods update.
Or you could see the methods, make a change and try to select a method, but you can't actually select it because removing focus from the postal code submitted the form instead.
Is it feasible to use the keydown event, but instead of doing the recalculate callback right away, start a short timer? When the timer expires the recalculation happens, but each event resets the timer so it doesn't make the ajax calls while you're still typing.
There was a problem hiding this comment.
I think the issue with this (after some playing around) is that if you take slightly longer to input your postal code it will try to update too early, but if the delay is too long we end up with roughly the same result but with more complexity. The trick would be getting the delay right, but I'm not sure what that "magic number" would be.
Instead of a blue or change of the postal code, we add a listener to every input element instead, and wait until all the required fields have been filled.
|
So the new triggering method requires all the required fields to be filled in before it "clicks" the button, and activates on keyup in any input field. |


Small changes that allow us to remove the Recalculate shipping button completely in favour of displaying them instead when the postal code is complete. Also allows us to update the shipping method when selected instead of when we submit the form and go to the next page.