├── LICENSE ├── composer.json ├── psalm-baseline.xml └── src ├── Api ├── Command │ ├── AddGiftCardToOrder.php │ ├── AddItemToCart.php │ ├── AssociateConfigurationToChannel.php │ ├── ConfigurationCodeAwareInterface.php │ ├── CreateGiftCardConfiguration.php │ ├── GiftCardCodeAwareInterface.php │ └── RemoveGiftCardFromOrder.php ├── CommandHandler │ ├── AddGiftCardToOrderHandler.php │ ├── AddItemToCartHandler.php │ ├── AssociateConfigurationToChannelHandler.php │ ├── CreateGiftCardConfigurationHandler.php │ └── RemoveGiftCardFromOrderHandler.php ├── Controller │ └── Action │ │ ├── DownloadGiftCardPdfAction.php │ │ ├── GiftCardBalanceAction.php │ │ ├── ResendGiftCardEmailAction.php │ │ └── UploadGiftCardConfigurationImageAction.php ├── DataPersister │ └── GiftCardDataPersister.php ├── DataTransformer │ ├── GiftCardCodeAwareInputCommandDataTransformer.php │ └── GiftCardConfigurationCodeAwareInputCommandDataTransformer.php └── Doctrine │ └── QueryCollectionExtension │ └── GiftCardsByLoggedInUserExtension.php ├── Applicator ├── GiftCardApplicator.php └── GiftCardApplicatorInterface.php ├── Controller └── Action │ ├── AddGiftCardToOrderAction.php │ ├── AddGiftCardToOrderCommand.php │ ├── Admin │ └── GenerateEncodedExamplePdfAction.php │ ├── DownloadGiftCardPdfAction.php │ ├── GiftCardBalanceAction.php │ ├── RemoveGiftCardFromOrderAction.php │ ├── ResendGiftCardEmailAction.php │ ├── SearchGiftCardAction.php │ └── SearchGiftCardCommand.php ├── DependencyInjection ├── Compiler │ ├── AddAdjustmentsToOrderAdjustmentClearerPass.php │ └── CreateServiceAliasesPass.php ├── Configuration.php └── SetonoSyliusGiftCardExtension.php ├── Doctrine └── ORM │ ├── CustomerRepositoryTrait.php │ ├── GiftCardConfigurationRepository.php │ ├── GiftCardRepository.php │ └── OrderRepositoryTrait.php ├── EmailManager ├── GiftCardEmailManager.php └── GiftCardEmailManagerInterface.php ├── EventSubscriber ├── DefaultGiftCardConfigurationSubscriber.php ├── GiftCardDeletionSubscriber.php └── SendEmailWithGiftCardToCustomerSubscriber.php ├── Exception ├── ChannelMismatchException.php ├── ExceptionInterface.php ├── GiftCardNotFoundException.php └── UnexpectedTypeException.php ├── Factory ├── GiftCardConfigurationFactory.php ├── GiftCardConfigurationFactoryInterface.php ├── GiftCardFactory.php └── GiftCardFactoryInterface.php ├── Fixture ├── Factory │ ├── GiftCardConfigurationExampleFactory.php │ └── GiftCardExampleFactory.php ├── GiftCardConfigurationFixture.php └── GiftCardFixture.php ├── Form ├── DataTransformer │ └── GiftCardToCodeDataTransformer.php ├── Extension │ ├── AddToCartTypeExtension.php │ └── ProductTypeExtension.php └── Type │ ├── AddGiftCardToOrderType.php │ ├── AddToCartGiftCardInformationType.php │ ├── CustomerAutocompleteChoiceType.php │ ├── DatePeriodType.php │ ├── GiftCardChannelConfigurationType.php │ ├── GiftCardConfigurationImageType.php │ ├── GiftCardConfigurationType.php │ ├── GiftCardSearchType.php │ ├── GiftCardType.php │ └── Rule │ └── HasNoGiftCardConfigurationType.php ├── Generator ├── GiftCardCodeGenerator.php └── GiftCardCodeGeneratorInterface.php ├── Grid └── FieldTypes │ └── StringFieldType.php ├── Mailer └── Emails.php ├── Menu ├── AccountMenuListener.php └── AdminMenuListener.php ├── Model ├── AdjustmentInterface.php ├── GiftCard.php ├── GiftCardBalance.php ├── GiftCardBalanceCollection.php ├── GiftCardChannelConfiguration.php ├── GiftCardChannelConfigurationInterface.php ├── GiftCardConfiguration.php ├── GiftCardConfigurationImage.php ├── GiftCardConfigurationImageInterface.php ├── GiftCardConfigurationInterface.php ├── GiftCardInterface.php ├── OrderInterface.php ├── OrderItemTrait.php ├── OrderItemUnitInterface.php ├── OrderItemUnitTrait.php ├── OrderTrait.php ├── ProductInterface.php └── ProductTrait.php ├── Modifier ├── OrderGiftCardAmountModifier.php └── OrderGiftCardAmountModifierInterface.php ├── Operator ├── OrderGiftCardOperator.php └── OrderGiftCardOperatorInterface.php ├── Order ├── AddToCartCommand.php ├── AddToCartCommandInterface.php ├── Factory │ ├── AddToCartCommandFactory.php │ ├── GiftCardInformationFactory.php │ └── GiftCardInformationFactoryInterface.php ├── GiftCardInformation.php └── GiftCardInformationInterface.php ├── OrderProcessor └── OrderGiftCardProcessor.php ├── Promotion └── Checker │ └── Rule │ └── HasNoGiftCardRuleChecker.php ├── Provider ├── DatePeriodUnitProvider.php ├── DatePeriodUnitProviderInterface.php ├── DefaultGiftCardTemplateContentProvider.php ├── DefaultGiftCardTemplateContentProviderInterface.php ├── GiftCardConfigurationProvider.php ├── GiftCardConfigurationProviderInterface.php ├── OrderEligibleTotalProvider.php ├── OrderEligibleTotalProviderInterface.php ├── PdfRenderingOptionsProvider.php └── PdfRenderingOptionsProviderInterface.php ├── Renderer ├── PdfRenderer.php ├── PdfRendererInterface.php └── PdfResponse.php ├── Repository ├── CustomerRepositoryInterface.php ├── GiftCardConfigurationRepositoryInterface.php ├── GiftCardRepositoryInterface.php └── OrderRepositoryInterface.php ├── Resolver ├── CustomerChannelResolver.php ├── CustomerChannelResolverInterface.php ├── LocaleResolver.php ├── LocaleResolverInterface.php ├── RedirectUrlResolver.php └── RedirectUrlResolverInterface.php ├── Resources ├── config │ ├── api_resources │ │ ├── GiftCard.xml │ │ ├── GiftCardConfiguration.xml │ │ ├── GiftCardConfigurationImage.xml │ │ └── Order.xml │ ├── app │ │ ├── config.yaml │ │ └── fixtures.yaml │ ├── doctrine │ │ └── model │ │ │ ├── GiftCard.orm.xml │ │ │ ├── GiftCardChannelConfiguration.orm.xml │ │ │ ├── GiftCardConfiguration.orm.xml │ │ │ └── GiftCardConfigurationImage.orm.xml │ ├── grids.yaml │ ├── grids │ │ ├── setono_sylius_gift_card_admin_gift_card.yaml │ │ ├── setono_sylius_gift_card_admin_gift_card_configuration.yaml │ │ ├── setono_sylius_gift_card_admin_gift_card_order.yaml │ │ └── setono_sylius_gift_card_shop_gift_card.yaml │ ├── routes.yaml │ ├── routes │ │ ├── admin.yaml │ │ ├── admin_ajax.yaml │ │ ├── admin_api.yaml │ │ └── shop.yaml │ ├── routes_no_locale.yaml │ ├── serialization │ │ ├── Channel.xml │ │ ├── Command │ │ │ ├── AddGiftCardToOrder.xml │ │ │ ├── AddItemToCartCommand.xml │ │ │ ├── AssociateConfigurationToChannel.xml │ │ │ ├── CreateGiftCardConfiguration.xml │ │ │ └── RemoveGiftCardFromOrder.xml │ │ ├── Customer.xml │ │ ├── GiftCard.xml │ │ ├── GiftCardBalance.xml │ │ ├── GiftCardChannelConfiguration.xml │ │ ├── GiftCardConfiguration.xml │ │ ├── GiftCardConfigurationImage.xml │ │ └── Product.xml │ ├── serializer │ │ └── Model.GiftCard.yml │ ├── services.xml │ ├── services │ │ ├── api.xml │ │ ├── api │ │ │ ├── command_handler.xml │ │ │ ├── controller.xml │ │ │ ├── data_persister.xml │ │ │ ├── data_transformer.xml │ │ │ └── doctrine.xml │ │ ├── applicator.xml │ │ ├── controller.xml │ │ ├── event_listener.xml │ │ ├── factory.xml │ │ ├── field_types.xml │ │ ├── fixture.xml │ │ ├── form.xml │ │ ├── generator.xml │ │ ├── menu.xml │ │ ├── misc.xml │ │ ├── modifier.xml │ │ ├── order.xml │ │ ├── order_processor.xml │ │ ├── promotion_rule.xml │ │ ├── provider.xml │ │ ├── renderer.xml │ │ ├── resolver.xml │ │ ├── serializer.xml │ │ ├── twig.xml │ │ ├── validator.xml │ │ └── voter.xml │ ├── state_machine │ │ ├── sylius_order.yaml │ │ ├── sylius_order_checkout.yaml │ │ └── sylius_order_payment.yaml │ ├── sylius_ui.yaml │ └── validation │ │ ├── AddGiftCardToOrderCommand.xml │ │ ├── AddToCardCommand.xml │ │ ├── AddToCardGiftCardInformation.xml │ │ ├── CreateGiftCardConfiguration.xml │ │ ├── GiftCard.xml │ │ ├── GiftCardChannelConfiguration.xml │ │ ├── GiftCardConfiguration.xml │ │ ├── GiftCardConfigurationImage.xml │ │ └── GiftCardSearchCommand.xml ├── fixtures │ └── default_background.png ├── public │ ├── setono-logo.png │ ├── setono-sylius-gift-card-add-gift-card-to-order.js │ ├── setono-sylius-gift-card-live-pdf-rendering.js │ └── setono-sylius-gift-card-send-notification-email.js ├── translations │ ├── flashes.da.yml │ ├── flashes.en.yml │ ├── flashes.fr.yml │ ├── messages.da.yml │ ├── messages.en.yml │ ├── messages.fr.yml │ ├── validators.da.yml │ ├── validators.en.yml │ └── validators.fr.yml └── views │ ├── Admin │ ├── GiftCard │ │ ├── Create │ │ │ └── _javascripts.html.twig │ │ ├── Grid │ │ │ ├── Action │ │ │ │ ├── create.html.twig │ │ │ │ ├── delete_conditional.html.twig │ │ │ │ ├── gift_card_balance.html.twig │ │ │ │ ├── list_conditional.html.twig │ │ │ │ └── resend_email.html.twig │ │ │ └── Field │ │ │ │ ├── amount.html.twig │ │ │ │ ├── channel_configurations.html.twig │ │ │ │ ├── customer.html.twig │ │ │ │ └── item_units_order.html.twig │ │ ├── _form.html.twig │ │ └── create.html.twig │ ├── GiftCardConfiguration │ │ ├── Create │ │ │ └── _breadcrumb.html.twig │ │ ├── Index │ │ │ └── _breadcrumb.html.twig │ │ ├── Update │ │ │ ├── _breadcrumb.html.twig │ │ │ └── _javascripts.html.twig │ │ ├── _form.html.twig │ │ └── _javascripts.html.twig │ ├── Order │ │ └── Grid │ │ │ └── Field │ │ │ └── coveredByGiftCards.html.twig │ └── giftCardBalance.html.twig │ ├── Cart │ └── _giftCard.html.twig │ ├── Email │ ├── giftCardToCustomer.html.twig │ └── giftCardsFromOrder.html.twig │ ├── Shop │ ├── Account │ │ └── GiftCard │ │ │ ├── Grid │ │ │ └── Field │ │ │ │ ├── amount.html.twig │ │ │ │ └── initial_amount.html.twig │ │ │ ├── Index │ │ │ ├── _breadcrumb.html.twig │ │ │ └── _header.html.twig │ │ │ └── index.html.twig │ ├── GiftCard │ │ └── search.html.twig │ ├── Product │ │ └── Show │ │ │ └── _addToCartGiftCardInformation.html.twig │ └── addGiftCardToOrder.html.twig │ └── templates │ └── bundles │ ├── SyliusAdminBundle │ ├── Form │ │ └── imagesTheme.html.twig │ └── Order │ │ └── Show │ │ └── Summary │ │ └── _totals.html.twig │ └── SyliusShopBundle │ ├── Cart │ ├── Summary │ │ └── _totals.html.twig │ └── summary.html.twig │ ├── Checkout │ └── _summary.html.twig │ └── Common │ └── Order │ └── Table │ └── _totals.html.twig ├── Security └── GiftCardVoter.php ├── Serializer └── Normalizer │ ├── GiftCardConfigurationNormalizer.php │ └── GiftCardNormalizer.php ├── SetonoSyliusGiftCardPlugin.php ├── Twig └── Extension │ ├── PdfExtension.php │ └── PdfRuntime.php └── Validator └── Constraints ├── DatePeriod.php ├── DatePeriodValidator.php ├── DefaultGiftCardConfigurationMustExist.php ├── DefaultGiftCardConfigurationMustExistValidator.php ├── GiftCardIsNotExpired.php ├── GiftCardIsNotExpiredValidator.php ├── HasBackgroundImage.php ├── HasBackgroundImageValidator.php └── Pdf ├── ValidOrientation.php ├── ValidOrientationValidator.php ├── ValidPageSize.php └── ValidPageSizeValidator.php /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 | -------------------------------------------------------------------------------- /psalm-baseline.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | LegacyIriConverterInterface|IriConverterInterface 6 | LegacyIriConverterInterface|IriConverterInterface 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /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/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/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/Api/Command/ConfigurationCodeAwareInterface.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/Api/Command/GiftCardCodeAwareInterface.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/Api/CommandHandler/AddGiftCardToOrderHandler.php: -------------------------------------------------------------------------------- 1 | giftCardRepository = $giftCardRepository; 29 | $this->orderRepository = $orderRepository; 30 | $this->giftCardApplicator = $giftCardApplicator; 31 | } 32 | 33 | public function __invoke(AddGiftCardToOrder $command): GiftCardInterface 34 | { 35 | $giftCardCode = $command->getGiftCardCode(); 36 | Assert::notNull($giftCardCode); 37 | 38 | $giftCard = $this->giftCardRepository->findOneByCode($giftCardCode); 39 | Assert::notNull($giftCard); 40 | 41 | /** @var OrderInterface|null $order */ 42 | $order = $this->orderRepository->findOneBy(['tokenValue' => $command->orderTokenValue]); 43 | Assert::notNull($order); 44 | 45 | $this->giftCardApplicator->apply($order, $giftCard); 46 | 47 | return $giftCard; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Api/CommandHandler/RemoveGiftCardFromOrderHandler.php: -------------------------------------------------------------------------------- 1 | giftCardRepository = $giftCardRepository; 29 | $this->orderRepository = $orderRepository; 30 | $this->giftCardApplicator = $giftCardApplicator; 31 | } 32 | 33 | public function __invoke(RemoveGiftCardFromOrder $command): GiftCardInterface 34 | { 35 | $giftCardCode = $command->getGiftCardCode(); 36 | Assert::notNull($giftCardCode); 37 | 38 | $giftCard = $this->giftCardRepository->findOneByCode($giftCardCode); 39 | Assert::notNull($giftCard); 40 | 41 | /** @var OrderInterface|null $order */ 42 | $order = $this->orderRepository->findOneBy(['tokenValue' => $command->orderTokenValue]); 43 | Assert::notNull($order); 44 | 45 | $this->giftCardApplicator->remove($order, $giftCard); 46 | 47 | return $giftCard; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /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/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/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/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/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/Api/DataTransformer/GiftCardConfigurationCodeAwareInputCommandDataTransformer.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/Applicator/GiftCardApplicatorInterface.php: -------------------------------------------------------------------------------- 1 | giftCard; 16 | } 17 | 18 | public function setGiftCard(?GiftCardInterface $giftCard): void 19 | { 20 | $this->giftCard = $giftCard; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /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/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/Controller/Action/SearchGiftCardCommand.php: -------------------------------------------------------------------------------- 1 | giftCard; 16 | } 17 | 18 | public function setGiftCard(?GiftCardInterface $giftCard): void 19 | { 20 | $this->giftCard = $giftCard; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/DependencyInjection/Compiler/AddAdjustmentsToOrderAdjustmentClearerPass.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/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 | -------------------------------------------------------------------------------- /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/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/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/EmailManager/GiftCardEmailManagerInterface.php: -------------------------------------------------------------------------------- 1 | $giftCards 17 | */ 18 | public function sendEmailWithGiftCardsFromOrder(OrderInterface $order, array $giftCards): void; 19 | } 20 | -------------------------------------------------------------------------------- /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/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriber.php: -------------------------------------------------------------------------------- 1 | giftCardEmailManager = $giftCardEmailManager; 24 | } 25 | 26 | public static function getSubscribedEvents(): array 27 | { 28 | return [ 29 | 'setono_sylius_gift_card.gift_card.post_create' => 'postCreate', 30 | ]; 31 | } 32 | 33 | public function postCreate(ResourceControllerEvent $event): void 34 | { 35 | $giftCard = $event->getSubject(); 36 | if (!$giftCard instanceof GiftCardInterface) { 37 | throw new UnexpectedTypeException($giftCard, GiftCardInterface::class); 38 | } 39 | 40 | $customer = $giftCard->getCustomer(); 41 | if (null === $customer) { 42 | return; 43 | } 44 | 45 | if (!$giftCard->getSendNotificationEmail()) { 46 | return; 47 | } 48 | 49 | $this->giftCardEmailManager->sendEmailToCustomerWithGiftCard($customer, $giftCard); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /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/Exception/ExceptionInterface.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/Exception/UnexpectedTypeException.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/Factory/GiftCardConfigurationFactoryInterface.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/Form/DataTransformer/GiftCardToCodeDataTransformer.php: -------------------------------------------------------------------------------- 1 | giftCardRepository = $giftCardRepository; 25 | $this->channelContext = $channelContext; 26 | } 27 | 28 | /** 29 | * @param GiftCardInterface|mixed $value 30 | */ 31 | public function transform($value): ?string 32 | { 33 | if (null === $value || '' === $value) { 34 | return $value; 35 | } 36 | 37 | Assert::isInstanceOf($value, GiftCardInterface::class); 38 | 39 | return $value->getCode(); 40 | } 41 | 42 | public function reverseTransform($value): ?GiftCardInterface 43 | { 44 | if (null === $value || '' === $value) { 45 | return null; 46 | } 47 | 48 | if (!is_string($value)) { 49 | throw new TransformationFailedException('Expected the value to be a string'); 50 | } 51 | 52 | $giftCard = $this->giftCardRepository->findOneEnabledByCodeAndChannel( 53 | $value, 54 | $this->channelContext->getChannel(), 55 | ); 56 | 57 | if (null !== $giftCard) { 58 | return $giftCard; 59 | } 60 | 61 | throw new TransformationFailedException('setono_sylius_gift_card.ui.gift_card_code_does_not_exist'); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /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/Form/Type/AddGiftCardToOrderType.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | final class AddGiftCardToOrderType extends AbstractType 18 | { 19 | private DataTransformerInterface $giftCardToCodeDataTransformer; 20 | 21 | private array $validationGroups; 22 | 23 | public function __construct(DataTransformerInterface $giftCardToCodeDataTransformer, array $validationGroups) 24 | { 25 | $this->giftCardToCodeDataTransformer = $giftCardToCodeDataTransformer; 26 | $this->validationGroups = $validationGroups; 27 | } 28 | 29 | public function buildForm(FormBuilderInterface $builder, array $options): void 30 | { 31 | $builder 32 | ->add('giftCard', TextType::class, [ 33 | 'label' => false, 34 | 'attr' => [ 35 | 'placeholder' => 'setono_sylius_gift_card.ui.enter_gift_card_code', 36 | ], 37 | 'invalid_message' => 'setono_sylius_gift_card.add_gift_card_to_order_command.gift_card.does_not_exist', 38 | ]) 39 | ; 40 | 41 | $builder->get('giftCard')->addModelTransformer($this->giftCardToCodeDataTransformer); 42 | } 43 | 44 | public function configureOptions(OptionsResolver $resolver): void 45 | { 46 | $resolver->setDefaults([ 47 | 'data_class' => AddGiftCardToOrderCommand::class, 48 | 'validation_groups' => $this->validationGroups, 49 | ]); 50 | } 51 | 52 | public function getBlockPrefix(): string 53 | { 54 | return 'setono_sylius_gift_card_add_gift_card_to_order'; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /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/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/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/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/Form/Type/GiftCardSearchType.php: -------------------------------------------------------------------------------- 1 | giftCardToCodeDataTransformer = $giftCardToCodeDataTransformer; 23 | $this->validationGroups = $validationGroups; 24 | } 25 | 26 | public function buildForm(FormBuilderInterface $builder, array $options): void 27 | { 28 | $builder 29 | ->add('giftCard', TextType::class, [ 30 | 'label' => false, 31 | 'attr' => [ 32 | 'placeholder' => 'setono_sylius_gift_card.ui.enter_gift_card_code', 33 | ], 34 | 'invalid_message' => 'setono_sylius_gift_card.gift_card_search_command.gift_card.does_not_exist', 35 | ]) 36 | ; 37 | 38 | $builder->get('giftCard')->addModelTransformer($this->giftCardToCodeDataTransformer); 39 | } 40 | 41 | public function configureOptions(OptionsResolver $resolver): void 42 | { 43 | $resolver->setDefaults([ 44 | 'data_class' => SearchGiftCardCommand::class, 45 | 'validation_groups' => $this->validationGroups, 46 | ]); 47 | } 48 | 49 | public function getBlockPrefix(): string 50 | { 51 | return 'setono_sylius_gift_card_gift_card_search'; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Form/Type/Rule/HasNoGiftCardConfigurationType.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/Generator/GiftCardCodeGeneratorInterface.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/Mailer/Emails.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/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/Model/AdjustmentInterface.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/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/Model/GiftCardChannelConfigurationInterface.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/Model/OrderItemTrait.php: -------------------------------------------------------------------------------- 1 | getProduct()->isGiftCard(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Model/OrderItemUnitInterface.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/Model/OrderTrait.php: -------------------------------------------------------------------------------- 1 | giftCards = new ArrayCollection(); 33 | } 34 | 35 | public function getGiftCards(): Collection 36 | { 37 | return $this->giftCards; 38 | } 39 | 40 | public function hasGiftCards(): bool 41 | { 42 | return !$this->giftCards->isEmpty(); 43 | } 44 | 45 | public function addGiftCard(GiftCardInterface $giftCard): void 46 | { 47 | assert($this instanceof OrderInterface); 48 | 49 | if (!$this->hasGiftCard($giftCard)) { 50 | $this->giftCards->add($giftCard); 51 | $giftCard->addAppliedOrder($this); 52 | } 53 | } 54 | 55 | public function removeGiftCard(GiftCardInterface $giftCard): void 56 | { 57 | assert($this instanceof OrderInterface); 58 | 59 | if ($this->hasGiftCard($giftCard)) { 60 | $this->giftCards->removeElement($giftCard); 61 | $giftCard->removeAppliedOrder($this); 62 | } 63 | } 64 | 65 | public function hasGiftCard(GiftCardInterface $giftCard): bool 66 | { 67 | return $this->giftCards->contains($giftCard); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Model/ProductInterface.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/Modifier/OrderGiftCardAmountModifierInterface.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/Order/AddToCartCommandInterface.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/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/Order/Factory/GiftCardInformationFactoryInterface.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/Order/GiftCardInformationInterface.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/Provider/DatePeriodUnitProvider.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 | 56 | TWIG; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Provider/DefaultGiftCardTemplateContentProviderInterface.php: -------------------------------------------------------------------------------- 1 | getTotal(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Provider/OrderEligibleTotalProviderInterface.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/Renderer/PdfRendererInterface.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/Repository/CustomerRepositoryInterface.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/Resolver/CustomerChannelResolverInterface.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/Resolver/RedirectUrlResolverInterface.php: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/Resources/config/doctrine/model/GiftCardConfiguration.orm.xml: -------------------------------------------------------------------------------- 1 | 3 | 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 | 32 | 33 | 34 | 35 | 36 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/Resources/config/doctrine/model/GiftCardConfigurationImage.orm.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /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/Resources/config/grids/setono_sylius_gift_card_admin_gift_card_configuration.yaml: -------------------------------------------------------------------------------- 1 | sylius_grid: 2 | grids: 3 | setono_sylius_gift_card_admin_gift_card_configuration: 4 | driver: 5 | name: doctrine/orm 6 | options: 7 | class: "%setono_sylius_gift_card.model.gift_card_configuration.class%" 8 | limits: [25, 50, 100] 9 | fields: 10 | code: 11 | type: string 12 | label: sylius.ui.code 13 | sortable: ~ 14 | enabled: 15 | type: twig 16 | label: sylius.ui.status 17 | sortable: ~ 18 | options: 19 | template: '@SyliusUi/Grid/Field/enabled.html.twig' 20 | default: 21 | type: twig 22 | label: sylius.ui.default 23 | sortable: ~ 24 | options: 25 | template: '@SyliusUi/Grid/Field/yesNo.html.twig' 26 | channel_configurations: 27 | type: twig 28 | label: setono_sylius_gift_card.ui.channel_configurations 29 | options: 30 | template: "@SetonoSyliusGiftCardPlugin/Admin/GiftCard/Grid/Field/channel_configurations.html.twig" 31 | filters: 32 | search: 33 | type: string 34 | label: sylius.ui.search 35 | options: 36 | fields: [code] 37 | actions: 38 | main: 39 | create: 40 | type: create 41 | item: 42 | update: 43 | type: update 44 | delete: 45 | type: gift_card_delete_conditional 46 | -------------------------------------------------------------------------------- /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/config/routes.yaml: -------------------------------------------------------------------------------- 1 | setono_sylius_gift_card_shop: 2 | resource: "@SetonoSyliusGiftCardPlugin/Resources/config/routes/shop.yaml" 3 | prefix: /{_locale} 4 | requirements: 5 | _locale: ^[A-Za-z]{2,4}(_([A-Za-z]{4}|[0-9]{3}))?(_([A-Za-z]{2}|[0-9]{3}))?$ 6 | 7 | setono_sylius_gift_card_admin: 8 | resource: "@SetonoSyliusGiftCardPlugin/Resources/config/routes/admin.yaml" 9 | prefix: /admin 10 | 11 | setono_sylius_gift_card_admin_ajax: 12 | resource: "@SetonoSyliusGiftCardPlugin/Resources/config/routes/admin_ajax.yaml" 13 | prefix: /admin/ajax 14 | 15 | setono_sylius_gift_card_admin_api: 16 | resource: "@SetonoSyliusGiftCardPlugin/Resources/config/routes/admin_api.yaml" 17 | prefix: /api/v{version} 18 | -------------------------------------------------------------------------------- /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/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/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/config/routes_no_locale.yaml: -------------------------------------------------------------------------------- 1 | setono_sylius_gift_card_shop: 2 | resource: "@SetonoSyliusGiftCardPlugin/Resources/config/routes/shop.yaml" 3 | 4 | setono_sylius_gift_card_admin: 5 | resource: "@SetonoSyliusGiftCardPlugin/Resources/config/routes/admin.yaml" 6 | prefix: /admin 7 | 8 | setono_sylius_gift_card_admin_ajax: 9 | resource: "@SetonoSyliusGiftCardPlugin/Resources/config/routes/admin_ajax.yaml" 10 | prefix: /admin/ajax 11 | 12 | setono_sylius_gift_card_admin_api: 13 | resource: "@SetonoSyliusGiftCardPlugin/Resources/config/routes/admin_api.yaml" 14 | prefix: /api/v{version} 15 | -------------------------------------------------------------------------------- /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/Resources/config/serialization/Command/AddGiftCardToOrder.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | shop:gift_card:add_to_order 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /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/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/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/serialization/Command/RemoveGiftCardFromOrder.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | shop:gift_card:remove_from_order 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /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/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/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/serialization/GiftCardConfiguration.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | admin:gift_card_configuration:read 10 | 11 | 12 | 13 | admin:gift_card_configuration:create 14 | admin:gift_card_configuration:read 15 | admin:gift_card_configuration:update 16 | 17 | 18 | 19 | admin:gift_card_configuration:create 20 | admin:gift_card_configuration:read 21 | admin:gift_card_configuration:update 22 | 23 | 24 | 25 | admin:gift_card_configuration:create 26 | admin:gift_card_configuration:read 27 | admin:gift_card_configuration:update 28 | 29 | 30 | 31 | admin:gift_card_configuration:read 32 | 33 | 34 | 35 | admin:gift_card_configuration:read 36 | 37 | 38 | 39 | admin:gift_card_configuration:read 40 | 41 | 42 | 43 | admin:gift_card_configuration:read 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /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/config/serialization/Product.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | admin:product:create 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /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/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/Resources/config/services/api.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/Resources/config/services/api/data_persister.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /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/services/api/doctrine.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/Resources/config/services/applicator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/Resources/config/services/event_listener.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 22 | 23 | 24 | 25 | 28 | 29 | 30 | 32 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /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/Resources/config/services/field_types.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /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/services/menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/Resources/config/services/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/Resources/config/services/modifier.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/Resources/config/services/order.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | Setono\SyliusGiftCardPlugin\Order\GiftCardInformation 7 | Setono\SyliusGiftCardPlugin\Order\AddToCartCommand 8 | 9 | 10 | 11 | 13 | %setono_sylius_gift_card.order.model.gift_card_information.class% 14 | 15 | 17 | 18 | 20 | %setono_sylius_gift_card.order.model.add_to_cart_command.class% 21 | 22 | 23 | 24 | 25 | %setono_sylius_gift_card.order.model.add_to_cart_command.class% 26 | %sylius.form.type.add_to_cart.validation_groups% 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/Resources/config/services/order_processor.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/Resources/config/services/promotion_rule.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 9 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/Resources/config/services/renderer.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /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/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/twig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/Resources/config/services/voter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /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/state_machine/sylius_order_checkout.yaml: -------------------------------------------------------------------------------- 1 | winzou_state_machine: 2 | sylius_order_checkout: 3 | callbacks: 4 | after: 5 | setono_gift_card_associate_to_customer: 6 | on: ["complete"] 7 | do: ["@setono_sylius_gift_card.operator.order_gift_card", "associateToCustomer"] 8 | args: ["object"] 9 | -------------------------------------------------------------------------------- /src/Resources/config/state_machine/sylius_order_payment.yaml: -------------------------------------------------------------------------------- 1 | winzou_state_machine: 2 | sylius_order_payment: 3 | callbacks: 4 | after: 5 | setono_gift_card_enable: 6 | on: ["pay"] 7 | do: ["@setono_sylius_gift_card.operator.order_gift_card", "enable"] 8 | args: ["object"] 9 | setono_gift_card_send: 10 | on: ["pay"] 11 | do: ["@setono_sylius_gift_card.operator.order_gift_card", "send"] 12 | args: ["object"] 13 | -------------------------------------------------------------------------------- /src/Resources/config/sylius_ui.yaml: -------------------------------------------------------------------------------- 1 | sylius_ui: 2 | events: 3 | sylius.shop.product.show.add_to_cart_form: 4 | blocks: 5 | setono_sylius_gift_card_information: 6 | template: '@SetonoSyliusGiftCardPlugin/Shop/Product/Show/_addToCartGiftCardInformation.html.twig' 7 | priority: 10 8 | -------------------------------------------------------------------------------- /src/Resources/config/validation/AddGiftCardToOrderCommand.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/Resources/config/validation/AddToCardCommand.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/Resources/config/validation/AddToCardGiftCardInformation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/Resources/config/validation/CreateGiftCardConfiguration.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 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 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /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/Resources/config/validation/GiftCardConfigurationImage.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/Resources/config/validation/GiftCardSearchCommand.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/Resources/fixtures/default_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Setono/SyliusGiftCardPlugin/0fc00ddaec0b6e32579ea14171c19dd4a7d5243c/src/Resources/fixtures/default_background.png -------------------------------------------------------------------------------- /src/Resources/public/setono-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Setono/SyliusGiftCardPlugin/0fc00ddaec0b6e32579ea14171c19dd4a7d5243c/src/Resources/public/setono-logo.png -------------------------------------------------------------------------------- /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/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/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/translations/flashes.da.yml: -------------------------------------------------------------------------------- 1 | setono_sylius_gift_card: 2 | gift_card: 3 | delete_error: Gavekortskoden kan ikke fjernes 4 | impossible_to_resend_email: 'Ikke muligt at sende email for gavekort med id "%id%" igen' 5 | not_found: 'Ikke muligt at finde gavekort med id "%id%"' 6 | read_error: Ikke muligt at se dette gavekort. 7 | resent: Emailen er blevet sendt igen 8 | gift_card_added: Gavekortet er blevet tilføjet til din ordre 9 | gift_card_removed: Gavekortet er blevet fjernet fra din ordre 10 | -------------------------------------------------------------------------------- /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/Resources/translations/flashes.fr.yml: -------------------------------------------------------------------------------- 1 | setono_sylius_gift_card: 2 | gift_card: 3 | delete_error: Le chèque-cadeau n'a pas pu être supprimé. 4 | impossible_to_resend_email: 'Impossible d''envoyer l''email pour le chèque-cadeau "%id%"' 5 | not_found: 'Impossible de trouver le chèque-cadeau "%id%"' 6 | read_error: Impossible the visualiser le chèque-cadeau. 7 | resent: L'email a bien été renvoyé 8 | gift_card_added: Le chèque-cadeau a été ajouté à votre commande 9 | gift_card_removed: Le chèque-cadeau a été supprimé de votre commande 10 | -------------------------------------------------------------------------------- /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/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/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/views/Admin/GiftCard/Create/_javascripts.html.twig: -------------------------------------------------------------------------------- 1 | 2 | 7 | -------------------------------------------------------------------------------- /src/Resources/views/Admin/GiftCard/Grid/Action/create.html.twig: -------------------------------------------------------------------------------- 1 | {# todo this should be a knp menu builder instead #} 2 | 9 | -------------------------------------------------------------------------------- /src/Resources/views/Admin/GiftCard/Grid/Action/delete_conditional.html.twig: -------------------------------------------------------------------------------- 1 | {% import '@SyliusUi/Macro/buttons.html.twig' as buttons %} 2 | 3 | {% set visible = options.visible is defined ? options.visible : true %} 4 | {% if visible %} 5 | {% include '@SyliusUi/Grid/Action/delete.html.twig' %} 6 | {% endif %} 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/Resources/views/Admin/GiftCard/Grid/Action/list_conditional.html.twig: -------------------------------------------------------------------------------- 1 | {% import '@SyliusUi/Macro/buttons.html.twig' as buttons %} 2 | 3 | {% set path = options.link.url|default(path(options.link.route, options.link.parameters)) %} 4 | {% set visible = options.visible is defined ? options.visible : true %} 5 | 6 | {% if visible %} 7 | {{ buttons.default(path, action.label, null, 'list', 'primary') }} 8 | {% endif %} 9 | -------------------------------------------------------------------------------- /src/Resources/views/Admin/GiftCard/Grid/Action/resend_email.html.twig: -------------------------------------------------------------------------------- 1 | {% import '@SyliusUi/Macro/buttons.html.twig' as buttons %} 2 | 3 | 4 | {% set visible = options.visible is defined ? options.visible : true %} 5 | 6 | {% if visible %} 7 | {% set path = options.link.url|default(path(options.link.route, options.link.parameters)) %} 8 | 9 | {{ buttons.default(path, action.label, null, 'mail', 'purple') }} 10 | {% endif %} 11 | -------------------------------------------------------------------------------- /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/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/Resources/views/Admin/GiftCard/Grid/Field/customer.html.twig: -------------------------------------------------------------------------------- 1 | {# @var data \Sylius\Component\Core\Model\CustomerInterface|null #} 2 | {% if data is null %} 3 | {{ 'setono_sylius_gift_card.ui.no_customer'|trans }} 4 | {% else %} 5 | {{ data.emailCanonical }} 6 | {% endif %} 7 | -------------------------------------------------------------------------------- /src/Resources/views/Admin/GiftCard/Grid/Field/item_units_order.html.twig: -------------------------------------------------------------------------------- 1 | {# @var \Sylius\Component\Core\Model\OrderItemUnitInterface data #} 2 | 3 | {% if data is not null %} 4 | {% set order = data.orderItem.order %} 5 | {% if order.number is null %} 6 | {{ 'setono_sylius_gift_card.ui.in_cart'|trans }} 7 | {% else %} 8 | #{{ order.number }} 9 | {% endif %} 10 | {% else %} 11 | {{ 'setono_sylius_gift_card.ui.manually_created'|trans }} 12 | {% endif %} 13 | -------------------------------------------------------------------------------- /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 | 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/Resources/views/Admin/GiftCard/create.html.twig: -------------------------------------------------------------------------------- 1 | {% for channel in channels %} 2 | 3 | {{ 'setono_sylius_gift_card.ui.create_for_channel'|trans({ '%channel%': channel.name }) }} 4 | 5 | {% endfor %} 6 | -------------------------------------------------------------------------------- /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/views/Admin/GiftCardConfiguration/Index/_breadcrumb.html.twig: -------------------------------------------------------------------------------- 1 | {% import '@SyliusAdmin/Macro/breadcrumb.html.twig' as breadcrumb %} 2 | 3 | {% set breadcrumbs = [ 4 | { label: 'sylius.ui.administration'|trans, url: path('sylius_admin_dashboard') }, 5 | { label: 'setono_sylius_gift_card.ui.gift_cards'|trans, url: path('setono_sylius_gift_card_admin_gift_card_index') }, 6 | { label: (metadata.applicationName~'.ui.'~metadata.pluralName)|trans }, 7 | ] 8 | %} 9 | 10 | {{ breadcrumb.crumble(breadcrumbs) }} 11 | -------------------------------------------------------------------------------- /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/views/Admin/GiftCardConfiguration/Update/_javascripts.html.twig: -------------------------------------------------------------------------------- 1 | 2 | 7 | -------------------------------------------------------------------------------- /src/Resources/views/Admin/GiftCardConfiguration/_javascripts.html.twig: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /src/Resources/views/Admin/Order/Grid/Field/coveredByGiftCards.html.twig: -------------------------------------------------------------------------------- 1 | {# @var \Setono\SyliusGiftCardPlugin\Model\OrderInterface data #} 2 | {% import "@SyliusAdmin/Common/Macro/money.html.twig" as money %} 3 | 4 | {% set giftCardAdjustment = constant('Setono\\SyliusGiftCardPlugin\\Model\\AdjustmentInterface::ORDER_GIFT_CARD_ADJUSTMENT') %} 5 | {% set giftCardAdjustmentsTotal = data.getAdjustmentsTotal(giftCardAdjustment) %} 6 | 7 | {{ money.format(-giftCardAdjustmentsTotal, data.currencyCode) }} 8 | -------------------------------------------------------------------------------- /src/Resources/views/Cart/_giftCard.html.twig: -------------------------------------------------------------------------------- 1 | {{ render(url('setono_sylius_gift_card_shop_partial_add_gift_card_to_order')) }} 2 | -------------------------------------------------------------------------------- /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/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/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/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/Resources/views/Shop/Account/GiftCard/Index/_breadcrumb.html.twig: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /src/Resources/views/Shop/Account/GiftCard/Index/_header.html.twig: -------------------------------------------------------------------------------- 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/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/Resources/views/Shop/GiftCard/search.html.twig: -------------------------------------------------------------------------------- 1 | {# @var \Setono\SyliusGiftCardPlugin\Model\GiftCardInterface giftCard #} 2 | {% extends '@SyliusShop/layout.html.twig' %} 3 | 4 | {% import "@SyliusShop/Common/Macro/money.html.twig" as money %} 5 | 6 | {% form_theme form '@SyliusShop/Form/theme.html.twig' %} 7 | 8 | {% block content %} 9 | 14 |
15 |

16 | {{ 'setono_sylius_gift_card.ui.gift_card_search'|trans }} 17 |

18 | 19 | {{ form_start(form, {'attr': {'class': 'ui form', 'novalidate': 'novalidate'}}) }} 20 | {{ form_errors(form) }} 21 | {{ form_row(form.giftCard) }} 22 | 23 | {{ form_row(form._token) }} 24 | {{ form_end(form, {'render_rest': false}) }} 25 | 26 | {% if giftCard is not null %} 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 |
{{ 'setono_sylius_gift_card.ui.gift_card'|trans }}{{ 'setono_sylius_gift_card.ui.amount'|trans }}{{ 'setono_sylius_gift_card.ui.initial_amount'|trans }}
{{ giftCard.code }}{{ money.format(giftCard.amount, giftCard.currencyCode) }}{{ money.format(giftCard.initialAmount, giftCard.currencyCode) }}
43 | {% endif %} 44 |
45 | {% endblock %} 46 | -------------------------------------------------------------------------------- /src/Resources/views/Shop/Product/Show/_addToCartGiftCardInformation.html.twig: -------------------------------------------------------------------------------- 1 | {% if form.giftCardInformation is defined %} 2 | {% set giftCardInformationForm = form.giftCardInformation %} 3 | {% if giftCardInformationForm.amount is defined %} 4 | {{ form_row(giftCardInformationForm.amount, sylius_test_form_attribute('gift-card-amount-input')) }} 5 | {% endif %} 6 | {{ form_row(giftCardInformationForm.customMessage, sylius_test_form_attribute('gift-card-custom-message-input')) }} 7 | {% endif %} 8 | -------------------------------------------------------------------------------- /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/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 | {{ form.vars.value.type }} 10 | {%- endif -%} 11 | 14 |
15 | {{- form_errors(form.file) -}} 16 |
17 | {% endblock %} 18 | -------------------------------------------------------------------------------- /src/Resources/views/templates/bundles/SyliusAdminBundle/Order/Show/Summary/_totals.html.twig: -------------------------------------------------------------------------------- 1 | {% import "@SyliusAdmin/Common/Macro/money.html.twig" as money %} 2 | 3 | {% set giftCardAdjustment = constant('Setono\\SyliusGiftCardPlugin\\Model\\AdjustmentInterface::ORDER_GIFT_CARD_ADJUSTMENT') %} 4 | {% set giftCardAdjustments = order.getAdjustments(giftCardAdjustment) %} 5 | {% set giftCardAdjustmentsTotal = order.getAdjustmentsTotal(giftCardAdjustment) %} 6 | 7 | 8 | 9 | {% if giftCardAdjustments is not empty %} 10 |
11 |
12 | {{ 'setono_sylius_gift_card.ui.gift_cards'|trans }}: 13 |
14 | {% for adjustment in giftCardAdjustments %} 15 |
16 |
{{ money.format(adjustment.amount, order.currencyCode) }}
17 | 24 |
25 | {% endfor %} 26 |
27 | {% else %} 28 |

{{ 'setono_sylius_gift_card.ui.no_gift_card'|trans }}.

29 | {% endif %} 30 | 31 | 32 | {{ 'setono_sylius_gift_card.ui.gift_cards_adjustment_total'|trans }}: 33 | {{ money.format(giftCardAdjustmentsTotal, order.currencyCode) }} 34 | 35 | 36 | -------------------------------------------------------------------------------- /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/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 | 27 | 30 | 31 | {% endfor %} 32 | 33 |
21 | {{ adjustment.originCode }} 22 | 23 | 24 | 25 | 26 | 28 | {{ money.convertAndFormat(-adjustment.amount) }} 29 |
34 |
35 | {% endif %} 36 | -------------------------------------------------------------------------------- /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/views/templates/bundles/SyliusShopBundle/Common/Order/Table/_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 giftCardTotal = order.getAdjustmentsTotal(giftCardAdjustment) %} 5 | 6 | {% if giftCardTotal %} 7 | {% set giftCardAdjustments = order.getAdjustments(giftCardAdjustment) %} 8 | 9 | {% if giftCardAdjustments is not empty %} 10 | 11 |
12 | {% for adjustment in giftCardAdjustments %} 13 |
14 |
15 | 16 | {{ adjustment.label }} 17 | 18 | {{ adjustment.originCode }} 19 | 20 | 21 |
22 | {{ money.convertAndFormat(adjustment.amount) }} 23 |
24 |
25 |
26 | {% endfor %} 27 |
28 | 29 | {% endif %} 30 | 31 | {{ 'setono_sylius_gift_card.ui.gift_cards_adjustment_total'|trans }}: {{ money.convertAndFormat(giftCardTotal) }} 32 | 33 | 34 | {% endif %} 35 | -------------------------------------------------------------------------------- /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/Twig/Extension/PdfExtension.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/Validator/Constraints/DatePeriod.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/Validator/Constraints/DefaultGiftCardConfigurationMustExist.php: -------------------------------------------------------------------------------- 1 | giftCardConfigurationRepository = $giftCardConfigurationRepository; 20 | } 21 | 22 | /** 23 | * @param mixed $value 24 | */ 25 | public function validate($value, Constraint $constraint): void 26 | { 27 | if (!$constraint instanceof DefaultGiftCardConfigurationMustExist) { 28 | throw new UnexpectedTypeException($constraint, DefaultGiftCardConfigurationMustExist::class); 29 | } 30 | 31 | if (!$value instanceof GiftCardConfigurationInterface) { 32 | throw new UnexpectedTypeException($value, GiftCardConfigurationInterface::class); 33 | } 34 | 35 | if ($value->isDefault()) { 36 | return; 37 | } 38 | 39 | $defaultGiftCardConfiguration = $this->giftCardConfigurationRepository->findDefault(); 40 | if (null === $defaultGiftCardConfiguration || $defaultGiftCardConfiguration->getId() === $value->getId()) { 41 | $this->context->buildViolation($constraint->message) 42 | ->atPath('default') 43 | ->addViolation() 44 | ; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Validator/Constraints/GiftCardIsNotExpired.php: -------------------------------------------------------------------------------- 1 | isExpired()) { 30 | $this->context->buildViolation($constraint->message)->addViolation(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Validator/Constraints/HasBackgroundImage.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/Validator/Constraints/Pdf/ValidOrientation.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/Validator/Constraints/Pdf/ValidPageSize.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 | --------------------------------------------------------------------------------