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.
▶▶ Skip screenshots and go to installation
$ composer require setono/sylius-gift-card-plugin
# config/packages/setono_sylius_gift_card.yaml
imports:
# ...
- { resource: "@SetonoSyliusGiftCardPlugin/Resources/config/app/config.yaml" }
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" }
# 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"
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],
// ...
];
You will find the templates you need to override in the test application.
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 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
sylius_product:
resources:
product:
classes:
model: App\Entity\Product\Product
$ bin/console doctrine:migrations:diff
$ bin/console doctrine:migrations:migrate
$ php bin/console assets:install
$ php bin/console cache:clear
$ composer tests
To run built-in application showing plugin at work, just run:
$ composer try
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.