@@ -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:
0 commit comments