Skip to content

Commit 3f10674

Browse files
authored
Order details: Display all items in a shipment when there are no created shipments (#16010)
2 parents 9040c91 + 640a385 commit 3f10674

File tree

6 files changed

+72
-261
lines changed

6 files changed

+72
-261
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [*] Jetpack setup: Native experience for the connection step [https://github.com/woocommerce/woocommerce-ios/pull/15983]
88
- [*] Payments: Updated the In-Person Payments `Learn More` redirection to display the correct page based on the selected payment provider [https://github.com/woocommerce/woocommerce-ios/pull/15998]
99
- [*] Add "POS" label in Most recent orders in My store dashboard [https://github.com/woocommerce/woocommerce-ios/pull/16006]
10+
- [*] Order details: Always show shipping labels section if order is eligible for label creation. [https://github.com/woocommerce/woocommerce-ios/pull/16010]
1011

1112
23.0
1213
-----

WooCommerce/Classes/ViewModels/Order Details/OrderDetailsDataSource.swift

Lines changed: 31 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,6 @@ final class OrderDetailsDataSource: NSObject {
6161
return true
6262
}
6363

64-
/// Whether the button to create shipping labels should be visible.
65-
///
66-
var shouldShowShippingLabelCreation: Bool {
67-
if featureFlags.isFeatureFlagEnabled(.revampedShippingLabelCreation) {
68-
return isEligibleForShippingLabelCreation && !isEligibleForPayment && shipments.isEmpty
69-
}
70-
return isEligibleForShippingLabelCreation && shippingLabels.nonRefunded.isEmpty && !isEligibleForPayment
71-
}
72-
7364
/// Whether the option to re-create shipping labels should be visible.
7465
///
7566
var shouldAllowRecreatingShippingLabels: Bool {
@@ -456,11 +447,6 @@ private extension OrderDetailsDataSource {
456447
configureShippingLabelDetail(cell: cell)
457448
case let cell as WCShipInstallTableViewCell where row == .installWCShip:
458449
configureInstallWCShip(cell: cell)
459-
case let cell as ImageAndTitleAndTextTableViewCell where row == .shippingLabelCreationInfo(showsSeparator: true),
460-
let cell as ImageAndTitleAndTextTableViewCell where row == .shippingLabelCreationInfo(showsSeparator: false):
461-
if case .shippingLabelCreationInfo(let showsSeparator) = row {
462-
configureShippingLabelCreationInfo(cell: cell, showsSeparator: showsSeparator)
463-
}
464450
case let cell as ImageAndTitleAndTextTableViewCell where row == .shippingLabelPrintingInfo:
465451
configureShippingLabelPrintingInfo(cell: cell)
466452
case let cell as LargeHeightLeftImageTableViewCell where row == .addOrderNote:
@@ -489,8 +475,6 @@ private extension OrderDetailsDataSource {
489475
configureCustomAmount(cell: cell, at: indexPath)
490476
case let cell as ButtonTableViewCell where row == .collectCardPaymentButton:
491477
configureCollectPaymentButton(cell: cell, at: indexPath)
492-
case let cell as ButtonTableViewCell where row == .shippingLabelCreateButton:
493-
configureCreateShippingLabelButton(cell: cell, at: indexPath)
494478
case let cell as ButtonTableViewCell where row == .markCompleteButton(style: .primary, showsBottomSpacing: true),
495479
let cell as ButtonTableViewCell where row == .markCompleteButton(style: .primary, showsBottomSpacing: false),
496480
let cell as ButtonTableViewCell where row == .markCompleteButton(style: .secondary, showsBottomSpacing: true),
@@ -721,33 +705,6 @@ private extension OrderDetailsDataSource {
721705
cell.hideSeparator()
722706
}
723707

724-
private func configureCreateShippingLabelButton(cell: ButtonTableViewCell, at indexPath: IndexPath) {
725-
cell.configure(style: .primary,
726-
title: Titles.createShippingLabel,
727-
bottomSpacing: 0) {
728-
self.onCellAction?(.createShippingLabel(shipmentIndex: nil), nil)
729-
}
730-
cell.hideSeparator()
731-
}
732-
733-
private func configureShippingLabelCreationInfo(cell: ImageAndTitleAndTextTableViewCell, showsSeparator: Bool) {
734-
cell.update(with: .imageAndTitleOnly(fontStyle: .footnote),
735-
data: .init(title: Title.shippingLabelCreationInfoAction,
736-
image: .infoOutlineFootnoteImage,
737-
imageTintColor: .systemColor(.secondaryLabel),
738-
numberOfLinesForTitle: 0,
739-
isActionable: false,
740-
showsSeparator: showsSeparator))
741-
742-
cell.selectionStyle = .default
743-
744-
cell.accessibilityTraits = .button
745-
cell.accessibilityLabel = Title.shippingLabelCreationInfoAction
746-
cell.accessibilityHint =
747-
NSLocalizedString("Tap to show information about creating a shipping label",
748-
comment: "VoiceOver accessibility hint for the row that shows information about creating a shipping label")
749-
}
750-
751708
private func configureShippingLabelDetail(cell: WooBasicTableViewCell) {
752709
cell.bodyLabel?.text = isEligibleForWooShipping ? Footer.viewShippingLabel : Footer.showShippingLabelDetails
753710
cell.applyPlainTextStyle()
@@ -1272,7 +1229,34 @@ extension OrderDetailsDataSource {
12721229
siteShippingMethods = resultsControllers.siteShippingMethods
12731230
productVariations = resultsControllers.productVariations
12741231
shippingLabels = resultsControllers.shippingLabels
1275-
shipments = resultsControllers.shipments
1232+
shipments = {
1233+
let cachedShipments = resultsControllers.shipments
1234+
if cachedShipments.isNotEmpty {
1235+
return cachedShipments
1236+
}
1237+
1238+
if !isEligibleForShippingLabelCreation || shippingLabels.isNotEmpty {
1239+
/// Skips creating shipments if order is not eligible for creating labels
1240+
/// If there are labels but not shipments, the labels were created with legacy plugin,
1241+
/// so skip creating shipments to display them the old way instead.
1242+
return []
1243+
}
1244+
1245+
/// returns a placeholder shipment with all the order items
1246+
return [WooShippingShipment(
1247+
siteID: order.siteID,
1248+
orderID: order.orderID,
1249+
index: "0",
1250+
items: order.items.map { item in
1251+
var subItems: [String] = []
1252+
for index in 0..<item.quantity.intValue {
1253+
subItems.append("\(item.itemID)-sub-\(index)")
1254+
}
1255+
return WooShippingShipmentItem(id: item.itemID, subItems: subItems)
1256+
},
1257+
shippingLabel: nil
1258+
)]
1259+
}()
12761260
shippingLabelOrderItemsAggregator = AggregatedShippingLabelOrderItems(
12771261
shippingLabels: shippingLabels,
12781262
orderItems: items,
@@ -1310,18 +1294,9 @@ extension OrderDetailsDataSource {
13101294

13111295
var rows: [Row] = Array(repeating: .aggregateOrderItem, count: aggregateOrderItemCount)
13121296

1313-
switch (shouldShowShippingLabelCreation, isProcessingStatus, isRefundedStatus, isEligibleForPayment) {
1314-
case (true, false, false, false):
1315-
// Order completed and eligible for shipping label creation:
1316-
rows.append(.shippingLabelCreateButton)
1317-
rows.append(.shippingLabelCreationInfo(showsSeparator: false))
1318-
case (true, true, false, false):
1319-
// Order processing shippable:
1320-
rows.append(.shippingLabelCreateButton)
1321-
rows.append(.markCompleteButton(style: .secondary, showsBottomSpacing: false))
1322-
rows.append(.shippingLabelCreationInfo(showsSeparator: false))
1323-
case (false, true, false, false):
1324-
// Order processing digital:
1297+
switch (isProcessingStatus, isRefundedStatus, isEligibleForPayment) {
1298+
case (true, false, false):
1299+
// Order processing:
13251300
rows.append(.markCompleteButton(style: .primary, showsBottomSpacing: true))
13261301
default:
13271302
break
@@ -1822,7 +1797,6 @@ extension OrderDetailsDataSource {
18221797
comment: "The title for the refunded amount cell")
18231798
static let netAmount = NSLocalizedString("Net Payment", comment: "The title for the net amount paid cell")
18241799
static let collectPayment = NSLocalizedString("Collect Payment", comment: "Text on the button that starts collecting a card present payment.")
1825-
static let createShippingLabel = NSLocalizedString("Create Shipping Label", comment: "Text on the button that starts shipping label creation")
18261800
static let reprintShippingLabel = NSLocalizedString("Print Shipping Label", comment: "Text on the button that prints a shipping label")
18271801
static let seeReceipt = NSLocalizedString(
18281802
"OrderDetailsDataSource.configureSeeReceipt.button.title",
@@ -1855,9 +1829,6 @@ extension OrderDetailsDataSource {
18551829
static let payment = NSLocalizedString("Payment Totals", comment: "Payment section title")
18561830
static let notes = NSLocalizedString("Order Notes", comment: "Order notes section title")
18571831
static let customFields = NSLocalizedString("View Custom Fields", comment: "Custom Fields section title")
1858-
static let shippingLabelCreationInfoAction =
1859-
NSLocalizedString("Learn more about creating labels with your mobile device",
1860-
comment: "Title of button in order details > info link for creating a shipping label on the mobile device.")
18611832
static let shippingLabelPackageFormat =
18621833
NSLocalizedString("Package %d",
18631834
comment: "Order shipping label package section title format. The number indicates the index of the shipping label package.")
@@ -2022,8 +1993,6 @@ extension OrderDetailsDataSource {
20221993
case trackingAdd
20231994
case collectCardPaymentButton
20241995
case installWCShip
2025-
case shippingLabelCreateButton
2026-
case shippingLabelCreationInfo(showsSeparator: Bool)
20271996
case shippingLabelDetail
20281997
case shippingLabelPrintingInfo
20291998
case shippingLabelProducts
@@ -2085,10 +2054,6 @@ extension OrderDetailsDataSource {
20852054
return ButtonTableViewCell.reuseIdentifier
20862055
case .installWCShip:
20872056
return WCShipInstallTableViewCell.reuseIdentifier
2088-
case .shippingLabelCreateButton:
2089-
return ButtonTableViewCell.reuseIdentifier
2090-
case .shippingLabelCreationInfo:
2091-
return ImageAndTitleAndTextTableViewCell.reuseIdentifier
20922057
case .shippingLabelDetail:
20932058
return WooBasicTableViewCell.reuseIdentifier
20942059
case .shippingLabelPrintingInfo:

WooCommerce/Classes/ViewModels/Order Details/OrderDetailsViewModel.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ final class OrderDetailsViewModel {
123123
/// The eligibility check for Woo Shipping can be updated late due to being async
124124
/// So the additional check for shipments determines if the new form should be displayed.
125125
var shouldNavigateToNewShippingLabelFlow: Bool {
126-
dataSource.isEligibleForWooShipping || dataSource.shipments.isNotEmpty
126+
dataSource.isEligibleForWooShipping
127127
}
128128

129129
private(set) lazy var editNoteViewModel: EditCustomerNoteViewModel = {
@@ -514,10 +514,6 @@ extension OrderDetailsViewModel {
514514
forceReadOnly: false)
515515
let navController = WooNavigationController(rootViewController: loaderViewController)
516516
viewController.present(navController, animated: true, completion: nil)
517-
case .shippingLabelCreationInfo:
518-
let infoViewController = ShippingLabelCreationInfoViewController()
519-
let navigationController = WooNavigationController(rootViewController: infoViewController)
520-
viewController.present(navigationController, animated: true, completion: nil)
521517
case .shippingLabelDetail:
522518
guard let shippingLabel = dataSource.shippingLabel(at: indexPath) else {
523519
return

WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Info/ShippingLabelCreationInfoViewController.swift

Lines changed: 0 additions & 58 deletions
This file was deleted.

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,6 @@
608608
02DFD5042B20486C0048CD70 /* ProductStepper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02DFD5032B20486C0048CD70 /* ProductStepper.swift */; };
609609
02DFD5062B2048C50048CD70 /* ProductStepperViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02DFD5052B2048C50048CD70 /* ProductStepperViewModel.swift */; };
610610
02DFD5082B205AEF0048CD70 /* ProductStepperViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02DFD5072B205AEF0048CD70 /* ProductStepperViewModelTests.swift */; };
611-
02DFECE725EE338F0070F212 /* ShippingLabelCreationInfoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02DFECE625EE338F0070F212 /* ShippingLabelCreationInfoViewController.swift */; };
612611
02E19B9C284743A40010B254 /* ProductImageUploader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02E19B9B284743A40010B254 /* ProductImageUploader.swift */; };
613612
02E222C829FBA60F004579A1 /* WooAnalyticsEvent+ProductFormAI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02E222C729FBA60F004579A1 /* WooAnalyticsEvent+ProductFormAI.swift */; };
614613
02E262C9238D0AD300B79588 /* ProductStockStatusListSelectorCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02E262C8238D0AD300B79588 /* ProductStockStatusListSelectorCommand.swift */; };
@@ -3802,7 +3801,6 @@
38023801
02DFD5032B20486C0048CD70 /* ProductStepper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductStepper.swift; sourceTree = "<group>"; };
38033802
02DFD5052B2048C50048CD70 /* ProductStepperViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductStepperViewModel.swift; sourceTree = "<group>"; };
38043803
02DFD5072B205AEF0048CD70 /* ProductStepperViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductStepperViewModelTests.swift; sourceTree = "<group>"; };
3805-
02DFECE625EE338F0070F212 /* ShippingLabelCreationInfoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelCreationInfoViewController.swift; sourceTree = "<group>"; };
38063804
02E19B9B284743A40010B254 /* ProductImageUploader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductImageUploader.swift; sourceTree = "<group>"; };
38073805
02E222C729FBA60F004579A1 /* WooAnalyticsEvent+ProductFormAI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WooAnalyticsEvent+ProductFormAI.swift"; sourceTree = "<group>"; };
38083806
02E262C8238D0AD300B79588 /* ProductStockStatusListSelectorCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductStockStatusListSelectorCommand.swift; sourceTree = "<group>"; };
@@ -6733,7 +6731,6 @@
67336731
children = (
67346732
CEAB739A2C81E3A000A7EB39 /* WooShipping Create Shipping Labels */,
67356733
DEE6437426D87C2D00888A75 /* Print Customs Form */,
6736-
02DFECE525EE33430070F212 /* Create Shipping Label Info */,
67376734
023D69BA2589BF2500F7DA72 /* Refund Shipping Label */,
67386735
023D69C52589BF5F00F7DA72 /* Print Shipping Label */,
67396736
53284F4A66A725F479CD9584 /* EUShippingNoticeTopBannerFactory.swift */,
@@ -7786,14 +7783,6 @@
77867783
path = "Beta features";
77877784
sourceTree = "<group>";
77887785
};
7789-
02DFECE525EE33430070F212 /* Create Shipping Label Info */ = {
7790-
isa = PBXGroup;
7791-
children = (
7792-
02DFECE625EE338F0070F212 /* ShippingLabelCreationInfoViewController.swift */,
7793-
);
7794-
path = "Create Shipping Label Info";
7795-
sourceTree = "<group>";
7796-
};
77977786
02E262C3238D04DB00B79588 /* ListSelector */ = {
77987787
isa = PBXGroup;
77997788
children = (
@@ -15413,7 +15402,6 @@
1541315402
2D88C1112DF883C300A6FB2C /* AttributedString+Helpers.swift in Sources */,
1541415403
CE2A9FC623BFFADE002BEC1C /* RefundedProductsViewModel.swift in Sources */,
1541515404
205B7EC32C19FC3000D14A36 /* PointOfSaleCardPresentPaymentConnectingToReaderAlertViewModel.swift in Sources */,
15416-
02DFECE725EE338F0070F212 /* ShippingLabelCreationInfoViewController.swift in Sources */,
1541715405
093B265527DE8F020026F92D /* UnitInputViewModel+BulkUpdatePrice.swift in Sources */,
1541815406
02C7EE8C2B22B21D008B7DF8 /* CollapsibleProductRowCardViewModel.swift in Sources */,
1541915407
0245465F24EE9106004F531C /* ProductVariationFormEventLogger.swift in Sources */,

0 commit comments

Comments
 (0)