Skip to content

Commit

Permalink
bug #10626 [Fixture] Do not skip payments and shipments manually (Zal…
Browse files Browse the repository at this point in the history
…es0123)

This PR was merged into the 1.4 branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | 1.4
| Bug fix?        | yes
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | introduces in #10618
| License         | MIT

There is no need to skip payment and shipment in order manually, as it's done automatically with [this callback](https://github.com/Sylius/Sylius/blob/60134b783c51c4b9da0b58c5a54482824a8baf8a/src/Sylius/Bundle/CoreBundle/Resources/config/app/state_machine/sylius_order_checkout.yml#L53) 🎉 

Commits
-------

fbb68f2 [Fixture] Do not skip payments and shipments manually
  • Loading branch information
pamil authored Aug 26, 2019
2 parents d417b25 + fbb68f2 commit 0b33732
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 21 deletions.
23 changes: 4 additions & 19 deletions src/Sylius/Bundle/CoreBundle/Fixture/OrderFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
use Doctrine\Common\Persistence\ObjectManager;
use SM\Factory\FactoryInterface as StateMachineFactoryInterface;
use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture;
use Sylius\Component\Core\Checker\OrderPaymentMethodSelectionRequirementCheckerInterface;
use Sylius\Component\Core\Checker\OrderShippingMethodSelectionRequirementCheckerInterface;
use Sylius\Component\Core\Model\AddressInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\OrderItemInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\OrderCheckoutStates;
use Sylius\Component\Core\OrderCheckoutTransitions;
use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface;
use Sylius\Component\Core\Repository\ShippingMethodRepositoryInterface;
Expand Down Expand Up @@ -70,12 +69,6 @@ class OrderFixture extends AbstractFixture
/** @var StateMachineFactoryInterface */
private $stateMachineFactory;

/** @var OrderShippingMethodSelectionRequirementCheckerInterface */
private $orderShippingMethodSelectionRequirementChecker;

/** @var OrderPaymentMethodSelectionRequirementCheckerInterface */
private $orderPaymentMethodSelectionRequirementChecker;

/** @var \Faker\Generator */
private $faker;

Expand All @@ -91,9 +84,7 @@ public function __construct(
PaymentMethodRepositoryInterface $paymentMethodRepository,
ShippingMethodRepositoryInterface $shippingMethodRepository,
FactoryInterface $addressFactory,
StateMachineFactoryInterface $stateMachineFactory,
OrderShippingMethodSelectionRequirementCheckerInterface $orderShippingMethodSelectionRequirementChecker,
OrderPaymentMethodSelectionRequirementCheckerInterface $orderPaymentMethodSelectionRequirementChecker
StateMachineFactoryInterface $stateMachineFactory
) {
$this->orderFactory = $orderFactory;
$this->orderItemFactory = $orderItemFactory;
Expand All @@ -107,8 +98,6 @@ public function __construct(
$this->shippingMethodRepository = $shippingMethodRepository;
$this->addressFactory = $addressFactory;
$this->stateMachineFactory = $stateMachineFactory;
$this->orderShippingMethodSelectionRequirementChecker = $orderShippingMethodSelectionRequirementChecker;
$this->orderPaymentMethodSelectionRequirementChecker = $orderPaymentMethodSelectionRequirementChecker;

$this->faker = \Faker\Factory::create();
}
Expand Down Expand Up @@ -228,9 +217,7 @@ private function address(OrderInterface $order, string $countryCode): void

private function selectShipping(OrderInterface $order): void
{
if (!$this->orderShippingMethodSelectionRequirementChecker->isShippingMethodSelectionRequired($order)) {
$this->applyCheckoutStateTransition($order, OrderCheckoutTransitions::TRANSITION_SKIP_SHIPPING);

if ($order->getCheckoutState() === OrderCheckoutStates::STATE_SHIPPING_SKIPPED) {
return;
}

Expand Down Expand Up @@ -259,9 +246,7 @@ private function selectShipping(OrderInterface $order): void

private function selectPayment(OrderInterface $order): void
{
if (!$this->orderPaymentMethodSelectionRequirementChecker->isPaymentMethodSelectionRequired($order)) {
$this->applyCheckoutStateTransition($order, OrderCheckoutTransitions::TRANSITION_SKIP_PAYMENT);

if ($order->getCheckoutState() === OrderCheckoutStates::STATE_PAYMENT_SKIPPED) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@
<argument type="service" id="sylius.repository.shipping_method" />
<argument type="service" id="sylius.factory.address" />
<argument type="service" id="sm.factory" />
<argument type="service" id="sylius.checker.order_shipping_method_selection_requirement" />
<argument type="service" id="sylius.checker.order_payment_method_selection_requirement" />

<tag name="sylius_fixtures.fixture" />
</service>
Expand Down
1 change: 1 addition & 0 deletions src/Sylius/Component/Core/OrderCheckoutStates.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ final class OrderCheckoutStates
public const STATE_PAYMENT_SELECTED = 'payment_selected';
public const STATE_PAYMENT_SKIPPED = 'payment_skipped';
public const STATE_SHIPPING_SELECTED = 'shipping_selected';
public const STATE_SHIPPING_SKIPPED = 'shipping_skipped';

private function __construct()
{
Expand Down

0 comments on commit 0b33732

Please sign in to comment.