reactioncommerce / reaction

Mailchimp Open Commerce is an API-first, headless commerce platform built using Node.js, React, GraphQL. Deployed via Docker and Kubernetes.
https://mailchimp.com/developer/open-commerce/
GNU General Public License v3.0
12.34k stars 2.17k forks source link

Receive server error when shipping order in Marketplace #3979

Closed brent-hoover closed 6 years ago

brent-hoover commented 6 years ago

Issue Description

Receive an error in the server console when shipping an order in the marketplace. Notification does not appear to be sent and order is not marked "shipped"

Exception while invoking method 'orders/shipmentShipped' WriteError({"code":11000,"index":0,"errmsg":"E11000 duplicate key error collection: meteor.OrderSearch index: _id_ dup key: { : \"hCWhcEw3KhbaaQ3Et\" }","op":{"_id":"hCWhcEw3KhbaaQ3Et","shopId":"J8Bhq3uTtdgwZx3rz","shippingName":"Brent Hoover","shippingPhone":"3236873265","billingName":"Brent Hoover","userEmails":["brent@reactioncommerce.com"],"shippingAddress":{"address":"2110 Main St. Suite 207","postal":"90405","city":"Santa Monica","region":"CA","country":"US"},"billingAddress":{"address":"2110 Main St. Suite 207","postal":"90405","city":"Santa Monica","region":"CA","country":"US"},"shippingStatus":"New","billingStatus":"completed","orderTotal":18.99,"orderDate":"2018/03/12","billingPhone":"3236873265","billingCard":"Visa 4242","currentWorkflowStatus":"coreOrderWorkflow/processing","product":{"title":["Dumb Product","Reaction Bag of Beans"]},"variants":{"title":["Size Nine","One pound bag"],"optionTitle":["Size 9","One pound bag"]}}})

Steps to Reproduce

  1. Configure for marketplace and second shop
  2. Create product in second shop
  3. In Primary shop place an order with a product from the main shop and from the second shop
  4. In the dashboard approve, capture, and attempt to ship the order
  5. Observe the error and that the order is not marked shipped

Versions

Node: 8.9.4
NPM: 5.6.0
Meteor Node: 8.9.4
Meteor NPM: 5.6.0
Reaction CLI: 0.28.0
Reaction: 1.9.0
Reaction branch: release-1.9.0
Docker: 17.12.0-ce
Akarshit commented 6 years ago

@zenweasel This is most prob. because how the layout is implemented in Reaction. So if I order 1 product from the Primary shop and 1 from the marketplace shop, this is what I get in the Order Summary window(The one you get when you click on a order from Orders's Menu in the Action bar) Order Part 1 ->

screen shot 2018-03-12 at 2 00 30 pm

and below that the same order again. Order Part 1(continued) ->

screen shot 2018-03-12 at 2 00 41 pm

Even the subtotal/payment calculated in these is incorrect. Do we want to display something like below? Order Part 1 -> summary/invoice/shipping of items from Primary Shop Order Part 2 -> summary/invoice/shipping of items from Marketplace Shop

Or we want just a single order which combines all the orders?

brent-hoover commented 6 years ago

A marketplace admin should just see a single order that combines all the orders for now

Akarshit commented 6 years ago

@zenweasel Right now the marketplace admin only sees only the items belongs to his shop in the order. While the primary owner sees both the items in the order.

brent-hoover commented 6 years ago

Yes, that is the expected/desired behavior

Akarshit commented 6 years ago

Isn't that confusing, because the Primary Owner can't "Approve/Capture" the item of the Marketplace Shop(I approved/captured the payment as primary owner and then when I login form the market place I again get the option to approve/capture the item.)

brent-hoover commented 6 years ago

It's the what we came up to when we finished this "alpha" version of the marketplace functionality. It's far from optimal but it worked for now.

Akarshit commented 6 years ago

@zenweasel This issue is a timing issue. When a order is updated, a hook is run to remove the old OrderSearch doc and add the new one. Since the orders is displayed twice, it is updated twice(and the hook runs almost together). In general the order of execution is

remove doc
insert doc
remove doc
insert doc

but in the rare case it becomes

remove doc
remove doc
insert doc
insert doc

You get the error in the issue. A easy way to fix this would be to change the insert operation to a upsert operation.

Also for the order being displayed twice. I checked and it is there since at-least release-1.6.

Should I proceed with just changing the insert to upsert?