Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly create/remove/prune shipping records everywhere #2847

Merged
merged 67 commits into from
Oct 6, 2017

Conversation

brent-hoover
Copy link
Collaborator

@brent-hoover brent-hoover commented Sep 13, 2017

Closes #2836 and #2870 #2838 (and probably a bunch of other bugs)

To Test

  1. Create a shop
  2. Enable Stripe Connect
  3. As the shop admin, add a product
  4. Enable flat rate shipping
  5. In your original browser, add only your newly created product
  6. Checkout
  7. Observe that shipping methods are properly displayed
  8. Checkout
  9. Observe there is no error

That's just the basic test case for the bugs, but really this PR became "make shipping work in marketplace" so it needs to get tested with all the various scenarios e.g.:

  1. Single shop with products for that shop
  2. Multi shop with just products for the second shop
  3. Multi-shop with products for both primary and merchant shop
  4. Shippo
  5. Flat-rate

@brent-hoover
Copy link
Collaborator Author

@kieckhafer Not sure that Stripe translations are in the scope of this PR. Maybe we can note on #3009?

Copy link
Contributor

@spencern spencern left a comment

Choose a reason for hiding this comment

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

Some changes, lots of questions.

// Because we are duplicating shipment quotes across shipping records
// we will get duplicate shipping quotes but we only want to diplay one
// So this function eliminates duplicates
function uniqObjects(methods) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could methods.reduce on line 15 instead of map, and check for uniqueness before pushing which would avoid the cost of looping through two extra times.

Not sure it's worth optimizing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't see how that would work. You can't compare them until you have stringified them.

});
}

// cartShippingQuotes
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be proper jsdoc using @private?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed


// Verify that we have a valid address to work with
let shippingErrorDetails;
cart.shipping.map((shippingRecord) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this a map and not a forEach (which doesn't return an array) or a find (which stops after the first match? In this case find seems like it would perform the correct function.

});

if (shippingErrorDetails) {
return [[shippingErrorDetails], []];
Copy link
Contributor

Choose a reason for hiding this comment

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

Comments would be helpful.

};
rates.push(errorDetails);
return [rates, retrialTargets];
return [[errorDetails], []];
Copy link
Contributor

Choose a reason for hiding this comment

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

My guess is we're returning an array of arrays here because we want to proceed to the next hook? Where does the error get logged or thrown? What does the empty array represent? I think some comments here would be good

Copy link
Collaborator Author

@brent-hoover brent-hoover Oct 5, 2017

Choose a reason for hiding this comment

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

I feel like these comments are about the error handling techniques of the shipping method hooks which I am not creating or changing, just correcting the fact that it calls out the wrong shipment method. These comments are valid but probably better for a separate issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

You were the reviewer on the PR (#2738) that introduced this pattern a few weeks ago and this is the first I've seen of this pattern.

We can punt to a separate issue to fix this, but I'd like to understand what is happening here if you know.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will go through the code and try to add comments to try and make this more clear. I do feel like the general pattern here makes sense and works well. It's a little challenging trying to deal with a series of Hooks that can be extended by any plugin and deal with feedback from each hook on how to proceed (do I retry?, etc.) especially since how they need to communicate is with a record on the cart.

The timing of putting in this change while also dealing with multi-shop was extremely unfortunate however.

});
});
const shopIds = Object.keys(cart.getItemsByShop());
shopIds.map((shopId) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

forEach?

"shipping.$.address": address
}
};
Cart.update(selector, update);
Copy link
Contributor

Choose a reason for hiding this comment

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

Any particular reason you're performing a Cart.update for each shop rather than updating the entire array of shipping records and then doing a single Cart.update?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed

});
});
const shopIds = Object.keys(cart.getItemsByShop());
shopIds.map((shopId) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

forEach?

const userId = cart.userId;
const account = Accounts.findOne(userId);
if (account && account.profile && account.profile.addressBook) {
const address = account.profile.addressBook.find((addressEntry) => addressEntry.isShippingDefault === true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we guaranteed to have an address with isShippingDefault, that's true from my recollection in which case 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

AFAIK if we have an addressBook we always have a default shipping address

const address = getDefaultAddress(cart);
if (address) {
const shopIds = Object.keys(cart.getItemsByShop());
shopIds.map((shopId) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

should be forEach

@kieckhafer
Copy link
Member

Looks like this is fixed in #3035 but for visibility just putting it here as well...

I cannot check out as a guest user, as I don't have an email address registered yet.

cart_checkout

@kieckhafer
Copy link
Member

When I have two shops, and I log out and use the site as an anonymous user, I seem to be stuck on the newest created shop (Reaction 1 in this case), even though I can see products from both shops.

I also cannot view any PDP's of either shop, I get an authorization error / sign in required.

reaction1

Don't know if this is an issue for this PR, just wanted to document as I couldn't get to the PDP -> Checkout to test this PR because of that error.

@brent-hoover
Copy link
Collaborator Author

@kieckhafer I think that's something we should definitely open an issue for (the not getting to the PDP error)

@brent-hoover
Copy link
Collaborator Author

@spencern Ready for re-review

@spencern
Copy link
Contributor

spencern commented Oct 5, 2017

@kieckhafer That may be an issue with us not changing back to the primary shop after a logout, I don't believe that this PR affects that.

Copy link
Contributor

@spencern spencern left a comment

Choose a reason for hiding this comment

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

Getting an endless spinner for the shipping step when checking out with 2 items from 2 different shops.

No client or server errors or warnings, but I'm only seeing one shipping record in the cart.

image

image

@brent-hoover
Copy link
Collaborator Author

@spencern That issue is fixed (again)

@spencern spencern merged commit b49d5a1 into marketplace Oct 6, 2017
@spencern spencern deleted the brent-fix-issue-2836 branch October 6, 2017 05:04
This was referenced Oct 6, 2017
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.

4 participants