mapProductConcreteTransfersToQuoteTransferItems()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 16
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * This file is part of the Spryker Commerce OS.
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
declare(strict_types = 1);
9
10
namespace PyzTest\Glue\Checkout;
11
12
use DateTime;
13
use Generated\Shared\DataBuilder\AddressBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBuilder\AddressBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Generated\Shared\DataBuilder\CustomerBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBuilder\CustomerBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Generated\Shared\DataBuilder\ItemBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBuilder\ItemBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Generated\Shared\DataBuilder\ShipmentBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBuilder\ShipmentBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Generated\Shared\DataBuilder\StoreRelationBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBuilder\StoreRelationBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Generated\Shared\Transfer\AddressTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\AddressTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Generated\Shared\Transfer\CustomerTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CustomerTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Generated\Shared\Transfer\ItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ItemTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use Generated\Shared\Transfer\MoneyValueTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\MoneyValueTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
use Generated\Shared\Transfer\PaymentMethodTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PaymentMethodTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use Generated\Shared\Transfer\PriceProductTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PriceProductTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use Generated\Shared\Transfer\ProductConcreteTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ProductConcreteTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use Generated\Shared\Transfer\QuoteTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\QuoteTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
use Generated\Shared\Transfer\RestAddressTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RestAddressTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
use Generated\Shared\Transfer\RestCheckoutDataTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RestCheckoutDataTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
use Generated\Shared\Transfer\RestCheckoutResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...heckoutResponseTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
use Generated\Shared\Transfer\RestCustomerTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RestCustomerTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
use Generated\Shared\Transfer\RestOrderDetailsAttributesTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...tailsAttributesTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
use Generated\Shared\Transfer\RestPaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RestPaymentTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
use Generated\Shared\Transfer\RestShipmentsTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RestShipmentsTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
use Generated\Shared\Transfer\RestShipmentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RestShipmentTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
use Generated\Shared\Transfer\ShipmentMethodTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ShipmentMethodTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
use Generated\Shared\Transfer\ShipmentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ShipmentTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
36
use Generated\Shared\Transfer\StockProductTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\StockProductTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
37
use Generated\Shared\Transfer\StoreRelationTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\StoreRelationTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
38
use Generated\Shared\Transfer\StoreTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\StoreTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
39
use Generated\Shared\Transfer\TotalsTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\TotalsTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
40
use Spryker\Glue\CheckoutRestApi\CheckoutRestApiConfig;
41
use Spryker\Glue\GlueApplication\Rest\RequestConstantsInterface;
42
use Spryker\Glue\OrdersRestApi\OrdersRestApiConfig;
43
use Spryker\Shared\Price\PriceConfig;
44
use Spryker\Shared\Shipment\ShipmentConfig;
45
use Spryker\Zed\Cart\Business\CartFacadeInterface;
46
use Spryker\Zed\Customer\Business\CustomerFacadeInterface;
47
use Spryker\Zed\Store\Business\StoreFacadeInterface;
48
use SprykerTest\Glue\Testify\Tester\ApiEndToEndTester;
49
50
/**
51
 * Inherited Methods
52
 *
53
 * @method void wantToTest($text)
54
 * @method void wantTo($text)
55
 * @method void execute($callable)
56
 * @method void expectTo($prediction)
57
 * @method void expect($prediction)
58
 * @method void amGoingTo($argumentation)
59
 * @method void am($role)
60
 * @method void lookForwardTo($achieveValue)
61
 * @method void comment($description)
62
 * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = null)
63
 *
64
 * @SuppressWarnings(\PyzTest\Glue\Checkout\PHPMD)
65
 */
66
class CheckoutApiTester extends ApiEndToEndTester
67
{
68
    use _generated\CheckoutApiTesterActions;
0 ignored issues
show
Bug introduced by
The type PyzTest\Glue\Checkout\_g...heckoutApiTesterActions was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
69
70
    /**
71
     * @var string
72
     */
73
    protected const REQUEST_PARAM_PAYMENT_METHOD_NAME_INVOICE = 'Invoice';
74
75
    /**
76
     * @var string
77
     */
78
    protected const REQUEST_PARAM_PAYMENT_PROVIDER_NAME_DUMMY_PAYMENT = 'DummyPayment';
79
80
    /**
81
     * @var string
82
     */
83
    protected const QUOTE_ITEM_OVERRIDE_DATA_PRODUCT = 'product';
84
85
    /**
86
     * @var string
87
     */
88
    protected const QUOTE_ITEM_OVERRIDE_DATA_SHIPMENT = 'shipment';
89
90
    /**
91
     * @var string
92
     */
93
    protected const QUOTE_ITEM_OVERRIDE_DATA_QUANTITY = 'quantity';
94
95
    /**
96
     * @var int
97
     */
98
    protected const DEFAULT_QUOTE_ITEM_QUANTITY = 10;
99
100
    /**
101
     * @return void
102
     */
103
    public function assertCheckoutResponseResourceHasCorrectData(): void
104
    {
105
        $this->amSure('The returned resource id should be null')
106
            ->whenI()
107
            ->seeSingleResourceIdEqualTo('');
0 ignored issues
show
Bug introduced by
It seems like seeSingleResourceIdEqualTo() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

107
            ->/** @scrutinizer ignore-call */ seeSingleResourceIdEqualTo('');
Loading history...
108
109
        $attributes = $this->getDataFromResponseByJsonPath('$.data.attributes');
110
111
        $this->assertNotEmpty(
112
            $attributes[RestCheckoutResponseTransfer::ORDER_REFERENCE],
113
            'The returned resource attributes order reference should not be empty',
114
        );
115
        $this->assertArrayHasKey(
116
            RestCheckoutResponseTransfer::IS_EXTERNAL_REDIRECT,
117
            $attributes,
118
            'The returned resource attributes should have an external redirect key',
119
        );
120
        $this->assertArrayHasKey(
121
            RestCheckoutResponseTransfer::REDIRECT_URL,
122
            $attributes,
123
            'The returned resource attributes should have a redirect URL key',
124
        );
125
    }
126
127
    /**
128
     * @return void
129
     */
130
    public function assertCheckoutDataResponseResourceHasCorrectData(): void
131
    {
132
        $this->amSure('The returned resource id should be null')
133
            ->whenI()
134
            ->seeSingleResourceIdEqualTo('');
135
136
        $attributes = $this->getDataFromResponseByJsonPath('$.data.attributes');
137
138
        $this->assertEmpty(
139
            $attributes[RestCheckoutDataTransfer::ADDRESSES],
140
            'The returned resource attributes addresses should be an empty array',
141
        );
142
    }
143
144
    /**
145
     * @param int $price
146
     *
147
     * @return void
148
     */
149
    public function assertShipmentExpensesHaveCorrectPrice(int $price): void
150
    {
151
        $this->amSure('The returned resource should have included orders resource')
152
            ->whenI()
153
            ->seeIncludesContainResourceOfType(OrdersRestApiConfig::RESOURCE_ORDERS);
0 ignored issues
show
Bug introduced by
It seems like seeIncludesContainResourceOfType() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

153
            ->/** @scrutinizer ignore-call */ seeIncludesContainResourceOfType(OrdersRestApiConfig::RESOURCE_ORDERS);
Loading history...
154
155
        $ordersAttributes = $this->getDataFromResponseByJsonPath(
156
            sprintf('$.included[?(@.type == %1$s)].attributes', json_encode(OrdersRestApiConfig::RESOURCE_ORDERS)),
157
        );
158
159
        $this->assertNotNull($ordersAttributes);
160
        $this->assertCount(1, $ordersAttributes);
161
        $restOrdersDetailsAttributesTransfer = (new RestOrderDetailsAttributesTransfer())->fromArray($ordersAttributes[0], true);
162
        $this->assertCount(1, $restOrdersDetailsAttributesTransfer->getExpenses());
163
164
        /** @var \Generated\Shared\Transfer\RestOrderExpensesAttributesTransfer $restOrderExpensesAttributesTransfer */
165
        $restOrderExpensesAttributesTransfer = $restOrdersDetailsAttributesTransfer->getExpenses()->getIterator()->current();
166
        $this->assertSame(ShipmentConfig::SHIPMENT_EXPENSE_TYPE, $restOrderExpensesAttributesTransfer->getType());
167
        $this->assertSame($price, $restOrderExpensesAttributesTransfer->getSumPrice());
168
    }
169
170
    /**
171
     * @param array<string> $includes
172
     *
173
     * @return string
174
     */
175
    public function buildCheckoutUrl(array $includes = []): string
176
    {
177
        return $this->formatFullUrl(
178
            '{resourceCheckout}' . $this->formatQueryInclude($includes),
179
            [
180
                'resourceCheckout' => CheckoutRestApiConfig::RESOURCE_CHECKOUT,
181
            ],
182
        );
183
    }
184
185
    /**
186
     * @param array<string> $includes
187
     *
188
     * @return string
189
     */
190
    public function buildCheckoutDataUrl(array $includes = []): string
191
    {
192
        return $this->formatFullUrl(
193
            '{resourceCheckoutData}' . $this->formatQueryInclude($includes),
194
            [
195
                'resourceCheckoutData' => CheckoutRestApiConfig::RESOURCE_CHECKOUT_DATA,
196
            ],
197
        );
198
    }
199
200
    /**
201
     * @return \Spryker\Zed\Store\Business\StoreFacadeInterface
202
     */
203
    public function getStoreFacade(): StoreFacadeInterface
204
    {
205
        return $this->getLocator()
206
            ->store()
207
            ->facade();
208
    }
209
210
    /**
211
     * @return \Spryker\Zed\Customer\Business\CustomerFacadeInterface
212
     */
213
    public function getCustomerFacade(): CustomerFacadeInterface
214
    {
215
        return $this->getLocator()
216
            ->customer()
217
            ->facade();
218
    }
219
220
    /**
221
     * @return \Spryker\Zed\Cart\Business\CartFacadeInterface
222
     */
223
    public function getCartFacade(): CartFacadeInterface
224
    {
225
        return $this->getLocator()->cart()->facade();
226
    }
227
228
    /**
229
     * @param \Generated\Shared\Transfer\AddressTransfer $addressTransfer
230
     *
231
     * @return array
232
     */
233
    public function getAddressRequestPayload(AddressTransfer $addressTransfer): array
234
    {
235
        return [
236
            RestAddressTransfer::SALUTATION => $addressTransfer->getSalutation(),
237
            RestAddressTransfer::FIRST_NAME => $addressTransfer->getFirstName(),
238
            RestAddressTransfer::LAST_NAME => $addressTransfer->getLastName(),
239
            RestAddressTransfer::ADDRESS1 => $addressTransfer->getAddress1(),
240
            RestAddressTransfer::ADDRESS2 => $addressTransfer->getAddress2(),
241
            RestAddressTransfer::ADDRESS3 => $addressTransfer->getAddress3(),
242
            RestAddressTransfer::ZIP_CODE => $addressTransfer->getZipCode(),
243
            RestAddressTransfer::CITY => $addressTransfer->getCity(),
244
            RestAddressTransfer::ISO2_CODE => $addressTransfer->getIso2Code(),
245
            RestAddressTransfer::PHONE => $addressTransfer->getPhone(),
246
            RestCustomerTransfer::EMAIL => $addressTransfer->getEmail(),
247
            RestAddressTransfer::IS_DEFAULT_BILLING => $addressTransfer->getIsDefaultBilling(),
248
            RestAddressTransfer::IS_DEFAULT_SHIPPING => $addressTransfer->getIsDefaultShipping(),
249
        ];
250
    }
251
252
    /**
253
     * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
254
     *
255
     * @return array
256
     */
257
    public function getCustomerRequestPayload(CustomerTransfer $customerTransfer): array
258
    {
259
        return [
260
            RestCustomerTransfer::SALUTATION => $customerTransfer->getSalutation(),
261
            RestCustomerTransfer::FIRST_NAME => $customerTransfer->getFirstName(),
262
            RestCustomerTransfer::LAST_NAME => $customerTransfer->getLastName(),
263
            RestCustomerTransfer::EMAIL => $customerTransfer->getEmail(),
264
        ];
265
    }
266
267
    /**
268
     * @param string $paymentMethodName
269
     * @param string $paymentProviderName
270
     *
271
     * @return array
272
     */
273
    public function getPaymentRequestPayload(
274
        string $paymentMethodName = self::REQUEST_PARAM_PAYMENT_METHOD_NAME_INVOICE,
275
        string $paymentProviderName = self::REQUEST_PARAM_PAYMENT_PROVIDER_NAME_DUMMY_PAYMENT,
276
    ): array {
277
        return [
278
            [
279
                RestPaymentTransfer::PAYMENT_METHOD_NAME => $paymentMethodName,
280
                RestPaymentTransfer::PAYMENT_PROVIDER_NAME => $paymentProviderName,
281
            ],
282
        ];
283
    }
284
285
    /**
286
     * @param int $idShipmentMethod
287
     *
288
     * @return array
289
     */
290
    public function getShipmentRequestPayload(int $idShipmentMethod): array
291
    {
292
        return [
293
            RestShipmentTransfer::ID_SHIPMENT_METHOD => $idShipmentMethod,
294
        ];
295
    }
296
297
    /**
298
     * @param \Generated\Shared\Transfer\ItemTransfer $itemTransfer
299
     * @param \Generated\Shared\Transfer\AddressTransfer|null $addressTransfer
300
     *
301
     * @return array<string, mixed>
302
     */
303
    public function getSplitShipmentRequestPayload(ItemTransfer $itemTransfer, ?AddressTransfer $addressTransfer = null): array
304
    {
305
        $shippingAddressPayload = $addressTransfer
306
            ? [RestAddressTransfer::ID => $addressTransfer->getUuidOrFail()]
307
            : $this->getAddressRequestPayload($itemTransfer->getShipmentOrFail()->getShippingAddressOrFail());
308
309
        return [
310
            RestShipmentsTransfer::ID_SHIPMENT_METHOD => $itemTransfer->getShipmentOrFail()->getMethodOrFail()->getIdShipmentMethodOrFail(),
311
            RestShipmentsTransfer::ITEMS => [$itemTransfer->getGroupKeyOrFail()],
312
            RestShipmentsTransfer::SHIPPING_ADDRESS => $shippingAddressPayload,
313
            RestShipmentsTransfer::REQUESTED_DELIVERY_DATE => (new DateTime('tomorrow'))->format('Y-m-d'),
314
        ];
315
    }
316
317
    /**
318
     * @param \Generated\Shared\Transfer\ProductConcreteTransfer $productConcreteTransfer
319
     * @param \Generated\Shared\Transfer\ShipmentMethodTransfer $shipmentMethodTransfer
320
     * @param int $quantity
321
     *
322
     * @return array
323
     */
324
    public function getQuoteItemOverrideData(
325
        ProductConcreteTransfer $productConcreteTransfer,
326
        ShipmentMethodTransfer $shipmentMethodTransfer,
327
        int $quantity = self::DEFAULT_QUOTE_ITEM_QUANTITY,
328
    ): array {
329
        return [
330
            static::QUOTE_ITEM_OVERRIDE_DATA_PRODUCT => $productConcreteTransfer,
331
            static::QUOTE_ITEM_OVERRIDE_DATA_SHIPMENT => [
332
                ShipmentTransfer::METHOD => $shipmentMethodTransfer,
333
            ],
334
            static::QUOTE_ITEM_OVERRIDE_DATA_QUANTITY => $quantity,
335
        ];
336
    }
337
338
    /**
339
     * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
340
     *
341
     * @return void
342
     */
343
    public function authorizeCustomerToGlue(CustomerTransfer $customerTransfer): void
344
    {
345
        $oauthResponseTransfer = $this->haveAuthorizationToGlue($customerTransfer);
346
        $this->amBearerAuthenticated($oauthResponseTransfer->getAccessToken());
347
    }
348
349
    /**
350
     * @return string
351
     */
352
    public function createGuestCustomerReference(): string
353
    {
354
        return uniqid('testReference', true);
355
    }
356
357
    /**
358
     * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
359
     * @param array<\Generated\Shared\Transfer\ProductConcreteTransfer> $productConcreteTransfers
360
     * @param array $overrideShipment
361
     *
362
     * @return \Generated\Shared\Transfer\QuoteTransfer
363
     */
364
    public function havePersistentQuoteWithItems(
365
        CustomerTransfer $customerTransfer,
366
        array $productConcreteTransfers,
367
        array $overrideShipment = [],
368
    ): QuoteTransfer {
369
        $shipmentTransfer = (new ShipmentBuilder($overrideShipment))
370
            ->withMethod()
371
            ->withShippingAddress();
372
373
        return $this->havePersistentQuote([
374
            QuoteTransfer::CUSTOMER => $customerTransfer,
375
            QuoteTransfer::TOTALS => (new TotalsTransfer())
376
                ->setSubtotal(random_int(1000, 10000))
377
                ->setPriceToPay(random_int(1000, 10000)),
378
            QuoteTransfer::ITEMS => $this->mapProductConcreteTransfersToQuoteTransferItems($productConcreteTransfers),
379
            QuoteTransfer::STORE => [StoreTransfer::NAME => 'DE'],
380
            QuoteTransfer::PRICE_MODE => PriceConfig::PRICE_MODE_GROSS,
381
            QuoteTransfer::BILLING_ADDRESS => (new AddressBuilder())->build(),
382
            QuoteTransfer::SHIPMENT => $shipmentTransfer,
383
        ]);
384
    }
385
386
    /**
387
     * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
388
     * @param array $overrideItems
389
     * @param string $priceMode
390
     *
391
     * @return \Generated\Shared\Transfer\QuoteTransfer
392
     */
393
    public function havePersistentQuoteWithItemsAndItemLevelShipment(
394
        CustomerTransfer $customerTransfer,
395
        array $overrideItems = [],
396
        string $priceMode = PriceConfig::PRICE_MODE_GROSS,
397
    ): QuoteTransfer {
398
        return $this->havePersistentQuote([
399
            QuoteTransfer::CUSTOMER => $customerTransfer,
400
            QuoteTransfer::TOTALS => (new TotalsTransfer())
401
                ->setSubtotal(random_int(1000, 10000))
402
                ->setPriceToPay(random_int(1000, 10000)),
403
            QuoteTransfer::ITEMS => $this->mapProductConcreteTransfersToQuoteTransferItemsWithItemLevelShipment($overrideItems),
404
            QuoteTransfer::STORE => [StoreTransfer::NAME => 'DE'],
405
            QuoteTransfer::PRICE_MODE => $priceMode,
406
            QuoteTransfer::BILLING_ADDRESS => (new AddressBuilder())->build(),
407
        ]);
408
    }
409
410
    /**
411
     * @param array $overrideCustomer
412
     *
413
     * @return \Generated\Shared\Transfer\QuoteTransfer
414
     */
415
    public function haveEmptyPersistentQuote(array $overrideCustomer = []): QuoteTransfer
416
    {
417
        return $this->havePersistentQuote([
418
            QuoteTransfer::CUSTOMER => (new CustomerBuilder($overrideCustomer))->build(),
419
            QuoteTransfer::BILLING_ADDRESS => (new AddressBuilder())->build(),
420
        ]);
421
    }
422
423
    /**
424
     * @return \Generated\Shared\Transfer\ProductConcreteTransfer
425
     */
426
    public function haveProductWithStock(): ProductConcreteTransfer
427
    {
428
        $productConcreteTransfer = $this->haveFullProduct();
429
430
        $this->haveProductInStockForStore($this->getStoreFacade()->getCurrentStore(), [
431
            StockProductTransfer::SKU => $productConcreteTransfer->getSku(),
432
            StockProductTransfer::IS_NEVER_OUT_OF_STOCK => 1,
433
        ]);
434
435
        $priceProductOverride = [
436
            PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(),
437
            PriceProductTransfer::SKU_PRODUCT => $productConcreteTransfer->getSku(),
438
            PriceProductTransfer::ID_PRODUCT => $productConcreteTransfer->getIdProductConcrete(),
439
            PriceProductTransfer::PRICE_TYPE_NAME => 'DEFAULT',
440
            PriceProductTransfer::MONEY_VALUE => [
441
                MoneyValueTransfer::NET_AMOUNT => 770,
442
                MoneyValueTransfer::GROSS_AMOUNT => 880,
443
            ],
444
        ];
445
        $this->havePriceProduct($priceProductOverride);
446
447
        return $productConcreteTransfer;
448
    }
449
450
    /**
451
     * @param array $override
452
     *
453
     * @return \Generated\Shared\Transfer\CustomerTransfer
454
     */
455
    public function createCustomerTransfer(array $override = []): CustomerTransfer
456
    {
457
        return (new CustomerBuilder($override))->build();
458
    }
459
460
    /**
461
     * @param array $override
462
     *
463
     * @return \Generated\Shared\Transfer\CustomerTransfer
464
     */
465
    public function haveCustomerWithPersistentAddress(array $override = []): CustomerTransfer
466
    {
467
        $customerTransfer = $this->haveCustomer($override);
468
469
        return $this->haveAddressForCustomer($customerTransfer);
470
    }
471
472
    /**
473
     * @param array $paymentMethodOverrideData
474
     * @param array $storeOverrideData
475
     *
476
     * @return \Generated\Shared\Transfer\PaymentMethodTransfer
477
     */
478
    public function havePaymentMethodWithStore(
479
        array $paymentMethodOverrideData = [],
480
        array $storeOverrideData = [
481
            StoreTransfer::NAME => 'DE',
482
            StoreTransfer::DEFAULT_CURRENCY_ISO_CODE => 'EUR',
483
            StoreTransfer::AVAILABLE_CURRENCY_ISO_CODES => ['EUR'],
484
        ],
485
    ): PaymentMethodTransfer {
486
        $storeTransfer = $this->haveStore($storeOverrideData);
487
        $storeRelationTransfer = (new StoreRelationBuilder())->seed([
488
            StoreRelationTransfer::ID_STORES => [
489
                $storeTransfer->getIdStore(),
490
            ],
491
            StoreRelationTransfer::STORES => [
492
                $storeTransfer,
493
            ],
494
        ])->build();
495
496
        $paymentMethodOverrideData = array_merge($paymentMethodOverrideData, [PaymentMethodTransfer::STORE_RELATION => $storeRelationTransfer]);
497
498
        return $this->havePaymentMethod($paymentMethodOverrideData);
499
    }
500
501
    /**
502
     * @param \Generated\Shared\Transfer\AddressTransfer $addressTransfer
503
     *
504
     * @return void
505
     */
506
    public function assertCustomerBillingAddressInOrders(AddressTransfer $addressTransfer): void
507
    {
508
        $jsonPath = sprintf('$..included[?(@.type == \'%s\')]', 'orders');
509
        $billingAddress = $this->getDataFromResponseByJsonPath($jsonPath)[0]['attributes']['billingAddress'];
510
511
        $this->assertSame($addressTransfer->getAddress1(), $billingAddress['address1']);
512
        $this->assertSame($addressTransfer->getAddress2(), $billingAddress['address2']);
513
        $this->assertSame($addressTransfer->getAddress3(), $billingAddress['address3']);
514
        $this->assertSame($addressTransfer->getCompany(), $billingAddress['company']);
515
        $this->assertSame($addressTransfer->getCity(), $billingAddress['city']);
516
        $this->assertSame($addressTransfer->getZipCode(), $billingAddress['zipCode']);
517
        $this->assertSame($addressTransfer->getIso2Code(), $billingAddress['iso2Code']);
518
    }
519
520
    /**
521
     * @param \Generated\Shared\Transfer\AddressTransfer $addressTransfer
522
     *
523
     * @return void
524
     */
525
    public function assertCustomerShippingAddressInOrderShipments(
526
        AddressTransfer $addressTransfer,
527
    ): void {
528
        $jsonPath = sprintf('$..included[?(@.type == \'%s\')]', 'order-shipments');
529
        $shippingAddress = $this->getDataFromResponseByJsonPath($jsonPath)[0]['attributes']['shippingAddress'];
530
531
        $this->assertSame($addressTransfer->getAddress1(), $shippingAddress['address1']);
532
        $this->assertSame($addressTransfer->getAddress2(), $shippingAddress['address2']);
533
        $this->assertSame($addressTransfer->getAddress3(), $shippingAddress['address3']);
534
        $this->assertSame($addressTransfer->getCompany(), $shippingAddress['company']);
535
        $this->assertSame($addressTransfer->getCity(), $shippingAddress['city']);
536
        $this->assertSame($addressTransfer->getZipCode(), $shippingAddress['zipCode']);
537
        $this->assertSame($addressTransfer->getIso2Code(), $shippingAddress['iso2Code']);
538
    }
539
540
    /**
541
     * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
542
     *
543
     * @return \Generated\Shared\Transfer\CustomerTransfer
544
     */
545
    protected function haveAddressForCustomer(CustomerTransfer $customerTransfer): CustomerTransfer
546
    {
547
        $addressTransfer = (new AddressBuilder([
548
            AddressTransfer::EMAIL => $customerTransfer->getEmail(),
549
            AddressTransfer::FK_CUSTOMER => $customerTransfer->getIdCustomer(),
550
            AddressTransfer::FIRST_NAME => $customerTransfer->getFirstName(),
551
            AddressTransfer::LAST_NAME => $customerTransfer->getLastName(),
552
        ]))->build();
553
        $customerFacade = $this->getCustomerFacade();
554
        $customerFacade->createAddress($addressTransfer);
555
556
        return $customerFacade->getCustomer($customerTransfer);
557
    }
558
559
    /**
560
     * @param array<\Generated\Shared\Transfer\ProductConcreteTransfer> $productConcreteTransfers
561
     *
562
     * @return array
563
     */
564
    protected function mapProductConcreteTransfersToQuoteTransferItems(array $productConcreteTransfers): array
565
    {
566
        $quoteTransferItems = [];
567
568
        foreach ($productConcreteTransfers as $productConcreteTransfer) {
569
            $quoteTransferItems[] = (new ItemBuilder([
570
                ItemTransfer::SKU => $productConcreteTransfer->getSku(),
571
                ItemTransfer::GROUP_KEY => $productConcreteTransfer->getSku(),
572
                ItemTransfer::ABSTRACT_SKU => $productConcreteTransfer->getAbstractSku(),
573
                ItemTransfer::ID_PRODUCT_ABSTRACT => $productConcreteTransfer->getFkProductAbstract(),
574
                ItemTransfer::QUANTITY => static::DEFAULT_QUOTE_ITEM_QUANTITY,
575
            ]))->build()
576
                ->modifiedToArray();
577
        }
578
579
        return $quoteTransferItems;
580
    }
581
582
    /**
583
     * @param array $overrideItems
584
     *
585
     * @return array
586
     */
587
    protected function mapProductConcreteTransfersToQuoteTransferItemsWithItemLevelShipment(array $overrideItems = []): array
588
    {
589
        $quoteTransferItems = [];
590
591
        foreach ($overrideItems as $overrideItem) {
592
            $productConcreteTransfer = $this->getProductConcreteTransferFromOverrideItemData($overrideItem);
593
            $overrideShipment = $this->getOverrideShipmentDataFromOverrideItemData($overrideItem);
594
595
            $quoteTransferItems[] = (new ItemBuilder([
596
                ItemTransfer::SKU => $productConcreteTransfer->getSku(),
597
                ItemTransfer::GROUP_KEY => $productConcreteTransfer->getSku(),
598
                ItemTransfer::ABSTRACT_SKU => $productConcreteTransfer->getAbstractSku(),
599
                ItemTransfer::ID_PRODUCT_ABSTRACT => $productConcreteTransfer->getFkProductAbstract(),
600
                ItemTransfer::QUANTITY => $this->getQuoteItemQuantityFromOverrideItemData($overrideItem),
601
            ]))->withShipment((new ShipmentBuilder($overrideShipment))
602
                ->withMethod()
603
                ->withShippingAddress())
604
                ->build()
605
                ->modifiedToArray();
606
        }
607
608
        return $quoteTransferItems;
609
    }
610
611
    /**
612
     * @param array $overrideItem
613
     *
614
     * @return \Generated\Shared\Transfer\ProductConcreteTransfer
615
     */
616
    protected function getProductConcreteTransferFromOverrideItemData(array $overrideItem): ProductConcreteTransfer
617
    {
618
        return $overrideItem[static::QUOTE_ITEM_OVERRIDE_DATA_PRODUCT];
619
    }
620
621
    /**
622
     * @param array $overrideItem
623
     *
624
     * @return array
625
     */
626
    protected function getOverrideShipmentDataFromOverrideItemData(array $overrideItem): array
627
    {
628
        return $overrideItem[static::QUOTE_ITEM_OVERRIDE_DATA_SHIPMENT];
629
    }
630
631
    /**
632
     * @param array $overrideItem
633
     *
634
     * @return int
635
     */
636
    protected function getQuoteItemQuantityFromOverrideItemData(array $overrideItem): int
637
    {
638
        return $overrideItem[static::QUOTE_ITEM_OVERRIDE_DATA_QUANTITY] ?? static::DEFAULT_QUOTE_ITEM_QUANTITY;
639
    }
640
641
    /**
642
     * @param array<string> $includes
643
     *
644
     * @return string
645
     */
646
    protected function formatQueryInclude(array $includes = []): string
647
    {
648
        if (!$includes) {
649
            return '';
650
        }
651
652
        return sprintf('?%s=%s', RequestConstantsInterface::QUERY_INCLUDE, implode(',', $includes));
653
    }
654
}
655