Skip to content

Commit

Permalink
CS fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zales0123 committed Jun 26, 2024
1 parent b052d06 commit d6f3b60
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/Adder/DiscountAdjustmentsAdder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace Setono\SyliusOrderEditPlugin\Adder;

use Sylius\Component\Core\Distributor\IntegerDistributorInterface;
use Sylius\Component\Core\Model\AdjustmentInterface;
use Sylius\Component\Core\Model\OrderItemInterface;
use Sylius\Component\Core\Model\OrderItemUnitInterface;
use Sylius\Component\Order\Factory\AdjustmentFactoryInterface;

final class DiscountAdjustmentsAdder implements DiscountAdjustmentsAdderInterface
Expand All @@ -21,14 +23,18 @@ public function add(OrderItemInterface $orderItem, string $adjustmentType, int $
$discounts = $this->integerDistributor->distribute($discount, $orderItem->getQuantity());
$units = $orderItem->getUnits();

/** @var int $discount */
foreach ($discounts as $i => $discount) {
/** @var AdjustmentInterface $adjustment */
$adjustment = $this->adjustmentFactory->createWithData(
$adjustmentType,
'Custom discount',
$discount,
);

$units->get($i)->addAdjustment($adjustment);
/** @var OrderItemUnitInterface $unit */
$unit = $units->get($i);
$unit->addAdjustment($adjustment);
}
}
}
1 change: 0 additions & 1 deletion src/Adder/DiscountAdjustmentsAdderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Setono\SyliusOrderEditPlugin\Adder;

use Sylius\Component\Core\Model\AdjustmentInterface;
use Sylius\Component\Core\Model\OrderItemInterface;

interface DiscountAdjustmentsAdderInterface
Expand Down
1 change: 0 additions & 1 deletion src/Form/Type/OrderDiscountCollectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public function __construct(
parent::__construct($adjustmentFactory, 'Custom discount', AdjustmentTypes::SETONO_ADMIN_ORDER_DISCOUNT);
}

/** @param OrderInterface $adjustable */
public function setDiscounts(AdjustableInterface $adjustable, array $discounts): void
{
Assert::isInstanceOf($adjustable, OrderInterface::class);
Expand Down
1 change: 0 additions & 1 deletion src/Form/Type/OrderItemDiscountCollectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public function __construct(
parent::__construct($adjustmentFactory, 'Custom item discount', AdjustmentTypes::SETONO_ADMIN_ORDER_ITEM_DISCOUNT);
}

/** @param OrderItemInterface $adjustable */
public function setDiscounts(AdjustableInterface $adjustable, array $discounts): void
{
Assert::isInstanceOf($adjustable, OrderItemInterface::class);
Expand Down
8 changes: 7 additions & 1 deletion src/Setter/OrderDiscountAdjustmentSetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use Setono\SyliusOrderEditPlugin\Adder\DiscountAdjustmentsAdderInterface;
use Setono\SyliusOrderEditPlugin\Model\AdjustmentTypes;
use Sylius\Component\Core\Distributor\MinimumPriceDistributorInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\OrderItemInterface;

final class OrderDiscountAdjustmentSetter implements OrderDiscountAdjustmentSetterInterface
{
Expand All @@ -19,14 +21,18 @@ public function __construct(

public function set(OrderInterface $order, int $discount): void
{
/** @var ChannelInterface $channel */
$channel = $order->getChannel();
$items = $order->getItems();

$distributedPrices = $this->minimumPriceDistributor->distribute($items->toArray(), $discount, $channel, true);

/** @var int $distribution */
foreach ($distributedPrices as $i => $distribution) {
/** @var OrderItemInterface $item */
$item = $items->get($i);
$this->orderItemDiscountAdjustmentAdder->add(
$items->get($i),
$item,
AdjustmentTypes::SETONO_ADMIN_ORDER_DISCOUNT,
-$distribution,
);
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Adder/DiscountAdjustmentsAdderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testItAddsDiscountAdjustmentsOnOrderItemUnits(): void

$item->getQuantity()->willReturn(3);
$item->getUnits()->willReturn(new ArrayCollection(
[$firstUnit->reveal(), $secondUnit->reveal(), $thirdUnit->reveal()]
[$firstUnit->reveal(), $secondUnit->reveal(), $thirdUnit->reveal()],
));

$integerDistributor->distribute(-1000, 3)->willReturn([-333, -333, -334]);
Expand All @@ -50,7 +50,7 @@ public function testItAddsDiscountAdjustmentsOnOrderItemUnits(): void
->willReturn($firstAdjustment->reveal(), $secondAdjustment->reveal())
;
$adjustmentFactory
->createWithData(AdjustmentTypes::SETONO_ADMIN_ORDER_DISCOUNT, 'Custom discount', -334,)
->createWithData(AdjustmentTypes::SETONO_ADMIN_ORDER_DISCOUNT, 'Custom discount', -334, )
->willReturn($thirdAdjustment->reveal())
;

Expand Down

0 comments on commit d6f3b60

Please sign in to comment.