-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor #12718 [POC] Add change of tax by address (arti0090)
This PR was merged into the 1.11-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | not sure | Related tickets | related to #10946 | License | MIT ![Zrzut ekranu 2021-06-18 o 08 33 40](https://user-images.githubusercontent.com/35863747/122517317-242e4b80-d010-11eb-83ea-0173209f8935.png) ![Zrzut ekranu 2021-06-18 o 08 33 50](https://user-images.githubusercontent.com/35863747/122517321-24c6e200-d010-11eb-9846-1143be126ab8.png) Commits ------- ff8d727 [POC] Add change of tax by address b05e446 Extract service 273c608 Minor fixes ae32ed2 Rebase and fixes d9b61b7 Add notes about new param
- Loading branch information
Showing
10 changed files
with
167 additions
and
38 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
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
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
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
37 changes: 37 additions & 0 deletions
37
src/Sylius/Component/Core/Resolver/TaxationAddressResolver.php
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 is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Component\Core\Resolver; | ||
|
||
use Sylius\Component\Core\Model\AddressInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
|
||
final class TaxationAddressResolver Implements TaxationAddressResolverInterface | ||
{ | ||
/** @var bool */ | ||
private $shippingAddressBasedTaxation; | ||
|
||
public function __construct(bool $shippingAddressBasedTaxation) | ||
{ | ||
$this->shippingAddressBasedTaxation = $shippingAddressBasedTaxation; | ||
} | ||
|
||
public function getTaxationAddressFromOrder(OrderInterface $order): ?AddressInterface | ||
{ | ||
if ($this->shippingAddressBasedTaxation) { | ||
return $order->getShippingAddress(); | ||
} | ||
|
||
return $order->getBillingAddress(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Sylius/Component/Core/Resolver/TaxationAddressResolverInterface.php
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 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Component\Core\Resolver; | ||
|
||
use Sylius\Component\Core\Model\AddressInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
|
||
interface TaxationAddressResolverInterface | ||
{ | ||
public function getTaxationAddressFromOrder(OrderInterface $order): ?AddressInterface; | ||
} |
61 changes: 61 additions & 0 deletions
61
src/Sylius/Component/Core/spec/Resolver/TaxationAddressResolverSpec.php
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,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Sylius\Component\Core\Resolver; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Sylius\Component\Core\Model\AddressInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Core\Resolver\TaxationAddressResolverInterface; | ||
|
||
final class TaxationAddressResolverSpec extends ObjectBehavior | ||
{ | ||
public function let(): void | ||
{ | ||
$this->beConstructedWith(false); | ||
} | ||
|
||
public function it_implements_taxation_address_resolver_interface(): void | ||
{ | ||
$this->shouldImplement(TaxationAddressResolverInterface::class); | ||
} | ||
|
||
public function it_returns_billing_address_from_order_if_it_has_default_parameter( | ||
OrderInterface $order, | ||
AddressInterface $billingAddress, | ||
AddressInterface $shippingAddress | ||
): void { | ||
$order->setBillingAddress($billingAddress); | ||
$order->setShippingAddress($shippingAddress); | ||
|
||
$order->getBillingAddress()->willReturn($billingAddress); | ||
|
||
$this->getTaxationAddressFromOrder($order)->shouldReturn($billingAddress); | ||
$this->getTaxationAddressFromOrder($order)->shouldNotReturn($shippingAddress); | ||
} | ||
|
||
public function it_returns_shipping_address_from_order_if_parameter_is_true( | ||
OrderInterface $order, | ||
AddressInterface $billingAddress, | ||
AddressInterface $shippingAddress | ||
): void { | ||
$this->beConstructedWith(true); | ||
$order->setBillingAddress($billingAddress); | ||
$order->setShippingAddress($shippingAddress); | ||
|
||
$order->getShippingAddress()->willReturn($shippingAddress); | ||
|
||
$this->getTaxationAddressFromOrder($order)->shouldReturn($shippingAddress); | ||
$this->getTaxationAddressFromOrder($order)->shouldNotReturn($billingAddress); | ||
} | ||
} |