-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
update product scheme to set country autovalue #2840
Conversation
lib/collections/schemas/helpers.js
Outdated
|
||
/** | ||
* shopDefaulCountry | ||
* @summary used for schema injection autoValue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hadn't seen @summary
or @example
used before - would you mind adding those to the ongoing discussion in docs? reactioncommerce/reaction-docs#275
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shopDefaultCountry
- minor typo!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Would like to see a little more inline comments and if you know of any other way to identify a Shop's primary address let's consider that, otherwise I'll 👍
lib/collections/schemas/helpers.js
Outdated
* @return {String} returns country value from default shop | ||
*/ | ||
export function shopDefaultCountry() { | ||
if (this.isSet && Meteor.isServer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can read through this, but I think it's probably worth adding a little more inline commentary as to what's going on for people who are less versed in how autoValue works.
lib/collections/schemas/helpers.js
Outdated
const shop = Shops.findOne({ | ||
_id: Reaction.getShopId() | ||
}); | ||
if (shop && shop.addressBook && shop.addressBook[0]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love that we're assuming that the 0th address is the correct address here, but I know that's a pattern that's older than this PR.
Is there an indicator that a shop is using a specific address as their "shop address" similar to how customers can have a default address? Is it the default flag? Or any other way to identify the Shop's main address?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe there is any way to determine the default
address, and calling on the [0]
is the way to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, there's a field on the schema that determines this.
isBillingDefault: {
label: "Make this your default billing address?",
type: Boolean
},
isShippingDefault: {
label: "Make this your default shipping address?",
type: Boolean
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not use that for Shops?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that it's currently set to True on one created shop. Even if we don't set it for now this feels like a more "future-proof" way of doing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^^ yeah... dunno why I didn't connect that, will update to use... one of the two. Which should be used for this? Shipping?
This is for the product origin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Shipping makes the most sense. That where you would have things shipped to is there you want to ship from. At least in most cases and as accurate as being the right country.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use default address field on shop address to ascertain the shop address.
lib/collections/schemas/helpers.js
Outdated
}); | ||
|
||
// Find the current shops primary address | ||
if (shop && shop.addressBook && shop.addressBook[0]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how much work this would really be, but why we don't extend this a little more, with the goal of removing [0]
dependencies, and remove the need refactor this again (so soon)? One approach that seems easy, could be to just set and check isShippingDefault
to know the origination country?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review approaches that remove [0]
@aaronjudd @zenweasel my latest update should take care of getting rid of using |
Tests are failing. |
@kieckhafer can you fix conflicts and tests here? |
fixed and fixed |
Update our product schema to set default origin country for Product and Variant.
Default country is country the shop address is based in.