Skip to content

feat: introduce shipment query, delete, return and multi-collo services#596

Open
NabDevs wants to merge 5 commits intov11from
feat/v11-int-1032-shipment-services
Open

feat: introduce shipment query, delete, return and multi-collo services#596
NabDevs wants to merge 5 commits intov11from
feat/v11-int-1032-shipment-services

Conversation

@NabDevs
Copy link
Contributor

@NabDevs NabDevs commented Mar 6, 2026

Migrates remaining MyParcelCollection functionality into dedicated service classes using the generated OpenAPI client as source of truth.

New services:

  • ShipmentQueryService (find, findMany, query, findByReferenceId)
  • ShipmentDeleteService (deleteMany)
  • ReturnShipmentService (createRelated, createUnrelated)
  • MultiColloShipmentService (splitShipment)

Refactored services:

  • ShipmentTrackTraceService: hybrid approach for street deserialization bug
  • ShipmentPrintService: migrated from MyParcelRequest to generated client
  • ShipmentLabelsService: removed MyParcelRequest dependency

Services using hybrid approach (request builder + manual send) include @todo markers for reverting once upstream spec/codegen fixes land.

INT-1032

@NabDevs NabDevs requested a review from a team as a code owner March 6, 2026 09:19
@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

❌ Patch coverage is 76.15385% with 62 lines in your changes missing coverage. Please review.
✅ Project coverage is 8.36%. Comparing base (c99f14f) to head (0512442).
⚠️ Report is 1 commits behind head on v11.

Files with missing lines Patch % Lines
...Generated/CoreApi/Model/FixedShipmentRecipient.php 0.00% 36 Missing ⚠️
...nt/Generated/CoreApi/Model/FixedShipmentSender.php 0.00% 15 Missing ⚠️
src/Services/Shipment/ShipmentQueryService.php 89.55% 7 Missing ⚠️
.../Services/MultiCollo/MultiColloShipmentService.php 94.28% 2 Missing ⚠️
src/Services/Returns/ReturnShipmentService.php 96.82% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##               v11    #596      +/-   ##
==========================================
+ Coverage     7.63%   8.36%   +0.73%     
- Complexity   22999   23054      +55     
==========================================
  Files          595     601       +6     
  Lines        56201   56387     +186     
==========================================
+ Hits          4289    4717     +428     
+ Misses       51912   51670     -242     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@myparcel-bot myparcel-bot bot force-pushed the feat/v11-int-1032-shipment-services branch from b4563e6 to b557f34 Compare March 10, 2026 12:08
@myparcel-bot myparcel-bot bot force-pushed the feat/v11-int-1032-shipment-services branch from f251f29 to cd5ca0f Compare March 16, 2026 08:51
NabDevs added 5 commits March 16, 2026 08:59
Migrates remaining MyParcelCollection functionality into dedicated
service classes using the generated OpenAPI client as source of truth.

New services:
- ShipmentQueryService (find, findMany, query, findByReferenceId)
- ShipmentDeleteService (deleteMany)
- ReturnShipmentService (createRelated, createUnrelated)
- MultiColloShipmentService (splitShipment)

Refactored services:
- ShipmentTrackTraceService: hybrid approach for street deserialization bug
- ShipmentPrintService: migrated from MyParcelRequest to generated client
- ShipmentLabelsService: removed MyParcelRequest dependency

Services using hybrid approach (request builder + manual send) include
@todo markers for reverting once upstream spec/codegen fixes land.
@myparcel-bot myparcel-bot bot force-pushed the feat/v11-int-1032-shipment-services branch from cd5ca0f to 0512442 Compare March 16, 2026 08:59
public function splitShipment(Shipment $shipment, int $amount): Shipment
{
if ($amount < 2) {
throw new InvalidArgumentException('Multi-collo requires at least 2 shipments');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following offline discussion: we do not have to validate this here.

$secondary = new SecondaryShipmentRequest();
$secondary->setReferenceIdentifier($referenceId);

$carrier = $main->getCarrier();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this assignment to outside the for loop just like weightPerCollo and referenceId. No reason for rejection just an observation.

public function deleteMany(array $shipmentIds): void
{
if (empty($shipmentIds)) {
throw new InvalidArgumentException('At least one shipment ID is required');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just return here as well, re: descussion about throwing errors. For consideration.

{
$shipments = $this->findManyByReferenceId([$referenceIdentifier]);

return $shipments[0] ?? null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think findManyByReferenceId may return multiple shipments for the same referenceId, which is a scenario that can happen in the real world I think. Should we not return an array of shipments as well here and let the consuming app decide what to do (error / log / present results) what happens when multiple shipments exist with the same referenceId?

$id = $shipment->getId();

if (null === $id) {
$merged[] = $shipment;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider this a bug, is it possible that a $shipment without an id is returned? If so, we are now silently assigning an id to it here in the $merged array because the keys are id’s, for instance 225 if the previous shipment had id 224, what happens when a shipment with id 225 is also in the loop?

$shipmentId = $tracktrace->getShipmentId();

$result[(int) $trackTrace->getShipmentId()] = $trackTrace;
if (null !== $shipmentId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a different approach from the ShipmentQueryService, now if there is no shipmentId we just ignore it. Is there a reason why these are different?

]);

$service = new ShipmentPrintService($this->getApiKey(), $api, $httpClient);
$service->setUserAgentForProposition('Magento', '2.4.7');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sanity check: is this useragent necessary for the test, and if so is a more generic one maybe clearer about the intent (for instance 'appname', 'v1.0.0')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants