Need help with query

(jalson1982) #1

Hello community. I have this query:

MATCH(o:Order {pickupDate:$pickupDate,status:$status})
MATCH (o)-[r:CONTAINS_ITEM]->(oi:OrderItem)
OPTIONAL MATCH (oi)<-[pck:PICKED]-(po:PreparedOrder)<-[:PREPARED_AS]-(o)
OPTIONAL MATCH (oi)-[:ALTERNATIVE]->(oia:OrderItem:Alternative)
WITH o, po, oi,pck,r, a, collect(distinct(oia)) as alternatives
WITH o, po,oi,pck,r, collect({ alternativesCollected: po.alternativesCollected,reason: a, alternatives:alternatives}) as items
WITH o,collect({weighing:oi.weighing,,quantity:r.withQuantity,,price:oi.price,weight:oi.weight,,alt:items,collectedQuantity:pck.quantity}) as mam
RETURN {, comment:o.comment,, pickupDate:o.pickupDate, pickupTime:o.pickupTime, pickupLocation:o.pickupLocation, paymentOption: o.paymentOption, customerPhone: o.customerPhone,status:o.status,items:mam} as preparedOrder

Issue with query is that each time when order completed it return not for example 10 items then 20 items, somehow it doubles items ( things with oi ). Any idea what is wrong?

(Ameyasoft) #2


Try replacing this: (oia:OrderItem:Alternative) (in line 4) with
(oia:Alternative) as you want to select alternative items added to the order.