Skip to content
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

Allow to use Sylius from 1.7 to 1.10 and php 7.4 and 8.0 #139

Merged
merged 64 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
3328bf3
Allow to use Sylious from 1.7 to 1.10 and php 7.4 and 8.0
Roshyo Aug 18, 2021
4c4da1e
normalize composer
Roshyo Aug 18, 2021
e4ba790
Fix ApiPlatform dependency
Roshyo Aug 19, 2021
6938892
Fix pipes (psalm, require-checker)
Roshyo Aug 19, 2021
1840f39
Fix Behat suite
Roshyo Aug 19, 2021
80e4bc5
Fix ECS
Roshyo Aug 19, 2021
e4ff195
Fix composer deps
Roshyo Aug 25, 2021
f95727e
Support only 1.10
Roshyo Aug 25, 2021
bbdf05c
Remove un-needed conflicts and add back roave security advisories for…
Roshyo Aug 26, 2021
b2fd5a8
Fix docblock
Roshyo Aug 26, 2021
9f04735
WIP: Adding ApiPlatform integration to GiftCards
Roshyo Aug 23, 2021
7dbc424
Add GiftCardConfiguration and its association ot channel
Roshyo Aug 25, 2021
3715b9c
Allow to add/remove configuration image
Roshyo Aug 25, 2021
40e8e21
Fix pipes
Roshyo Aug 25, 2021
9e098a6
Move sylius_api to global packages
Roshyo Aug 25, 2021
439b5ef
Add first Specs
Roshyo Aug 25, 2021
1c42535
Migrate Unit test from Spec to PHPUnit
Roshyo Aug 25, 2021
0b5429a
Fix CS
Roshyo Aug 25, 2021
c851683
Remove autowire from services
Roshyo Aug 26, 2021
8a1dee9
Fix dependency
Roshyo Aug 26, 2021
d179d65
Move PHPUnit folder
Roshyo Aug 26, 2021
9e4e645
Rename PHPUnit to Unit
Roshyo Aug 26, 2021
956490c
Merge pull request #140 from Setono/integrate-api-platform
Roshyo Aug 26, 2021
b6034f3
Fix JWT config
loevgaard Aug 26, 2021
39426ab
Updated keys according to passphrase
loevgaard Aug 26, 2021
ba4561e
Add endpoint to 'search' for gift card code
loevgaard Aug 26, 2021
c0240fe
Add more elaborate description
loevgaard Aug 26, 2021
2951e05
Merge pull request #141 from Setono/api-search
loevgaard Aug 26, 2021
790754d
Expose Admin resend email route
Roshyo Aug 27, 2021
0fd65aa
Fix Unit namespace + Add API support information
Roshyo Aug 27, 2021
99ae416
Fix CS and Psalm
Roshyo Aug 27, 2021
2d6b84e
Update src/Resources/config/api_resources/GiftCard.xml
Roshyo Aug 27, 2021
7e55336
Use null comparison instead of isntanceof
Roshyo Aug 27, 2021
58290fc
Keep $data instead of new variable
Roshyo Aug 27, 2021
9eabdb0
Merge pull request #143 from Setono/expose-admin-resend-email
Roshyo Aug 27, 2021
a0e93b9
Export Download gift card PDF to API + tests
Roshyo Aug 27, 2021
2ccb33f
Fix Item operation name
Roshyo Aug 27, 2021
cb4810e
Fix using interface instead of Real class
Roshyo Aug 27, 2021
5729572
Improve Answer doc
Roshyo Aug 27, 2021
fcb6c40
Update src/Resources/config/services/misc.xml
Roshyo Aug 27, 2021
d345e0d
Use KNP SNappy interface
Roshyo Aug 27, 2021
ed27786
Update src/Resources/config/api_resources/GiftCard.xml
Roshyo Aug 27, 2021
47126f1
Merge pull request #142 from Setono/api-download-pdf
Roshyo Aug 27, 2021
9163b10
Expose Add GC to order
Roshyo Aug 27, 2021
aa16785
Fix Repo namespace
Roshyo Aug 27, 2021
68141d7
Add also remove route
Roshyo Aug 27, 2021
530b684
Expose Customer GiftCards in shop
Roshyo Sep 1, 2021
8bfb7af
Fix composer dependencies
Roshyo Sep 1, 2021
09f2737
Integrate change requests and fix QB
Roshyo Sep 1, 2021
287c43c
Merge pull request #147 from Setono/expose-customer-shop-gc
Roshyo Sep 1, 2021
31cf532
Expose Gift card balance
Roshyo Aug 27, 2021
85c4698
Merge pull request #144 from Setono/expose-balance
Roshyo Sep 1, 2021
59a9f2b
Update src/Resources/config/api_resources/GiftCard.xml
Roshyo Sep 1, 2021
d82b711
Update src/Resources/config/api_resources/GiftCard.xml
Roshyo Sep 1, 2021
e7c3ace
Add missing Handler service
Roshyo Sep 1, 2021
8d26003
Merge remote-tracking branch 'main/expose-add-gc-to-order' into expos…
Roshyo Sep 1, 2021
b532c3a
Rename unit test method name
Roshyo Sep 1, 2021
443bc1a
Merge pull request #145 from Setono/expose-add-gc-to-order
Roshyo Sep 1, 2021
648fde2
Add first Behat scenario for API
Roshyo Sep 1, 2021
8116351
Remove un-necessary contexts
Roshyo Sep 1, 2021
a3b3fdb
Remove public where not needed
Roshyo Sep 1, 2021
f85c6c5
Merge pull request #149 from Setono/add-api-behat
Roshyo Sep 2, 2021
bcac310
Allow to create Product GC from API
Roshyo Sep 3, 2021
adc7513
Merge pull request #151 from Setono/add-product-create-gc
Roshyo Sep 3, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ can be used for auditing.

![Screenshot showing gift card admin create page](docs/images/admin-gift-card-create.png)

## Api platform support

Everything related to Gift Card can be done via API. Whether it is admin or shop actions

## Installation

### Require plugin with composer:
Expand Down
2 changes: 1 addition & 1 deletion behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ imports:

default:
extensions:
Lakion\Behat\MinkDebugExtension:
FriendsOfBehat\MinkDebugExtension:
directory: etc/build
clean_start: false
screenshot: true
Expand Down
5 changes: 4 additions & 1 deletion composer-require-checker.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
"string",
"true",
"void",
"Sylius\\Bundle\\CoreBundle\\Application\\SyliusPluginTrait",
"Setono\\SyliusCatalogPromotionPlugin\\Rule\\Rule",
"Sylius\\Bundle\\ApiBundle\\Command\\CommandAwareDataTransformerInterface",
"Sylius\\Bundle\\ApiBundle\\Context\\UserContextInterface",
"Sylius\\Bundle\\ApiBundle\\DataTransformer\\CommandDataTransformerInterface",
"Sylius\\Bundle\\CoreBundle\\Application\\SyliusPluginTrait",
"Sylius\\Bundle\\ChannelBundle\\Form\\Type\\ChannelChoiceType",
"Sylius\\Bundle\\CoreBundle\\Application\\SyliusPluginTrait",
"Sylius\\Bundle\\CoreBundle\\Fixture\\AbstractResourceFixture",
Expand Down
17 changes: 10 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
"php": ">=7.4",
"ext-filter": "*",
"ext-mbstring": "*",
"api-platform/core": "^2.6",
"doctrine/collections": "^1.6",
"doctrine/dbal": "^2.13",
"doctrine/orm": "^2.7",
"doctrine/persistence": "^1.3 || ^2.2",
"friendsofsymfony/rest-bundle": "^2.8",
"fzaninotto/faker": "^1.9",
"fakerphp/faker": "^1.9.0",
"knplabs/knp-menu": "^3.2",
"knplabs/knp-snappy": "^1.2",
"knplabs/knp-snappy-bundle": "^1.7",
Expand All @@ -22,6 +23,7 @@
"symfony/form": "^4.4 || ^5.0",
"symfony/http-foundation": "^4.4 || ^5.0.7",
"symfony/http-kernel": "^4.4 || ^5.1.5",
"symfony/messenger": "^4.4 || ^5.0",
"symfony/options-resolver": "^4.4 || ^5.0",
"symfony/property-access": "^4.4 || ^5.0",
"symfony/routing": "^4.4 || ^5.0",
Expand All @@ -32,18 +34,19 @@
"webmozart/assert": "^1.10"
},
"require-dev": {
"doctrine/doctrine-bundle": "^1.2.13",
"friendsofsymfony/oauth-server-bundle": ">2.0.0-alpha.0 ^2.0@dev",
"matthiasnoback/symfony-config-test": "^4.2",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"phpspec/phpspec": "^7.0",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.5",
"psalm/plugin-phpunit": "^0.16.0",
"psalm/plugin-symfony": "^2.1",
"roave/security-advisories": "dev-latest",
Roshyo marked this conversation as resolved.
Show resolved Hide resolved
"setono/code-quality-pack": "^2.1",
"setono/sylius-behat-pack": "^0.1",
"setono/sylius-catalog-promotion-plugin": "^0.2.0",
"sylius/sylius": "~1.7.0",
"setono/code-quality-pack": "^2.1.2",
"setono/sylius-behat-pack": "^0.2",
"setono/sylius-catalog-promotion-plugin": "^0.4",
"sylius/sylius": "~1.10.0",
"symfony/debug-bundle": "^5.1",
"symfony/dotenv": "^5.1",
"symfony/intl": "^4.4 || ^5.0",
Expand Down
17 changes: 17 additions & 0 deletions features/admin/browse_gift_cards.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@managing_gift_cards
Feature: Browsing existing gift cards
In order to manage the existing gift cards
As an Administrator
I want to browse existing gift cards

Background:
Given the store operates on a single channel in "United States"
And I am logged in as an administrator
And the store has a gift card with code "GIFT-CARD-100" valued at "$100"
And the store has a gift card with code "GIFT-CARD-200" valued at "$200"

@api
Scenario: Browsing gift cards
When I browse gift cards
Then I should see a gift card with code "GIFT-CARD-100" valued at "$100"
And I should see a gift card with code "GIFT-CARD-200" valued at "$200"
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</coverage>
<testsuites>
<testsuite name="SetonoSyliusGiftCardPlugin Test Suite">
<directory>tests</directory>
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
<php>
Expand Down
27 changes: 27 additions & 0 deletions src/Api/Command/AddGiftCardToOrder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusGiftCardPlugin\Api\Command;

class AddGiftCardToOrder implements GiftCardCodeAwareInterface
{
public ?string $giftCardCode = null;

public string $orderTokenValue;

public function __construct(string $orderTokenValue)
{
$this->orderTokenValue = $orderTokenValue;
}

public function getGiftCardCode(): ?string
{
return $this->giftCardCode;
}

public function setGiftCardCode(?string $giftCardCode): void
{
$this->giftCardCode = $giftCardCode;
}
}
30 changes: 30 additions & 0 deletions src/Api/Command/AssociateConfigurationToChannel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusGiftCardPlugin\Api\Command;

class AssociateConfigurationToChannel implements ConfigurationCodeAwareInterface
{
public ?string $configurationCode = null;

public string $localeCode;

public string $channelCode;

public function __construct(string $localeCode, string $channelCode)
{
$this->localeCode = $localeCode;
$this->channelCode = $channelCode;
}

public function getConfigurationCode(): ?string
{
return $this->configurationCode;
}

public function setConfigurationCode(?string $configurationCode): void
{
$this->configurationCode = $configurationCode;
}
}
14 changes: 14 additions & 0 deletions src/Api/Command/ConfigurationCodeAwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusGiftCardPlugin\Api\Command;

use Sylius\Bundle\ApiBundle\Command\CommandAwareDataTransformerInterface;

interface ConfigurationCodeAwareInterface extends CommandAwareDataTransformerInterface
{
public function getConfigurationCode(): ?string;

public function setConfigurationCode(?string $configurationCode): void;
}
14 changes: 14 additions & 0 deletions src/Api/Command/GiftCardCodeAwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusGiftCardPlugin\Api\Command;

use Sylius\Bundle\ApiBundle\Command\CommandAwareDataTransformerInterface;

interface GiftCardCodeAwareInterface extends CommandAwareDataTransformerInterface
{
public function getGiftCardCode(): ?string;

public function setGiftCardCode(?string $giftCardCode): void;
}
27 changes: 27 additions & 0 deletions src/Api/Command/RemoveGiftCardFromOrder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusGiftCardPlugin\Api\Command;

class RemoveGiftCardFromOrder implements GiftCardCodeAwareInterface
{
public ?string $giftCardCode = null;

public string $orderTokenValue;

public function __construct(string $orderTokenValue)
{
$this->orderTokenValue = $orderTokenValue;
}

public function getGiftCardCode(): ?string
{
return $this->giftCardCode;
}

public function setGiftCardCode(?string $giftCardCode): void
{
$this->giftCardCode = $giftCardCode;
}
}
50 changes: 50 additions & 0 deletions src/Api/CommandHandler/AddGiftCardToOrderHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusGiftCardPlugin\Api\CommandHandler;

use Setono\SyliusGiftCardPlugin\Api\Command\AddGiftCardToOrder;
use Setono\SyliusGiftCardPlugin\Applicator\GiftCardApplicatorInterface;
use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface;
use Setono\SyliusGiftCardPlugin\Model\OrderInterface;
use Setono\SyliusGiftCardPlugin\Repository\GiftCardRepositoryInterface;
use Setono\SyliusGiftCardPlugin\Repository\OrderRepositoryInterface;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
use Webmozart\Assert\Assert;

final class AddGiftCardToOrderHandler implements MessageHandlerInterface
{
private GiftCardRepositoryInterface $giftCardRepository;

private OrderRepositoryInterface $orderRepository;

private GiftCardApplicatorInterface $giftCardApplicator;

public function __construct(
GiftCardRepositoryInterface $giftCardRepository,
OrderRepositoryInterface $orderRepository,
GiftCardApplicatorInterface $giftCardApplicator
) {
$this->giftCardRepository = $giftCardRepository;
$this->orderRepository = $orderRepository;
$this->giftCardApplicator = $giftCardApplicator;
}

public function __invoke(AddGiftCardToOrder $command): GiftCardInterface
{
$giftCardCode = $command->getGiftCardCode();
Assert::notNull($giftCardCode);

$giftCard = $this->giftCardRepository->findOneByCode($giftCardCode);
Assert::notNull($giftCard);

/** @var OrderInterface|null $order */
$order = $this->orderRepository->findOneBy(['tokenValue' => $command->orderTokenValue]);
Assert::notNull($order);

$this->giftCardApplicator->apply($order, $giftCard);

return $giftCard;
}
}
78 changes: 78 additions & 0 deletions src/Api/CommandHandler/AssociateConfigurationToChannelHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusGiftCardPlugin\Api\CommandHandler;

use Setono\SyliusGiftCardPlugin\Api\Command\AssociateConfigurationToChannel;
use Setono\SyliusGiftCardPlugin\Model\GiftCardChannelConfigurationInterface;
use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationInterface;
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
use Webmozart\Assert\Assert;

final class AssociateConfigurationToChannelHandler implements MessageHandlerInterface
{
private RepositoryInterface $giftCardConfigurationRepository;

private ChannelRepositoryInterface $channelRepository;

private RepositoryInterface $localeRepository;

private RepositoryInterface $giftCardChannelConfigurationRepository;

private FactoryInterface $giftCardChannelConfigurationFactory;

public function __construct(
RepositoryInterface $giftCardConfigurationRepository,
ChannelRepositoryInterface $channelRepository,
RepositoryInterface $localeRepository,
RepositoryInterface $giftCardChannelConfigurationRepository,
FactoryInterface $giftCardChannelConfigurationFactory
) {
$this->giftCardConfigurationRepository = $giftCardConfigurationRepository;
$this->channelRepository = $channelRepository;
$this->localeRepository = $localeRepository;
$this->giftCardChannelConfigurationRepository = $giftCardChannelConfigurationRepository;
$this->giftCardChannelConfigurationFactory = $giftCardChannelConfigurationFactory;
}

public function __invoke(AssociateConfigurationToChannel $command): GiftCardConfigurationInterface
{
Assert::notNull($command->getConfigurationCode());

/** @var GiftCardConfigurationInterface|null $configuration */
$configuration = $this->giftCardConfigurationRepository->findOneBy(['code' => $command->getConfigurationCode()]);
Assert::notNull($configuration);

$channel = $this->channelRepository->findOneByCode($command->channelCode);
Assert::notNull($channel);

/** @var LocaleInterface|null $locale */
$locale = $this->localeRepository->findOneBy(['code' => $command->localeCode]);
Assert::notNull($locale);

/** @var GiftCardChannelConfigurationInterface|null $existingChannelConfiguration */
$existingChannelConfiguration = $this->giftCardChannelConfigurationRepository->findOneBy([
'configuration' => $configuration,
'channel' => $channel,
'locale' => $locale,
]);
if (null !== $existingChannelConfiguration) {
return $configuration;
}

/** @var GiftCardChannelConfigurationInterface $channelConfiguration */
$channelConfiguration = $this->giftCardChannelConfigurationFactory->createNew();
$channelConfiguration->setConfiguration($configuration);
$channelConfiguration->setChannel($channel);
$channelConfiguration->setLocale($locale);

$configuration->addChannelConfiguration($channelConfiguration);

return $configuration;
}
}
Loading