myparcelnl / pdk

MyParcel Plugin Development Kit
0 stars 0 forks source link

Duplicate carriers when using PostNL custom contracts #284

Open mariuszsienkiewicz opened 2 months ago

mariuszsienkiewicz commented 2 months ago

@EdieLemoine: When fetching carriers from the MyParcel API, when PostNL custom contract carrier is enabled, multiple postnl carriers are returned. This causes problems all over the place. We need to correct this manually before saving these carriers in the PDK.

Original myparcelnl/prestashop issue content

Version check

PrestaShop version

8.1.5

PHP version

8.1.28

What went wrong?

I have tried to test the myparcelnl on stock PrestaShop 8.1.5 installation.

It seems that there is an issue when trying to save the API key for the first time (and after deleting the API key and setting it up again the issue occurs too).

Error log is below.

From what I can understand, the issue is that PostNL Carrier is duplicated (I don't know why) and the PostNL (Custom contract) use the same name. CarrierCollection which is used in the process of setting up new carriers contain seven MyParcelNL\Pdk\Carrier\Model\Carrier objects and three of them have the same name:

[0] => MyParcelNL\Pdk\Carrier\Model\Carrier Object
    (
    [cloned:protected] => 
    [attributes:protected] => Array
            (
                [externalIdentifier] => 
                [id] => 1
                [name] => postnl
                [human] => PostNL
                [contractId] => 
                [enabled] => 1
                [isDefault] => 1
                [label] => 
                [optional] => 0
                [primary] => 1
                [type] => main
[1] => MyParcelNL\Pdk\Carrier\Model\Carrier Object
    (
    [cloned:protected] => 
    [attributes:protected] => Array
            (
                [externalIdentifier] => 
                [id] => 1
                [name] => postnl
                [human] => PostNL
                [contractId] => 
                [enabled] => 1
                [isDefault] => 1
                [label] => 
                [optional] => 0
                [primary] => 1
                [type] => main
[2] => MyParcelNL\Pdk\Carrier\Model\Carrier Object 
    (
    [cloned:protected] => 
        [attributes:protected] => Array
            (
                [externalIdentifier] => 
                [id] => 1
                [name] => postnl
                [human] => PostNL
                [contractId] => <redacted>
                [enabled] => 1
                [isDefault] => 1
                [label] => 
                [optional] => 0
                [primary] => 1
                [type] => custom

There is one more bug (duplicated PostNL) in the configuration page too (screenshot below) that is probably related to this issue.

Reproduction steps

  1. Install the plugin on stock PrestaShop 8.1.5
  2. Go to the configuration page
  3. Save the API key - error
  4. Refresh
    • Configuration page now shows in the Carriers tab two PostNL tabs.

Relevant log output

accountUpdate ERROR handler ApiException: An exception occurred while executing 'INSERT INTO ps_myparcelnl_carrier_mapping (carrier_id, myparcel_carrier, date_upd, date_add) VALUES (?, ?, ?, ?)' with params [6, "postnl", "2024-04-24 13:33:08", "2024-04-24 13:33:08"]: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'postnl' for key 'myparcel_carrier'
    rn https://domain.com/modules/myparcelnl/views/js/backend/admin/dist/index.iife.js:15
    doRequest https://domain.com/modules/myparcelnl/views/js/backend/admin/dist/index.iife.js:21
index.iife.js:21:1018
    log https://domain.com/modules/myparcelnl/views/js/backend/admin/dist/index.iife.js:21
    error https://domain.com/modules/myparcelnl/views/js/backend/admin/dist/index.iife.js:21
    Xy https://domain.com/modules/myparcelnl/views/js/backend/admin/dist/index.iife.js:21

Additional context

image

EdieLemoine commented 2 months ago

Hi @mariuszsienkiewicz, this is a very specific issue with the way custom PostNL contracts are currently handled by our API. You might see this issue disappear if you disable your custom PostNL contract in your MyParcel account. Obviously that's not a real fix, but this is an issue we're aware of and will actually fix in the PDK soon.

maikelwever commented 4 days ago

I have the exact same problem, but I don't have any custom contracts with PostNL. It seems to be related to the duplicate entries for regular non-custom-contract PostNL.

An exception occurred while executing 'INSERT INTO ps_myparcelnl_carrier_mapping (carrier_id, myparcel_carrier, date_upd, date_add) VALUES (?, ?, ?, ?)' with params [36, "postnl", "2024-07-05 16:42:59", "2024-07-05 16:42:59"]:SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'postnl' for key 'myparcel_carrier'

PrestaShop version: 8.1.7 PHP version: 8.3.8 (also tried with 8.1.28, same result) MyParcel Module version: myparcelnl-prestashop-4.0.0-beta.3.zip (reports as v4.0.0-be)

The plugin also creates duplicate entries for PostNL in the PrestaShop carriers list:

image