Skip to content

Commit

Permalink
fix(carriers): fix carriers and payment methods not being linked
Browse files Browse the repository at this point in the history
- occurs when carriers are updated after the initial creation
  • Loading branch information
EdieLemoine committed Nov 22, 2023
1 parent 19d3b33 commit 2228f71
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 54 deletions.
13 changes: 1 addition & 12 deletions src/Carrier/Service/CarrierBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ private function createCarrier(): void

$psCarrier->name = $psCarrier->name ?? $this->myParcelCarrier->human;
$psCarrier->active = $this->psCarrierService->carrierIsActive($this->myParcelCarrier);
$psCarrier->id_reference = $this->createCarrierIdReference();
$psCarrier->deleted = false;
$psCarrier->external_module_name = $module->name;
$psCarrier->is_module = true;
Expand All @@ -200,16 +199,6 @@ private function createCarrier(): void
$this->psCarrier = $psCarrier;
}

/**
* @return int
*/
private function createCarrierIdReference(): int
{
$carrierId = str_pad((string) $this->myParcelCarrier->id, 3, '0');

return (int) ($carrierId . $this->myParcelCarrier->subscriptionId);
}

/**
* @return null|\Carrier
*/
Expand All @@ -223,6 +212,6 @@ private function getExistingPsCarrier(): ?PsCarrier
return $this->psCarrierService->get($mapping->getCarrierId());
}

return $this->psCarrierService->getByReference($this->createCarrierIdReference());
return null;
}
}
42 changes: 0 additions & 42 deletions tests/Unit/Service/PsCarrierServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use MyParcelNL\Pdk\Base\Support\Collection;
use MyParcelNL\Pdk\Carrier\Collection\CarrierCollection;
use MyParcelNL\Pdk\Carrier\Model\Carrier;
use MyParcelNL\Pdk\Carrier\Model\CarrierFactory;
use MyParcelNL\Pdk\Facade\Actions;
use MyParcelNL\Pdk\Facade\Pdk;
use MyParcelNL\Pdk\Tests\Api\Response\ExampleAclResponse;
Expand Down Expand Up @@ -189,47 +188,6 @@ function doSnapshotTest(Collection $carrierMappings, Collection $psCarriers): vo
]);
});

it('uses existing carrier if reference id matches', function (CarrierFactory $factory) {
setupAccountAndCarriers(factory(CarrierCollection::class)->push($factory));

$carrier = $factory->make();

/** @see \MyParcelNL\PrestaShop\Carrier\Service\CarrierBuilder::createCarrierIdReference() */
$referenceId = (int) (str_pad((string) $carrier->id, 3, '0') . $carrier->subscriptionId);

psFactory(PsCarrier::class)
->withIdReference($referenceId)
->store();

/** @var PsCarrierServiceInterface $service */
$service = Pdk::get(PsCarrierServiceInterface::class);
$service->updateCarriers();

$psCarriers = new Collection(PsCarrier::getCarriers(0));

expect($psCarriers->count())
->toBe(1)
->and($psCarriers->first())
->toHaveKeysAndValues([
'id' => 1,
'id_reference' => $referenceId,
'name' => $carrier->human,
]);
})->with([
'only id' => function () {
return factory(Carrier::class)
->fromPostNL()
->withHuman('Carrier');
},

'id and subscription id' => function () {
return factory(Carrier::class)
->fromDhlForYou()
->withHuman('Carrier')
->withSubscriptionId(8123);
},
]);

it('enables carriers based on settings', function (array $settings, bool $result) {
setupCarrierActiveSettings($settings)->store();

Expand Down

0 comments on commit 2228f71

Please sign in to comment.