Skip to content

Shipment creation fails: PUDO id is provided but main service type is not PUDO #180

Description

@gadnis

parcelShopId is sent for non-PUDO shipments, causing shipment creation to fail

Environment

  • PrestaShop: 1.7.6.8
  • DPD Baltics module: 3.2.22
  • Order page: legacy admin order page
  • DPD API: https://esiunta.dpd.lt/api/v1/

Problem

Creating and printing a label for a home-delivery order fails when the employee clicks the save_and_print action.

The DPD API returns:

PUDO id is provided but main service type is not PUDO

Example response:

[
  {
    "type": "https://esiunta.dpd.lt/api/v1/problems/address_conflict",
    "title": "PUDO id is provided but main service type is not PUDO",
    "detail": {},
    "instance": ""
  }
]

PUDO deliveries continue to work correctly. The issue affects home-delivery orders.

Verified order data

The affected order used the following DPD product:

Product: D-B2C (home delivery)
is_pudo: 0

The related shipment had no PUDO ID, and there was no related row in dpd_pudo_cart. This confirms that the incorrect PUDO ID did not originate from the stored order or shipment data.

Root cause

In src/Service/API/ShipmentApiService.php, parcelShopId is added to the shipment request whenever ShipmentData::getSelectedPudoId() returns a value:

if ($shipmentData->getSelectedPudoId()) {
    $shipmentCreationRequest = $this->setPudoData($shipmentCreationRequest, $shipmentData);
}

getSelectedPudoId() only returns the value stored in the DTO. It does not verify that the selected DPD product is a PUDO service.

On the legacy admin order page, a parcel-shop ID can be present in the submitted form even when the selected product is a home-delivery service. Consequently, the API request contains both:

main service: D-B2C
parcelShopId: <a parcel-shop ID>

The DPD API rejects this conflicting combination.

Suggested fix

File:

src/Service/API/ShipmentApiService.php

Method:

ShipmentApiService::createShipment()

Only add PUDO data when the selected DPD product is actually a PUDO product:

-if ($shipmentData->getSelectedPudoId()) {
+if ($dpdProduct->is_pudo && $shipmentData->getSelectedPudoId()) {
     $shipmentCreationRequest = $this->setPudoData($shipmentCreationRequest, $shipmentData);
 }

The product is loaded server-side earlier in the same method:

$dpdProduct = new DPDProduct($shipmentData->getProduct());

The shipment request must include parcelShopId only when the selected main service is a PUDO service. Checking only whether a PUDO ID has a value is insufficient and can produce an invalid API request.

Result after applying the fix

  • Home-delivery labels can be created and printed again.
  • PUDO label creation continues to work.
  • parcelShopId is not included for products where is_pudo = 0.

Steps to reproduce

  1. Open a home-delivery order on the PrestaShop 1.7.6.8 legacy admin order page.
  2. Ensure that the selected DPD product is D-B2C and has is_pudo = 0.
  3. Click the button with data-action="save_and_print".
  4. Observe that shipment creation fails with PUDO id is provided but main service type is not PUDO when a parcel-shop ID is present in the submitted shipment data.

Expected behavior

parcelShopId must only be included in a shipment creation request when the selected main service is a PUDO service.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions