Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"require": {
"php": "~7.3 || ~7.4 || ~8.0 || ~8.1 || ~8.2",
"alma/alma-php-client": ">=1.11.2",
"sylius/sylius": ">=v1.9.0",
"sylius/sylius": ">=v2.1.6",
"ext-json": "*"
},
"require-dev": {
Expand All @@ -30,7 +30,6 @@
"friends-of-behat/suite-settings-extension": "^1.0",
"friends-of-behat/symfony-extension": "^2.1",
"friends-of-behat/variadic-extension": "^1.3",
"friendsofsymfony/oauth-server-bundle": "^1.6 || >2.0.0-alpha.0 ^2.0@dev",
"lakion/mink-debug-extension": "^2.0.0",
"phpspec/phpspec": "^7.0",
"phpstan/extension-installer": "^1.0",
Expand All @@ -39,14 +38,13 @@
"phpstan/phpstan-strict-rules": "^0.12.0",
"phpstan/phpstan-webmozart-assert": "0.12.12",
"phpunit/phpunit": "^9.5",
"sensiolabs/security-checker": "^6.0",
"sylius-labs/coding-standard": "^3.1",
"symfony/browser-kit": "^4.4 || ^5.2",
"symfony/debug-bundle": "^4.4 || ^5.2",
"sylius-labs/coding-standard": "^4.4",
"symfony/browser-kit": "^7.3",
"symfony/debug-bundle": "^7.3",
"symfony/dotenv": "^4.4 || ^5.2",
"symfony/intl": "^4.4 || ^5.2",
"symfony/web-profiler-bundle": "^4.4 || ^5.2",
"vimeo/psalm": "4.6.4"
"symfony/intl": "^6.4 || ^7.2",
"symfony/web-profiler-bundle": "^7.3",
"vimeo/psalm": "6.13.1"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -74,7 +72,8 @@
"symfony/thanks": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true,
"symfony/flex": true
"symfony/flex": true,
"php-http/discovery": true
}
}
}
17 changes: 3 additions & 14 deletions src/DataBuilder/CartDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,13 @@ class CartDataBuilder implements DataBuilderInterface
* @var CacheManager
*/
private $liipCacheManager;
/**
* @var TaxRateResolverInterface
*/
private $taxRateResolver;

public function __construct(
RouterInterface $router,
CacheManager $liipCacheManager,
TaxRateResolverInterface $taxRateResolver
) {
$this->router = $router;
$this->liipCacheManager = $liipCacheManager;
$this->taxRateResolver = $taxRateResolver;
}

public function __invoke(array $data, PaymentInterface $payment): array
Expand Down Expand Up @@ -93,7 +87,7 @@ private function getItems(OrderInterface $order): array
'url' => $this->getProductUrl($product),
'picture_url' => $this->getProductPictureUrl($variant),
'requires_shipping' => $variant->isShippingRequired(),
'taxes_included' => $this->isTaxIncluded($variant),
'taxes_included' => $this->isTaxIncluded(),
];
}, $items));
}
Expand Down Expand Up @@ -172,14 +166,9 @@ private function getProductPictureUrl(ProductVariantInterface $variant): string
return $url;
}

private function isTaxIncluded(ProductVariantInterface $variant): bool
private function isTaxIncluded(): bool
{
$taxRate = $this->taxRateResolver->resolve($variant);
if ($taxRate === null) {
return false;
}

return $taxRate->isIncludedInPrice();
return true;
}

private function getDiscounts(OrderInterface $order): array
Expand Down
24 changes: 22 additions & 2 deletions src/DataBuilder/ShippingInfoDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\Model\ShipmentInterface;
use Sylius\Component\Core\Model\ShippingMethodInterface;
use Sylius\Component\Registry\PrioritizedServiceRegistryInterface;
use Sylius\Component\Registry\ServiceRegistryInterface;
use Sylius\Component\Shipping\Calculator\CalculatorInterface;
use Sylius\Component\Shipping\Model\ShippingMethodInterface as BaseShippingMethodInterface;
Expand All @@ -30,7 +31,7 @@ class ShippingInfoDataBuilder implements DataBuilderInterface

public function __construct(
ServiceRegistryInterface $calculators,
ShippingMethodsResolverInterface $methodsResolver
$methodsResolver
) {
$this->methodsResolver = $methodsResolver;
$this->calculators = $calculators;
Expand Down Expand Up @@ -84,7 +85,8 @@ private function getAvailableOptions(array $shipments): array
$options = [];

foreach ($shipments as $shipment) {
if (!$this->methodsResolver->supports($shipment)) {
$resolver = $this->getActualResolver();
if (!$resolver->supports($shipment)) {
continue;
}

Expand All @@ -98,6 +100,24 @@ private function getAvailableOptions(array $shipments): array
return $options;
}

/**
* Récupère le bon resolver selon le type injecté
*/
private function getActualResolver(): ShippingMethodsResolverInterface
{
if ($this->methodsResolver instanceof ShippingMethodsResolverInterface) {
return $this->methodsResolver;
}

// Si c'est un PrioritizedServiceRegistry, récupérer le premier resolver
if ($this->methodsResolver instanceof PrioritizedServiceRegistryInterface) {
$resolvers = $this->methodsResolver->all();
return reset($resolvers); // Premier resolver
}

throw new \InvalidArgumentException('Invalid shipping methods resolver type');
}

private function buildShippingOption(ShipmentInterface $shipment, BaseShippingMethodInterface $method): array
{
/** @var ShippingMethodTranslationInterface $methodTranslation */
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/config/services/data_builders.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ services:
class: Alma\SyliusPaymentPlugin\DataBuilder\ShippingInfoDataBuilder
arguments:
$calculators: '@sylius.registry.shipping_calculator'
$methodsResolver: '@sylius.shipping_methods_resolver'
$methodsResolver: '@sylius.registry.shipping_methods_resolver'
tags:
- name: alma_sylius_payment_plugin.payment_data_builder
id: shipping_info
Expand All @@ -42,7 +42,7 @@ services:
arguments:
$router: '@router'
$liipCacheManager: '@liip_imagine.cache.manager'
$taxRateResolver: '@sylius.tax_rate_resolver'
# $taxRateResolver: '@sylius.tax_rate_resolver'
tags:
- name: alma_sylius_payment_plugin.payment_data_builder
id: cart
Expand Down
Loading