Skip to content

Commit 1e6b5b2

Browse files
authored
Merge pull request #8699 from woocommerce/issue/8577-warn-about-variations
Bulk Editing: Warn about variations in price flow
2 parents 33e8e47 + 4f9d55c commit 1e6b5b2

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

WooCommerce/Classes/ViewRelated/Products/PriceInputViewModel.swift

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,29 @@ final class PriceInputViewModel {
8686
/// Returns the footer text to be displayed with information about the current bulk price and how many products will be updated.
8787
///
8888
var footerText: String {
89-
let numberOfProducts = productListViewModel.selectedProductsCount
90-
let numberOfProductsText = String.pluralize(numberOfProducts,
91-
singular: Localization.productsNumberSingularFooter,
92-
plural: Localization.productsNumberPluralFooter)
89+
var footerData: [String] = []
9390

9491
switch productListViewModel.commonPriceForSelectedProducts {
9592
case .none:
96-
return [Localization.currentPriceNoneFooter, numberOfProductsText].joined(separator: " ")
93+
footerData.append(Localization.currentPriceNoneFooter)
9794
case .mixed:
98-
return [Localization.currentPriceMixedFooter, numberOfProductsText].joined(separator: " ")
95+
footerData.append(Localization.currentPriceMixedFooter)
9996
case let .value(price):
10097
let currentPriceText = String.localizedStringWithFormat(Localization.currentPriceFooter, formatPriceString(price))
101-
return [currentPriceText, numberOfProductsText].joined(separator: " ")
98+
footerData.append(currentPriceText)
99+
}
100+
101+
if productListViewModel.selectedVariableProductsCount > 0 {
102+
footerData.append(Localization.variationsWarning)
102103
}
104+
105+
let numberOfProducts = productListViewModel.selectedProductsCount - productListViewModel.selectedVariableProductsCount
106+
let numberOfProductsText = String.pluralize(numberOfProducts,
107+
singular: Localization.productsNumberSingularFooter,
108+
plural: Localization.productsNumberPluralFooter)
109+
footerData.append(numberOfProductsText)
110+
111+
return footerData.joined(separator: " ")
103112
}
104113

105114
/// It formats a price `String` according to the current price settings.
@@ -134,5 +143,7 @@ private extension PriceInputViewModel {
134143
static let currentPriceNoneFooter = NSLocalizedString("Current price is not set.",
135144
comment: "Message in the footer of bulk price setting screen, when none of the"
136145
+ " products have price value.")
146+
static let variationsWarning = NSLocalizedString("Prices for variations won't be updated.",
147+
comment: "Message in the footer of bulk price setting screen, when variable products are selected")
137148
}
138149
}

WooCommerce/Classes/ViewRelated/Products/ProductsListViewModel.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ class ProductListViewModel {
2323
selectedProducts.count
2424
}
2525

26+
var selectedVariableProductsCount: Int {
27+
selectedProducts.filter({ $0.productType == .variable }).count
28+
}
29+
30+
var onlyVariableProductsSelected: Bool {
31+
selectedProducts.filter({ $0.productType != .variable }).isEmpty
32+
}
33+
2634
var bulkEditActionIsEnabled: Bool {
2735
!selectedProducts.isEmpty
2836
}

WooCommerce/Classes/ViewRelated/Products/ProductsViewController.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,9 @@ private extension ProductsViewController {
363363
let cancelAction = UIAlertAction(title: Localization.cancel, style: .cancel)
364364

365365
actionSheet.addAction(updateStatus)
366-
actionSheet.addAction(updatePrice)
366+
if !viewModel.onlyVariableProductsSelected {
367+
actionSheet.addAction(updatePrice)
368+
}
367369
actionSheet.addAction(cancelAction)
368370

369371
if let popoverController = actionSheet.popoverPresentationController {

WooCommerce/WooCommerceTests/ViewRelated/Products/ProductListViewModelTests.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,30 @@ final class ProductListViewModelTests: XCTestCase {
139139
XCTAssertEqual(viewModel.selectedProductsCount, 0)
140140
}
141141

142+
func test_variation_helpers_work_correctly() {
143+
// Given
144+
let viewModel = ProductListViewModel(siteID: sampleSiteID, stores: storesManager)
145+
let sampleProduct1 = Product.fake().copy(productID: 1)
146+
let sampleProduct2 = Product.fake().copy(productID: 2, productTypeKey: "variable")
147+
148+
// When
149+
viewModel.selectProduct(sampleProduct1)
150+
viewModel.selectProduct(sampleProduct2)
151+
152+
// Then
153+
XCTAssertEqual(viewModel.selectedProductsCount, 2)
154+
XCTAssertEqual(viewModel.selectedVariableProductsCount, 1)
155+
XCTAssertFalse(viewModel.onlyVariableProductsSelected)
156+
157+
// When
158+
viewModel.deselectProduct(sampleProduct1)
159+
160+
// Then
161+
XCTAssertEqual(viewModel.selectedProductsCount, 1)
162+
XCTAssertEqual(viewModel.selectedVariableProductsCount, 1)
163+
XCTAssertTrue(viewModel.onlyVariableProductsSelected)
164+
}
165+
142166
func test_common_status_works_correctly() {
143167
// Given
144168
let viewModel = ProductListViewModel(siteID: sampleSiteID, stores: storesManager)

0 commit comments

Comments
 (0)