├── src
├── Resources
│ ├── views
│ │ ├── Cart
│ │ │ └── _giftCard.html.twig
│ │ ├── Admin
│ │ │ ├── GiftCard
│ │ │ │ ├── Grid
│ │ │ │ │ ├── Field
│ │ │ │ │ │ ├── amount.html.twig
│ │ │ │ │ │ ├── customer.html.twig
│ │ │ │ │ │ ├── item_units_order.html.twig
│ │ │ │ │ │ └── channel_configurations.html.twig
│ │ │ │ │ └── Action
│ │ │ │ │ │ ├── delete_conditional.html.twig
│ │ │ │ │ │ ├── gift_card_balance.html.twig
│ │ │ │ │ │ ├── list_conditional.html.twig
│ │ │ │ │ │ ├── create.html.twig
│ │ │ │ │ │ └── resend_email.html.twig
│ │ │ │ ├── Create
│ │ │ │ │ └── _javascripts.html.twig
│ │ │ │ ├── create.html.twig
│ │ │ │ └── _form.html.twig
│ │ │ ├── GiftCardConfiguration
│ │ │ │ ├── _javascripts.html.twig
│ │ │ │ ├── Update
│ │ │ │ │ ├── _javascripts.html.twig
│ │ │ │ │ └── _breadcrumb.html.twig
│ │ │ │ ├── Index
│ │ │ │ │ └── _breadcrumb.html.twig
│ │ │ │ └── Create
│ │ │ │ │ └── _breadcrumb.html.twig
│ │ │ └── Order
│ │ │ │ └── Grid
│ │ │ │ └── Field
│ │ │ │ └── coveredByGiftCards.html.twig
│ │ ├── Shop
│ │ │ ├── Account
│ │ │ │ └── GiftCard
│ │ │ │ │ ├── Grid
│ │ │ │ │ └── Field
│ │ │ │ │ │ ├── amount.html.twig
│ │ │ │ │ │ └── initial_amount.html.twig
│ │ │ │ │ ├── Index
│ │ │ │ │ ├── _header.html.twig
│ │ │ │ │ └── _breadcrumb.html.twig
│ │ │ │ │ └── index.html.twig
│ │ │ ├── Product
│ │ │ │ └── Show
│ │ │ │ │ └── _addToCartGiftCardInformation.html.twig
│ │ │ ├── addGiftCardToOrder.html.twig
│ │ │ └── GiftCard
│ │ │ │ └── search.html.twig
│ │ ├── templates
│ │ │ └── bundles
│ │ │ │ ├── SyliusShopBundle
│ │ │ │ ├── Cart
│ │ │ │ │ ├── Summary
│ │ │ │ │ │ └── _totals.html.twig
│ │ │ │ │ └── summary.html.twig
│ │ │ │ ├── Checkout
│ │ │ │ │ └── _summary.html.twig
│ │ │ │ └── Common
│ │ │ │ │ └── Order
│ │ │ │ │ └── Table
│ │ │ │ │ └── _totals.html.twig
│ │ │ │ └── SyliusAdminBundle
│ │ │ │ ├── Form
│ │ │ │ └── imagesTheme.html.twig
│ │ │ │ └── Order
│ │ │ │ └── Show
│ │ │ │ └── Summary
│ │ │ │ └── _totals.html.twig
│ │ └── Email
│ │ │ ├── giftCardToCustomer.html.twig
│ │ │ └── giftCardsFromOrder.html.twig
│ ├── public
│ │ ├── setono-logo.png
│ │ ├── setono-sylius-gift-card-live-pdf-rendering.js
│ │ ├── setono-sylius-gift-card-add-gift-card-to-order.js
│ │ └── setono-sylius-gift-card-send-notification-email.js
│ ├── fixtures
│ │ └── default_background.png
│ ├── config
│ │ ├── routes
│ │ │ ├── admin_api.yaml
│ │ │ ├── admin_ajax.yaml
│ │ │ └── shop.yaml
│ │ ├── sylius_ui.yaml
│ │ ├── state_machine
│ │ │ ├── sylius_order_checkout.yaml
│ │ │ ├── sylius_order_payment.yaml
│ │ │ └── sylius_order.yaml
│ │ ├── services
│ │ │ ├── voter.xml
│ │ │ ├── api.xml
│ │ │ ├── modifier.xml
│ │ │ ├── field_types.xml
│ │ │ ├── api
│ │ │ │ ├── data_persister.xml
│ │ │ │ ├── doctrine.xml
│ │ │ │ └── data_transformer.xml
│ │ │ ├── applicator.xml
│ │ │ ├── misc.xml
│ │ │ ├── promotion_rule.xml
│ │ │ ├── order_processor.xml
│ │ │ ├── menu.xml
│ │ │ ├── twig.xml
│ │ │ ├── renderer.xml
│ │ │ ├── serializer.xml
│ │ │ ├── resolver.xml
│ │ │ ├── generator.xml
│ │ │ ├── factory.xml
│ │ │ ├── order.xml
│ │ │ └── event_listener.xml
│ │ ├── serialization
│ │ │ ├── Product.xml
│ │ │ ├── Command
│ │ │ │ ├── AddGiftCardToOrder.xml
│ │ │ │ ├── RemoveGiftCardFromOrder.xml
│ │ │ │ ├── AssociateConfigurationToChannel.xml
│ │ │ │ ├── AddItemToCartCommand.xml
│ │ │ │ └── CreateGiftCardConfiguration.xml
│ │ │ ├── Channel.xml
│ │ │ ├── GiftCardBalance.xml
│ │ │ ├── GiftCardChannelConfiguration.xml
│ │ │ ├── Customer.xml
│ │ │ ├── GiftCardConfigurationImage.xml
│ │ │ └── GiftCardConfiguration.xml
│ │ ├── routes_no_locale.yaml
│ │ ├── doctrine
│ │ │ └── model
│ │ │ │ ├── GiftCardConfigurationImage.orm.xml
│ │ │ │ ├── GiftCardChannelConfiguration.orm.xml
│ │ │ │ └── GiftCardConfiguration.orm.xml
│ │ ├── routes.yaml
│ │ ├── validation
│ │ │ ├── GiftCardConfigurationImage.xml
│ │ │ ├── AddToCardCommand.xml
│ │ │ ├── AddToCardGiftCardInformation.xml
│ │ │ ├── GiftCardSearchCommand.xml
│ │ │ ├── AddGiftCardToOrderCommand.xml
│ │ │ ├── GiftCardChannelConfiguration.xml
│ │ │ └── CreateGiftCardConfiguration.xml
│ │ ├── grids
│ │ │ ├── setono_sylius_gift_card_admin_gift_card_order.yaml
│ │ │ └── setono_sylius_gift_card_admin_gift_card_configuration.yaml
│ │ ├── grids.yaml
│ │ ├── serializer
│ │ │ └── Model.GiftCard.yml
│ │ ├── services.xml
│ │ └── app
│ │ │ └── fixtures.yaml
│ └── translations
│ │ ├── flashes.en.yml
│ │ ├── flashes.da.yml
│ │ ├── flashes.fr.yml
│ │ ├── validators.fr.yml
│ │ ├── validators.en.yml
│ │ └── validators.da.yml
├── Exception
│ ├── ExceptionInterface.php
│ ├── GiftCardNotFoundException.php
│ ├── UnexpectedTypeException.php
│ └── ChannelMismatchException.php
├── Generator
│ ├── GiftCardCodeGeneratorInterface.php
│ └── GiftCardCodeGenerator.php
├── Provider
│ ├── DatePeriodUnitProviderInterface.php
│ ├── DefaultGiftCardTemplateContentProviderInterface.php
│ ├── OrderEligibleTotalProviderInterface.php
│ ├── DatePeriodUnitProvider.php
│ ├── OrderEligibleTotalProvider.php
│ ├── GiftCardConfigurationProviderInterface.php
│ ├── PdfRenderingOptionsProvider.php
│ └── DefaultGiftCardTemplateContentProvider.php
├── Model
│ ├── GiftCardConfigurationImage.php
│ ├── GiftCardConfigurationImageInterface.php
│ ├── AdjustmentInterface.php
│ ├── OrderItemTrait.php
│ ├── OrderItemUnitInterface.php
│ ├── ProductInterface.php
│ ├── GiftCardChannelConfigurationInterface.php
│ ├── OrderItemUnitTrait.php
│ ├── OrderInterface.php
│ ├── GiftCardBalance.php
│ ├── ProductTrait.php
│ ├── GiftCardChannelConfiguration.php
│ └── OrderTrait.php
├── Mailer
│ └── Emails.php
├── Resolver
│ ├── RedirectUrlResolverInterface.php
│ ├── CustomerChannelResolverInterface.php
│ ├── LocaleResolverInterface.php
│ ├── CustomerChannelResolver.php
│ └── RedirectUrlResolver.php
├── Validator
│ └── Constraints
│ │ ├── Pdf
│ │ ├── ValidPageSize.php
│ │ ├── ValidOrientation.php
│ │ ├── ValidPageSizeValidator.php
│ │ └── ValidOrientationValidator.php
│ │ ├── GiftCardIsNotExpired.php
│ │ ├── DatePeriod.php
│ │ ├── HasBackgroundImage.php
│ │ ├── DefaultGiftCardConfigurationMustExist.php
│ │ ├── GiftCardIsNotExpiredValidator.php
│ │ ├── HasBackgroundImageValidator.php
│ │ ├── DatePeriodValidator.php
│ │ └── DefaultGiftCardConfigurationMustExistValidator.php
├── Modifier
│ └── OrderGiftCardAmountModifierInterface.php
├── Order
│ ├── GiftCardInformationInterface.php
│ ├── Factory
│ │ ├── GiftCardInformationFactoryInterface.php
│ │ ├── GiftCardInformationFactory.php
│ │ └── AddToCartCommandFactory.php
│ ├── AddToCartCommandInterface.php
│ ├── GiftCardInformation.php
│ └── AddToCartCommand.php
├── Repository
│ ├── CustomerRepositoryInterface.php
│ ├── GiftCardConfigurationRepositoryInterface.php
│ ├── OrderRepositoryInterface.php
│ └── GiftCardRepositoryInterface.php
├── Factory
│ ├── GiftCardConfigurationFactoryInterface.php
│ ├── GiftCardFactoryInterface.php
│ └── GiftCardConfigurationFactory.php
├── Form
│ ├── Type
│ │ ├── Rule
│ │ │ └── HasNoGiftCardConfigurationType.php
│ │ ├── GiftCardConfigurationImageType.php
│ │ ├── GiftCardChannelConfigurationType.php
│ │ ├── DatePeriodType.php
│ │ ├── CustomerAutocompleteChoiceType.php
│ │ ├── GiftCardSearchType.php
│ │ └── AddGiftCardToOrderType.php
│ ├── Extension
│ │ └── ProductTypeExtension.php
│ └── DataTransformer
│ │ └── GiftCardToCodeDataTransformer.php
├── Api
│ ├── Command
│ │ ├── GiftCardCodeAwareInterface.php
│ │ ├── ConfigurationCodeAwareInterface.php
│ │ ├── AddGiftCardToOrder.php
│ │ ├── RemoveGiftCardFromOrder.php
│ │ ├── AssociateConfigurationToChannel.php
│ │ ├── AddItemToCart.php
│ │ └── CreateGiftCardConfiguration.php
│ ├── Controller
│ │ └── Action
│ │ │ ├── GiftCardBalanceAction.php
│ │ │ ├── ResendGiftCardEmailAction.php
│ │ │ └── DownloadGiftCardPdfAction.php
│ ├── DataTransformer
│ │ ├── GiftCardCodeAwareInputCommandDataTransformer.php
│ │ └── GiftCardConfigurationCodeAwareInputCommandDataTransformer.php
│ ├── DataPersister
│ │ └── GiftCardDataPersister.php
│ └── CommandHandler
│ │ ├── AddGiftCardToOrderHandler.php
│ │ └── RemoveGiftCardFromOrderHandler.php
├── Twig
│ └── Extension
│ │ ├── PdfExtension.php
│ │ └── PdfRuntime.php
├── Operator
│ └── OrderGiftCardOperatorInterface.php
├── Controller
│ └── Action
│ │ ├── SearchGiftCardCommand.php
│ │ ├── AddGiftCardToOrderCommand.php
│ │ ├── SearchGiftCardAction.php
│ │ └── GiftCardBalanceAction.php
├── EmailManager
│ └── GiftCardEmailManagerInterface.php
├── Doctrine
│ └── ORM
│ │ ├── CustomerRepositoryTrait.php
│ │ ├── OrderRepositoryTrait.php
│ │ └── GiftCardConfigurationRepository.php
├── Menu
│ ├── AccountMenuListener.php
│ └── AdminMenuListener.php
├── Fixture
│ ├── GiftCardConfigurationFixture.php
│ └── GiftCardFixture.php
├── Applicator
│ └── GiftCardApplicatorInterface.php
├── DependencyInjection
│ └── Compiler
│ │ ├── CreateServiceAliasesPass.php
│ │ └── AddAdjustmentsToOrderAdjustmentClearerPass.php
├── Renderer
│ ├── PdfRendererInterface.php
│ └── PdfResponse.php
├── SetonoSyliusGiftCardPlugin.php
├── Promotion
│ └── Checker
│ │ └── Rule
│ │ └── HasNoGiftCardRuleChecker.php
├── EventSubscriber
│ ├── GiftCardDeletionSubscriber.php
│ └── SendEmailWithGiftCardToCustomerSubscriber.php
└── Grid
│ └── FieldTypes
│ └── StringFieldType.php
├── psalm-baseline.xml
└── LICENSE
/src/Resources/views/Cart/_giftCard.html.twig:
--------------------------------------------------------------------------------
1 | {{ render(url('setono_sylius_gift_card_shop_partial_add_gift_card_to_order')) }}
2 |
--------------------------------------------------------------------------------
/src/Resources/public/setono-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Setono/SyliusGiftCardPlugin/HEAD/src/Resources/public/setono-logo.png
--------------------------------------------------------------------------------
/src/Resources/fixtures/default_background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Setono/SyliusGiftCardPlugin/HEAD/src/Resources/fixtures/default_background.png
--------------------------------------------------------------------------------
/src/Resources/views/Admin/GiftCard/Grid/Field/amount.html.twig:
--------------------------------------------------------------------------------
1 | {% import "@SyliusAdmin/Common/Macro/money.html.twig" as money %}
2 |
3 | {{ money.format(data.amount, data.currencyCode) }}
4 |
--------------------------------------------------------------------------------
/src/Resources/views/Shop/Account/GiftCard/Grid/Field/amount.html.twig:
--------------------------------------------------------------------------------
1 | {% import "@SyliusShop/Common/Macro/money.html.twig" as money %}
2 |
3 | {{ money.format(data.amount, data.currencyCode) }}
4 |
--------------------------------------------------------------------------------
/src/Resources/views/Admin/GiftCardConfiguration/_javascripts.html.twig:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/src/Resources/views/Shop/Account/GiftCard/Grid/Field/initial_amount.html.twig:
--------------------------------------------------------------------------------
1 | {% import "@SyliusShop/Common/Macro/money.html.twig" as money %}
2 |
3 | {{ money.format(data.initialAmount, data.currencyCode) }}
4 |
--------------------------------------------------------------------------------
/src/Exception/ExceptionInterface.php:
--------------------------------------------------------------------------------
1 |
2 | {{ 'setono_sylius_gift_card.ui.gift_cards'|trans }}
3 |
4 | {{ sylius_template_event('setono_sylius_gift_card.shop.account.gift_card.index.header', {'giftCards': resources}) }}
5 |
6 |
--------------------------------------------------------------------------------
/src/Provider/DefaultGiftCardTemplateContentProviderInterface.php:
--------------------------------------------------------------------------------
1 |
2 |
7 |
--------------------------------------------------------------------------------
/src/Resources/config/routes/admin_api.yaml:
--------------------------------------------------------------------------------
1 | setono_sylius_gift_card_admin_api_gift_card:
2 | resource: |
3 | alias: setono_sylius_gift_card.gift_card
4 | section: admin_api
5 | form: Setono\SyliusGiftCardPlugin\Form\Type\GiftCardType
6 | serialization_version: $version
7 | type: sylius.resource_api
8 |
--------------------------------------------------------------------------------
/src/Resources/views/Admin/GiftCard/Create/_javascripts.html.twig:
--------------------------------------------------------------------------------
1 |
2 |
7 |
--------------------------------------------------------------------------------
/src/Resources/views/Admin/GiftCard/Grid/Action/gift_card_balance.html.twig:
--------------------------------------------------------------------------------
1 | {% import '@SyliusUi/Macro/buttons.html.twig' as buttons %}
2 |
3 | {{ buttons.default(
4 | path('setono_sylius_gift_card_admin_gift_card_balance'),
5 | 'setono_sylius_gift_card.ui.balance'|trans,
6 | null,
7 | 'balance scale',
8 | 'grey')
9 | }}
10 |
--------------------------------------------------------------------------------
/src/Model/GiftCardConfigurationImageInterface.php:
--------------------------------------------------------------------------------
1 |
3 | {{ 'setono_sylius_gift_card.ui.create_for_channel'|trans({ '%channel%': channel.name }) }}
4 |
5 | {% endfor %}
6 |
--------------------------------------------------------------------------------
/src/Model/AdjustmentInterface.php:
--------------------------------------------------------------------------------
1 | getProduct()->isGiftCard();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Resources/views/Admin/GiftCard/Grid/Action/create.html.twig:
--------------------------------------------------------------------------------
1 | {# todo this should be a knp menu builder instead #}
2 |
3 |
4 | {{ 'sylius.ui.create'|trans }}
5 |
8 |
9 |
--------------------------------------------------------------------------------
/src/Order/GiftCardInformationInterface.php:
--------------------------------------------------------------------------------
1 | {{ data.emailCanonical }}
6 | {% endif %}
7 |
--------------------------------------------------------------------------------
/psalm-baseline.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | LegacyIriConverterInterface|IriConverterInterface
6 | LegacyIriConverterInterface|IriConverterInterface
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/Factory/GiftCardConfigurationFactoryInterface.php:
--------------------------------------------------------------------------------
1 |
2 | {{ 'sylius.ui.home'|trans }}
3 | /
4 | {{ 'sylius.ui.my_account'|trans }}
5 | /
6 | {{ 'setono_sylius_gift_card.ui.gift_cards'|trans }}
7 |
8 |
--------------------------------------------------------------------------------
/src/Validator/Constraints/DatePeriod.php:
--------------------------------------------------------------------------------
1 | getTotal();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Resources/config/services/voter.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/Resources/translations/flashes.en.yml:
--------------------------------------------------------------------------------
1 | setono_sylius_gift_card:
2 | gift_card:
3 | delete_error: The gift card code can't be removed.
4 | impossible_to_resend_email: 'Impossible to re send email for gift card with id "%id%"'
5 | not_found: 'Impossible to find gift card with id "%id%"'
6 | read_error: Impossible to view this gift card.
7 | resent: The email has successfully been resent
8 | gift_card_added: Gift card was added to your order
9 | gift_card_removed: Gift card removed from your order
10 |
--------------------------------------------------------------------------------
/src/Validator/Constraints/DefaultGiftCardConfigurationMustExist.php:
--------------------------------------------------------------------------------
1 | #{{ order.number }}
9 | {% endif %}
10 | {% else %}
11 | {{ 'setono_sylius_gift_card.ui.manually_created'|trans }}
12 | {% endif %}
13 |
--------------------------------------------------------------------------------
/src/Operator/OrderGiftCardOperatorInterface.php:
--------------------------------------------------------------------------------
1 | giftCard;
16 | }
17 |
18 | public function setGiftCard(?GiftCardInterface $giftCard): void
19 | {
20 | $this->giftCard = $giftCard;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Resources/config/serialization/Product.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 | admin:product:create
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/Controller/Action/AddGiftCardToOrderCommand.php:
--------------------------------------------------------------------------------
1 | giftCard;
16 | }
17 |
18 | public function setGiftCard(?GiftCardInterface $giftCard): void
19 | {
20 | $this->giftCard = $giftCard;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Resolver/LocaleResolverInterface.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 | shop:gift_card:add_to_order
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/Resources/config/doctrine/model/GiftCardConfigurationImage.orm.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/Resources/config/serialization/Command/RemoveGiftCardFromOrder.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 | shop:gift_card:remove_from_order
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/Resources/config/services/api.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/Resources/views/templates/bundles/SyliusShopBundle/Cart/Summary/_totals.html.twig:
--------------------------------------------------------------------------------
1 | {% import "@SyliusShop/Common/Macro/money.html.twig" as money %}
2 |
3 | {% set giftCardAdjustment = constant('Setono\\SyliusGiftCardPlugin\\Model\\AdjustmentInterface::ORDER_GIFT_CARD_ADJUSTMENT') %}
4 | {% set giftCardAdjustmentsTotal = cart.getAdjustmentsTotal(giftCardAdjustment) %}
5 |
6 | {% if giftCardAdjustmentsTotal != 0 %}
7 |
8 | | {{ 'setono_sylius_gift_card.ui.gift_cards_adjustment_total'|trans }}: |
9 | {{ money.convertAndFormat(giftCardAdjustmentsTotal) }} |
10 |
11 | {% endif %}
12 |
--------------------------------------------------------------------------------
/src/EmailManager/GiftCardEmailManagerInterface.php:
--------------------------------------------------------------------------------
1 | $giftCards
17 | */
18 | public function sendEmailWithGiftCardsFromOrder(OrderInterface $order, array $giftCards): void;
19 | }
20 |
--------------------------------------------------------------------------------
/src/Resources/config/services/modifier.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/Exception/GiftCardNotFoundException.php:
--------------------------------------------------------------------------------
1 | giftCard = $giftCard;
17 |
18 | parent::__construct(sprintf('The gift card with code "%s" was not found', $this->giftCard));
19 | }
20 |
21 | public function getGiftCard(): string
22 | {
23 | return $this->giftCard;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Resources/config/serialization/Channel.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 | admin:gift_card:read
10 |
11 |
12 |
13 | admin:gift_card:read
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/Provider/GiftCardConfigurationProviderInterface.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/Api/Command/AddGiftCardToOrder.php:
--------------------------------------------------------------------------------
1 | orderTokenValue = $orderTokenValue;
16 | }
17 |
18 | public function getGiftCardCode(): ?string
19 | {
20 | return $this->giftCardCode;
21 | }
22 |
23 | public function setGiftCardCode(?string $giftCardCode): void
24 | {
25 | $this->giftCardCode = $giftCardCode;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Model/ProductInterface.php:
--------------------------------------------------------------------------------
1 | orderTokenValue = $orderTokenValue;
16 | }
17 |
18 | public function getGiftCardCode(): ?string
19 | {
20 | return $this->giftCardCode;
21 | }
22 |
23 | public function setGiftCardCode(?string $giftCardCode): void
24 | {
25 | $this->giftCardCode = $giftCardCode;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Resources/views/Admin/GiftCard/Grid/Field/channel_configurations.html.twig:
--------------------------------------------------------------------------------
1 | {% import '@SyliusUi/Macro/labels.html.twig' as label %}
2 |
3 | {# @var \Setono\SyliusGiftCardPlugin\Model\GiftCardChannelConfigurationInterface[] data #}
4 | {% for channelConfiguration in data %}
5 |
6 | {# @var \Setono\SyliusGiftCardPlugin\Model\GiftCardChannelConfigurationInterface channelConfiguration #}
7 | {% include '@SyliusAdmin/Common/_channel.html.twig' with {'channel': channelConfiguration.channel} %}
8 |
9 | {% if channelConfiguration.locale is not null %}
10 | {{ label.default(channelConfiguration.locale.code) }}
11 | {% endif %}
12 |
13 | {% endfor %}
14 |
--------------------------------------------------------------------------------
/src/Exception/UnexpectedTypeException.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/Model/GiftCardChannelConfigurationInterface.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/Doctrine/ORM/CustomerRepositoryTrait.php:
--------------------------------------------------------------------------------
1 | createQueryBuilder('o')
20 | ->andWhere('o.email LIKE :phrase')
21 | ->setParameter('phrase', '%' . $email . '%')
22 | ->setMaxResults($limit)
23 | ->getQuery()
24 | ->getResult()
25 | ;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Resources/views/Shop/Account/GiftCard/index.html.twig:
--------------------------------------------------------------------------------
1 | {% extends '@SyliusShop/Account/layout.html.twig' %}
2 |
3 | {% block breadcrumb %}
4 | {% include '@SetonoSyliusGiftCardPlugin/Shop/Account/GiftCard/Index/_breadcrumb.html.twig' %}
5 | {% endblock %}
6 |
7 | {% block subcontent %}
8 | {% include '@SetonoSyliusGiftCardPlugin/Shop/Account/GiftCard/Index/_header.html.twig' %}
9 |
10 | {{ sylius_template_event('setono_sylius_gift_card.shop.account.gift_card.index.after_content_header', {'giftCards': resources}) }}
11 |
12 | {{ sylius_grid_render(resources, '@SyliusShop/Grid/_default.html.twig') }}
13 |
14 | {{ sylius_template_event('setono_sylius_gift_card.shop.account.gift_card.index.after_grid', {'giftCards': resources}) }}
15 | {% endblock %}
16 |
--------------------------------------------------------------------------------
/src/Repository/OrderRepositoryInterface.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/Menu/AccountMenuListener.php:
--------------------------------------------------------------------------------
1 | getMenu();
15 |
16 | $this->addGiftCardsMenu($menu);
17 | }
18 |
19 | private function addGiftCardsMenu(ItemInterface $menu): void
20 | {
21 | $menu->addChild('gift_cards', ['route' => 'setono_sylius_gift_card_shop_gift_card_index'])
22 | ->setLabel('setono_sylius_gift_card.ui.gift_cards')
23 | ->setLabelAttribute('icon', 'gift');
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Resources/public/setono-sylius-gift-card-live-pdf-rendering.js:
--------------------------------------------------------------------------------
1 | (function ($) {
2 | 'use strict';
3 |
4 | $.fn.extend({
5 | applyPdfChanges: function () {
6 | const $element = $(this);
7 | const url = $element.data('url');
8 |
9 | $element.on('click', function (event) {
10 | event.preventDefault();
11 |
12 | $.ajax(url, {
13 | method: 'POST',
14 | data: $('form[name="setono_sylius_gift_card_gift_card_configuration"]').serialize(),
15 | success(response) {
16 | $('.js-ssgc-live-render-container').html(``);
17 | },
18 | });
19 | });
20 | },
21 | });
22 | })(jQuery);
23 |
--------------------------------------------------------------------------------
/src/Model/OrderItemUnitTrait.php:
--------------------------------------------------------------------------------
1 | giftCard;
17 | }
18 |
19 | public function setGiftCard(GiftCardInterface $giftCard): void
20 | {
21 | if ($this->giftCard === $giftCard) {
22 | return;
23 | }
24 |
25 | $this->giftCard = $giftCard;
26 |
27 | $giftCard->setOrderItemUnit($this);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Resources/config/validation/AddToCardCommand.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/Model/OrderInterface.php:
--------------------------------------------------------------------------------
1 |
14 | * @return Collection|GiftCardInterface[]
15 | */
16 | public function getGiftCards(): Collection;
17 |
18 | public function hasGiftCards(): bool;
19 |
20 | public function addGiftCard(GiftCardInterface $giftCard): void;
21 |
22 | public function removeGiftCard(GiftCardInterface $giftCard): void;
23 |
24 | public function hasGiftCard(GiftCardInterface $giftCard): bool;
25 | }
26 |
--------------------------------------------------------------------------------
/src/Resources/config/grids/setono_sylius_gift_card_admin_gift_card_order.yaml:
--------------------------------------------------------------------------------
1 | sylius_grid:
2 | grids:
3 | setono_sylius_gift_card_admin_gift_card_order:
4 | extends: sylius_admin_order
5 | driver:
6 | options:
7 | repository:
8 | method: createCompletedQueryBuilderByGiftCard
9 | arguments:
10 | giftCard: $id
11 | fields:
12 | coveredByGiftCards:
13 | type: twig
14 | label: setono_sylius_gift_card.ui.covered_by_gift_cards
15 | path: .
16 | options:
17 | template: "@SetonoSyliusGiftCardPlugin/Admin/Order/Grid/Field/coveredByGiftCards.html.twig"
18 |
--------------------------------------------------------------------------------
/src/Resources/views/Email/giftCardToCustomer.html.twig:
--------------------------------------------------------------------------------
1 | {# @var \Sylius\Component\Core\Model\CustomerInterface customer #}
2 | {# @var \Setono\SyliusGiftCardPlugin\Model\GiftCardInterface giftCard #}
3 | {% extends '@SyliusAdmin/Email/layout.html.twig' %}
4 |
5 | {% block subject %}{{ 'setono_sylius_gift_card.email.new_gift_card'|trans }}{% endblock %}
6 |
7 | {% block content %}
8 | {# This needs to be imported here since the rendering of emails only take the block to render it. Not whole template #}
9 | {% import "@SyliusShop/Common/Macro/money.html.twig" as money %}
10 | {{ 'setono_sylius_gift_card.email.new_gift_card_intro'|trans }}
11 |
12 | {{ giftCard.code }} ({{ 'setono_sylius_gift_card.email.balance'|trans }}: {{ money.convertAndFormat(giftCard.amount) }})
13 | {% endblock %}
14 |
--------------------------------------------------------------------------------
/src/Resources/views/templates/bundles/SyliusShopBundle/Checkout/_summary.html.twig:
--------------------------------------------------------------------------------
1 | {% import "@SyliusShop/Common/Macro/money.html.twig" as money %}
2 |
3 | {% set giftCardAdjustment = constant('Setono\\SyliusGiftCardPlugin\\Model\\AdjustmentInterface::ORDER_GIFT_CARD_ADJUSTMENT') %}
4 | {% set giftCardAdjustmentsTotal = order.getAdjustmentsTotal(giftCardAdjustment) %}
5 |
6 | {% if giftCardAdjustmentsTotal != 0 %}
7 |
8 | |
9 | {{ 'setono_sylius_gift_card.ui.gift_cards_adjustment_total'|trans }}:
10 | |
11 |
12 | {{ money.convertAndFormat(giftCardAdjustmentsTotal) }}
13 | |
14 |
15 | {% endif %}
16 |
--------------------------------------------------------------------------------
/src/Resources/config/validation/AddToCardGiftCardInformation.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/Api/Controller/Action/GiftCardBalanceAction.php:
--------------------------------------------------------------------------------
1 | giftCardRepository = $giftCardRepository;
17 | }
18 |
19 | public function __invoke(): GiftCardBalanceCollection
20 | {
21 | return GiftCardBalanceCollection::createFromGiftCards(
22 | $this->giftCardRepository->findEnabled(),
23 | );
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Resources/views/Admin/GiftCardConfiguration/Create/_breadcrumb.html.twig:
--------------------------------------------------------------------------------
1 | {% import '@SyliusAdmin/Macro/breadcrumb.html.twig' as breadcrumb %}
2 |
3 | {% set index_url = path(
4 | configuration.vars.index.route.name|default(configuration.getRouteName('index')),
5 | configuration.vars.index.route.parameters|default(configuration.vars.route.parameters|default({}))
6 | )
7 | %}
8 |
9 | {% set breadcrumbs = [
10 | { label: 'sylius.ui.administration'|trans, url: path('sylius_admin_dashboard') },
11 | { label: 'setono_sylius_gift_card.ui.gift_cards'|trans, url: path('setono_sylius_gift_card_admin_gift_card_index') },
12 | { label: (metadata.applicationName~'.ui.'~metadata.pluralName)|trans, url: index_url },
13 | { label: 'sylius.ui.new'|trans }
14 | ]
15 | %}
16 |
17 | {{ breadcrumb.crumble(breadcrumbs) }}
18 |
--------------------------------------------------------------------------------
/src/Resources/config/serialization/Command/AssociateConfigurationToChannel.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 | admin:gift_card_configuration:associate_channel
10 |
11 |
12 |
13 | admin:gift_card_configuration:associate_channel
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/Resources/config/state_machine/sylius_order.yaml:
--------------------------------------------------------------------------------
1 | winzou_state_machine:
2 | sylius_order:
3 | callbacks:
4 | after:
5 | setono_decrement_gift_card_amount:
6 | on: ["create"]
7 | do: ["@setono_sylius_gift_card.modifier.order_gift_card_amount", "decrement"]
8 | args: ["object"]
9 | setono_increment_gift_card_amount:
10 | on: ["cancel"]
11 | do: ["@setono_sylius_gift_card.modifier.order_gift_card_amount", "increment"]
12 | args: ["object"]
13 | setono_order_cancellation_gift_card:
14 | on: ["cancel"]
15 | do: ["@setono_sylius_gift_card.operator.order_gift_card", "disable"]
16 | args: ["object"]
17 |
--------------------------------------------------------------------------------
/src/Resources/config/services/api/doctrine.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/Resources/config/services/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/Resources/config/services/promotion_rule.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
9 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/Provider/PdfRenderingOptionsProvider.php:
--------------------------------------------------------------------------------
1 | getPageSize();
15 | if (null !== $pageSize) {
16 | $options['page-size'] = $pageSize;
17 | }
18 |
19 | $orientation = $giftCardConfiguration->getOrientation();
20 | if (null !== $orientation) {
21 | $options['orientation'] = $orientation;
22 | }
23 |
24 | return $options;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Api/Command/AssociateConfigurationToChannel.php:
--------------------------------------------------------------------------------
1 | localeCode = $localeCode;
18 | $this->channelCode = $channelCode;
19 | }
20 |
21 | public function getConfigurationCode(): ?string
22 | {
23 | return $this->configurationCode;
24 | }
25 |
26 | public function setConfigurationCode(?string $configurationCode): void
27 | {
28 | $this->configurationCode = $configurationCode;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Resources/config/validation/GiftCardSearchCommand.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/Resources/config/serialization/GiftCardBalance.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 | admin:gift_card_balance:read
10 |
11 |
12 |
13 | admin:gift_card_balance:read
14 |
15 |
16 |
17 | admin:gift_card_balance:read
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/Resources/views/Email/giftCardsFromOrder.html.twig:
--------------------------------------------------------------------------------
1 | {# @var \Setono\SyliusGiftCardPlugin\Model\GiftCardInterface[] giftCards #}
2 | {% extends '@SyliusAdmin/Email/layout.html.twig' %}
3 |
4 | {% block subject %}{{ 'setono_sylius_gift_card.email.your_gift_card'|trans }}{% endblock %}
5 |
6 | {% block content %}
7 | {# This needs to be imported here since the rendering of emails only take the block to render it. Not whole template #}
8 | {% import "@SyliusShop/Common/Macro/money.html.twig" as money %}
9 |
10 | {{ 'setono_sylius_gift_card.email.your_gift_cards_you_bought_in_the_order'|trans ~ ' ' ~ order.number }}:
11 |
12 |
13 | {% for giftCard in giftCards %}
14 | {{ giftCard.code }} ({{ 'setono_sylius_gift_card.email.balance'|trans }}: {{ money.convertAndFormat(giftCard.amount) }})
15 | {% endfor %}
16 | {% endblock %}
17 |
--------------------------------------------------------------------------------
/src/Api/Command/AddItemToCart.php:
--------------------------------------------------------------------------------
1 | amount = $amount;
20 | $this->customMessage = $customMessage;
21 | }
22 |
23 | public function getAmount(): ?int
24 | {
25 | return $this->amount;
26 | }
27 |
28 | public function getCustomMessage(): ?string
29 | {
30 | return $this->customMessage;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Order/Factory/GiftCardInformationFactory.php:
--------------------------------------------------------------------------------
1 | */
13 | private string $className;
14 |
15 | /**
16 | * @param class-string $className
17 | */
18 | public function __construct(string $className)
19 | {
20 | $this->className = $className;
21 | }
22 |
23 | public function createNew(OrderItemInterface $orderItem): GiftCardInformationInterface
24 | {
25 | return new $this->className($orderItem->getUnitPrice());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Resources/views/Admin/GiftCardConfiguration/Update/_breadcrumb.html.twig:
--------------------------------------------------------------------------------
1 | {% import '@SyliusAdmin/Macro/breadcrumb.html.twig' as breadcrumb %}
2 |
3 | {% set index_url = path(
4 | configuration.vars.index.route.name|default(configuration.getRouteName('index')),
5 | configuration.vars.index.route.parameters|default(configuration.vars.route.parameters|default({}))
6 | )
7 | %}
8 |
9 | {% set breadcrumbs = [
10 | { label: 'sylius.ui.administration'|trans, url: path('sylius_admin_dashboard') },
11 | { label: 'setono_sylius_gift_card.ui.gift_cards'|trans, url: path('setono_sylius_gift_card_admin_gift_card_index') },
12 | { label: (metadata.applicationName~'.ui.'~metadata.pluralName)|trans, url: index_url },
13 | { label: resource.name|default(resource.code|default(resource.id)) },
14 | { label: 'sylius.ui.edit'|trans }
15 | ]
16 | %}
17 |
18 | {{ breadcrumb.crumble(breadcrumbs) }}
19 |
--------------------------------------------------------------------------------
/src/Resources/config/serialization/GiftCardChannelConfiguration.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 | admin:gift_card_configuration:read
10 |
11 |
12 |
13 | admin:gift_card_configuration:read
14 |
15 |
16 |
17 | admin:gift_card_configuration:read
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/Resources/config/services/order_processor.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/Resources/views/templates/bundles/SyliusAdminBundle/Form/imagesTheme.html.twig:
--------------------------------------------------------------------------------
1 | {% extends '@!SyliusAdmin/Form/imagesTheme.html.twig' %}
2 |
3 | {% block setono_sylius_gift_card_gift_card_configuration_image_widget %}
4 | {%- if form.type is defined -%}
5 | {{- form_row(form.type) -}}
6 | {%- endif -%}
7 |
8 | {%- if form.vars.value.path|default(null) is not null -%}
9 |
10 | {%- endif -%}
11 |
12 | {{- form_widget(form.file) -}}
13 |
14 |
15 | {{- form_errors(form.file) -}}
16 |
17 | {% endblock %}
18 |
--------------------------------------------------------------------------------
/src/Fixture/GiftCardConfigurationFixture.php:
--------------------------------------------------------------------------------
1 | children()
21 | ->scalarNode('code')->cannotBeEmpty()->end()
22 | ->scalarNode('background_image')->cannotBeEmpty()->end()
23 | ->booleanNode('enabled')->end()
24 | ->booleanNode('default')->end()
25 | ;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Fixture/GiftCardFixture.php:
--------------------------------------------------------------------------------
1 | children()
21 | ->scalarNode('code')->cannotBeEmpty()->end()
22 | ->scalarNode('channel')->cannotBeEmpty()->end()
23 | ->scalarNode('currency')->cannotBeEmpty()->end()
24 | ->floatNode('amount')->end()
25 | ->booleanNode('enabled')->end()
26 | ;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Resources/public/setono-sylius-gift-card-add-gift-card-to-order.js:
--------------------------------------------------------------------------------
1 | (function ($) {
2 | 'use strict';
3 |
4 | $.fn.extend({
5 | addGiftCardToOrder: function () {
6 | const $element = $(this);
7 | const url = $element.data('action');
8 | const redirectUrl = $element.data('redirect');
9 |
10 | $element.on('submit', function (event) {
11 | event.preventDefault();
12 |
13 | $.ajax(url, {
14 | method: 'POST',
15 | data: $element.serialize(),
16 | success: function () {
17 | window.location.href = redirectUrl;
18 | },
19 | error: function (xhr) {
20 | $('.setono-sylius-gift-card-gift-card-block').replaceWith(xhr.responseText);
21 |
22 | $('#setono-sylius-gift-card-add-gift-card-to-order').addGiftCardToOrder();
23 | },
24 | });
25 | });
26 |
27 | },
28 | });
29 | })(jQuery);
30 |
--------------------------------------------------------------------------------
/src/Order/GiftCardInformation.php:
--------------------------------------------------------------------------------
1 | amount = $amount;
16 | $this->customMessage = $customMessage;
17 | }
18 |
19 | public function getAmount(): int
20 | {
21 | return $this->amount;
22 | }
23 |
24 | public function setAmount(int $amount): void
25 | {
26 | $this->amount = $amount;
27 | }
28 |
29 | public function getCustomMessage(): ?string
30 | {
31 | return $this->customMessage;
32 | }
33 |
34 | public function setCustomMessage(?string $customMessage): void
35 | {
36 | $this->customMessage = $customMessage;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Menu/AdminMenuListener.php:
--------------------------------------------------------------------------------
1 | getMenu();
15 |
16 | $this->addCatalogChild($menu);
17 | }
18 |
19 | private function addCatalogChild(ItemInterface $menu): void
20 | {
21 | $submenu = $menu->getChild('catalog');
22 | $item = $submenu instanceof ItemInterface ? $submenu : $menu->getFirstChild();
23 | $item
24 | ->addChild('gift_cards', [
25 | 'route' => 'setono_sylius_gift_card_admin_gift_card_index',
26 | ])
27 | ->setLabel('setono_sylius_gift_card.ui.gift_cards')
28 | ->setLabelAttribute('icon', 'gift')
29 | ;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Resources/config/services/menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
13 |
14 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/Applicator/GiftCardApplicatorInterface.php:
--------------------------------------------------------------------------------
1 | currencyCode = $currencyCode;
18 | }
19 |
20 | public function add(int $amount): void
21 | {
22 | ++$this->count;
23 | $this->total += $amount;
24 | }
25 |
26 | public function getCurrencyCode(): string
27 | {
28 | return $this->currencyCode;
29 | }
30 |
31 | public function getCount(): int
32 | {
33 | return $this->count;
34 | }
35 |
36 | public function getTotal(): int
37 | {
38 | return $this->total;
39 | }
40 |
41 | public function getAverageAmount(): int
42 | {
43 | return (int) round($this->total / $this->count);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Resources/config/serialization/Command/AddItemToCartCommand.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 | shop:cart:add_item
10 |
11 |
12 | shop:cart:add_item
13 |
14 |
15 | shop:cart:add_item
16 |
17 |
18 | shop:cart:add_item
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/Model/ProductTrait.php:
--------------------------------------------------------------------------------
1 | giftCard;
20 | }
21 |
22 | public function setGiftCard(bool $isGiftCard): void
23 | {
24 | $this->giftCard = $isGiftCard;
25 | }
26 |
27 | public function isGiftCardAmountConfigurable(): bool
28 | {
29 | return $this->giftCardAmountConfigurable;
30 | }
31 |
32 | public function setGiftCardAmountConfigurable(bool $giftCardAmountConfigurable): void
33 | {
34 | $this->giftCardAmountConfigurable = $giftCardAmountConfigurable;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Resources/config/services/twig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
9 |
10 |
11 |
12 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/Resources/config/services/renderer.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/Form/Type/GiftCardConfigurationImageType.php:
--------------------------------------------------------------------------------
1 | remove('type');
19 | }
20 | }
21 |
22 | public function configureOptions(OptionsResolver $resolver): void
23 | {
24 | parent::configureOptions($resolver);
25 |
26 | $resolver->setDefault('remove_type', false);
27 | $resolver->setAllowedTypes('remove_type', ['bool']);
28 | }
29 |
30 | public function getBlockPrefix(): string
31 | {
32 | return 'setono_sylius_gift_card_gift_card_configuration_image';
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Resources/config/services/api/data_transformer.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
10 |
11 |
12 |
13 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/Resources/config/validation/AddGiftCardToOrderCommand.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/DependencyInjection/Compiler/CreateServiceAliasesPass.php:
--------------------------------------------------------------------------------
1 | has('sylius.api.context.user')) {
17 | return;
18 | }
19 |
20 | // this should not be possible after the check above, but we need to check it, obviously. This service was added in 1.11
21 | if (!$container->has(UserContextInterface::class)) {
22 | return;
23 | }
24 |
25 | $container->setAlias('sylius.api.context.user', UserContextInterface::class);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Setono
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/Api/DataTransformer/GiftCardCodeAwareInputCommandDataTransformer.php:
--------------------------------------------------------------------------------
1 | setGiftCardCode($giftCard->getCode());
22 |
23 | return $object;
24 | }
25 |
26 | /**
27 | * @param object $object
28 | */
29 | public function supportsTransformation($object): bool
30 | {
31 | return $object instanceof GiftCardCodeAwareInterface;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Resources/views/Admin/GiftCard/_form.html.twig:
--------------------------------------------------------------------------------
1 | {{ form_errors(form) }}
2 |
3 |
4 |
5 | {{ form_errors(form) }}
6 | {{ form_row(form.code) }}
7 | {{ form_row(form.enabled) }}
8 | {{ form_row(form.expiresAt) }}
9 | {{ form_row(form.customer, {'attr': {'data-target': '.js-ssgc-send-customer-email'}}) }}
10 | {% if form.sendNotificationEmail is defined %}
11 |
12 |
{{ 'setono_sylius_gift_card.ui.customer_help_text'|trans }}
13 | {{ form_row(form.sendNotificationEmail) }}
14 |
15 | {% endif %}
16 |
17 |
18 |
19 |
20 |
21 | {{ form_row(form.currencyCode) }}
22 | {{ form_row(form.amount) }}
23 | {{ form_row(form.customMessage) }}
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/Form/Extension/ProductTypeExtension.php:
--------------------------------------------------------------------------------
1 | add('giftCard', CheckboxType::class, [
17 | 'required' => false,
18 | 'label' => 'setono_sylius_gift_card.form.product.gift_card',
19 | ]);
20 | $builder->add('giftCardAmountConfigurable', CheckboxType::class, [
21 | 'required' => false,
22 | 'label' => 'setono_sylius_gift_card.form.product.gift_card_amount_configurable',
23 | ]);
24 | }
25 |
26 | public static function getExtendedTypes(): iterable
27 | {
28 | return [
29 | ProductType::class,
30 | ];
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Api/Command/CreateGiftCardConfiguration.php:
--------------------------------------------------------------------------------
1 | code = $code;
33 | $this->default = $default;
34 | $this->enabled = $enabled;
35 | $this->defaultValidityPeriod = $defaultValidityPeriod;
36 | $this->pageSize = $pageSize;
37 | $this->orientation = $orientation;
38 | $this->template = $template;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/Validator/Constraints/GiftCardIsNotExpiredValidator.php:
--------------------------------------------------------------------------------
1 | isExpired()) {
30 | $this->context->buildViolation($constraint->message)->addViolation();
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Form/Type/GiftCardChannelConfigurationType.php:
--------------------------------------------------------------------------------
1 | add('channel', ChannelChoiceType::class, [
17 | 'label' => 'setono_sylius_gift_card.form.channel_configuration.channel',
18 | 'expanded' => false,
19 | 'multiple' => false,
20 | ]);
21 | $builder->add('locale', LocaleChoiceType::class, [
22 | 'label' => 'setono_sylius_gift_card.form.channel_configuration.locale',
23 | ]);
24 | }
25 |
26 | public function getBlockPrefix(): string
27 | {
28 | return 'setono_sylius_gift_card_gift_card_channel_configuration';
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Renderer/PdfRendererInterface.php:
--------------------------------------------------------------------------------
1 | has('sylius.order_processing.order_adjustments_clearer')) {
17 | return;
18 | }
19 |
20 | $clearerDefinition = $container->getDefinition('sylius.order_processing.order_adjustments_clearer');
21 |
22 | $adjustmentsToRemove = $clearerDefinition->getArgument(0);
23 | Assert::isArray($adjustmentsToRemove);
24 |
25 | $adjustmentsToRemove[] = AdjustmentInterface::ORDER_GIFT_CARD_ADJUSTMENT;
26 |
27 | $clearerDefinition->setArgument(0, $adjustmentsToRemove);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/SetonoSyliusGiftCardPlugin.php:
--------------------------------------------------------------------------------
1 | addCompilerPass(new AddAdjustmentsToOrderAdjustmentClearerPass());
23 | $container->addCompilerPass(new CreateServiceAliasesPass());
24 | }
25 |
26 | public function getSupportedDrivers(): array
27 | {
28 | return [
29 | SyliusResourceBundle::DRIVER_DOCTRINE_ORM,
30 | ];
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Resources/public/setono-sylius-gift-card-send-notification-email.js:
--------------------------------------------------------------------------------
1 | (function ($) {
2 | 'use strict';
3 |
4 | $.fn.extend({
5 | sendNotificationEmailInput: function () {
6 | const $customerInput = $(this);
7 | const $sendCustomerNotificationEmail = $($customerInput.data('target'));
8 |
9 | if ($customerInput.val() !== '') {
10 | $sendCustomerNotificationEmail.show();
11 | } else {
12 | $sendCustomerNotificationEmail.hide();
13 | }
14 |
15 | $('label[for="setono_sylius_gift_card_gift_card_customer"]').prepend('');
16 |
17 | $customerInput.on('change', () => {
18 | if ($customerInput.val() !== '') {
19 | $sendCustomerNotificationEmail.show();
20 | } else {
21 | $sendCustomerNotificationEmail.hide();
22 | }
23 | });
24 |
25 | $('.js-ssgc-clear-input').on('click', () => {
26 | $customerInput.parent().children('div.text').html('');
27 | $customerInput.val('');
28 | $customerInput.trigger('change');
29 | });
30 | }
31 | });
32 | })(jQuery);
33 |
--------------------------------------------------------------------------------
/src/Resources/config/grids.yaml:
--------------------------------------------------------------------------------
1 | imports:
2 | - { resource: "@SetonoSyliusGiftCardPlugin/Resources/config/grids/setono_sylius_gift_card_admin_gift_card.yaml" }
3 | - { resource: "@SetonoSyliusGiftCardPlugin/Resources/config/grids/setono_sylius_gift_card_admin_gift_card_configuration.yaml" }
4 | - { resource: "@SetonoSyliusGiftCardPlugin/Resources/config/grids/setono_sylius_gift_card_admin_gift_card_order.yaml" }
5 | - { resource: "@SetonoSyliusGiftCardPlugin/Resources/config/grids/setono_sylius_gift_card_shop_gift_card.yaml" }
6 |
7 | sylius_grid:
8 | templates:
9 | action:
10 | gift_card_create: "@SetonoSyliusGiftCardPlugin/Admin/GiftCard/Grid/Action/create.html.twig"
11 | gift_card_delete_conditional: "@SetonoSyliusGiftCardPlugin/Admin/GiftCard/Grid/Action/delete_conditional.html.twig"
12 | gift_card_balance: "@SetonoSyliusGiftCardPlugin/Admin/GiftCard/Grid/Action/gift_card_balance.html.twig"
13 | gift_card_list_conditional: "@SetonoSyliusGiftCardPlugin/Admin/GiftCard/Grid/Action/list_conditional.html.twig"
14 | gift_card_resend_email: '@SetonoSyliusGiftCardPlugin/Admin/GiftCard/Grid/Action/resend_email.html.twig'
15 |
--------------------------------------------------------------------------------
/src/Exception/ChannelMismatchException.php:
--------------------------------------------------------------------------------
1 | getName(),
22 | (string) $actualChannel->getName(),
23 | ));
24 | $this->actualChannel = $actualChannel;
25 | $this->expectedChannel = $expectedChannel;
26 | }
27 |
28 | public function getActualChannel(): ChannelInterface
29 | {
30 | return $this->actualChannel;
31 | }
32 |
33 | public function getExpectedChannel(): ChannelInterface
34 | {
35 | return $this->expectedChannel;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Resources/config/serialization/Customer.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 | admin:gift_card:read
10 |
11 |
12 |
13 | admin:gift_card:read
14 |
15 |
16 |
17 | admin:gift_card:read
18 |
19 |
20 |
21 | admin:gift_card:read
22 |
23 |
24 |
25 | admin:gift_card:read
26 |
27 |
28 |
29 | admin:gift_card:read
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/Twig/Extension/PdfRuntime.php:
--------------------------------------------------------------------------------
1 | PDFRenderer = $giftCardPDFRenderer;
23 | $this->giftCardFactory = $giftCardFactory;
24 | }
25 |
26 | public function getBase64EncodedExamplePdfContent(GiftCardConfigurationInterface $giftCardChannelConfiguration): string
27 | {
28 | $giftCard = $this->giftCardFactory->createExample();
29 |
30 | return $this->PDFRenderer->render($giftCard, $giftCardChannelConfiguration)->getEncodedContent();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Order/AddToCartCommand.php:
--------------------------------------------------------------------------------
1 | cart = $cart;
24 | $this->cartItem = $cartItem;
25 | $this->giftCardInformation = $giftCardInformation;
26 | }
27 |
28 | public function getCart(): OrderInterface
29 | {
30 | return $this->cart;
31 | }
32 |
33 | public function getCartItem(): OrderItemInterface
34 | {
35 | return $this->cartItem;
36 | }
37 |
38 | public function getGiftCardInformation(): GiftCardInformationInterface
39 | {
40 | return $this->giftCardInformation;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Resources/config/validation/GiftCardChannelConfiguration.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/Validator/Constraints/Pdf/ValidPageSizeValidator.php:
--------------------------------------------------------------------------------
1 | availablePageSizes = $availableOrientations;
18 | }
19 |
20 | /**
21 | * @param mixed $value
22 | */
23 | public function validate($value, Constraint $constraint): void
24 | {
25 | if (!$constraint instanceof ValidPageSize) {
26 | throw new UnexpectedTypeException($constraint, ValidPageSize::class);
27 | }
28 |
29 | if (null === $value || '' === $value) {
30 | return;
31 | }
32 |
33 | if (!\in_array($value, $this->availablePageSizes, true)) {
34 | $this->context->buildViolation($constraint->message)
35 | ->addViolation();
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Resources/config/routes/admin_ajax.yaml:
--------------------------------------------------------------------------------
1 | setono_sylius_gift_card_admin_ajax_customer_by_email_phrase:
2 | path: /customer/search
3 | methods: [GET]
4 | defaults:
5 | _controller: sylius.controller.customer::indexAction
6 | _format: json
7 | _sylius:
8 | serialization_groups: [Default]
9 | permission: true
10 | repository:
11 | method: findByEmailPartForGiftCard
12 | arguments:
13 | email: $phrase
14 |
15 | setono_sylius_gift_card_admin_ajax_customer_by_email:
16 | path: /customer/email
17 | methods: [GET]
18 | defaults:
19 | _controller: sylius.controller.customer::indexAction
20 | _format: json
21 | _sylius:
22 | serialization_groups: [Default]
23 | permission: true
24 | repository:
25 | method: findBy
26 | arguments: [email: $email]
27 |
28 | setono_sylius_gift_card_admin_ajax_generate_pdf:
29 | path: /gift-card-configurations/{id}/generate-encoded-example-pdf
30 | methods: [ PUT ]
31 | controller: setono_sylius_gift_card.controller.action.generate_encoded_example_pdf
32 | requirements:
33 | id: \d+
34 |
--------------------------------------------------------------------------------
/src/Factory/GiftCardFactoryInterface.php:
--------------------------------------------------------------------------------
1 | setConfigurationCode($giftCardConfiguration->getCode());
22 |
23 | return $object;
24 | }
25 |
26 | /**
27 | * @param object $object
28 | */
29 | public function supportsTransformation($object): bool
30 | {
31 | return $object instanceof ConfigurationCodeAwareInterface;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Validator/Constraints/Pdf/ValidOrientationValidator.php:
--------------------------------------------------------------------------------
1 | availableOrientations = $availableOrientations;
18 | }
19 |
20 | /**
21 | * @param mixed $value
22 | */
23 | public function validate($value, Constraint $constraint): void
24 | {
25 | if (!$constraint instanceof ValidOrientation) {
26 | throw new UnexpectedTypeException($constraint, ValidOrientation::class);
27 | }
28 |
29 | if (null === $value || '' === $value) {
30 | return;
31 | }
32 |
33 | if (!\in_array($value, $this->availableOrientations, true)) {
34 | $this->context->buildViolation($constraint->message)
35 | ->addViolation();
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Promotion/Checker/Rule/HasNoGiftCardRuleChecker.php:
--------------------------------------------------------------------------------
1 | getItems();
22 | foreach ($items as $orderItem) {
23 | /** @var ProductInterface|null $product */
24 | $product = $orderItem->getProduct();
25 | if (null === $product) {
26 | // Ignore if no product
27 | continue;
28 | }
29 |
30 | if ($product->isGiftCard()) {
31 | return false;
32 | }
33 | }
34 |
35 | return true;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Renderer/PdfResponse.php:
--------------------------------------------------------------------------------
1 | 'application/pdf',
20 | 'Content-Disposition' => HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $filename),
21 | ]);
22 | }
23 |
24 | public static function fromGiftCard(string $content, GiftCardInterface $giftCard): self
25 | {
26 | return new self($content, sprintf('gift_card_%s.pdf', (string) $giftCard->getCode()));
27 | }
28 |
29 | /**
30 | * Returns the PDF content as a base64 encoded string
31 | */
32 | public function getEncodedContent(): string
33 | {
34 | return base64_encode($this->content);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Resources/config/services/serializer.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
17 |
18 |
19 | media/image
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/Resources/config/services/resolver.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
9 |
10 |
11 |
12 |
13 |
15 |
16 |
17 |
18 |
19 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/Api/Controller/Action/ResendGiftCardEmailAction.php:
--------------------------------------------------------------------------------
1 | giftCardEmailManager = $giftCardEmailManager;
19 | }
20 |
21 | public function __invoke(GiftCardInterface $data): Response
22 | {
23 | if (($order = $data->getOrder()) !== null) {
24 | $this->giftCardEmailManager->sendEmailWithGiftCardsFromOrder($order, [$data]);
25 | } elseif (($customer = $data->getCustomer()) !== null) {
26 | $this->giftCardEmailManager->sendEmailToCustomerWithGiftCard($customer, $data);
27 | } else {
28 | throw new BadRequestHttpException();
29 | }
30 |
31 | return new Response(null, Response::HTTP_NO_CONTENT);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Validator/Constraints/HasBackgroundImageValidator.php:
--------------------------------------------------------------------------------
1 | getBackgroundImage();
28 |
29 | if (null === $backgroundImage) {
30 | return;
31 | }
32 |
33 | if (null === $backgroundImage->getFile() && null === $backgroundImage->getPath()) {
34 | $this->context->buildViolation($constraint->message)
35 | ->addViolation();
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/EventSubscriber/GiftCardDeletionSubscriber.php:
--------------------------------------------------------------------------------
1 | 'onGiftCardPreDelete',
18 | ];
19 | }
20 |
21 | /**
22 | * Prevent gift card code deletion if it not deletable
23 | */
24 | public function onGiftCardPreDelete(ResourceControllerEvent $event): void
25 | {
26 | $giftCard = $event->getSubject();
27 |
28 | if (!$giftCard instanceof GiftCardInterface) {
29 | throw new UnexpectedTypeException(
30 | $giftCard,
31 | GiftCardInterface::class,
32 | );
33 | }
34 |
35 | if (!$giftCard->isDeletable()) {
36 | $event->stop('setono_sylius_gift_card.gift_card.delete_error');
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Order/Factory/AddToCartCommandFactory.php:
--------------------------------------------------------------------------------
1 | */
15 | private string $className;
16 |
17 | private GiftCardInformationFactoryInterface $giftCardInformationFactory;
18 |
19 | /**
20 | * @param class-string $className
21 | */
22 | public function __construct(
23 | string $className,
24 | GiftCardInformationFactoryInterface $giftCardInformationFactory,
25 | ) {
26 | $this->className = $className;
27 | $this->giftCardInformationFactory = $giftCardInformationFactory;
28 | }
29 |
30 | public function createWithCartAndCartItem(OrderInterface $cart, OrderItemInterface $cartItem): AddToCartCommandInterface
31 | {
32 | return new $this->className($cart, $cartItem, $this->giftCardInformationFactory->createNew($cartItem));
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Resources/views/Shop/addGiftCardToOrder.html.twig:
--------------------------------------------------------------------------------
1 | {% form_theme form '@SyliusShop/Form/theme.html.twig' %}
2 |
3 |
4 |
5 |
6 | {{ form_start(form, {
7 | 'action': path('setono_sylius_gift_card_shop_partial_add_gift_card_to_order'),
8 | 'attr': {
9 | 'id': 'setono-sylius-gift-card-add-gift-card-to-order',
10 | 'class': 'ui loadable form',
11 | 'novalidate': 'novalidate',
12 | 'data-action': path('setono_sylius_gift_card_shop_ajax_add_gift_card_to_order'),
13 | 'data-redirect': path('sylius_shop_cart_summary')
14 | }
15 | }) }}
16 | {{ form_row(form._token) }}
17 | {{ form_end(form, {'render_rest': false}) }}
18 |
19 |
20 |
21 | {{ form_widget(form.giftCard, {'attr': {'form': 'setono-sylius-gift-card-add-gift-card-to-order'}}) }}
22 |
25 |
26 |
27 | {{ form_errors(form.giftCard) }}
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/Controller/Action/SearchGiftCardAction.php:
--------------------------------------------------------------------------------
1 | formFactory = $formFactory;
24 | $this->twig = $twig;
25 | }
26 |
27 | public function __invoke(Request $request): Response
28 | {
29 | $searchGiftCardCommand = new SearchGiftCardCommand();
30 | $form = $this->formFactory->create(GiftCardSearchType::class, $searchGiftCardCommand);
31 | $form->handleRequest($request);
32 |
33 | return new Response($this->twig->render('@SetonoSyliusGiftCardPlugin/Shop/GiftCard/search.html.twig', [
34 | 'form' => $form->createView(),
35 | 'giftCard' => ($form->isSubmitted() && $form->isValid()) ? $searchGiftCardCommand->getGiftCard() : null,
36 | ]));
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Resources/config/services/generator.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
8 |
9 | %setono_sylius_gift_card.code_length%
10 |
11 |
12 |
14 |
15 |
16 |
17 |
18 |
19 | %kernel.cache_dir%
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/Resources/config/doctrine/model/GiftCardChannelConfiguration.orm.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/Form/Type/DatePeriodType.php:
--------------------------------------------------------------------------------
1 | datePeriodUnitProvider = $datePeriodUnitProvider;
20 | }
21 |
22 | public function buildForm(FormBuilderInterface $builder, array $options): void
23 | {
24 | $builder->add('value', IntegerType::class, [
25 | 'label' => 'setono_sylius_gift_card.form.date_period.value',
26 | ]);
27 | $builder->add('unit', ChoiceType::class, [
28 | 'label' => 'setono_sylius_gift_card.form.date_period.unit',
29 | 'choices' => $this->datePeriodUnitProvider->getPeriodUnits(),
30 | 'choice_label' => function (string $choice): string {
31 | return \sprintf('setono_sylius_gift_card.form.date_period.unit_%s', $choice);
32 | },
33 | ]);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Controller/Action/GiftCardBalanceAction.php:
--------------------------------------------------------------------------------
1 | giftCardRepository = $giftCardRepository;
27 | $this->twig = $twig;
28 | }
29 |
30 | public function __invoke(Request $request): Response
31 | {
32 | $giftCardBalanceCollection = GiftCardBalanceCollection::createFromGiftCards(
33 | $this->giftCardRepository->findEnabled(),
34 | );
35 |
36 | return new Response($this->twig->render('@SetonoSyliusGiftCardPlugin/Admin/giftCardBalance.html.twig', [
37 | 'giftCardBalanceCollection' => $giftCardBalanceCollection,
38 | ]));
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/Resources/config/serialization/Command/CreateGiftCardConfiguration.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 | admin:gift_card_configuration:create
10 |
11 |
12 | admin:gift_card_configuration:create
13 |
14 |
15 | admin:gift_card_configuration:create
16 |
17 |
18 | admin:gift_card_configuration:create
19 |
20 |
21 | admin:gift_card_configuration:create
22 |
23 |
24 | admin:gift_card_configuration:create
25 |
26 |
27 | admin:gift_card_configuration:create
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/src/Resources/config/serializer/Model.GiftCard.yml:
--------------------------------------------------------------------------------
1 | Setono\SyliusGiftCardPlugin\Model\GiftCard:
2 | exclusion_policy: ALL
3 | xml_root_name: setono_sylius_gift_card
4 | properties:
5 | code:
6 | expose: true
7 | type: string
8 | groups: [Default, Detailed]
9 | currencyCode:
10 | expose: true
11 | type: string
12 | groups: [Default, Detailed]
13 | amount:
14 | expose: true
15 | type: integer
16 | groups: [Default, Detailed]
17 | initialAmount:
18 | expose: true
19 | type: integer
20 | groups: [Default, Detailed]
21 | enabled:
22 | expose: true
23 | type: boolean
24 | groups: [Default, Detailed]
25 | createdAt:
26 | expose: true
27 | type: DateTime
28 | groups: [Default, Detailed]
29 | virtual_properties:
30 | getCustomerIdentification:
31 | serialized_name: customer
32 | expose: true
33 | type: array
34 | groups: [Default, Detailed]
35 | getOrderIdentification:
36 | serialized_name: order
37 | expose: true
38 | type: array
39 | groups: [Default, Detailed]
40 | getChannelCode:
41 | serialized_name: channel
42 | expose: true
43 | type: string
44 | groups: [Default, Detailed]
45 |
--------------------------------------------------------------------------------
/src/Resources/translations/validators.fr.yml:
--------------------------------------------------------------------------------
1 | setono_sylius_gift_card:
2 | add_gift_card_to_order_command:
3 | gift_card:
4 | does_not_exist: Ce code de chèque-cadeau n'existe pas
5 | is_expired: Ce chèque-cadeau a expiré
6 | not_blank: Veuillez renseigner un code
7 | channel_configuration:
8 | unique_channel_locale: Cette combinaison de canal et langue est déjà utilisée
9 | gift_card:
10 | code:
11 | not_blank: Veuillez renseigner un code
12 | unique: Le code doit être unique
13 | max_length: Le code ne doit pas dépasser {{ limit }} caractères|Le code ne doit pas dépasser {{ limit }} caractères
14 | amount:
15 | not_blank: Veuillez renseigner un montant
16 | integer: Le montant doit être un entier
17 | min: Le montant ne dois pas être en-dessous de 1
18 | send_notification_email:
19 | boolean: L'envoi de l'email de notification doit être un booléen
20 | gift_card_configuration:
21 | background_image_required: L'image de fond est requise
22 | default_configuration_must_exist: Si aucune autre configuration n'existe, vous devez marquer cette configuration par défaut. Sinon, vous devez marquer une autre configuration par défaut avant de décocher cette
23 | gift_card_search_command:
24 | gift_card:
25 | does_not_exist: Ce code de chèque-cadeau n'existe pas
26 | not_blank: Veuillez renseigner un code
27 |
--------------------------------------------------------------------------------
/src/Resources/translations/validators.en.yml:
--------------------------------------------------------------------------------
1 | setono_sylius_gift_card:
2 | add_gift_card_to_order_command:
3 | gift_card:
4 | does_not_exist: The gift card with this code does not exist
5 | is_expired: The entered gift card is expired
6 | not_blank: Please enter code
7 | channel_configuration:
8 | unique_channel_locale: This combination of channel and locale are already used
9 | gift_card:
10 | code:
11 | not_blank: Please enter code
12 | unique: Code must be unique
13 | max_length: Code must not be longer than {{ limit }} characters|Code must not be longer than {{ limit }} characters
14 | amount:
15 | not_blank: Please enter amount
16 | integer: Amount must be an integer
17 | min: Amount cannot be lower than 1
18 | greater_than_or_equal: The amount must be greater than or equal to 1
19 | send_notification_email:
20 | boolean: Send notification email must be a boolean
21 | gift_card_configuration:
22 | background_image_required: The background image is required
23 | default_configuration_must_exist: If no other configurations exist you must mark this configuration the default. Else you must mark another configuration as default before unchecking this
24 | gift_card_search_command:
25 | gift_card:
26 | does_not_exist: The gift card with this code does not exist
27 | not_blank: Please enter code
28 |
--------------------------------------------------------------------------------
/src/Api/Controller/Action/DownloadGiftCardPdfAction.php:
--------------------------------------------------------------------------------
1 | configurationProvider = $configurationProvider;
25 | $this->pdfRenderer = $giftCardPDFRenderer;
26 | }
27 |
28 | public function __invoke(GiftCardInterface $data): Response
29 | {
30 | $configuration = $this->configurationProvider->getConfigurationForGiftCard($data);
31 | if (!$configuration instanceof GiftCardConfigurationInterface) {
32 | throw new NotFoundHttpException('No configuration found for this GiftCard');
33 | }
34 |
35 | return $this->pdfRenderer->render($data, $configuration);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Model/GiftCardChannelConfiguration.php:
--------------------------------------------------------------------------------
1 | id;
24 | }
25 |
26 | public function getChannel(): ?ChannelInterface
27 | {
28 | return $this->channel;
29 | }
30 |
31 | public function setChannel(?ChannelInterface $channel): void
32 | {
33 | Assert::notNull($channel);
34 | $this->channel = $channel;
35 | }
36 |
37 | public function getLocale(): ?LocaleInterface
38 | {
39 | return $this->locale;
40 | }
41 |
42 | public function setLocale(LocaleInterface $locale): void
43 | {
44 | $this->locale = $locale;
45 | }
46 |
47 | public function getConfiguration(): ?GiftCardConfigurationInterface
48 | {
49 | return $this->configuration;
50 | }
51 |
52 | public function setConfiguration(?GiftCardConfigurationInterface $configuration): void
53 | {
54 | $this->configuration = $configuration;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/Resources/config/serialization/GiftCardConfigurationImage.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 | admin:gift_card_configuration_image:read
10 |
11 | admin:gift_card_configuration:read
12 |
13 |
14 |
15 | admin:gift_card_configuration_image:read
16 | admin:gift_card_configuration_image:create
17 |
18 | admin:gift_card_configuration:read
19 |
20 |
21 |
22 | admin:gift_card_configuration_image:read
23 |
24 | admin:gift_card_configuration:read
25 |
26 |
27 |
28 | admin:gift_card_configuration_image:read
29 | admin:gift_card_configuration_image:create
30 |
31 |
32 |
33 | admin:gift_card_configuration_image:create
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/src/Resources/translations/validators.da.yml:
--------------------------------------------------------------------------------
1 | setono_sylius_gift_card:
2 | add_gift_card_to_order_command:
3 | gift_card:
4 | does_not_exist: Der findes ikke et gavekort med denne kode
5 | is_expired: Gavekortet er udløbet
6 | not_blank: Indtast venligst din kode
7 | channel_configuration:
8 | unique_channel_locale: Kombinationen af denne kanal og lokalitet er allerede brugt
9 | gift_card:
10 | code:
11 | not_blank: Indtast venligst din kode
12 | unique: Koden skal være unik
13 | max_length: Koden må ikke være længere end {{ limit }} karakterer|Koden må ikke være længere end {{ limit }} karakterer
14 | amount:
15 | not_blank: Indtast venligst beløb
16 | integer: Beløb skal være heltal
17 | min: Beløbet kan ikke være mindre en 1
18 | greater_than_or_equal: Beløbet skal være større eller lig med 1
19 | send_notification_email:
20 | boolean: Send notification email must be a boolean
21 | gift_card_configuration:
22 | background_image_required: Baggrundsbillede er påkrævet
23 | default_configuration_must_exist: Hvis der ikke findes andre konfigurationer, skal du markere denne konfiguration som standard. Ellers skal du markere en anden konfiguration som standard, før du fjerner markeringen af denne
24 | gift_card_search_command:
25 | gift_card:
26 | does_not_exist: Gavekort med denne kode eksisterer ikke
27 | not_blank: Indtast venligst din kode
28 |
--------------------------------------------------------------------------------
/src/Api/DataPersister/GiftCardDataPersister.php:
--------------------------------------------------------------------------------
1 | decoratedDataPersister = $decoratedDataPersister;
18 | }
19 |
20 | /**
21 | * @param mixed $data
22 | */
23 | public function supports($data, array $context = []): bool
24 | {
25 | return $data instanceof GiftCardInterface;
26 | }
27 |
28 | /**
29 | * @param GiftCardInterface|mixed $data
30 | *
31 | * @return object|void
32 | */
33 | public function persist($data, array $context = [])
34 | {
35 | Assert::isInstanceOf($data, GiftCardInterface::class);
36 |
37 | $data->setOrigin(GiftCardInterface::ORIGIN_API);
38 |
39 | return $this->decoratedDataPersister->persist($data, $context);
40 | }
41 |
42 | /**
43 | * @param GiftCardInterface|mixed $data
44 | *
45 | * @return mixed
46 | */
47 | public function remove($data, array $context = [])
48 | {
49 | return $this->decoratedDataPersister->remove($data, $context);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/Resources/config/services.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/Validator/Constraints/DatePeriodValidator.php:
--------------------------------------------------------------------------------
1 | datePeriodUnitProvider = $datePeriodUnitProvider;
20 | }
21 |
22 | /**
23 | * @param mixed $value
24 | */
25 | public function validate($value, Constraint $constraint): void
26 | {
27 | if (!$constraint instanceof DatePeriod) {
28 | throw new UnexpectedTypeException($constraint, DatePeriod::class);
29 | }
30 |
31 | if (null === $value || '' === $value) {
32 | return;
33 | }
34 |
35 | Assert::string($value);
36 | [$duration, $unit] = \explode(' ', $value);
37 | if ((int) $duration <= 0) {
38 | $this->context->buildViolation($constraint->invalidDuration)->addViolation();
39 | }
40 |
41 | if (!\in_array($unit, $this->datePeriodUnitProvider->getPeriodUnits())) {
42 | $this->context->buildViolation($constraint->invalidUnit)->addViolation();
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Resolver/CustomerChannelResolver.php:
--------------------------------------------------------------------------------
1 | orderRepository = $orderRepository;
23 | $this->channelRepository = $channelRepository;
24 | }
25 |
26 | public function resolve(CustomerInterface $customer): ChannelInterface
27 | {
28 | $latestOrder = $this->orderRepository->findLatestByCustomer($customer);
29 | if (null !== $latestOrder) {
30 | $channel = $latestOrder->getChannel();
31 | if (null !== $channel) {
32 | return $channel;
33 | }
34 | }
35 |
36 | /** @var ChannelInterface|null $channel */
37 | $channel = $this->channelRepository->findOneBy([
38 | 'enabled' => true,
39 | ]);
40 |
41 | if (null === $channel) {
42 | throw new \RuntimeException('There are no enabled channels');
43 | }
44 |
45 | return $channel;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/Doctrine/ORM/OrderRepositoryTrait.php:
--------------------------------------------------------------------------------
1 | createQueryBuilder('o')
22 | ->andWhere('o.customer = :customer')
23 | ->setParameter('customer', $customer)
24 | ->addOrderBy('o.createdAt', 'DESC')
25 | ->setMaxResults(1)
26 | ->getQuery()
27 | ->getOneOrNullResult()
28 | ;
29 | }
30 |
31 | public function createQueryBuilderByGiftCard(string $giftCardId): QueryBuilder
32 | {
33 | assert($this instanceof EntityRepository);
34 |
35 | return $this->createQueryBuilder('o')
36 | ->join('o.giftCards', 'g')
37 | ->andWhere('g.id = :id')
38 | ->setParameter('id', $giftCardId)
39 | ;
40 | }
41 |
42 | public function createCompletedQueryBuilderByGiftCard(string $giftCardId): QueryBuilder
43 | {
44 | return $this->createQueryBuilderByGiftCard($giftCardId)
45 | ->andWhere('o.checkoutState = :checkoutState')
46 | ->setParameter('checkoutState', OrderCheckoutStates::STATE_COMPLETED)
47 | ;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/Doctrine/ORM/GiftCardConfigurationRepository.php:
--------------------------------------------------------------------------------
1 | createQueryBuilder('o')
19 | ->join('o.channelConfigurations', 'c')
20 | ->andWhere('c.channel = :channel')
21 | ->andWhere('c.locale = :locale')
22 | ->setParameters([
23 | 'channel' => $channel,
24 | 'locale' => $locale,
25 | ])
26 | ->getQuery()
27 | ->getOneOrNullResult()
28 | ;
29 |
30 | Assert::nullOrIsInstanceOf($obj, GiftCardConfigurationInterface::class);
31 |
32 | return $obj;
33 | }
34 |
35 | public function findDefault(): ?GiftCardConfigurationInterface
36 | {
37 | $obj = $this->findOneBy([
38 | 'default' => true,
39 | ]);
40 |
41 | Assert::nullOrIsInstanceOf($obj, GiftCardConfigurationInterface::class);
42 |
43 | return $obj;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Resources/config/app/fixtures.yaml:
--------------------------------------------------------------------------------
1 | sylius_fixtures:
2 | suites:
3 | default:
4 | fixtures:
5 |
6 | # Random
7 | setono_gift_card:
8 | options:
9 | random: 20
10 |
11 | # Few more disabled
12 | setono_gift_card_channel_specific:
13 | name: setono_gift_card
14 | options:
15 | random: 2
16 | prototype:
17 | enabled: false
18 |
19 | setono_gift_card_custom:
20 | name: setono_gift_card
21 | options:
22 | custom:
23 | gift_card_one_usd:
24 | code: '1USD'
25 | channel: 'FASHION_WEB'
26 | currency: 'USD'
27 | amount: 1.00
28 | gift_card_two_usd:
29 | code: '2USD'
30 | channel: 'FASHION_WEB'
31 | amount: 2.00
32 |
33 | setono_gift_card_configuration:
34 | options:
35 | custom:
36 | default_configuration:
37 | code: 'default_configuration'
38 | background_image: '@SetonoSyliusGiftCardPlugin/Resources/fixtures/default_background.png'
39 | enabled: true
40 | default: true
41 |
--------------------------------------------------------------------------------
/src/Resolver/RedirectUrlResolver.php:
--------------------------------------------------------------------------------
1 | router = $router;
19 | }
20 |
21 | public function getUrlToRedirectTo(Request $request, string $defaultRoute): string
22 | {
23 | /** @var mixed $redirect */
24 | $redirect = $request->attributes->get('redirect');
25 | if (is_array($redirect)) {
26 | if (isset($redirect[0]) && is_string($redirect[0])) {
27 | return $this->router->generate($redirect[0]);
28 | }
29 |
30 | if (isset($redirect['route'], $redirect['parameters']) && is_string($redirect['route']) && is_array($redirect['parameters'])) {
31 | return $this->router->generate($redirect['route'], $redirect['parameters']);
32 | }
33 | }
34 |
35 | $referrer = $request->headers->get('referer');
36 | if (is_string($referrer)) {
37 | /** @var mixed $redirectTo */
38 | $redirectTo = filter_var($referrer, FILTER_SANITIZE_URL);
39 |
40 | if (is_string($redirectTo)) {
41 | return $redirectTo;
42 | }
43 | }
44 |
45 | return $this->router->generate($defaultRoute);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/Generator/GiftCardCodeGenerator.php:
--------------------------------------------------------------------------------
1 | giftCardRepository = $giftCardRepository;
26 | $this->codeLength = $codeLength;
27 | }
28 |
29 | public function generate(): string
30 | {
31 | do {
32 | // if we didn't remove the 'hard to read' characters we would only have to
33 | // generate codeLength / 2 bytes because hex uses two characters to represent one byte
34 | /** @psalm-suppress ArgumentTypeCoercion */
35 | $code = bin2hex(random_bytes($this->codeLength));
36 | $code = preg_replace('/[01]/', '', $code); // remove hard to read characters
37 | $code = mb_strtoupper(mb_substr($code, 0, $this->codeLength));
38 | } while (mb_strlen($code) !== $this->codeLength || $this->exists($code));
39 |
40 | return $code;
41 | }
42 |
43 | private function exists(string $code): bool
44 | {
45 | return null !== $this->giftCardRepository->findOneByCode($code);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/Resources/config/routes/shop.yaml:
--------------------------------------------------------------------------------
1 | setono_sylius_gift_card_shop_search_gift_card:
2 | path: /gift-card/search
3 | methods: [GET,POST]
4 | defaults:
5 | _controller: setono_sylius_gift_card.controller.action.search_gift_card
6 |
7 | setono_sylius_gift_card_shop_remove_gift_card_from_order:
8 | path: /gift-card/{giftCard}/remove-from-order
9 | methods: GET
10 | defaults:
11 | _controller: setono_sylius_gift_card.controller.action.remove_gift_card_from_order
12 |
13 | setono_sylius_gift_card_shop_partial_add_gift_card_to_order:
14 | path: /_partial/gift-card/add-to-order
15 | methods: [ GET, POST ]
16 | defaults:
17 | _controller: setono_sylius_gift_card.controller.action.add_gift_card_to_order
18 |
19 | setono_sylius_gift_card_shop_ajax_add_gift_card_to_order:
20 | path: /ajax/gift-card/add-to-order
21 | methods: [ GET, POST ]
22 | defaults:
23 | _controller: setono_sylius_gift_card.controller.action.add_gift_card_to_order
24 |
25 | setono_sylius_gift_card_shop_gift_card_index:
26 | path: /account/gift-cards
27 | methods: [ GET ]
28 | defaults:
29 | _controller: setono_sylius_gift_card.controller.gift_card::indexAction
30 | _sylius:
31 | section: shop
32 | grid: setono_sylius_gift_card_shop_gift_card
33 | template: '@SetonoSyliusGiftCardPlugin/Shop/Account/GiftCard/index.html.twig'
34 |
35 | setono_sylius_gift_card_shop_gift_card_pdf:
36 | path: /gift-cards/{id}/pdf
37 | requirements:
38 | id: \d+
39 | methods: [ GET ]
40 | defaults:
41 | _controller: setono_sylius_gift_card.controller.action.download_pdf
42 | _sylius:
43 | section: shop
44 |
--------------------------------------------------------------------------------
/src/Resources/views/templates/bundles/SyliusShopBundle/Cart/summary.html.twig:
--------------------------------------------------------------------------------
1 | {# @var \Setono\SyliusGiftCardPlugin\Model\OrderInterface cart #}
2 | {% import "@SyliusShop/Common/Macro/money.html.twig" as money %}
3 |
4 | {% set giftCardAdjustment = constant('Setono\\SyliusGiftCardPlugin\\Model\\AdjustmentInterface::ORDER_GIFT_CARD_ADJUSTMENT') %}
5 | {% set giftCardAdjustments = cart.getAdjustments(giftCardAdjustment) %}
6 |
7 | {% if giftCardAdjustments.count > 0 %}
8 |
9 |
10 | {{ 'setono_sylius_gift_card.ui.applied_gift_cards'|trans }}
11 |
12 |
13 | {{ sylius_template_event('setono_sylius_gift_card.shop.cart.summary.applied_gift_cards', {'cart': cart}) }}
14 |
15 |
16 |
17 | {% for adjustment in giftCardAdjustments %}
18 | {# @var \Setono\SyliusGiftCardPlugin\Model\AdjustmentInterface adjustment #}
19 |
20 | |
21 | {{ adjustment.originCode }}
22 |
23 |
24 |
25 |
26 | |
27 |
28 | {{ money.convertAndFormat(-adjustment.amount) }}
29 | |
30 |
31 | {% endfor %}
32 |
33 |
34 |
35 | {% endif %}
36 |
--------------------------------------------------------------------------------
/src/Resources/config/services/factory.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
20 |
21 |
22 | %setono_sylius_gift_card.pdf_rendering.default_orientation%
23 | %setono_sylius_gift_card.pdf_rendering.default_page_size%
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/Factory/GiftCardConfigurationFactory.php:
--------------------------------------------------------------------------------
1 | decoratedFactory = $decoratedFactory;
28 | $this->defaultGiftCardTemplateContentProvider = $defaultGiftCardTemplateContentProvider;
29 | $this->defaultOrientation = $defaultOrientation;
30 | $this->defaultPageSize = $defaultPageSize;
31 | }
32 |
33 | public function createNew(): GiftCardConfigurationInterface
34 | {
35 | /** @var GiftCardConfigurationInterface $configuration */
36 | $configuration = $this->decoratedFactory->createNew();
37 |
38 | $configuration->setOrientation($this->defaultOrientation);
39 | $configuration->setPageSize($this->defaultPageSize);
40 | $configuration->setTemplate($this->defaultGiftCardTemplateContentProvider->getContent());
41 |
42 | return $configuration;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/Form/Type/CustomerAutocompleteChoiceType.php:
--------------------------------------------------------------------------------
1 | urlGenerator = $urlGenerator;
21 | }
22 |
23 | public function configureOptions(OptionsResolver $resolver): void
24 | {
25 | $resolver->setDefaults([
26 | 'resource' => 'sylius.customer',
27 | 'choice_name' => 'email',
28 | 'choice_value' => 'email',
29 | ]);
30 | }
31 |
32 | public function buildView(FormView $view, FormInterface $form, array $options): void
33 | {
34 | $view->vars['remote_criteria_type'] = 'contains';
35 | $view->vars['remote_criteria_name'] = 'phrase';
36 | $view->vars['remote_url'] = $this->urlGenerator->generate('setono_sylius_gift_card_admin_ajax_customer_by_email_phrase');
37 | $view->vars['load_edit_url'] = $this->urlGenerator->generate('setono_sylius_gift_card_admin_ajax_customer_by_email');
38 | }
39 |
40 | public function getBlockPrefix(): string
41 | {
42 | return 'setono_sylius_gift_card_customer_autocomplete_choice';
43 | }
44 |
45 | public function getParent(): string
46 | {
47 | return ResourceAutocompleteChoiceType::class;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/Grid/FieldTypes/StringFieldType.php:
--------------------------------------------------------------------------------
1 | propertyAccessor = $propertyAccessor;
22 | }
23 |
24 | public function render(Field $field, $data, array $options): string
25 | {
26 | try {
27 | if (!is_object($data) && !is_array($data)) {
28 | throw new InvalidArgumentException('The $data should be either an array or an object');
29 | }
30 |
31 | /** @var mixed $value */
32 | $value = $this->propertyAccessor->getValue($data, $field->getPath());
33 | Assert::true(self::isStringable($value));
34 | } catch (Throwable $e) {
35 | return '';
36 | }
37 |
38 | return htmlspecialchars((string) $value);
39 | }
40 |
41 | public function configureOptions(OptionsResolver $resolver): void
42 | {
43 | }
44 |
45 | /**
46 | * @param mixed $value
47 | *
48 | * @psalm-assert-if-true null|scalar|object $value
49 | */
50 | private static function isStringable($value): bool
51 | {
52 | return $value === null || is_scalar($value) || (is_object($value) && method_exists($value, '__toString'));
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Provider/DefaultGiftCardTemplateContentProvider.php:
--------------------------------------------------------------------------------
1 |
13 |
14 |
15 |
44 |
45 |
46 | {{ giftCard.amount }}
47 | {{ giftCard.code }}
48 | {% if giftCard.customMessage is not null %}
49 | {{ giftCard.customMessage }}
50 | {% endif %}
51 | {% if giftCard.expiresAt is not null %}
52 | Expires: {{ giftCard.expiresAt|date('Y-m-d') }}
53 | {% endif %}
54 |
55 |