-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(orders): implement automatic order status updates
- Loading branch information
1 parent
68d04f2
commit 9af8725
Showing
8 changed files
with
250 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** @noinspection PhpUnhandledExceptionInspection,StaticClosureCanBeUsedInspection */ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\PrestaShop\Pdk\Order\Service; | ||
|
||
use MyParcelNL\Pdk\App\Order\Contract\OrderStatusServiceInterface; | ||
use MyParcelNL\Pdk\Facade\Pdk; | ||
use MyParcelNL\PrestaShop\Tests\Uses\UsesMockPsPdkInstance; | ||
use Order as PsOrder; | ||
use function MyParcelNL\Pdk\Tests\usesShared; | ||
use function MyParcelNL\PrestaShop\psFactory; | ||
|
||
usesShared(new UsesMockPsPdkInstance()); | ||
|
||
it('retrieves all order statuses', function () { | ||
/** @var OrderStatusServiceInterface $service */ | ||
$service = Pdk::get(OrderStatusServiceInterface::class); | ||
|
||
/** @see UsesMockPsPdkInstance::createOrderStates() */ | ||
expect($service->all())->toBe([ | ||
1 => 'Awaiting check payment', | ||
2 => 'Payment accepted', | ||
3 => 'Processing in progress', | ||
4 => 'Shipped', | ||
5 => 'Delivered', | ||
6 => 'Canceled', | ||
7 => 'Refunded', | ||
8 => 'Payment error', | ||
9 => 'On backorder (paid)', | ||
10 => 'Awaiting bank wire payment', | ||
11 => 'Remote payment accepted', | ||
12 => 'On backorder (not paid)', | ||
13 => 'Awaiting Cash On Delivery validation', | ||
]); | ||
}); | ||
|
||
it('updates order status', function () { | ||
psFactory(PsOrder::class) | ||
->withId(14) | ||
->store(); | ||
psFactory(PsOrder::class) | ||
->withId(16) | ||
->store(); | ||
|
||
/** @var OrderStatusServiceInterface $service */ | ||
$service = Pdk::get(OrderStatusServiceInterface::class); | ||
|
||
$service->updateStatus([14, 16], '4'); | ||
|
||
$order14 = new PsOrder(14); | ||
$order16 = new PsOrder(16); | ||
|
||
expect($order14->current_state) | ||
->toBe(4) | ||
->and($order16->current_state) | ||
->toBe(4); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use MyParcelNL\Pdk\Tests\Factory\Contract\FactoryInterface; | ||
use MyParcelNL\PrestaShop\Tests\Factory\AbstractPsObjectModelFactory; | ||
|
||
/** | ||
* @method $this withColor(string $color) | ||
* @method $this withDeleted(int $deleted) | ||
* @method $this withDelivery(int $delivery) | ||
* @method $this withHidden(int $hidden) | ||
* @method $this withIdLang(int $idLang) | ||
* @method $this withIdOrderState(int $idOrderState) | ||
* @method $this withInvoice(int $invoice) | ||
* @method $this withLang(int|Lang|LangFactory $lang) | ||
* @method $this withLogable(int $logable) | ||
* @method $this withModuleName(string $moduleName) | ||
* @method $this withName(string $name) | ||
* @method $this withOrderState(int|OrderState|OrderStateFactory $orderState) | ||
* @method $this withPaid(int $paid) | ||
* @method $this withPdfDelivery(int $pdfDelivery) | ||
* @method $this withPdfInvoice(int $pdfInvoice) | ||
* @method $this withSendEmail(int $sendEmail) | ||
* @method $this withShipped(int $shipped) | ||
* @method $this withTemplate(string $template) | ||
* @method $this withUnremovable(int $unremovable) | ||
*/ | ||
final class OrderStateFactory extends AbstractPsObjectModelFactory | ||
{ | ||
protected function createDefault(): FactoryInterface | ||
{ | ||
return $this | ||
->withColor('#34209E') | ||
->withDeleted(0) | ||
->withDelivery(0) | ||
->withHidden(0) | ||
->withLogable(0) | ||
->withPaid(0) | ||
->withPdfDelivery(0) | ||
->withPdfInvoice(0) | ||
->withShipped(0) | ||
->withUnremovable(0) | ||
->withLang(1); | ||
} | ||
|
||
protected function getObjectModelClass(): string | ||
{ | ||
return OrderState::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,3 @@ public function hydrate(array $keyValueData): void; | |
|
||
public function save(): void; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters