-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding of tracking code to fulfillment programmatically #529
Comments
I share the same issues that @chladog describes. This solution will be a nice feature to have in Vendure since every Order in my e-commerce needs a tracking code and everyone is generated by an external API, never is inputted by a user. I had created a repo to maintain some packages to help in these shipping problems (like maintain a list of boxes with dimensions, add dimensional custom fields in product, a helper to calculate how many items you can put in a box, how many boxes will be necessary to create a box) and I use the same approach that @chladog wants in this issue. This solution will fix this UI / UX problems related to tracking code |
@chladog @michaelbromley Would be nice to have a field called like |
I see this as a case-based flow that should be implemented in new TrackingCodeStrategy. - the strategy (it being aware of Order and Fulfillment) would call provider's API creating a packet and return the tracking code, the trakcingcodeurl, or even barcode image url. Then your strategy code would handle saving it as fulfillment customfields (#525 + #464). When I'm writing this it comes to my mind that this shipping-dependent code invocation feature does not have to be strictly related to tracking codes (e.g. provider supports creation of the packet via API, but not tracking feature). |
Hi all, I've been re-reading this thread and trying to get a clear picture of exactly what is needed here. Since this issue was opened we now have #510 implemented, so some of the issues may be a bit easier to deal with. Let me try to state the problem succinctly and then propose a rough sketch of a solution. Then you can tell me whether that seems to cover your conceivable use-cases. ProblemWe need to be able to have control over how Fulfillments are created, so that we can programatically populate certain fields (tracking code, custom fields) of a Fulfillment without the need for manual input by an administrator. Solution
interface FulfillmentStrategy<Data = unknown> extends InjectableStrategy {
readonly name: string;
defineInputType(): DocumentNode;
createFulfillment(
ctx: RequestContext,
order: Order,
data: Data,
): Promise<Partial<Fulfillment>>;
} This works in a similar way to the AuthenticationStrategy, where the So for a purely programmatic strategy, the input can be empty. Then, during the
Exampleinterface ShippoData {
serviceType: string;
}
class ShippoFulfillmentStrategy implements FulfillmentStrategy<ShippoData> {
readonly name = 'Shippo';
private shippo;
init() {
this.shippo = require('shippo')('<YOUR_PRIVATE_KEY>');
}
defineInputType(): DocumentNode {
return gql`
input ShippoInput {
serviceType: String!
}
`;
}
createFulfillment(
ctx: RequestContext,
order: Order,
data: ShippoData,
): Promise<Partial<Fulfillment>> {
const shipment = this.getShipmentFromOrder(order);
const transaction = this.shippo.transaction.create({
shipment,
servicelevel_token: data.serviceType,
carrier_account: "558c84bbc25a4f609f9ba02da9791fe4",
label_file_type: "png"
});
return {
trackingCode: transaction.tracking_number,
customFields: {
labelUrl: transaction.label_url,
}
};
}
private getShipmentFromOrder(order: Order): ShippoShipment {
// ...
}
} |
I think your proposal fits my use-case. Mind cancellation of fulfillment (#565) e.g. we cancel fulfillment so we want to call delivery api to cancel the packet. |
Relates to #529. This commit introduces a new FulfillmentHandler class which can be used to define how Fulfillments are created. BREAKING CHANGE: The Fulfillment and ShippingMethod entities have new fields relating to FulfillmentHandlers. This will require a DB migration, though no custom data migration will be needed for this particular change. The `addFulfillmentToOrder` mutation input has changed: the `method` & `trackingCode` fields have been replaced by a `handler` field which accepts a FulfillmentHandler code, and any expected arguments defined by that handler.
Is your feature request related to a problem? Please describe.
I'm using API of the delivery service. I create a "digital twin" packet via API and I receive a tracking code. This code is printed and sticked to the physical package - then either courier collects the package or we deliver it to delivery service collection point (physically being Shipped).
In the flow I need to have tracking code after order confirmation, but before shipping the goods (creation of fulfillment).
Describe the solution you'd like
Describe alternatives you've considered
Currently I make API request on Pending to Shipped state transition.
But this has several problems:
The text was updated successfully, but these errors were encountered: