Skip to content
Open
67 changes: 67 additions & 0 deletions src/ApiPlatform/Resources/Customer/CustomerCart.php
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,
Comment thread
cnavarro-prestashop marked this conversation as resolved.
CustomerConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
],
)]
class CustomerCart
{
public int $customerId;

public int $cartId;

public string $creationDate;

public string $totalPrice;
}
72 changes: 72 additions & 0 deletions src/ApiPlatform/Resources/Customer/CustomerOrder.php
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,
Comment thread
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 src/ApiPlatform/Resources/Customer/CustomerPrivateNote.php
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]
Comment thread
cnavarro-prestashop marked this conversation as resolved.
#[CleanHtml]
public ?string $privateNote;
}
54 changes: 54 additions & 0 deletions src/ApiPlatform/Resources/Customer/TransformGuestToCustomer.php
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'],
Comment thread
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;
}
Loading
Loading