1+ import { TypeAccepted } from "@commercelayer/react-components/lib/esm/utils/getLineItemsCount"
12import CommerceLayer , {
23 Order ,
34 Address ,
@@ -15,6 +16,8 @@ import CommerceLayer, {
1516} from "@commercelayer/sdk"
1617import i18n from "i18next"
1718
19+ import { LINE_ITEMS_SHIPPABLE } from "components/utils/constants"
20+
1821interface FetchOrderByIdProps {
1922 orderId : string
2023 accessToken : string
@@ -198,7 +201,7 @@ async function checkIfShipmentRequired(
198201 } )
199202 ) . line_items ?. filter (
200203 ( line_item ) =>
201- ( line_item . item_type === "skus" || line_item . item_type === "bundles" ) &&
204+ LINE_ITEMS_SHIPPABLE . includes ( line_item . item_type as TypeAccepted ) &&
202205 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
203206 // @ts -ignore
204207 ! line_item . item ?. do_not_ship
@@ -226,6 +229,29 @@ export const fetchOrderById = async ({
226229 try {
227230 const fetchOrder = async ( ) => {
228231 return cl . orders . retrieve ( orderId , {
232+ fields : {
233+ orders : [
234+ "id" ,
235+ "guest" ,
236+ "shipping_country_code_lock" ,
237+ "customer_email" ,
238+ "status" ,
239+ "return_url" ,
240+ "tax_included" ,
241+ "requires_billing_info" ,
242+ "total_amount_with_taxes_float" ,
243+ "language_code" ,
244+ "shipping_address" ,
245+ "billing_address" ,
246+ "shipments" ,
247+ "payment_method" ,
248+ "payment_source" ,
249+ "customer" ,
250+ ] ,
251+ shipments : [ "shipping_method" ] ,
252+ customer : [ "customer_addresses" ] ,
253+ customer_addresses : [ "address" ] ,
254+ } ,
229255 include : [
230256 "shipping_address" ,
231257 "billing_address" ,
@@ -409,9 +435,11 @@ export const fetchOrderById = async ({
409435 paymentMethod ?. payment_source_type === "stripe_payments" ||
410436 paymentMethod ?. payment_source_type === "braintree_payments"
411437
412- const allAvailablePaymentMethods = ( await cl . payment_methods . list ( ) ) . filter (
413- ( { disabled_at } ) => disabled_at === null
414- )
438+ const allAvailablePaymentMethods = (
439+ await cl . payment_methods . list ( {
440+ fields : { payment_methods : [ "disabled_at" , "id" ] } ,
441+ } )
442+ ) . filter ( ( { disabled_at } ) => disabled_at === null )
415443
416444 // If we have a customer with a single payment method
417445 // the payment method is automatically selected
@@ -420,7 +448,8 @@ export const fetchOrderById = async ({
420448 //! isGuest &&
421449 isPaymentRequired &&
422450 ! hasPaymentMethod &&
423- allAvailablePaymentMethods . length === 1
451+ allAvailablePaymentMethods . length === 1 &&
452+ ! order . payment_method ?. id
424453 ) {
425454 try {
426455 await cl . orders . update ( {
0 commit comments