-
Notifications
You must be signed in to change notification settings - Fork 45
Merge the Customer endpoints into one domain PR #428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PrestaEdit
wants to merge
10
commits into
PrestaShop:dev
Choose a base branch
from
PrestaEdit:domain/customer
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0ef04ae
Add Customer private-note endpoint
PrestaEdit 03fc93a
Add Customer orders and carts read endpoints
PrestaEdit 8fa495f
Add Customer transform-guest-to-customer endpoint
PrestaEdit 41a300a
Add customer address-creation info read endpoint
PrestaEdit 5a2c8ef
Fix CS import order + Rector pluralization (info -> infos)
PrestaEdit 4c19fd3
Merge the Customer endpoints into one domain PR
PrestaEdit a60a464
Fix customer orders and carts endpoints returning only the identifier
PrestaEdit ef549e1
Declare the customer collections exactly like ProductImageList
PrestaEdit 9d23e65
Address the review on the Customer endpoints
mattgoud fd7bc01
Address the second review on the Customer endpoints
mattgoud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,67 @@ | ||
| <?php | ||
| /** | ||
| * Copyright since 2007 PrestaShop SA and Contributors | ||
| * PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
| * | ||
| * NOTICE OF LICENSE | ||
| * | ||
| * This source file is subject to the Academic Free License version 3.0 | ||
| * that is bundled with this package in the file LICENSE.md. | ||
| * It is also available through the world-wide-web at this URL: | ||
| * https://opensource.org/licenses/AFL-3.0 | ||
| * If you did not receive a copy of the license and are unable to | ||
| * obtain it through the world-wide-web, please send an email | ||
| * to license@prestashop.com so we can send you a copy immediately. | ||
| * | ||
| * @author PrestaShop SA and Contributors <contact@prestashop.com> | ||
| * @copyright Since 2007 PrestaShop SA and Contributors | ||
| * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Customer; | ||
|
|
||
| use ApiPlatform\Metadata\ApiResource; | ||
| use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerConstraintException; | ||
| use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerNotFoundException; | ||
| use PrestaShop\PrestaShop\Core\Domain\Customer\Query\GetCustomerCarts; | ||
| use PrestaShopBundle\ApiPlatform\Metadata\CQRSGetCollection; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
|
|
||
| /** | ||
| * One cart of a customer, as summarized by GetCustomerCarts. | ||
| * | ||
| * The query returns a list, so this is a collection operation, declared like ProductImageList: | ||
| * QueryResultSerializerTrait only wraps a query result behind "_queryResult" when it is a | ||
| * scalar, so the ['[_queryResult]' => '[carts]'] mapping the source PR used could never fill | ||
| * anything and the response came back with the identifier alone. | ||
| * | ||
| * Only the carts that were never turned into an order are listed: the core calls | ||
| * Cart::getCustomerCarts($customerId, false), so a customer whose carts all became orders | ||
| * gets an empty list. | ||
| */ | ||
| #[ApiResource( | ||
| operations: [ | ||
| new CQRSGetCollection( | ||
| uriTemplate: '/customers/{customerId}/carts', | ||
| requirements: ['customerId' => '\d+'], | ||
| CQRSQuery: GetCustomerCarts::class, | ||
| scopes: ['customer_read'], | ||
| ), | ||
| ], | ||
| exceptionToStatus: [ | ||
| CustomerNotFoundException::class => Response::HTTP_NOT_FOUND, | ||
| CustomerConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, | ||
| ], | ||
| )] | ||
| class CustomerCart | ||
| { | ||
| public int $customerId; | ||
|
|
||
| public int $cartId; | ||
|
|
||
| public string $creationDate; | ||
|
|
||
| public string $totalPrice; | ||
| } | ||
This file contains hidden or 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,72 @@ | ||
| <?php | ||
| /** | ||
| * Copyright since 2007 PrestaShop SA and Contributors | ||
| * PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
| * | ||
| * NOTICE OF LICENSE | ||
| * | ||
| * This source file is subject to the Academic Free License version 3.0 | ||
| * that is bundled with this package in the file LICENSE.md. | ||
| * It is also available through the world-wide-web at this URL: | ||
| * https://opensource.org/licenses/AFL-3.0 | ||
| * If you did not receive a copy of the license and are unable to | ||
| * obtain it through the world-wide-web, please send an email | ||
| * to license@prestashop.com so we can send you a copy immediately. | ||
| * | ||
| * @author PrestaShop SA and Contributors <contact@prestashop.com> | ||
| * @copyright Since 2007 PrestaShop SA and Contributors | ||
| * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Customer; | ||
|
|
||
| use ApiPlatform\Metadata\ApiResource; | ||
| use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerConstraintException; | ||
| use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerNotFoundException; | ||
| use PrestaShop\PrestaShop\Core\Domain\Customer\Query\GetCustomerOrders; | ||
| use PrestaShopBundle\ApiPlatform\Metadata\CQRSGetCollection; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
|
|
||
| /** | ||
| * One order of a customer, as summarized by GetCustomerOrders. | ||
| * | ||
| * The query returns a list, so this is a collection operation, declared like ProductImageList: | ||
| * QueryResultSerializerTrait only wraps a query result behind "_queryResult" when it is a | ||
| * scalar, so the ['[_queryResult]' => '[orders]'] mapping the source PR used could never fill | ||
| * anything and the response came back with the identifier alone. | ||
| */ | ||
| #[ApiResource( | ||
| operations: [ | ||
| new CQRSGetCollection( | ||
| uriTemplate: '/customers/{customerId}/orders', | ||
| requirements: ['customerId' => '\d+'], | ||
| CQRSQuery: GetCustomerOrders::class, | ||
| scopes: ['customer_read'], | ||
| ), | ||
| ], | ||
| exceptionToStatus: [ | ||
| CustomerNotFoundException::class => Response::HTTP_NOT_FOUND, | ||
|
cnavarro-prestashop marked this conversation as resolved.
|
||
| CustomerConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, | ||
| ], | ||
| )] | ||
| class CustomerOrder | ||
| { | ||
| public int $customerId; | ||
|
|
||
| public int $orderId; | ||
|
|
||
| public string $orderPlacedDate; | ||
|
|
||
| public string $paymentMethodName; | ||
|
|
||
| public string $orderStatus; | ||
|
|
||
| public int $orderProductsCount; | ||
|
|
||
| /** | ||
| * Amount actually received (total_paid_real), not the order total. | ||
| */ | ||
| public string $totalPaid; | ||
| } | ||
61 changes: 61 additions & 0 deletions
61
src/ApiPlatform/Resources/Customer/CustomerPrivateNote.php
This file contains hidden or 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,61 @@ | ||
| <?php | ||
| /** | ||
| * Copyright since 2007 PrestaShop SA and Contributors | ||
| * PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
| * | ||
| * NOTICE OF LICENSE | ||
| * | ||
| * This source file is subject to the Academic Free License version 3.0 | ||
| * that is bundled with this package in the file LICENSE.md. | ||
| * It is also available through the world-wide-web at this URL: | ||
| * https://opensource.org/licenses/AFL-3.0 | ||
| * If you did not receive a copy of the license and are unable to | ||
| * obtain it through the world-wide-web, please send an email | ||
| * to license@prestashop.com so we can send you a copy immediately. | ||
| * | ||
| * @author PrestaShop SA and Contributors <contact@prestashop.com> | ||
| * @copyright Since 2007 PrestaShop SA and Contributors | ||
| * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Customer; | ||
|
|
||
| use ApiPlatform\Metadata\ApiResource; | ||
| use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\CleanHtml; | ||
| use PrestaShop\PrestaShop\Core\Domain\Customer\Command\SetPrivateNoteAboutCustomerCommand; | ||
| use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerConstraintException; | ||
| use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerNotFoundException; | ||
| use PrestaShopBundle\ApiPlatform\Metadata\CQRSPartialUpdate; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
| use Symfony\Component\Validator\Constraints as Assert; | ||
|
|
||
| #[ApiResource( | ||
| operations: [ | ||
| new CQRSPartialUpdate( | ||
| uriTemplate: '/customers/{customerId}/private-notes', | ||
| requirements: ['customerId' => '\d+'], | ||
| output: false, | ||
| read: false, | ||
| CQRSCommand: SetPrivateNoteAboutCustomerCommand::class, | ||
| scopes: ['customer_write'], | ||
| ), | ||
| ], | ||
| exceptionToStatus: [ | ||
| CustomerNotFoundException::class => Response::HTTP_NOT_FOUND, | ||
| CustomerConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, | ||
| ], | ||
| )] | ||
| class CustomerPrivateNote | ||
| { | ||
| public int $customerId; | ||
|
|
||
| /** | ||
| * Nullable so that an explicit null reaches the NotNull constraint and gets the same 422 | ||
| * as an omitted field, instead of a 400 from the denormalizer. | ||
| */ | ||
| #[Assert\NotNull] | ||
|
cnavarro-prestashop marked this conversation as resolved.
|
||
| #[CleanHtml] | ||
| public ?string $privateNote; | ||
| } | ||
54 changes: 54 additions & 0 deletions
54
src/ApiPlatform/Resources/Customer/TransformGuestToCustomer.php
This file contains hidden or 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,54 @@ | ||
| <?php | ||
| /** | ||
| * Copyright since 2007 PrestaShop SA and Contributors | ||
| * PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
| * | ||
| * NOTICE OF LICENSE | ||
| * | ||
| * This source file is subject to the Academic Free License version 3.0 | ||
| * that is bundled with this package in the file LICENSE.md. | ||
| * It is also available through the world-wide-web at this URL: | ||
| * https://opensource.org/licenses/AFL-3.0 | ||
| * If you did not receive a copy of the license and are unable to | ||
| * obtain it through the world-wide-web, please send an email | ||
| * to license@prestashop.com so we can send you a copy immediately. | ||
| * | ||
| * @author PrestaShop SA and Contributors <contact@prestashop.com> | ||
| * @copyright Since 2007 PrestaShop SA and Contributors | ||
| * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Customer; | ||
|
|
||
| use ApiPlatform\Metadata\ApiResource; | ||
| use PrestaShop\PrestaShop\Core\Domain\Customer\Command\TransformGuestToCustomerCommand; | ||
| use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerConstraintException; | ||
| use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerNotFoundException; | ||
| use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerTransformationException; | ||
| use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
|
|
||
| #[ApiResource( | ||
| operations: [ | ||
| new CQRSUpdate( | ||
| uriTemplate: '/customers/{customerId}/transform-to-customer', | ||
| requirements: ['customerId' => '\d+'], | ||
| output: false, | ||
| allowEmptyBody: true, | ||
| CQRSCommand: TransformGuestToCustomerCommand::class, | ||
| scopes: ['customer_write'], | ||
|
cnavarro-prestashop marked this conversation as resolved.
|
||
| validationContext: ['groups' => ['Default', 'Update']], | ||
| ), | ||
| ], | ||
| exceptionToStatus: [ | ||
| CustomerNotFoundException::class => Response::HTTP_NOT_FOUND, | ||
| CustomerConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, | ||
| CustomerTransformationException::class => Response::HTTP_UNPROCESSABLE_ENTITY, | ||
| ], | ||
| )] | ||
| class TransformGuestToCustomer | ||
| { | ||
| public int $customerId; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.