Skip to content

Commit ef9b8d3

Browse files
author
Gerald Baulig
committed
fix(dhl): activate service attribute parser
1 parent c63a517 commit ef9b8d3

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

src/services/fulfillment.ts

+4
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,10 @@ export class FulfillmentService
896896
const variant = product.variants.find(
897897
v => v.id === p.variant_id
898898
);
899+
variant.attributes = [
900+
...(variant.attributes ?? []),
901+
...(product.attributes ?? []),
902+
];
899903
const courier = courier_map[product.courier_id]?.payload;
900904
const stub = Stub.getInstance(courier);
901905
const taxes = product.tax_ids.map(

src/stubs/dhl_soap.ts

+28-14
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/fulfillment_product.js';
2727
import { BigNumber } from 'bignumber.js';
2828
import { Package } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/product.js';
29+
import { Attribute } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/attribute.js';
2930

3031
dayjs.extend(customParseFormat);
3132

@@ -166,6 +167,7 @@ const DefaultUrns = {
166167
dhl_roundWeightUp: 'urn:restorecommerce:fulfillment:product:attribute:dhl:roundWeightUp',
167168
dhl_stepPrice: 'urn:restorecommerce:fulfillment:product:attribute:dhl:stepPrice',
168169
dhl_stepWeight: 'urn:restorecommerce:fulfillment:product:attribute:dhl:stepWeightInKg',
170+
dhl_premium: 'urn:restorecommerce:fulfillment:product:attribute:dhl:service',
169171
};
170172

171173
type KnownUrns = typeof DefaultUrns;
@@ -437,14 +439,20 @@ export class DHLSoap extends Stub {
437439
}
438440
}
439441

440-
protected parseService (attributes: any[]) {
441-
return attributes.filter((att: any) =>
442-
att.id.startsWith(this.urns.dhl_service)
442+
protected parseService (attributes: Attribute[]) {
443+
return attributes?.reverse().filter((att: Attribute) =>
444+
att.id?.startsWith(this.urns.dhl_service)
443445
).map((att: any) => ({
444446
[att.value]: {
445-
attributes: Object.assign({}, ...att.attribute.map((att: any) => ({
446-
[att.id]: att.value
447-
})))}
447+
attributes: Object.assign(
448+
{
449+
active: "1",
450+
},
451+
...att.attribute.map(
452+
(att: any) => ({[att.id]: att.value})
453+
)
454+
)
455+
}
448456
}));
449457
}
450458

@@ -624,6 +632,17 @@ export class DHLSoap extends Stub {
624632
},
625633
ShipmentOrder: requests.map((request, i): ShipmentOrder => {
626634
const packaging = request.payload.packaging;
635+
const variant = {
636+
...(request.product.variants?.find(
637+
v => packaging.parcels.map(
638+
p => p.variant_id.includes(v.id)
639+
)
640+
) ?? {})
641+
}
642+
variant.attributes = [
643+
...(variant.attributes ?? []),
644+
...(request.product?.attributes ?? []),
645+
];
627646
return {
628647
sequenceNumber: i + 1,
629648
Shipment: {
@@ -673,24 +692,19 @@ export class DHLSoap extends Stub {
673692
shipmentDate: new Date().toISOString().slice(0,10),
674693
costCenter: '',
675694
customerReference: request.payload.id,
676-
product: request.product.attributes.find(
695+
product: variant.attributes.find(
677696
att => att.id === this.urns.dhl_productName
678697
)?.value,
679-
accountNumber: request.product.attributes.find(
698+
accountNumber: variant.attributes.find(
680699
att => att.id === this.urns.dhl_accountNumber
681700
)?.value ?? this.stub_config?.ordering?.account_number,
682-
// Service: parseService(request.parcel.attributes),
701+
Service: this.parseService(variant.attributes),
683702
ShipmentItem: {
684703
heightInCM: request.parcel.package.size_in_cm.height,
685704
lengthInCM: request.parcel.package.size_in_cm.length,
686705
widthInCM: request.parcel.package.size_in_cm.width,
687706
weightInKG: request.parcel.package.weight_in_kg,
688707
},
689-
/* No longer supported!!!
690-
Notification: {
691-
recipientEmailAddress: packaging.notify
692-
}
693-
*/
694708
}
695709
}
696710
};

0 commit comments

Comments
 (0)