Skip to content

Commit

Permalink
bug #11418 set default value for Channel taxCalculationStrategy (oall…
Browse files Browse the repository at this point in the history
…ain)

This PR was merged into the 1.7 branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | master
| Bug fix?        | yes
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | fixes #11414 
| License         | MIT



Commits
-------

f4f0ed899d9709b6667b38e9ab7c5fbe641c1be1 set default value for Channel taxCalculationStrategy
0dd21deac7687c6a7f487733ca68704ec7516e37 factory extends component factory
  • Loading branch information
lchrusciel committed Sep 7, 2020
2 parents 83f32f3 + 1c7f36a commit 630e5e8
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 4 deletions.
55 changes: 55 additions & 0 deletions Factory/ChannelFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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\Factory;

use Sylius\Component\Channel\Model\ChannelInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;

class ChannelFactory implements ChannelFactoryInterface
{
/** @var FactoryInterface */
private $decoratedFactory;

/** @var string */
private $defaultCalculationStrategy;

public function __construct(FactoryInterface $decoratedFactory, string $defaultCalculationStrategy)
{
$this->decoratedFactory = $decoratedFactory;
$this->defaultCalculationStrategy = $defaultCalculationStrategy;
}

/**
* {@inheritdoc}
*/
public function createNew(): ChannelInterface
{
/** @var \Sylius\Component\Core\Model\ChannelInterface $channel */
$channel = $this->decoratedFactory->createNew();
$channel->setTaxCalculationStrategy($this->defaultCalculationStrategy);

return $channel;
}

/**
* {@inheritdoc}
*/
public function createNamed(string $name): ChannelInterface
{
$channel = $this->createNew();
$channel->setName($name);

return $channel;
}
}
22 changes: 22 additions & 0 deletions Factory/ChannelFactoryInterface.php
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\Factory;

use Sylius\Component\Channel\Factory\ChannelFactoryInterface as BaseChannelFactoryInterface;
use Sylius\Component\Channel\Model\ChannelInterface;

interface ChannelFactoryInterface extends BaseChannelFactoryInterface
{
public function createNamed(string $name): ChannelInterface;
}
2 changes: 1 addition & 1 deletion Test/Services/DefaultChannelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Sylius\Component\Core\Test\Services;

use Sylius\Component\Channel\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Currency\Model\CurrencyInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
Expand Down
2 changes: 1 addition & 1 deletion Test/Services/DefaultUnitedStatesChannelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Sylius\Component\Addressing\Factory\ZoneFactoryInterface;
use Sylius\Component\Addressing\Model\CountryInterface;
use Sylius\Component\Addressing\Model\ZoneInterface;
use Sylius\Component\Channel\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Currency\Model\CurrencyInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
Expand Down
45 changes: 45 additions & 0 deletions spec/Factory/ChannelFactorySpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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\Factory;

use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;

final class ChannelFactorySpec extends ObjectBehavior
{
function let(FactoryInterface $decoratedFactory): void
{
$this->beConstructedWith($decoratedFactory, 'order_items_based');
}

function it_implements_channel_factory_interface(): void
{
$this->shouldImplement(ChannelFactoryInterface::class);
}

function it_is_a_resource_factory(): void
{
$this->shouldImplement(FactoryInterface::class);
}

function it_creates_a_new_channel(FactoryInterface $decoratedFactory, ChannelInterface $channel): void
{
$decoratedFactory->createNew()->willReturn($channel);
$channel->setTaxCalculationStrategy('order_items_based')->shouldBeCalled();

$this->createNew()->shouldReturn($channel);
}
}
2 changes: 1 addition & 1 deletion spec/Test/Services/DefaultChannelFactorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace spec\Sylius\Component\Core\Test\Services;

use PhpSpec\ObjectBehavior;
use Sylius\Component\Channel\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Test\Services\DefaultChannelFactoryInterface;
use Sylius\Component\Currency\Model\CurrencyInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Sylius\Component\Addressing\Factory\ZoneFactoryInterface;
use Sylius\Component\Addressing\Model\CountryInterface;
use Sylius\Component\Addressing\Model\ZoneInterface;
use Sylius\Component\Channel\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Test\Services\DefaultChannelFactoryInterface;
use Sylius\Component\Currency\Model\CurrencyInterface;
Expand Down

0 comments on commit 630e5e8

Please sign in to comment.