Skip to content

Commit

Permalink
fix(product-sync): variant create or remove actions should be execute…
Browse files Browse the repository at this point in the history
…d first (fixes #130)
  • Loading branch information
lojzatran committed Aug 29, 2016
1 parent 2599b5b commit 594a2bb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/coffee/sync/product-sync.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ class ProductSync extends BaseSync

_doMapActions: (diff, new_obj, old_obj) ->
allActions = []
allActions.push @_mapActionOrNot 'variants', => @_utils.actionsMapVariants(diff, old_obj, new_obj)
allActions.push @_mapActionOrNot 'base', => @_utils.actionsMapBase(diff, old_obj)
allActions.push @_mapActionOrNot 'references', => @_utils.actionsMapReferences(diff, old_obj, new_obj)
allActions.push @_mapActionOrNot 'prices', => @_utils.actionsMapPrices(diff, old_obj, new_obj)
allActions.push @_mapActionOrNot 'attributes', => @_utils.actionsMapAttributes(diff, old_obj, new_obj, @sameForAllAttributeNames)
allActions.push @_mapActionOrNot 'images', => @_utils.actionsMapImages(diff, old_obj, new_obj)
allActions.push @_mapActionOrNot 'variants', => @_utils.actionsMapVariants(diff, old_obj, new_obj)
allActions.push @_mapActionOrNot 'categories', => @_utils.actionsMapCategories(diff)
_.flatten allActions

Expand Down
8 changes: 4 additions & 4 deletions src/spec/sync/product-sync.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ describe 'ProductSync', ->
update = @sync.buildActions(NEW_PRODUCT, OLD_PRODUCT).getUpdatePayload()
expected_update =
actions: [
{ action: 'removeVariant', id: 4 }
{ action: 'addVariant', sku: 'new', attributes: [ { name: 'what', value: 'no ID' } ] }
{ action: 'addVariant', attributes: [ { name: 'what', value: 'no SKU' } ] }
{ action: 'changeName', name: {en: 'Foo', de: undefined, it: 'Boo'} }
{ action: 'changeSlug', slug: {en: 'foo', it: 'boo'} }
{ action: 'setCategoryOrderHint', categoryId : 'myFancyCategoryId', orderHint : 0.9 }
Expand All @@ -150,9 +153,6 @@ describe 'ProductSync', ->
{ action: 'addPrice', variantId: 77, price: { value: { currencyCode: 'EUR', centAmount: 4790 }, country: 'AT', customerGroup: { id: 'special-price-id', typeId: 'customer-group' } } }
{ action: 'addPrice', variantId: 77, price: { value: { currencyCode: 'EUR', centAmount: 6559 }, country: 'FR' } }
{ action: 'addPrice', variantId: 77, price: { value: { currencyCode: 'EUR', centAmount: 13118 }, country: 'BE' } }
{ action: 'removeVariant', id: 4 }
{ action: 'addVariant', sku: 'new', attributes: [ { name: 'what', value: 'no ID' } ] }
{ action: 'addVariant', attributes: [ { name: 'what', value: 'no SKU' } ] }
]
version: OLD_PRODUCT.version
expect(update).toEqual expected_update
Expand Down Expand Up @@ -183,10 +183,10 @@ describe 'ProductSync', ->
update = @sync.buildActions(newProduct, oldProduct).getUpdatePayload()
expected_update =
actions: [
{ action: 'addVariant', sku: 'v4', attributes: [{ name: 'foo', value: 'i dont care' }] }
{ action: 'setAttribute', variantId: 1, name: 'foo', value: 'new value' }
{ action: 'setAttribute', variantId: 2, name: 'foo', value: 'another value' }
{ action: 'setAttribute', variantId: 3, name: 'foo', value: 'yet another' }
{ action: 'addVariant', sku: 'v4', attributes: [{ name: 'foo', value: 'i dont care' }] }
]
version: oldProduct.version
expect(update).toEqual expected_update

0 comments on commit 594a2bb

Please sign in to comment.