diff --git a/src/Form/Type/ShippingGatewayType.php b/src/Form/Type/ShippingGatewayType.php index 52d427e..f8cffe1 100644 --- a/src/Form/Type/ShippingGatewayType.php +++ b/src/Form/Type/ShippingGatewayType.php @@ -17,6 +17,8 @@ use Symfony\Component\Form\Extension\Core\Type\NumberType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Form\FormEvent; +use Symfony\Component\Form\FormEvents; use Symfony\Component\Validator\Constraints\NotBlank; final class ShippingGatewayType extends AbstractType @@ -97,6 +99,17 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('is_return', CheckboxType::class, [ 'label' => 'bitbag_sylius_inpost_plugin.ui.is_return', ]) + ->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event): void { + $data = $event->getData(); + if (isset($data['organization_id'])){ + $event + ->getForm() + ->add('is_quick_return', CheckboxType::class, [ + 'label' => 'bitbag_sylius_inpost_plugin.ui.is_quick_return', + ]) + ; + } + }) ->add('additional_services', ChoiceType::class, [ 'label' => 'bitbag_sylius_inpost_plugin.ui.additional_services', 'choices' => self::ADDITIONAL_SERVICE_CHOICES, diff --git a/src/Resolver/IsQuickReturnResolver.php b/src/Resolver/IsQuickReturnResolver.php new file mode 100644 index 0000000..ba88bf7 --- /dev/null +++ b/src/Resolver/IsQuickReturnResolver.php @@ -0,0 +1,37 @@ +shippingGatewayRepository = $shippingGatewayRepository; + } + + public function getIsQuickReturn(): bool + { + $shippingGateway = $this->shippingGatewayRepository + ->findOneByCode(OrganizationIdResolverInterface::INPOST_CODE); + + $config = $shippingGateway->getConfig(); + + if (null === $config){ + throw new \Exception('Can not found config data'); + } + + return $config['is_quick_return'] ?? false; + } +} diff --git a/src/Resolver/IsQuickReturnResolverInterface.php b/src/Resolver/IsQuickReturnResolverInterface.php new file mode 100644 index 0000000..f127661 --- /dev/null +++ b/src/Resolver/IsQuickReturnResolverInterface.php @@ -0,0 +1,14 @@ +shippingGatewayRepository = $shippingGatewayRepository; + } + + public function getOrganizationId(): string + { + $shippingGateway = $this->shippingGatewayRepository->findOneByCode(self::INPOST_CODE); + $config = $shippingGateway->getConfig(); + + if (null === $config){ + throw new \Exception('Can not found config data'); + } + + return $config['organization_id'] ?? ''; + } +} diff --git a/src/Resolver/OrganizationIdResolverInterface.php b/src/Resolver/OrganizationIdResolverInterface.php new file mode 100644 index 0000000..105d6a4 --- /dev/null +++ b/src/Resolver/OrganizationIdResolverInterface.php @@ -0,0 +1,16 @@ + + + + + + + + + + + + + diff --git a/src/Resources/config/services/twig_extension.xml b/src/Resources/config/services/twig_extension.xml new file mode 100644 index 0000000..8a4797f --- /dev/null +++ b/src/Resources/config/services/twig_extension.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + diff --git a/src/Resources/translations/messages.en.yml b/src/Resources/translations/messages.en.yml index 47a86a8..88c48a4 100644 --- a/src/Resources/translations/messages.en.yml +++ b/src/Resources/translations/messages.en.yml @@ -14,6 +14,8 @@ bitbag_sylius_inpost_plugin: selected_point: Selected point no_point_selected: No point selected not_blank: This field cannot be blank + is_quick_return: Quick Return + quick_return: Quick Return main_service: inpost_locker_standard: Inpost Locker Standard inpost_locker_pass_thru: Inpost Locker Pass Thru @@ -28,4 +30,4 @@ bitbag_sylius_inpost_plugin: sms: SMS Notification email: E-mail Notification saturday: Saturday Delivery - rod: ROD \ No newline at end of file + rod: ROD diff --git a/src/TwigExtension/ShippingInpostCodeExtension.php b/src/TwigExtension/ShippingInpostCodeExtension.php new file mode 100644 index 0000000..5f1b59f --- /dev/null +++ b/src/TwigExtension/ShippingInpostCodeExtension.php @@ -0,0 +1,54 @@ +isQuickReturnResolver = $isQuickReturnResolver; + $this->organizationIdResolver = $organizationIdResolver; + + } + + public function getFunctions(): array + { + return [ + new TwigFunction('quick_return', [$this, 'isInpostShippingCode']), + ]; + } + + public function isInpostShippingCode(): string + { + $isQuickReturn = $this->isQuickReturnResolver->getIsQuickReturn(); + $organizationId = $this->organizationIdResolver->getOrganizationId(); + + if ($isQuickReturn && $organizationId !== "") { + return sprintf("%s%s",self::ULR_TO_INPOST_QUICK_RETURN, $organizationId); + } + + return ""; + } +} diff --git a/tests/Application/templates/bundles/SyliusShopBundle/Grid/Action/quickReturn.html.twig b/tests/Application/templates/bundles/SyliusShopBundle/Grid/Action/quickReturn.html.twig new file mode 100644 index 0000000..0a15769 --- /dev/null +++ b/tests/Application/templates/bundles/SyliusShopBundle/Grid/Action/quickReturn.html.twig @@ -0,0 +1,5 @@ +{% import '@SyliusUi/Macro/buttons.html.twig' as buttons %} + +{% if data.point and quick_return() != "" %} + {{ buttons.default(quick_return(), action.label, null, 'redo', 'purple' ) }} +{% endif %}