Skip to content

Commit b83b1a7

Browse files
authored
Merge pull request #7067 from woocommerce/issue/7027-wrong-product-row
Order Creation: Display and adjust quantity for order items as expected in Products section
2 parents 375b2e5 + c046489 commit b83b1a7

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [*] Order Creation: Fixes a bug where selecting a variable product to add to a new order would sometimes open the wrong list of product variations. [https://github.com/woocommerce/woocommerce-ios/pull/7042]
99
- [*] Collect payment button on Order Details no longer flickers when the screen loads [https://github.com/woocommerce/woocommerce-ios/pull/7043]
1010
- [*] Issue refund button on Order Details is shown for all paid orders [https://github.com/woocommerce/woocommerce-ios/pull/7046]
11+
- [*] Order Creation: Fixes several bugs with the Products section not showing the correct order items or not correctly updating the item quantity. [https://github.com/woocommerce/woocommerce-ios/pull/7067]
1112

1213
9.3
1314
-----

WooCommerce/Classes/ViewRelated/Orders/Order Creation/NewOrderViewModel.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ final class NewOrderViewModel: ObservableObject {
9595

9696
/// Products list
9797
///
98-
private var allProducts: [Product] {
99-
productsResultsController.fetchedObjects
100-
}
98+
private var allProducts: [Product] = []
10199

102100
/// Product Variations Results Controller.
103101
///
@@ -109,9 +107,7 @@ final class NewOrderViewModel: ObservableObject {
109107

110108
/// Product Variations list
111109
///
112-
private var allProductVariations: [ProductVariation] {
113-
productVariationsResultsController.fetchedObjects
114-
}
110+
private var allProductVariations: [ProductVariation] = []
115111

116112
/// View model for the product list
117113
///
@@ -549,6 +545,10 @@ private extension NewOrderViewModel {
549545
/// Adds a selected product (from the product list) to the order.
550546
///
551547
func addProductToOrder(_ product: Product) {
548+
if !allProducts.contains(product) {
549+
allProducts.append(product)
550+
}
551+
552552
let input = OrderSyncProductInput(product: .product(product), quantity: 1)
553553
orderSynchronizer.setProduct.send(input)
554554

@@ -558,6 +558,10 @@ private extension NewOrderViewModel {
558558
/// Adds a selected product variation (from the product list) to the order.
559559
///
560560
func addProductVariationToOrder(_ variation: ProductVariation) {
561+
if !allProductVariations.contains(variation) {
562+
allProductVariations.append(variation)
563+
}
564+
561565
let input = OrderSyncProductInput(product: .variation(variation), quantity: 1)
562566
orderSynchronizer.setProduct.send(input)
563567

@@ -777,6 +781,7 @@ private extension NewOrderViewModel {
777781
func updateProductsResultsController() {
778782
do {
779783
try productsResultsController.performFetch()
784+
allProducts = productsResultsController.fetchedObjects
780785
} catch {
781786
DDLogError("⛔️ Error fetching products for new order: \(error)")
782787
}
@@ -787,6 +792,7 @@ private extension NewOrderViewModel {
787792
func updateProductVariationsResultsController() {
788793
do {
789794
try productVariationsResultsController.performFetch()
795+
allProductVariations = productVariationsResultsController.fetchedObjects
790796
} catch {
791797
DDLogError("⛔️ Error fetching product variations for new order: \(error)")
792798
}

0 commit comments

Comments
 (0)