-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from BitBagCommerce/OPSRC-518/add_quick_return
Opsrc 518/add quick return
- Loading branch information
Showing
13 changed files
with
248 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] ?? ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ""; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
tests/Application/templates/bundles/SyliusShopBundle/Grid/Action/quickReturn.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |