Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
51 changes: 0 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,31 +150,6 @@ class Order extends BaseOrder implements SetonoSyliusGiftCardPluginOrderInterfac
}
```

**Extend `OrderItem`**

```php
<?php

# src/Entity/Order/OrderItem.php

declare(strict_types=1);

namespace App\Entity\Order;

use Doctrine\ORM\Mapping as ORM;
use Setono\SyliusGiftCardPlugin\Model\OrderItemTrait as SetonoSyliusGiftCardOrderItemTrait;
use Sylius\Component\Core\Model\OrderItem as BaseOrderItem;

/**
* @ORM\Entity
* @ORM\Table(name="sylius_order_item")
*/
class OrderItem extends BaseOrderItem
{
use SetonoSyliusGiftCardOrderItemTrait;
}
```

**Extend `OrderItemUnit`**

```php
Expand Down Expand Up @@ -273,32 +248,6 @@ sylius_product:
model: App\Entity\Product\Product
```

### Copy Api Resources

Resources declaration that need to be copied are:
* [Order.xml](src/Resources/config/api_resources/Order.xml)

If you already have them overriden, just change the following routes:

**[Order.xml](src/Resources/config/api_resources/Order.xml)**
```xml
<itemOperation name="shop_add_item">
<attribute name="method">PATCH</attribute>
<attribute name="path">/shop/orders/{tokenValue}/items</attribute>
<attribute name="messenger">input</attribute>
<attribute name="input">Setono\SyliusGiftCardPlugin\Api\Command\AddItemToCart</attribute> <!-- This has been changed compared to the core -->
<attribute name="normalization_context">
<attribute name="groups">shop:cart:read</attribute>
</attribute>
<attribute name="denormalization_context">
<attribute name="groups">shop:cart:add_item</attribute>
</attribute>
<attribute name="openapi_context">
<attribute name="summary">Adds Item to cart</attribute>
</attribute>
</itemOperation>
```

### Update your database:

```bash
Expand Down
96 changes: 51 additions & 45 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"php": ">=8.1",
"ext-filter": "*",
"ext-mbstring": "*",
"api-platform/core": "^2.6",
"doctrine/collections": "^1.8",
"api-platform/core": "^4.0.3",
"doctrine/collections": "^2.2",
"doctrine/dbal": "^2.13 || ^3.0",
"doctrine/orm": "^2.7",
"doctrine/persistence": "^1.3 || ^2.5 || ^3.0",
Expand All @@ -17,52 +17,53 @@
"knplabs/knp-snappy": "^1.4",
"knplabs/knp-snappy-bundle": "^1.9",
"setono/doctrine-object-manager-trait": "^1.1",
"sylius/api-bundle": "^1.10",
"sylius/channel": "^1.0",
"sylius/channel-bundle": "^1.0",
"sylius/core": "^1.0",
"sylius/core-bundle": "^1.0",
"sylius/currency": "^1.0",
"sylius/customer": "^1.0",
"sylius/api-bundle": "^2.0",
"sylius/channel": "^2.0",
"sylius/channel-bundle": "^2.0",
"sylius/core": "^2.0",
"sylius/core-bundle": "^2.0",
"sylius/currency": "^2.0",
"sylius/customer": "^2.0",
"sylius/grid-bundle": "^1.0",
"sylius/locale": "^1.0",
"sylius/locale-bundle": "^1.0",
"sylius/locale": "^2.0",
"sylius/locale-bundle": "^2.0",
"sylius/mailer-bundle": "^1.6 || ^2.0",
"sylius/money-bundle": "^1.0",
"sylius/order": "^1.10",
"sylius/order-bundle": "^1.0",
"sylius/product": "^1.0",
"sylius/product-bundle": "^1.0",
"sylius/promotion": "^1.0",
"sylius/money-bundle": "^2.0",
"sylius/order": "^2.0",
"sylius/order-bundle": "^2.0",
"sylius/product": "^2.0",
"sylius/product-bundle": "^2.0",
"sylius/promotion": "^2.0",
"sylius/resource-bundle": "^1.8",
"sylius/shipping-bundle": "^1.0",
"sylius/ui-bundle": "^1.0",
"sylius/user": "^1.0",
"symfony/config": "^5.4 || ^6.4",
"symfony/dependency-injection": "^5.4 || ^6.4",
"symfony/event-dispatcher": "^5.4 || ^6.4",
"symfony/form": "^5.4 || ^6.4",
"symfony/http-foundation": "^5.4 || ^6.4",
"symfony/http-kernel": "^5.4 || ^6.4",
"symfony/messenger": "^5.4 || ^6.4",
"symfony/options-resolver": "^5.4 || ^6.4",
"symfony/property-access": "^5.4 || ^6.4",
"symfony/routing": "^5.4 || ^6.4",
"symfony/security-core": "^5.4 || ^6.4",
"symfony/serializer": "^5.4 || ^6.4",
"symfony/translation-contracts": "^2.4",
"symfony/validator": "^5.4 || ^6.4",
"sylius/shipping-bundle": "^2.0",
"sylius/ui-bundle": "^2.0",
"sylius/user": "^2.0",
"symfony/config": "^6.4 || ^7.0",
"symfony/dependency-injection": "^6.4 || ^7.0",
"symfony/event-dispatcher": "^6.4 || ^7.0",
"symfony/form": "^6.4 || ^7.0",
"symfony/http-foundation": "^6.4 || ^7.0",
"symfony/http-kernel": "^6.4 || ^7.0",
"symfony/messenger": "^6.4 || ^7.0",
"symfony/options-resolver": "^6.4 || ^7.0",
"symfony/property-access": "^6.4 || ^7.0",
"symfony/routing": "^6.4 || ^7.0",
"symfony/security-core": "^6.4 || ^7.0",
"symfony/serializer": "^6.4 || ^7.0",
"symfony/translation-contracts": "^2.4 || ^3.5",
"symfony/validator": "^6.4 || ^7.0",
"twig/twig": "^2.15 || ^3.5",
"webimpress/safe-writer": "^2.2",
"webmozart/assert": "^1.11"
},
"require-dev": {
"babdev/pagerfanta-bundle": "^3.8",
"babdev/pagerfanta-bundle": "^4.4",
"behat/behat": "^3.14",
"dmore/behat-chrome-extension": "^1.4",
"dmore/chrome-mink-driver": "^2.9",
"doctrine/doctrine-bundle": "^2.7",
"infection/infection": "^0.27.10",
"jms/serializer-bundle": "^4.2",
"lexik/jwt-authentication-bundle": "^2.17",
"lexik/jwt-authentication-bundle": "^3.1",
"matthiasnoback/symfony-config-test": "^4.3 || ^5.1",
"matthiasnoback/symfony-dependency-injection-test": "^4.3 || ^5.1",
"php-http/message-factory": "^1.1",
Expand All @@ -74,13 +75,14 @@
"psalm/plugin-symfony": "^5.0",
"setono/code-quality-pack": "^2.7",
"setono/sylius-behat-pack": "^0.2.2",
"sylius/sylius": "~1.12.13",
"symfony/debug-bundle": "^5.4 || ^6.4",
"symfony/dotenv": "^5.4 || ^6.4",
"symfony/intl": "^5.4 || ^6.4",
"symfony/property-info": "^5.4 || ^6.4",
"symfony/web-profiler-bundle": "^5.4 || ^6.4",
"symfony/webpack-encore-bundle": "^1.17.2",
"sylius/sylius": "~2.0.5",
"sylius/sylius-rector": "^2.0",
"symfony/debug-bundle": "^6.4 || ^7.0",
"symfony/dotenv": "^6.4 || ^7.0",
"symfony/intl": "^6.4 || ^7.0",
"symfony/property-info": "^6.4 || ^7.0",
"symfony/web-profiler-bundle": "^6.4 || ^7.0",
"symfony/webpack-encore-bundle": "^1.17.2 || ^2.2.0",
"weirdan/doctrine-psalm-plugin": "^2.9",
"willdurand/negotiation": "^3.1"
},
Expand All @@ -103,9 +105,13 @@
"dealerdirect/phpcodesniffer-composer-installer": false,
"ergebnis/composer-normalize": true,
"infection/extension-installer": true,
"php-http/discovery": true,
"symfony/thanks": false
},
"sort-packages": true
"sort-packages": true,
"platform": {
"php": "8.3.99"
}
},
"scripts": {
"analyse": "psalm",
Expand Down
40 changes: 40 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Doctrine\Set\DoctrineSetList;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\Symfony\Set\FOSRestSetList;
use Rector\Symfony\Set\JMSSetList;
use Rector\Symfony\Set\SensiolabsSetList;
use Rector\Symfony\Set\SymfonySetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->importNames();
$rectorConfig->import(__DIR__ . '/vendor/sylius/sylius-rector/config/config.php');
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
__DIR__ . '/rector.php',
]);

$rectorConfig->skip([
__DIR__ . '/tests/Application/var'
]);

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81, // Adapt this to your PHP version
SetList::CODE_QUALITY,
SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES,
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
DoctrineSetList::MONGODB__ANNOTATIONS_TO_ATTRIBUTES,
DoctrineSetList::GEDMO_ANNOTATIONS_TO_ATTRIBUTES,
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES,
FOSRestSetList::ANNOTATIONS_TO_ATTRIBUTES,
JMSSetList::ANNOTATIONS_TO_ATTRIBUTES,
SensiolabsSetList::ANNOTATIONS_TO_ATTRIBUTES,
]);
};
5 changes: 1 addition & 4 deletions src/Api/Command/AddGiftCardToOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ class AddGiftCardToOrder implements GiftCardCodeAwareInterface
{
public ?string $giftCardCode = null;

public string $orderTokenValue;

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

public function getGiftCardCode(): ?string
Expand Down
11 changes: 2 additions & 9 deletions src/Api/Command/AddItemToCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,9 @@

class AddItemToCart extends BaseAddItemToCart
{
protected ?int $amount;

protected ?string $customMessage;

public function __construct(string $productVariantCode, int $quantity, int $amount = null, string $customMessage = null)
public function __construct(string $orderTokenValue, string $productVariantCode, int $quantity, protected ?int $amount = null, protected ?string $customMessage = null)
{
parent::__construct($productVariantCode, $quantity);

$this->amount = $amount;
$this->customMessage = $customMessage;
parent::__construct($orderTokenValue, $productVariantCode, $quantity);
}

public function getAmount(): ?int
Expand Down
8 changes: 1 addition & 7 deletions src/Api/Command/AssociateConfigurationToChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@ class AssociateConfigurationToChannel implements ConfigurationCodeAwareInterface
{
public ?string $configurationCode = null;

public string $localeCode;

public string $channelCode;

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

public function getConfigurationCode(): ?string
Expand Down
4 changes: 1 addition & 3 deletions src/Api/Command/ConfigurationCodeAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace Setono\SyliusGiftCardPlugin\Api\Command;

use Sylius\Bundle\ApiBundle\Command\CommandAwareDataTransformerInterface;

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

Expand Down
32 changes: 2 additions & 30 deletions src/Api/Command/CreateGiftCardConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,7 @@

class CreateGiftCardConfiguration
{
public string $code;

public bool $default = false;

public bool $enabled = true;

public ?string $defaultValidityPeriod = null;

public ?string $pageSize = null;

public ?string $orientation = null;

public ?string $template = null;

public function __construct(
string $code,
bool $default = false,
bool $enabled = true,
?string $defaultValidityPeriod = null,
?string $pageSize = null,
?string $orientation = null,
?string $template = null,
) {
$this->code = $code;
$this->default = $default;
$this->enabled = $enabled;
$this->defaultValidityPeriod = $defaultValidityPeriod;
$this->pageSize = $pageSize;
$this->orientation = $orientation;
$this->template = $template;
public function __construct(public string $code, public bool $default = false, public bool $enabled = true, public ?string $defaultValidityPeriod = null, public ?string $pageSize = null, public ?string $orientation = null, public ?string $template = null)
{
}
}
4 changes: 1 addition & 3 deletions src/Api/Command/GiftCardCodeAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace Setono\SyliusGiftCardPlugin\Api\Command;

use Sylius\Bundle\ApiBundle\Command\CommandAwareDataTransformerInterface;

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

Expand Down
5 changes: 1 addition & 4 deletions src/Api/Command/RemoveGiftCardFromOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ class RemoveGiftCardFromOrder implements GiftCardCodeAwareInterface
{
public ?string $giftCardCode = null;

public string $orderTokenValue;

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

public function getGiftCardCode(): ?string
Expand Down
16 changes: 2 additions & 14 deletions src/Api/CommandHandler/AddGiftCardToOrderHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,8 @@

final class AddGiftCardToOrderHandler
{
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 __construct(private readonly GiftCardRepositoryInterface $giftCardRepository, private readonly OrderRepositoryInterface $orderRepository, private readonly GiftCardApplicatorInterface $giftCardApplicator)
{
}

public function __invoke(AddGiftCardToOrder $command): GiftCardInterface
Expand Down
Loading