Skip to content

Comments

Shipping info update#2

Open
gmemstr wants to merge 11 commits intoAcroMedia:8.x-1.xfrom
gmemstr:shipping-info-update
Open

Shipping info update#2
gmemstr wants to merge 11 commits intoAcroMedia:8.x-1.xfrom
gmemstr:shipping-info-update

Conversation

@gmemstr
Copy link

@gmemstr gmemstr commented Jul 27, 2018

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.

*/
function orange_ecom_starter_commerce_checkout_pane_info_alter(&$checkout_panes) {
if($checkout_panes['shipping_information']) { return false; }
} No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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").

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

* 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; }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 be if (.
  • 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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been removed completely since it didn't actually do anything.

console.log('blur!');
$('input[id^=edit-shipping-information-recalculate-shipping]').mousedown();
});
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@gmemstr gmemstr force-pushed the shipping-info-update branch from 9f98513 to 8868b68 Compare August 8, 2018 23:11
Gabriel Simmer added 4 commits August 8, 2018 16:12
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this comment about? Is this something that should be removed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a note to myself about where something was located and I forgot about, removed.

* 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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.


/**
* Ajax callback for refreshing the order shipping method, this will eventually
* be moved to the commerce shipping module instead.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
 */

// 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 () {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

peek 2018-08-09 14-16

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.

peek 2018-08-09 14-12

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Gabriel Simmer added 2 commits August 9, 2018 15:18
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.
@gmemstr
Copy link
Author

gmemstr commented Aug 17, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants