setono / sylius-gift-card-plugin
Gift card plugin for Sylius
Installs: 149 664
Dependents: 1
Suggesters: 0
Security: 0
Stars: 45
Watchers: 7
Forks: 42
Open Issues: 25
Type:sylius-plugin
Requires
- php: >=8.1
- ext-filter: *
- ext-mbstring: *
- api-platform/core: ^2.6
- doctrine/collections: ^1.8
- doctrine/dbal: ^2.13 || ^3.0
- doctrine/orm: ^2.7
- doctrine/persistence: ^1.3 || ^2.5 || ^3.0
- fakerphp/faker: ^1.21
- knplabs/knp-menu: ^3.3
- 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/grid-bundle: ^1.0
- sylius/locale: ^1.0
- sylius/locale-bundle: ^1.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/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
- twig/twig: ^2.15 || ^3.5
- webimpress/safe-writer: ^2.2
- webmozart/assert: ^1.11
Requires (Dev)
- babdev/pagerfanta-bundle: ^3.8
- behat/behat: ^3.14
- doctrine/doctrine-bundle: ^2.7
- infection/infection: ^0.27.10
- jms/serializer-bundle: ^4.2
- lexik/jwt-authentication-bundle: ^2.17
- matthiasnoback/symfony-config-test: ^4.3 || ^5.1
- matthiasnoback/symfony-dependency-injection-test: ^4.3 || ^5.1
- php-http/message-factory: ^1.1
- phpspec/phpspec: ^7.4
- phpspec/prophecy-phpunit: ^2.0.2
- phpunit/phpunit: ^9.6.17
- polishsymfonycommunity/symfony-mocker-container: ^1.0.7
- psalm/plugin-phpunit: ^0.18.4
- 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
- weirdan/doctrine-psalm-plugin: ^2.9
- willdurand/negotiation: ^3.1
- 0.12.x-dev
- v0.12.0-alpha.8
- v0.12.0-alpha.7
- v0.12.0-alpha.6
- v0.12.0-alpha.5
- v0.12.0-alpha.4
- v0.12.0-alpha.3
- v0.12.0-alpha.2
- v0.12.0-alpha
- 0.11.x-dev
- v0.11.10
- v0.11.9
- v0.11.8
- v0.11.7
- v0.11.6
- v0.11.5
- v0.11.4
- v0.11.3
- v0.11.2
- v0.11.1
- v0.11.0
- v0.10.5
- v0.10.4
- v0.10.3
- v0.10.2
- v0.10.1
- v0.10.0
- v0.9.0
- v0.8.7
- v0.8.6
- v0.8.5
- v0.8.4
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.0
- v0.6.5
- v0.6.4
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.0
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.1
- v0.3.0
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.0
- dev-refactor
- dev-dependabot/composer/setono/sylius-catalog-promotion-plugin-tw-0.5
- dev-use-same-input-discount-gift-card
- dev-fix-psalm-totally-typed
- dev-fix-19-compatibility
- dev-59-use-same-input-promotion-gc
This package is auto-updated.
Last update: 2024-12-07 12:23:50 UTC
README
Add gift card functionality to your store:
- Buy gift cards
- Use gift cards to purchase products
- See the balance of a gift card by looking up the gift card code
The administrator will have access to a dashboard showing the total outstanding balance of gift cards which can be used for auditing.
Screenshots
▶▶ Skip screenshots and go to installation
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:
$ composer require setono/sylius-gift-card-plugin
Import configuration:
# config/packages/setono_sylius_gift_card.yaml imports: # ... - { resource: "@SetonoSyliusGiftCardPlugin/Resources/config/app/config.yaml" }
(Optional) Import fixtures
If you wish to have some gift cards to play with in your application during development.
# config/packages/setono_sylius_gift_card.yaml imports: # ... - { resource: "@SetonoSyliusGiftCardPlugin/Resources/config/app/fixtures.yaml" }
Import routing:
# config/routes.yaml setono_sylius_gift_card: resource: "@SetonoSyliusGiftCardPlugin/Resources/config/routes.yaml"
or if your app doesn't use locales:
# config/routes.yaml setono_sylius_gift_card: resource: "@SetonoSyliusGiftCardPlugin/Resources/config/routes_no_locale.yaml"
Add plugin class to your bundles.php
:
Make sure you add it before SyliusGridBundle
, otherwise you'll get
You have requested a non-existent parameter "setono_sylius_gift_card.model.gift_card.class".
exception.
<?php $bundles = [ // ... Setono\SyliusGiftCardPlugin\SetonoSyliusGiftCardPlugin::class => ['all' => true], Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true], // ... ];
Copy templates
You will find the templates you need to override in the test application.
Extend entities
Extend Product
<?php # src/Entity/Product/Product.php declare(strict_types=1); namespace App\Entity\Product; use Doctrine\ORM\Mapping as ORM; use Setono\SyliusGiftCardPlugin\Model\ProductInterface as SetonoSyliusGiftCardProductInterface; use Setono\SyliusGiftCardPlugin\Model\ProductTrait as SetonoSyliusGiftCardProductTrait; use Sylius\Component\Core\Model\Product as BaseProduct; /** * @ORM\Entity * @ORM\Table(name="sylius_product") */ class Product extends BaseProduct implements SetonoSyliusGiftCardProductInterface { use SetonoSyliusGiftCardProductTrait; }
Extend Order
<?php # src/Entity/Order/Order.php declare(strict_types=1); namespace App\Entity\Order; use Setono\SyliusGiftCardPlugin\Model\OrderInterface as SetonoSyliusGiftCardPluginOrderInterface; use Setono\SyliusGiftCardPlugin\Model\OrderTrait as SetonoSyliusGiftCardPluginOrderTrait; use Sylius\Component\Core\Model\Order as BaseOrder; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="sylius_order") */ class Order extends BaseOrder implements SetonoSyliusGiftCardPluginOrderInterface { use SetonoSyliusGiftCardPluginOrderTrait { SetonoSyliusGiftCardPluginOrderTrait::__construct as private __giftCardTraitConstruct; } public function __construct() { $this->__giftCardTraitConstruct(); parent::__construct(); } }
Extend OrderItem
<?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 # src/Entity/Order/OrderItemUnit.php declare(strict_types=1); namespace App\Entity\Order; use Doctrine\ORM\Mapping as ORM; use Setono\SyliusGiftCardPlugin\Model\OrderItemUnitInterface as SetonoSyliusGiftCardOrderItemUnitInterface; use Setono\SyliusGiftCardPlugin\Model\OrderItemUnitTrait as SetonoSyliusGiftCardOrderItemUnitTrait; use Sylius\Component\Core\Model\OrderItemUnit as BaseOrderItemUnit; /** * @ORM\Entity * @ORM\Table(name="sylius_order_item_unit") */ class OrderItemUnit extends BaseOrderItemUnit implements SetonoSyliusGiftCardOrderItemUnitInterface { use SetonoSyliusGiftCardOrderItemUnitTrait; }
Extend OrderRepository
:
<?php # src/Doctrine/ORM/OrderRepository.php declare(strict_types=1); namespace App\Doctrine\ORM; use Setono\SyliusGiftCardPlugin\Repository\OrderRepositoryInterface as SetonoSyliusGiftCardPluginOrderRepositoryInterface; use Setono\SyliusGiftCardPlugin\Doctrine\ORM\OrderRepositoryTrait as SetonoSyliusGiftCardPluginOrderRepositoryTrait; use Sylius\Bundle\CoreBundle\Doctrine\ORM\OrderRepository as BaseOrderRepository; class OrderRepository extends BaseOrderRepository implements SetonoSyliusGiftCardPluginOrderRepositoryInterface { use SetonoSyliusGiftCardPluginOrderRepositoryTrait; }
Extend CustomerRepository
:
<?php # src/Doctrine/ORM/CustomerRepository.php declare(strict_types=1); namespace App\Doctrine\ORM; use Setono\SyliusGiftCardPlugin\Repository\CustomerRepositoryInterface as SetonoSyliusGiftCardPluginCustomerRepositoryInterface; use Setono\SyliusGiftCardPlugin\Doctrine\ORM\CustomerRepositoryTrait as SetonoSyliusGiftCardPluginCustomerRepositoryTrait; use Sylius\Bundle\CoreBundle\Doctrine\ORM\CustomerRepository as BaseCustomerRepository; class CustomerRepository extends BaseCustomerRepository implements SetonoSyliusGiftCardPluginCustomerRepositoryInterface { use SetonoSyliusGiftCardPluginCustomerRepositoryTrait; }
- Add configuration:
# config/services.yaml sylius_customer: resources: customer: classes: repository: App\Doctrine\ORM\CustomerRepository sylius_order: resources: order: classes: model: App\Entity\Order\Order repository: App\Doctrine\ORM\OrderRepository order_item: classes: model: App\Entity\Order\OrderItem order_item_unit: classes: model: App\Entity\Order\OrderItemUnit sylius_product: resources: product: classes: model: App\Entity\Product\Product
Copy Api Resources
Resources declaration that need to be copied are:
If you already have them overriden, just change the following routes:
<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:
$ bin/console doctrine:migrations:diff $ bin/console doctrine:migrations:migrate
Install assets:
$ php bin/console assets:install
Clear cache:
$ php bin/console cache:clear
Configuration
Change redirect routes on add/remove gift card to/from order
You can customize where you will be redirected after adding or removing a gift card. To do so, you can simply change the route configuration :
setono_sylius_gift_card_shop_remove_gift_card_from_order: path: /gift-card/{giftCard}/remove-from-order methods: GET defaults: _controller: setono_sylius_gift_card.controller.action.remove_gift_card_from_order redirect: route: sylius_shop_cart_summary parameters: []
The same applies for the setono_sylius_gift_card_shop_partial_add_gift_card_to_order
route
You can also override or decorate the service setono_sylius_gift_card.resolver.redirect_url
to define a more custom way of redirecting
Usage
In order to find out how to use the GiftCard plugin, please refer to the usage.
Development
Testing
$ composer tests
Playing
To run built-in application showing plugin at work, just run:
$ composer try
Contribution
Learn more about our contribution workflow on http://docs.sylius.org/en/latest/contributing/.
Please, run composer all
to run all checks and tests before making pull request.