spree / spree_wombat

Connect your Spree Commerce storefront to Wombat
BSD 3-Clause "New" or "Revised" License
31 stars 53 forks source link

Merge quantity of units when serializing shipment.items #49

Open huoxito opened 10 years ago

huoxito commented 10 years ago

Currently when receiving that shipment back via a webhook from wombat the extention would complain about a diff in the items.

e.g. The received shipment items do not match with the shipment, diff: [{:sku=>"123", :quantity=>1}, {:sku=>"123", :quantity=>1}]

Before:

    items: [{ product_id: 1, quantity: 1 }, { product_id: 1, quantity: 1 }]

Now:

    items: [{ product_id: 1, quantity: 2 }]

// @JDutil @peterberkenbosch could you please review?

I think this is ok given the shipment.items key would be a representation of what we want in wombat and not what we have in spree exactly (inventory units don't have a quantity in spree).

athal7 commented 10 years ago

fyi this is going to conflict with https://github.com/spree/spree_wombat/commit/918f215b2ee93b6a7c2cab79bcd2f43e11cdb825

JDutil commented 10 years ago

This looks okay to me, but I had merged PRs before that changed shipments to use the IU serializer instead of the LI serializer which this feels like it's reverting back.

I don't remember the exact reason for the change off hand, but the commits referenced by @athal7 seem to be the ones.

huoxito commented 10 years ago

just pushed an updated version, would you guys mind showing how does this idea conflict with https://github.com/spree/spree_wombat/commit/918f215b2ee93b6a7c2cab79bcd2f43e11cdb825 I dont get it. Perhaps we're missing a spec?

I don't see the handler specs using the same serializers here on the examples.

athal7 commented 10 years ago

That handler checks whether the shipment items is valid by building back up its own representation of the shipment items (maybe should use the serializer?) and comparing against the payload. It builds the items with the quantity of the inventory unit if that field exists, but for now a quantity of 1. Therefore if shipment items have a quantity of greater than 1, the handler will think that payload is invalid since it doesn't match a subset of the shipment items representation it builds.

huoxito commented 10 years ago

thanks @athal7

I'm very confused about having a quantity key but this quantity key can't be greater than 1? Why is that? Sounds like we should also fix the handler code then?

We need to figure this. Again the motivation for this fix started from this error:

The received shipment items do not match with the shipment, diff: [{:sku=>"123", :quantity=>1}, {:sku=>"123", :quantity=>1}]

athal7 commented 10 years ago

That diff may just mean that those items exist in the payload but are unexpected as far as the shipment is concerned

athal7 commented 10 years ago

Quantity key is there to support the upcoming addition of inventory item quantity as well as to maintain consistency with the line item payload that existed prior to the change to use inventory units

frahugo commented 10 years ago

Any news on this issue? we have to merge JSON every morning in Wombat for shipments that got some line items exploded.

huoxito commented 10 years ago

@frahugo yes I'm double checking the shipment handler code today and should be resolved soon along with this.

peterberkenbosch commented 9 years ago

@huoxito the handler code will make inventory_units based on the quantity. https://github.com/spree/spree_wombat/blob/master/lib/spree/wombat/handler/add_shipment_handler.rb#L73

huoxito commented 9 years ago

Thats the add to shipment handler @peterberkenbosch, we need to fix it on the update handler here, many other services can return shipment.items with quantity > 1 and too bad the handler cant deal with it.