|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Gewebe\SyliusVATPlugin\Fixture\Factory; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Persistence\ObjectManager; |
|
8
|
|
|
use Gewebe\SyliusVATPlugin\Entity\VatNumberAddressInterface; |
|
9
|
|
|
use Sylius\Abstraction\StateMachine\StateMachineInterface; |
|
10
|
|
|
use Sylius\Bundle\CoreBundle\Fixture\Factory\OrderExampleFactory as BaseOrderExampleFactory; |
|
11
|
|
|
use Sylius\Component\Addressing\Model\CountryInterface; |
|
12
|
|
|
use Sylius\Component\Core\Checker\OrderPaymentMethodSelectionRequirementCheckerInterface; |
|
13
|
|
|
use Sylius\Component\Core\Checker\OrderShippingMethodSelectionRequirementCheckerInterface; |
|
14
|
|
|
use Sylius\Component\Core\Model\AddressInterface; |
|
15
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
|
16
|
|
|
use Sylius\Component\Core\Model\CustomerInterface; |
|
17
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
|
18
|
|
|
use Sylius\Component\Core\Model\OrderItemInterface; |
|
19
|
|
|
use Sylius\Component\Core\OrderCheckoutTransitions; |
|
20
|
|
|
use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface; |
|
21
|
|
|
use Sylius\Component\Core\Repository\ProductRepositoryInterface; |
|
22
|
|
|
use Sylius\Component\Core\Repository\ShippingMethodRepositoryInterface; |
|
23
|
|
|
use Sylius\Component\Order\Modifier\OrderItemQuantityModifierInterface; |
|
24
|
|
|
use Sylius\Resource\Doctrine\Persistence\RepositoryInterface; |
|
25
|
|
|
use Sylius\Resource\Factory\FactoryInterface; |
|
26
|
|
|
|
|
27
|
|
|
final class OrderExampleFactory extends BaseOrderExampleFactory |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @param FactoryInterface<OrderInterface> $orderFactory |
|
31
|
|
|
* @param FactoryInterface<OrderItemInterface> $orderItemFactory |
|
32
|
|
|
* @param RepositoryInterface<ChannelInterface> $channelRepository |
|
33
|
|
|
* @param RepositoryInterface<CustomerInterface> $customerRepository |
|
34
|
|
|
* @param RepositoryInterface<CountryInterface> $countryRepository |
|
35
|
|
|
* @param FactoryInterface<AddressInterface> $addressFactory |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct( |
|
38
|
|
|
protected FactoryInterface $orderFactory, |
|
39
|
|
|
protected FactoryInterface $orderItemFactory, |
|
40
|
|
|
protected OrderItemQuantityModifierInterface $orderItemQuantityModifier, |
|
41
|
|
|
protected ObjectManager $orderManager, |
|
42
|
|
|
protected RepositoryInterface $channelRepository, |
|
43
|
|
|
protected RepositoryInterface $customerRepository, |
|
44
|
|
|
protected ProductRepositoryInterface $productRepository, |
|
45
|
|
|
protected RepositoryInterface $countryRepository, |
|
46
|
|
|
protected PaymentMethodRepositoryInterface $paymentMethodRepository, |
|
47
|
|
|
protected ShippingMethodRepositoryInterface $shippingMethodRepository, |
|
48
|
|
|
protected FactoryInterface $addressFactory, |
|
49
|
|
|
protected StateMachineInterface $stateMachineFactory, |
|
50
|
|
|
protected OrderShippingMethodSelectionRequirementCheckerInterface $orderShippingMethodSelectionRequirementChecker, |
|
51
|
|
|
protected OrderPaymentMethodSelectionRequirementCheckerInterface $orderPaymentMethodSelectionRequirementChecker, |
|
52
|
|
|
) { |
|
53
|
|
|
parent::__construct( |
|
54
|
|
|
$orderFactory, |
|
55
|
|
|
$orderItemFactory, |
|
56
|
|
|
$orderItemQuantityModifier, |
|
57
|
|
|
$orderManager, |
|
58
|
|
|
$channelRepository, |
|
59
|
|
|
$customerRepository, |
|
60
|
|
|
$productRepository, |
|
61
|
|
|
$countryRepository, |
|
62
|
|
|
$paymentMethodRepository, |
|
63
|
|
|
$shippingMethodRepository, |
|
64
|
|
|
$addressFactory, |
|
65
|
|
|
$stateMachineFactory, |
|
66
|
|
|
$orderShippingMethodSelectionRequirementChecker, |
|
67
|
|
|
$orderPaymentMethodSelectionRequirementChecker, |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
protected function address(OrderInterface $order, string $countryCode): void |
|
72
|
|
|
{ |
|
73
|
|
|
/** @var VatNumberAddressInterface $address */ |
|
74
|
|
|
$address = $this->addressFactory->createNew(); |
|
75
|
|
|
$address->setFirstName($this->faker->firstName()); |
|
76
|
|
|
$address->setLastName($this->faker->lastName()); |
|
77
|
|
|
$address->setStreet($this->faker->streetAddress()); |
|
78
|
|
|
$address->setCountryCode($countryCode); |
|
79
|
|
|
$address->setCity($this->faker->city()); |
|
80
|
|
|
$address->setPostcode($this->faker->postcode()); |
|
81
|
|
|
$address->setVatValid(false); |
|
82
|
|
|
|
|
83
|
|
|
$order->setShippingAddress($address); |
|
84
|
|
|
$order->setBillingAddress(clone $address); |
|
85
|
|
|
|
|
86
|
|
|
$this->applyCheckoutStateTransition($order, OrderCheckoutTransitions::TRANSITION_ADDRESS); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|