forked from PrestaShop/ps_apiresources
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ci): move tests and endpoint from core
- Loading branch information
Showing
10 changed files
with
1,595 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?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 Open Software License (OSL 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/OSL-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 [email protected] so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://devdocs.prestashop.com/ for more information. | ||
* | ||
* @author PrestaShop SA and Contributors <[email protected]> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PrestaShop\Module\APIResources\ApiPlatform\Resources; | ||
|
||
use ApiPlatform\Metadata\ApiResource; | ||
use ApiPlatform\Metadata\Put; | ||
use PrestaShop\PrestaShop\Core\Domain\CartRule\Command\EditCartRuleCommand; | ||
use PrestaShopBundle\ApiPlatform\Processor\CommandProcessor; | ||
|
||
#[ApiResource( | ||
operations: [ | ||
new Put( | ||
uriTemplate: '/cart-rule', | ||
processor: CommandProcessor::class, | ||
extraProperties: ['CQRSCommand' => EditCartRuleCommand::class] | ||
), | ||
], | ||
)] | ||
class CartRule | ||
{ | ||
public int $cartRuleId; | ||
|
||
public string $description; | ||
|
||
public string $code; | ||
|
||
public array $minimumAmount; | ||
|
||
public bool $minimumAmountShippingIncluded; | ||
|
||
public int $customerId; | ||
|
||
public array $localizedNames; | ||
|
||
public bool $highlightInCart; | ||
|
||
public bool $allowPartialUse; | ||
|
||
public int $priority; | ||
|
||
public bool $active; | ||
|
||
public array $validityDateRange; | ||
|
||
public int $totalQuantity; | ||
|
||
public int $quantityPerUser; | ||
|
||
public array $cartRuleAction; | ||
} |
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,119 @@ | ||
<?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 Open Software License (OSL 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/OSL-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 [email protected] so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://devdocs.prestashop.com/ for more information. | ||
* | ||
* @author PrestaShop SA and Contributors <[email protected]> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PrestaShop\Module\APIResources\ApiPlatform\Resources; | ||
|
||
use ApiPlatform\Core\Annotation\ApiProperty; | ||
use ApiPlatform\Metadata\ApiResource; | ||
use PrestaShop\PrestaShop\Core\Domain\Customer\Group\Command\AddCustomerGroupCommand; | ||
use PrestaShop\PrestaShop\Core\Domain\Customer\Group\Command\DeleteCustomerGroupCommand; | ||
use PrestaShop\PrestaShop\Core\Domain\Customer\Group\Command\EditCustomerGroupCommand; | ||
use PrestaShop\PrestaShop\Core\Domain\Customer\Group\Exception\GroupNotFoundException; | ||
use PrestaShop\PrestaShop\Core\Domain\Customer\Group\Query\GetCustomerGroupForEditing; | ||
use PrestaShop\PrestaShop\Core\Domain\Customer\Group\QueryResult\EditableCustomerGroup; | ||
use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate; | ||
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete; | ||
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet; | ||
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate; | ||
|
||
#[ApiResource( | ||
operations: [ | ||
new CQRSGet( | ||
uriTemplate: '/customers/group/{customerGroupId}', | ||
CQRSQuery: GetCustomerGroupForEditing::class, | ||
scopes: [ | ||
'customer_group_read', | ||
], | ||
// QueryResult format doesn't match with ApiResource, so we can specify a mapping so that it is normalized with extra fields adapted for the ApiResource DTO | ||
CQRSQueryMapping: [ | ||
// EditableCustomerGroup::$id is normalized as [customerGroupId] | ||
'[id]' => '[customerGroupId]', | ||
// EditableCustomerGroup::$reduction is normalized as [reductionPercent] | ||
'[reduction]' => '[reductionPercent]', | ||
], | ||
), | ||
new CQRSCreate( | ||
uriTemplate: '/customers/group', | ||
CQRSCommand: AddCustomerGroupCommand::class, | ||
CQRSQuery: GetCustomerGroupForEditing::class, | ||
scopes: [ | ||
'customer_group_write', | ||
], | ||
// Here, we use query mapping to adapt normalized query result for the ApiPlatform DTO | ||
CQRSQueryMapping: [ | ||
'[id]' => '[customerGroupId]', | ||
'[reduction]' => '[reductionPercent]', | ||
], | ||
// Here, we use command mapping to adapt the normalized command result for the CQRS query | ||
CQRSCommandMapping: [ | ||
'[groupId]' => '[customerGroupId]', | ||
], | ||
), | ||
new CQRSUpdate( | ||
uriTemplate: '/customers/group/{customerGroupId}', | ||
CQRSCommand: EditCustomerGroupCommand::class, | ||
CQRSQuery: GetCustomerGroupForEditing::class, | ||
scopes: [ | ||
'customer_group_write', | ||
], | ||
// Here we use the ApiResource DTO mapping to transform the normalized query result | ||
ApiResourceMapping: [ | ||
'[id]' => '[customerGroupId]', | ||
'[reduction]' => '[reductionPercent]', | ||
], | ||
), | ||
new CQRSDelete( | ||
uriTemplate: '/customers/group/{customerGroupId}', | ||
CQRSQuery: DeleteCustomerGroupCommand::class, | ||
scopes: [ | ||
'customer_group_write', | ||
], | ||
// Here, we use query mapping to adapt URI parameters to the expected constructor parameter name | ||
CQRSQueryMapping: [ | ||
'[customerGroupId]' => '[groupId]', | ||
], | ||
), | ||
], | ||
exceptionToStatus: [GroupNotFoundException::class => 404], | ||
)] | ||
class CustomerGroup | ||
{ | ||
#[ApiProperty(identifier: true)] | ||
public int $customerGroupId; | ||
|
||
public array $localizedNames; | ||
|
||
public float $reductionPercent; | ||
|
||
public bool $displayPriceTaxExcluded; | ||
|
||
public bool $showPrice; | ||
|
||
public array $shopIds; | ||
} |
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,108 @@ | ||
<?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 Open Software License (OSL 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/OSL-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 [email protected] so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://devdocs.prestashop.com/ for more information. | ||
* | ||
* @author PrestaShop SA and Contributors <[email protected]> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PrestaShop\Module\APIResources\ApiPlatform\Resources; | ||
|
||
use ApiPlatform\Core\Annotation\ApiProperty; | ||
use ApiPlatform\Metadata\ApiResource; | ||
use ApiPlatform\Metadata\GetCollection; | ||
use PrestaShop\PrestaShop\Core\Domain\Product\Query\SearchProducts; | ||
use PrestaShopBundle\ApiPlatform\Provider\QueryProvider; | ||
|
||
#[ApiResource( | ||
operations: [ | ||
new GetCollection( | ||
uriTemplate: '/products/search/{phrase}/{resultsLimit}/{isoCode}', | ||
openapiContext: [ | ||
'parameters' => [ | ||
[ | ||
'name' => 'phrase', | ||
'in' => 'path', | ||
'required' => true, | ||
'schema' => [ | ||
'type' => 'string', | ||
], | ||
], | ||
[ | ||
'name' => 'resultsLimit', | ||
'in' => 'path', | ||
'required' => true, | ||
'schema' => [ | ||
'type' => 'int', | ||
], | ||
], | ||
[ | ||
'name' => 'isoCode', | ||
'in' => 'path', | ||
'required' => true, | ||
'schema' => [ | ||
'type' => 'string', | ||
], | ||
], | ||
[ | ||
'name' => 'orderId', | ||
'in' => 'query', | ||
'required' => false, | ||
'schema' => [ | ||
'type' => 'int', | ||
], | ||
], | ||
], | ||
], | ||
provider: QueryProvider::class, | ||
extraProperties: [ | ||
'CQRSQuery' => SearchProducts::class, | ||
] | ||
), | ||
], | ||
)] | ||
class FoundProduct | ||
{ | ||
#[ApiProperty(identifier: true)] | ||
public int $productId; | ||
|
||
public bool $availableOutOfStock; | ||
|
||
public string $name; | ||
|
||
public float $taxRate; | ||
|
||
public string $formattedPrice; | ||
|
||
public float $priceTaxIncl; | ||
|
||
public float $priceTaxExcl; | ||
|
||
public int $stock; | ||
|
||
public string $location; | ||
|
||
public array $combinations; | ||
|
||
public array $customizationFields; | ||
} |
Oops, something went wrong.