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

feat(product-sync): add support for changeMasterVariant, refactor product sync #272

Merged
merged 10 commits into from
Dec 4, 2018

Conversation

junajan
Copy link
Contributor

@junajan junajan commented Nov 30, 2018

Summary

Resolves #271

Description

This PR changes how we generate product update actions. Before we used jsondiffpatch on the whole product. Now, when syncing variants, we match variants by id/key/sku and diff only matched variants which are present in both old and new product.

Todo

  • Tests
    • Unit
    • Integration
    • Acceptance
  • Documentation

@junajan junajan self-assigned this Nov 30, 2018
@coveralls
Copy link

coveralls commented Nov 30, 2018

Coverage Status

Coverage decreased (-0.008%) to 97.649% when pulling befdf4c on 271-product-sync-with-change-master-variant into ea8b004 on master.

@junajan junajan changed the title WIP: chore(product-sync): install necessary dependency, test CI tests feat(product-sync): add support for changeMasterVariant, refactor product sync Nov 30, 2018
@daern91 daern91 requested a review from Babanila December 3, 2018 12:44
src/coffee/sync/product-sync.coffee Show resolved Hide resolved
src/coffee/sync/product-sync.coffee Show resolved Hide resolved
src/coffee/sync/utils/product.coffee Show resolved Hide resolved
src/coffee/sync/utils/product.coffee Outdated Show resolved Hide resolved
src/coffee/sync/utils/product.coffee Outdated Show resolved Hide resolved
src/spec/sync/product-sync.spec.coffee Outdated Show resolved Hide resolved
Copy link
Contributor

@daern91 daern91 left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this PR. Code looked fine to me. However, I don't have a ton of expertise on this syncer so please also await @butenkor and @lojzatran's reviews


if diff
actions = []
# TODO check action group for base variant update actions - original was attributes
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this TODO supposed to be added in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed todo here - 01fd315 .. these actions for updating sku/key were under attributes action group before so it is I guess ok if we keep it that way ..

variant1 and variant2 and (
(!isNil(variant1.id) and variant1.id == variant2.id) or
(!isNil(variant1.key) and variant1.key == variant2.key) or
(!isNil(variant1.sku) and variant1.sku == variant2.sku)
Copy link
Contributor

Choose a reason for hiding this comment

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

this isNil threw me a little, is it not enough to do
variant1.id === variant2.id
or
variant1.id and variant1.id === variant2.id)

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we don't use isNil, it would match incorrectly variants where existing and the new variant id is undefined even when skus and keys are different.

If we change it to variant1.id and variant1.id === variant2.id it won't work when id is 0.

Copy link
Contributor

Choose a reason for hiding this comment

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

ahh.. I see. Thanks for explaining.

buildAddVariantActions: (newVariant) ->
addAction = _.deepClone(newVariant)
delete addAction._NEW_ARRAY_INDEX
delete addAction._MATCH_CRITERIA
Copy link
Contributor

Choose a reason for hiding this comment

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

huh, where did these two come from? _MATCH_CRITERIA and _NEW_ARRAY_INDEX

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @daern91 - these properties are created by jsondiffpatcher

#
# diff - {Object} The result of diff from `jsondiffpatch`
# old_obj - {Object} The existing product
# new_obj - {Object} The product to be updated
#
# Returns {Array} The list of actions, or empty if there are none
actionsMapReferences: (diff, old_obj, new_obj) ->
actionsMapReferences: (diff, new_obj, old_obj) ->
Copy link
Contributor

Choose a reason for hiding this comment

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

ahh, thanks for this one.. nice with some more consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sadly, there are much more places which would need this change ..

@@ -228,14 +249,14 @@ class ProductUtils extends BaseUtils

_.sortBy actions, (a) -> a.action is 'addToCategory'

# Private: map product prices
# Map product prices
Copy link
Contributor

Choose a reason for hiding this comment

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

Im not aware of these ones. What does this change do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just removes private flag from documentation I guess.. because we call this method from outside

# { action: 'addVariant', attributes: [ { name: 'some', value: 'thing' } ] }
# { action: 'addVariant', attributes: [ { name: 'yet', value: 'another' } ] }
# { action: 'addVariant', sku: 'v10', attributes: [ { name: 'something', value: 'else' } ] }
# { action: 'addVariant', sku: 'SKUwins' }
Copy link
Contributor

Choose a reason for hiding this comment

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

this todo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

instead of removing and adding all variants, we remove just those which are not present in the product draft, update the rest and do not care about the order of variants

@junajan
Copy link
Contributor Author

junajan commented Dec 4, 2018

Hello @daern91, @lojzatran - it looks like I don't have rights to merge this PR.. could you please merge it and do a release? so we can bump sdk dependency in the importer.

@daern91 daern91 merged commit 9e0a797 into master Dec 4, 2018
@daern91 daern91 deleted the 271-product-sync-with-change-master-variant branch December 4, 2018 15:53
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