Skip to content

Commit 84ca53d

Browse files
authored
Fixed: Canceling an item from the order view and refreshing the page caused promotional items to endlessly duplicate in the ITEM_CREATED status. (#1142)
Fixed: Canceling an item from the order view and refreshing the page caused promotional items to endlessly duplicate in the ITEM_CREATED status. (OFBIZ-12104) Explanation: 1. The recreateOrderAdjustments service created new promotional items but failed to link them to their ship groups (OrderItemShipGroupAssoc). Without this link, the cancellation service could not identify or remove them during subsequent runs, causing items to accumulate. 2. New promotional items were hardcoded to the ITEM_CREATED status, even if the parent order was already ORDER_APPROVED. Thanks to Rashi Dhagat for reporting issue.
1 parent 615a6fe commit 84ca53d

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

applications/order/src/main/groovy/org/apache/ofbiz/order/order/OrderServicesScript.groovy

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import org.apache.ofbiz.order.shoppingcart.ShoppingCart
3131
import org.apache.ofbiz.order.shoppingcart.ShoppingCartItem
3232

3333
import java.sql.Timestamp
34-
3534
/**
3635
* Service to create OrderHeader
3736
*/
@@ -214,21 +213,37 @@ Map recreateOrderAdjustments() {
214213
// a new order item is created
215214
GenericValue newOrderItem = makeValue('OrderItem')
216215
newOrderItem.with {
217-
orderId = parameters.orderId
216+
orderId = order.get("orderId")
218217
orderItemTypeId = item.getItemType()
219218
selectedAmount = item.getSelectedAmount()
220219
unitPrice = item.getBasePrice()
221220
unitListPrice = item.getListPrice()
222-
itemDescription = item.getName(dispatcher)
221+
itemDescription = item.getDescription()
223222
statusId = item.getStatusId()
224223
productId = item.getProductId()
225224
quantity = item.getQuantity()
226225
isModifiedPrice = 'N'
227226
isPromo = 'Y'
228-
statusId = newOrderItem.statusId ?: 'ITEM_CREATED'
227+
statusId = order.statusId == 'ORDER_APPROVED' ? 'ITEM_APPROVED' : 'ITEM_CREATED'
229228
}
230229
newOrderItem.orderItemSeqId = delegator.getNextSeqId('OrderItem')
231230
newOrderItem.create()
231+
232+
// create the OrderItemShipGroupAssoc
233+
int itemIndex = cart.getItemIndex(item)
234+
int shipGroupIndex = cart.getItemShipGroupIndex(itemIndex)
235+
def csi = cart.getShipInfo(shipGroupIndex)
236+
String shipGroupSeqId = csi.getShipGroupSeqId()
237+
238+
GenericValue newOisga = makeValue('OrderItemShipGroupAssoc')
239+
newOisga.with {
240+
orderId = order.orderId
241+
orderItemSeqId = newOrderItem.orderItemSeqId
242+
shipGroupSeqId = shipGroupSeqId
243+
quantity = newOrderItem.quantity
244+
}
245+
newOisga.create()
246+
232247
// And the orderItemSeqId is assigned to the shopping cart item
233248
item.setOrderItemSeqId(newOrderItem.orderItemSeqId)
234249
}

0 commit comments

Comments
 (0)