Skip to content

Commit

Permalink
Merge pull request #15 from BitBagCommerce/OPSRC-518/add_quick_return
Browse files Browse the repository at this point in the history
Opsrc 518/add quick return
  • Loading branch information
PiotrSzymanski2000 authored Apr 27, 2022
2 parents 84f7368 + c026c5c commit c92d4db
Show file tree
Hide file tree
Showing 13 changed files with 248 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/Form/Type/ShippingGatewayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
37 changes: 37 additions & 0 deletions src/Resolver/IsQuickReturnResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace BitBag\SyliusInPostPlugin\Resolver;

use BitBag\SyliusShippingExportPlugin\Repository\ShippingGatewayRepositoryInterface;

final class IsQuickReturnResolver implements IsQuickReturnResolverInterface
{
private ShippingGatewayRepositoryInterface $shippingGatewayRepository;

public function __construct(ShippingGatewayRepositoryInterface $shippingGatewayRepository)
{
$this->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;
}
}
14 changes: 14 additions & 0 deletions src/Resolver/IsQuickReturnResolverInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

namespace BitBag\SyliusInPostPlugin\Resolver;

interface IsQuickReturnResolverInterface
{
public function getIsQuickReturn(): bool;
}
36 changes: 36 additions & 0 deletions src/Resolver/OrganizationIdResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace BitBag\SyliusInPostPlugin\Resolver;

use BitBag\SyliusShippingExportPlugin\Entity\ShippingGatewayInterface;
use BitBag\SyliusShippingExportPlugin\Repository\ShippingGatewayRepositoryInterface;

final class OrganizationIdResolver implements OrganizationIdResolverInterface
{
private ShippingGatewayRepositoryInterface $shippingGatewayRepository;

public function __construct(ShippingGatewayRepositoryInterface $shippingGatewayRepository)
{
$this->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'] ?? '';
}
}
16 changes: 16 additions & 0 deletions src/Resolver/OrganizationIdResolverInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

namespace BitBag\SyliusInPostPlugin\Resolver;

interface OrganizationIdResolverInterface
{
public const INPOST_CODE = 'inpost';

public function getOrganizationId(): string;
}
1 change: 1 addition & 0 deletions src/Resources/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ imports:
- { resource: "@BitBagSyliusInPostPlugin/Resources/config/services.xml" }
- { resource: "@BitBagSyliusInPostPlugin/Resources/config/resource/bitbag_inpost.yml" }
- { resource: "@BitBagSyliusInPostPlugin/Resources/config/sylius_ui.yml" }
- { resource: "@BitBagSyliusInPostPlugin/Resources/config/grid/*" }
twig:
globals:
inpost_client: '@bitbag.sylius_inpost_plugin.api.web_client'
34 changes: 34 additions & 0 deletions src/Resources/config/grid/order.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski

sylius_grid:
templates:
action:
shop_quick_return: "@SyliusShop/Grid/Action/quickReturn.html.twig"
grids:
sylius_shop_account_order:
actions:
item:
quick_return:
type: shop_quick_return
label: bitbag_sylius_inpost_plugin.ui.quick_return
options:
link:
route: sylius_shop_account_order_return

show:
type: shop_show
label: sylius.ui.show
options:
link:
route: sylius_shop_account_order_show
parameters:
number: resource.number
pay:
type: shop_pay
label: sylius.ui.pay
options:
link:
route: sylius_shop_order_show
parameters:
tokenValue: resource.tokenValue
2 changes: 1 addition & 1 deletion src/Resources/config/routes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ bitbag_sylius_inpost_plugin_admin_add_point_to_order:
path: /admin/point
methods: [POST]
defaults:
_controller: bitbag.sylius_inpost_plugin.controller.add_point_to_order:addPointToOrderAction
_controller: bitbag.sylius_inpost_plugin.controller.add_point_to_order:addPointToOrderAction
22 changes: 22 additions & 0 deletions src/Resources/config/services/resolver.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service
class="BitBag\SyliusInPostPlugin\Resolver\OrganizationIdResolver"
id="bitbag.sylius_inpost_plugin.resolver.organization_id_resolver"
public="true"
>
<argument type="service" id="bitbag.repository.shipping_gateway"/>
</service>

<service
class="BitBag\SyliusInPostPlugin\Resolver\IsQuickReturnResolver"
id="bitbag.sylius_inpost_plugin.resolver.is_quick_return_resolver"
public="true"
>
<argument type="service" id="bitbag.repository.shipping_gateway"/>
</service>
</services>
</container>
12 changes: 12 additions & 0 deletions src/Resources/config/services/twig_extension.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="BitBag\SyliusInPostPlugin\TwigExtension\ShippingInpostCodeExtension" public="false">
<argument type="service" id="bitbag.sylius_inpost_plugin.resolver.is_quick_return_resolver"/>
<argument type="service" id="bitbag.sylius_inpost_plugin.resolver.organization_id_resolver"/>
<tag name="twig.extension" />
</service>
</services>
</container>
4 changes: 3 additions & 1 deletion src/Resources/translations/messages.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,4 +30,4 @@ bitbag_sylius_inpost_plugin:
sms: SMS Notification
email: E-mail Notification
saturday: Saturday Delivery
rod: ROD
rod: ROD
54 changes: 54 additions & 0 deletions src/TwigExtension/ShippingInpostCodeExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace BitBag\SyliusInPostPlugin\TwigExtension;

use BitBag\SyliusInPostPlugin\Resolver\IsQuickReturnResolverInterface;
use BitBag\SyliusInPostPlugin\Resolver\OrganizationIdResolverInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

final class ShippingInpostCodeExtension extends AbstractExtension
{
public const ULR_TO_INPOST_QUICK_RETURN = "https://www.szybkiezwroty.pl/";

public IsQuickReturnResolverInterface $isQuickReturnResolver;

private OrganizationIdResolverInterface $organizationIdResolver;


public function __construct(
IsQuickReturnResolverInterface $isQuickReturnResolver,
OrganizationIdResolverInterface $organizationIdResolver
) {
$this->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 "";
}
}
Original file line number Diff line number Diff line change
@@ -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 %}

0 comments on commit c92d4db

Please sign in to comment.