Completed
Push — a-bulwa-travis-is-2 ( 7c64aa )
by Kamil
41:24
created

ProductContext::thisProductHasOptionWithValues()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
cc 2
eloc 12
nc 2
nop 3
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Behat\Context\Setup;
13
14
use Behat\Behat\Context\Context;
15
use Behat\Gherkin\Node\TableNode;
16
use Behat\Mink\Element\NodeElement;
17
use Doctrine\Common\Persistence\ObjectManager;
18
use Sylius\Component\Attribute\Factory\AttributeFactoryInterface;
19
use Sylius\Component\Core\Formatter\StringInflector;
20
use Sylius\Component\Core\Model\ChannelInterface;
21
use Sylius\Component\Core\Model\ImageInterface;
22
use Sylius\Component\Core\Model\ProductInterface;
23
use Sylius\Component\Core\Model\ProductTranslationInterface;
24
use Sylius\Component\Core\Model\ProductVariantInterface;
25
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
26
use Sylius\Behat\Service\SharedStorageInterface;
27
use Sylius\Component\Core\Uploader\ImageUploaderInterface;
28
use Sylius\Component\Product\Factory\ProductFactoryInterface;
29
use Sylius\Component\Product\Model\ProductAttributeInterface;
30
use Sylius\Component\Product\Model\ProductAttributeValueInterface;
31
use Sylius\Component\Product\Model\ProductOptionInterface;
32
use Sylius\Component\Product\Model\ProductOptionValueInterface;
33
use Sylius\Component\Resource\Factory\FactoryInterface;
34
use Sylius\Component\Taxation\Model\TaxCategoryInterface;
35
use Sylius\Component\Product\Resolver\ProductVariantResolverInterface;
36
use Symfony\Component\HttpFoundation\File\UploadedFile;
37
38
/**
39
 * @author Arkadiusz Krakowiak <[email protected]>
40
 * @author Mateusz Zalewski <[email protected]>
41
 * @author Magdalena Banasiak <[email protected]>
42
 */
43
final class ProductContext implements Context
44
{
45
    /**
46
     * @var SharedStorageInterface
47
     */
48
    private $sharedStorage;
49
50
    /**
51
     * @var ProductRepositoryInterface
52
     */
53
    private $productRepository;
54
55
    /**
56
     * @var ProductFactoryInterface
57
     */
58
    private $productFactory;
59
60
    /**
61
     * @var FactoryInterface
62
     */
63
    private $productTranslationFactory;
64
65
    /**
66
     * @var AttributeFactoryInterface
67
     */
68
    private $productAttributeFactory;
69
70
    /**
71
     * @var FactoryInterface
72
     */
73
    private $productVariantFactory;
74
75
    /**
76
     * @var FactoryInterface
77
     */
78
    private $attributeValueFactory;
79
80
    /**
81
     * @var FactoryInterface
82
     */
83
    private $productOptionFactory;
84
85
    /**
86
     * @var FactoryInterface
87
     */
88
    private $productOptionValueFactory;
89
90
    /**
91
     * @var FactoryInterface
92
     */
93
    private $productImageFactory;
94
95
    /**
96
     * @var ObjectManager
97
     */
98
    private $objectManager;
99
100
    /**
101
     * @var ProductVariantResolverInterface
102
     */
103
    private $defaultVariantResolver;
104
105
    /**
106
     * @var ImageUploaderInterface
107
     */
108
    private $imageUploader;
109
110
    /**
111
     * @var array
112
     */
113
    private $minkParameters;
114
115
    /**
116
     * @param SharedStorageInterface $sharedStorage
117
     * @param ProductRepositoryInterface $productRepository
118
     * @param ProductFactoryInterface $productFactory
119
     * @param FactoryInterface $productTranslationFactory
120
     * @param AttributeFactoryInterface $productAttributeFactory
121
     * @param FactoryInterface $productVariantFactory
122
     * @param FactoryInterface $attributeValueFactory
123
     * @param FactoryInterface $productOptionFactory
124
     * @param FactoryInterface $productOptionValueFactory
125
     * @param FactoryInterface $productImageFactory
126
     * @param ObjectManager $objectManager
127
     * @param ProductVariantResolverInterface $defaultVariantResolver
128
     * @param ImageUploaderInterface $imageUploader
129
     * @param array $minkParameters
130
     */
131
    public function __construct(
132
        SharedStorageInterface $sharedStorage,
133
        ProductRepositoryInterface $productRepository,
134
        ProductFactoryInterface $productFactory,
135
        FactoryInterface $productTranslationFactory,
136
        AttributeFactoryInterface $productAttributeFactory,
137
        FactoryInterface $attributeValueFactory,
138
        FactoryInterface $productVariantFactory,
139
        FactoryInterface $productOptionFactory,
140
        FactoryInterface $productOptionValueFactory,
141
        FactoryInterface $productImageFactory,
142
        ObjectManager $objectManager,
143
        ProductVariantResolverInterface $defaultVariantResolver,
144
        ImageUploaderInterface $imageUploader,
145
        array $minkParameters
146
    ) {
147
        $this->sharedStorage = $sharedStorage;
148
        $this->productRepository = $productRepository;
149
        $this->productFactory = $productFactory;
150
        $this->productTranslationFactory = $productTranslationFactory;
151
        $this->productAttributeFactory = $productAttributeFactory;
152
        $this->attributeValueFactory = $attributeValueFactory;
153
        $this->productVariantFactory = $productVariantFactory;
154
        $this->productOptionFactory = $productOptionFactory;
155
        $this->productOptionValueFactory = $productOptionValueFactory;
156
        $this->productImageFactory = $productImageFactory;
157
        $this->objectManager = $objectManager;
158
        $this->imageUploader = $imageUploader;
159
        $this->defaultVariantResolver = $defaultVariantResolver;
160
        $this->minkParameters = $minkParameters;
161
    }
162
163
    /**
164
     * @Given the store has a product :productName
165
     * @Given the store has a :productName product
166
     * @Given /^the store(?:| also) has a product "([^"]+)" priced at ("[^"]+")$/
167
     */
168
    public function storeHasAProductPricedAt($productName, $price = 0)
169
    {
170
        $product = $this->createProduct($productName, $price);
171
172
        $product->setDescription('Awesome '.$productName);
173
174
        if ($this->sharedStorage->has('channel')) {
175
            $product->addChannel($this->sharedStorage->get('channel'));
176
        }
177
178
        $this->saveProduct($product);
179
    }
180
181
    /**
182
     * @Given the store( also) has a product :productName with code :code
183
     * @Given the store( also) has a product :productName with code :code, created at :date
184
     */
185
    public function storeHasProductWithCode($productName, $code, $date = null)
186
    {
187
        $product = $this->createProduct($productName, 0, $date);
188
189
        $product->setCode($code);
190
191
        if ($this->sharedStorage->has('channel')) {
192
            $product->addChannel($this->sharedStorage->get('channel'));
193
        }
194
195
        $this->saveProduct($product);
196
    }
197
198
    /**
199
     * @Given /^(this product) is named "([^"]+)" (in the "([^"]+)" locale)$/
200
     */
201
    public function thisProductIsNamedIn(ProductInterface $product, $name, $locale)
202
    {
203
        /** @var ProductTranslationInterface $translation */
204
        $translation = $this->productTranslationFactory->createNew();
205
        $translation->setLocale($locale);
206
        $translation->setName($name);
207
208
        $product->addTranslation($translation);
0 ignored issues
show
Documentation introduced by
$translation is of type object<Sylius\Component\...ctTranslationInterface>, but the function expects a object<Sylius\Component\...l\TranslationInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
209
210
        $this->objectManager->flush();
211
    }
212
213
    /**
214
     * @Given the store has a :productName configurable product
215
     */
216
    public function storeHasAConfigurableProduct($productName)
217
    {
218
        /** @var ProductInterface $product */
219
        $product = $this->productFactory->createNew();
220
221
        $product->setName($productName);
222
        $product->setCode(StringInflector::nameToUppercaseCode($productName));
223
        $product->setDescription('Awesome '.$productName);
224
225
        if ($this->sharedStorage->has('channel')) {
226
            $channel = $this->sharedStorage->get('channel');
227
            $product->addChannel($channel);
228
        }
229
230
        $this->saveProduct($product);
231
    }
232
233
    /**
234
     * @Given the store has :firstProductName and :secondProductName products
235
     */
236
    public function theStoreHasAProductAnd($firstProductName, $secondProductName)
237
    {
238
        $this->saveProduct($this->createProduct($firstProductName));
239
        $this->saveProduct($this->createProduct($secondProductName));
240
    }
241
242
    /**
243
     * @Given /^the (product "[^"]+") has(?:| a) "([^"]+)" variant priced at ("[^"]+")$/
244
     * @Given /^(this product) has "([^"]+)" variant priced at ("[^"]+")$/
245
     */
246
    public function theProductHasVariantPricedAt(ProductInterface $product, $productVariantName, $price)
247
    {
248
        $product->setVariantSelectionMethod(ProductInterface::VARIANT_SELECTION_CHOICE);
249
250
        /** @var ProductVariantInterface $variant */
251
        $variant = $this->productVariantFactory->createNew();
252
253
        $variant->setName($productVariantName);
254
        $variant->setCode(StringInflector::nameToUppercaseCode($productVariantName));
255
        $variant->setPrice($price);
256
        $variant->setProduct($product);
257
        $product->addVariant($variant);
258
259
        $this->objectManager->flush();
260
261
        $this->sharedStorage->set('variant', $variant);
262
    }
263
264
    /**
265
     * @Given /^there is product "([^"]+)" available in ((?:this|that|"[^"]+") channel)$/
266
     * @Given /^the store has a product "([^"]+)" available in ("([^"]+)" channel)$/
267
     */
268
    public function thereIsProductAvailableInGivenChannel($productName, ChannelInterface $channel)
269
    {
270
        $product = $this->createProduct($productName);
271
272
        $product->setDescription('Awesome ' . $productName);
273
        $product->addChannel($channel);
274
275
        $this->saveProduct($product);
276
    }
277
278
    /**
279
     * @Given /^([^"]+) belongs to ("[^"]+" tax category)$/
280
     */
281
    public function productBelongsToTaxCategory(ProductInterface $product, TaxCategoryInterface $taxCategory)
282
    {
283
        /** @var ProductVariantInterface $variant */
284
        $variant = $this->defaultVariantResolver->getVariant($product);
285
        $variant->setTaxCategory($taxCategory);
286
287
        $this->objectManager->flush();
288
    }
289
290
    /**
291
     * @Given /^(it) comes in the following variations:$/
292
     */
293
    public function itComesInTheFollowingVariations(ProductInterface $product, TableNode $table)
294
    {
295
        foreach ($table->getHash() as $variantHash) {
296
            /** @var ProductVariantInterface $variant */
297
            $variant = $this->productVariantFactory->createNew();
298
299
            $variant->setName($variantHash['name']);
300
            $variant->setCode(StringInflector::nameToUppercaseCode($variantHash['name']));
301
            $variant->setPrice($this->getPriceFromString(str_replace(['$', '€', '£'], '', $variantHash['price'])));
302
            $variant->setProduct($product);
303
            $product->addVariant($variant);
304
        }
305
306
        $this->objectManager->flush();
307
    }
308
309
    /**
310
     * @Given /^("[^"]+" variant of product "[^"]+") belongs to ("[^"]+" tax category)$/
311
     */
312
    public function productVariantBelongsToTaxCategory(
313
        ProductVariantInterface $productVariant,
314
        TaxCategoryInterface $taxCategory
315
    ) {
316
        $productVariant->setTaxCategory($taxCategory);
317
        $this->objectManager->flush($productVariant);
318
    }
319
320
    /**
321
     * @Given /^(this product) has ([^"]+) attribute "([^"]+)" with value "([^"]+)"$/
322
     */
323
    public function thisProductHasAttributeWithValue(ProductInterface $product, $productAttributeType, $productAttributeName, $value)
324
    {
325
        $attribute = $this->createProductAttribute($productAttributeType,$productAttributeName);
326
        $attributeValue = $this->createProductAttributeValue($value, $attribute);
327
        $product->addAttribute($attributeValue);
328
329
        $this->objectManager->flush();
330
    }
331
332
    /**
333
     * @Given /^(this product) has percent attribute "([^"]+)" with value ([^"]+)%$/
334
     */
335
    public function thisProductHasPercentAttributeWithValue(ProductInterface $product, $productAttributeName, $value)
336
    {
337
        $attribute = $this->createProductAttribute('percent',$productAttributeName);
338
        $attributeValue = $this->createProductAttributeValue($value/100, $attribute);
339
        $product->addAttribute($attributeValue);
340
341
        $this->objectManager->flush();
342
    }
343
344
    /**
345
     * @Given /^(this product) has ([^"]+) attribute "([^"]+)" set to "([^"]+)"$/
346
     */
347
    public function thisProductHasCheckboxAttributeWithValue(ProductInterface $product, $productAttributeType, $productAttributeName, $value)
348
    {
349
        $attribute = $this->createProductAttribute($productAttributeType, $productAttributeName);
350
        $booleanValue = ('Yes' === $value);
351
        $attributeValue = $this->createProductAttributeValue($booleanValue, $attribute);
0 ignored issues
show
Documentation introduced by
$booleanValue is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
352
        $product->addAttribute($attributeValue);
353
354
        $this->objectManager->flush();
355
    }
356
357
    /**
358
     * @Given /^(this product) has ([^"]+) attribute "([^"]+)" with date "([^"]+)"$/
359
     */
360
    public function thisProductHasDateTimeAttributeWithDate(ProductInterface $product, $productAttributeType, $productAttributeName, $date)
361
    {
362
        $attribute = $this->createProductAttribute($productAttributeType, $productAttributeName);
363
        $attributeValue = $this->createProductAttributeValue(new \DateTime($date), $attribute);
0 ignored issues
show
Documentation introduced by
new \DateTime($date) is of type object<DateTime>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
364
365
        $product->addAttribute($attributeValue);
366
367
        $this->objectManager->flush();
368
    }
369
370
    /**
371
     * @Given /^(this product) has option "([^"]+)" with values "([^"]+)" and "([^"]+)"$/
372
     * @Given /^(this product) has option "([^"]+)" with values "([^"]+)", "([^"]+)" and "([^"]+)"$/
373
     */
374
    public function thisProductHasOptionWithValues(ProductInterface $product, $optionName, ...$values)
375
    {
376
        /** @var ProductOptionInterface $option */
377
        $option = $this->productOptionFactory->createNew();
378
379
        $option->setName($optionName);
380
        $option->setCode(StringInflector::nameToUppercaseCode($optionName));
381
382
        $this->sharedStorage->set(sprintf('%s_option', $optionName), $option);
383
384
        foreach ($values as $key => $value) {
385
            $optionValue = $this->addProductOption($option, $value, StringInflector::nameToUppercaseCode($value));
386
            $this->sharedStorage->set(sprintf('%s_option_%s_value', $value, strtolower($optionName)), $optionValue);
387
        }
388
389
        $product->addOption($option);
390
        $product->setVariantSelectionMethod(ProductInterface::VARIANT_SELECTION_MATCH);
391
392
        $this->objectManager->persist($option);
393
        $this->objectManager->flush();
394
    }
395
396
    /**
397
     * @Given /^there (?:is|are) (\d+) unit(?:|s) of (product "([^"]+)") available in the inventory$/
398
     * @When product :product quantity is changed to :quantity
399
     */
400
    public function thereIsQuantityOfProducts($quantity, ProductInterface $product)
401
    {
402
        /** @var ProductVariantInterface $productVariant */
403
        $productVariant = $this->defaultVariantResolver->getVariant($product);
404
        $productVariant->setOnHand($quantity);
405
406
        $this->objectManager->flush();
407
    }
408
409
    /**
410
     * @Given /^the (product "([^"]+)") is out of stock$/
411
     */
412
    public function theProductIsOutOfStock(ProductInterface $product)
413
    {
414
        /** @var ProductVariantInterface $productVariant */
415
        $productVariant = $this->defaultVariantResolver->getVariant($product);
416
        $productVariant->setTracked(true);
417
        $productVariant->setOnHand(0);
418
419
        $this->objectManager->flush();
420
    }
421
422
    /**
423
     * @When other customer has bought :quantity :product products by this time
424
     */
425
    public function otherCustomerHasBoughtProductsByThisTime($quantity, ProductInterface $product)
426
    {
427
        /** @var ProductVariantInterface $productVariant */
428
        $productVariant = $this->defaultVariantResolver->getVariant($product);
429
        $productVariant->setOnHand($productVariant->getOnHand() - $quantity);
430
431
        $this->objectManager->flush();
432
    }
433
434
    /**
435
     * @Given /^(this product) is tracked by the inventory$/
436
     * @Given /^(?:|the )("[^"]+" product) is(?:| also) tracked by the inventory$/
437
     */
438
    public function thisProductIsTrackedByTheInventory(ProductInterface $product)
439
    {
440
        /** @var ProductVariantInterface $productVariant */
441
        $productVariant = $this->defaultVariantResolver->getVariant($product);
442
        $productVariant->setTracked(true);
443
444
        $this->objectManager->flush();
445
    }
446
447
    /**
448
     * @Given /^(this product) is available in "([^"]+)" ([^"]+) priced at ("[^"]+")$/
449
     */
450
    public function thisProductIsAvailableInSize(ProductInterface $product, $optionValueName, $optionName, $price)
451
    {
452
        /** @var ProductVariantInterface $variant */
453
        $variant = $this->productVariantFactory->createNew();
454
455
        $optionValue = $this->sharedStorage->get(sprintf('%s_option_%s_value', $optionValueName, $optionName));
456
457
        $variant->addOptionValue($optionValue);
458
        $variant->setPrice($price);
459
        $variant->setCode(sprintf("%s_%s", $product->getCode(), $optionValueName));
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal %s_%s does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
460
461
        $product->addVariant($variant);
462
        $this->objectManager->flush();
463
    }
464
465
    /**
466
     * @Given /^(this product) has (this product option)$/
467
     * @Given /^(this product) has a ("[^"]+" option)$/
468
     * @Given /^(this product) has an ("[^"]+" option)$/
469
     */
470
    public function thisProductHasThisProductOption(ProductInterface $product, ProductOptionInterface $option)
471
    {
472
        $product->addOption($option);
473
474
        $this->objectManager->flush();
475
    }
476
477
    /**
478
     * @Given /^there are ([^"]+) units of ("[^"]+" variant of product "[^"]+") available in the inventory$/
479
     */
480
    public function thereAreItemsOfProductInVariantAvailableInTheInventory($quantity, ProductVariantInterface $productVariant)
481
    {
482
        $productVariant->setTracked(true);
483
        $productVariant->setOnHand($quantity);
484
485
        $this->objectManager->flush();
486
    }
487
488
    /**
489
     * @Given /^the ("[^"]+" product variant) is tracked by the inventory$/
490
     */
491
    public function theProductVariantIsTrackedByTheInventory(ProductVariantInterface $productVariant)
492
    {
493
        $productVariant->setTracked(true);
494
495
        $this->objectManager->flush();
496
    }
497
498
    /**
499
     * @Given /^(this product)'s price is ("[^"]+")$/
500
     * @Given /^the (product "[^"]+") changed its price to ("[^"]+")$/
501
     */
502
    public function theProductChangedItsPriceTo(ProductInterface $product, $price)
503
    {
504
        /** @var ProductVariantInterface $productVariant */
505
        $productVariant = $this->defaultVariantResolver->getVariant($product);
506
        $productVariant->setPrice($price);
507
508
        $this->objectManager->flush();
509
    }
510
511
    /**
512
     * @Given /^(this product) has(?:| also) an image "([^"]+)" with a code "([^"]+)"$/
513
     * @Given /^the ("[^"]+" product) has(?:| also) an image "([^"]+)" with a code "([^"]+)"$/
514
     */
515
    public function thisProductHasAnImageWithACode(ProductInterface $product, $imagePath, $imageCode)
516
    {
517
        $filesPath = $this->getParameter('files_path');
518
519
        /** @var ImageInterface $productImage */
520
        $productImage = $this->productImageFactory->createNew();
521
        $productImage->setFile(new UploadedFile($filesPath.$imagePath, basename($imagePath)));
522
        $productImage->setCode($imageCode);
523
        $this->imageUploader->upload($productImage);
524
525
        $product->addImage($productImage);
526
527
        $this->objectManager->flush($product);
528
    }
529
530
    /**
531
     * @param string $type
532
     * @param string $name
533
     * @param string $code
534
     *
535
     * @return ProductAttributeInterface
536
     */
537
    private function createProductAttribute($type, $name, $code = 'PA112')
538
    {
539
        $productAttribute = $this->productAttributeFactory->createTyped($type);
540
        $productAttribute->setCode($code);
541
        $productAttribute->setName($name);
542
543
        $this->objectManager->persist($productAttribute);
544
545
        return $productAttribute;
546
    }
547
548
    /**
549
     * @param string $value
550
     *
551
     * @return ProductAttributeValueInterface
552
     */
553
    private function createProductAttributeValue($value, ProductAttributeInterface $attribute)
554
    {
555
        /** @var ProductAttributeValueInterface $attributeValue */
556
        $attributeValue = $this->attributeValueFactory->createNew();
557
        $attributeValue->setAttribute($attribute);
558
        $attributeValue->setValue($value);
559
560
        $this->objectManager->persist($attributeValue);
561
562
        return $attributeValue;
563
    }
564
565
    /**
566
     * @param string $price
567
     *
568
     * @return int
569
     */
570
    private function getPriceFromString($price)
571
    {
572
        return (int) round(($price * 100), 2);
573
    }
574
575
    /**
576
     * @param string $productName
577
     * @param int $price
578
     *
579
     * @return ProductInterface
580
     */
581
    private function createProduct($productName, $price = 0, $date = null)
582
    {
583
        /** @var ProductInterface $product */
584
        $product = $this->productFactory->createWithVariant();
585
586
        $product->setName($productName);
587
        $product->setCode(StringInflector::nameToUppercaseCode($productName));
588
        $product->setCreatedAt(new \DateTime($date));
589
590
        /** @var ProductVariantInterface $productVariant */
591
        $productVariant = $this->defaultVariantResolver->getVariant($product);
592
        $productVariant->setPrice($price);
593
        $productVariant->setCode($product->getCode());
594
595
        return $product;
596
    }
597
598
    /**
599
     * @param ProductOptionInterface $option
600
     * @param string $value
601
     * @param string $code
602
     *
603
     * @return ProductOptionValueInterface
604
     */
605
    private function addProductOption(ProductOptionInterface $option, $value, $code)
606
    {
607
        /** @var ProductOptionValueInterface $optionValue */
608
        $optionValue = $this->productOptionValueFactory->createNew();
609
610
        $optionValue->setValue($value);
611
        $optionValue->setCode($code);
612
        $optionValue->setOption($option);
613
614
        $option->addValue($optionValue);
615
616
        return $optionValue;
617
    }
618
619
    /**
620
     * @param ProductInterface $product
621
     */
622
    private function saveProduct(ProductInterface $product)
623
    {
624
        $this->productRepository->add($product);
625
        $this->sharedStorage->set('product', $product);
626
    }
627
628
    /**
629
     * @param string $name
630
     *
631
     * @return NodeElement
632
     */
633
    private function getParameter($name)
634
    {
635
        return isset($this->minkParameters[$name]) ? $this->minkParameters[$name] : null;
636
    }
637
}
638