-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from PrestaShop/dev
Merge dev into main
- Loading branch information
Showing
18 changed files
with
1,868 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Integration tests | ||
on: | ||
push: | ||
pull_request: | ||
|
||
permissions: | ||
contents: read # to clone the repos and get release assets (shivammathur/setup-php) | ||
|
||
jobs: | ||
integration: | ||
permissions: | ||
contents: read # to clone the repos and get release assets (shivammathur/setup-php) | ||
name: Integration tests | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php: [ '8.1', '8.2' ] | ||
fail-fast: false | ||
steps: | ||
- name: Checkout module code | ||
uses: actions/checkout@v3 | ||
with: | ||
path: ps_apiresources | ||
- uses: actions/checkout@v3 | ||
name: Checkout PrestaShop repository | ||
with: | ||
fetch-depth: 0 | ||
repository: PrestaShop/PrestaShop | ||
path: prestashop | ||
- name: Build Docker | ||
run: | | ||
cd prestashop | ||
USER_ID=$(id -u) GROUP_ID=$(id -g) PS_INSTALL_AUTO=0 docker-compose build --no-cache && docker-compose up -d --force-recreate | ||
if [ $? -ne 0 ]; then | ||
echo "docker install failed" | ||
exit | ||
fi | ||
bash -l -c 'while [[ "$(curl -L -s -o /dev/null -w %{http_code} 'http://localhost:8001/install-dev/')" != "200" ]]; do echo "waiting for shop install"; sleep 5; done' | ||
USER_ID=$(id -u) GROUP_ID=$(id -g) docker exec prestashop_prestashop-git_1 php bin/console prestashop:module uninstall ps_apiresources | ||
- name: Install Module | ||
run: | | ||
rm -rf prestashop/modules/ps_apiresources | ||
mkdir -p prestashop/modules/ps_apiresources | ||
cp -r ps_apiresources/* prestashop/modules/ps_apiresources | ||
ls -l prestashop/modules/ps_apiresources | ||
USER_ID=$(id -u) GROUP_ID=$(id -g) docker exec prestashop_prestashop-git_1 composer install --no-interaction --working-dir=/var/www/html/modules/ps_apiresources | ||
USER_ID=$(id -u) GROUP_ID=$(id -g) docker exec prestashop_prestashop-git_1 php bin/console prestashop:module install ps_apiresources | ||
USER_ID=$(id -u) GROUP_ID=$(id -g) docker exec prestashop_prestashop-git_1 composer create-test-db | ||
- name: Run integration tests | ||
run : | | ||
USER_ID=$(id -u) GROUP_ID=$(id -g) docker exec prestashop_prestashop-git_1 vendor/bin/phpunit -c modules/ps_apiresources/tests/Integration/phpunit.xml |
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,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\Metadata\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; | ||
} |
Oops, something went wrong.