Complex classes like ProductContext often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ProductContext, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
48 | final class ProductContext implements Context |
||
49 | { |
||
50 | /** |
||
51 | * @var SharedStorageInterface |
||
52 | */ |
||
53 | private $sharedStorage; |
||
54 | |||
55 | /** |
||
56 | * @var ProductRepositoryInterface |
||
57 | */ |
||
58 | private $productRepository; |
||
59 | |||
60 | /** |
||
61 | * @var ProductFactoryInterface |
||
62 | */ |
||
63 | private $productFactory; |
||
64 | |||
65 | /** |
||
66 | * @var FactoryInterface |
||
67 | */ |
||
68 | private $productTranslationFactory; |
||
69 | |||
70 | /** |
||
71 | * @var FactoryInterface |
||
72 | */ |
||
73 | private $productVariantFactory; |
||
74 | |||
75 | /** |
||
76 | * @var FactoryInterface |
||
77 | */ |
||
78 | private $productVariantTranslationFactory; |
||
79 | |||
80 | /** |
||
81 | * @var FactoryInterface |
||
82 | */ |
||
83 | private $channelPricingFactory; |
||
84 | |||
85 | /** |
||
86 | * @var FactoryInterface |
||
87 | */ |
||
88 | private $productOptionFactory; |
||
89 | |||
90 | /** |
||
91 | * @var FactoryInterface |
||
92 | */ |
||
93 | private $productOptionValueFactory; |
||
94 | |||
95 | /** |
||
96 | * @var FactoryInterface |
||
97 | */ |
||
98 | private $productImageFactory; |
||
99 | |||
100 | /** |
||
101 | * @var ObjectManager |
||
102 | */ |
||
103 | private $objectManager; |
||
104 | |||
105 | /** |
||
106 | * @var ProductVariantResolverInterface |
||
107 | */ |
||
108 | private $defaultVariantResolver; |
||
109 | |||
110 | /** |
||
111 | * @var ImageUploaderInterface |
||
112 | */ |
||
113 | private $imageUploader; |
||
114 | |||
115 | /** |
||
116 | * @var SlugGeneratorInterface |
||
117 | */ |
||
118 | private $slugGenerator; |
||
119 | |||
120 | /** |
||
121 | * @var array |
||
122 | */ |
||
123 | private $minkParameters; |
||
124 | |||
125 | /** |
||
126 | * @param SharedStorageInterface $sharedStorage |
||
127 | * @param ProductRepositoryInterface $productRepository |
||
128 | * @param ProductFactoryInterface $productFactory |
||
129 | * @param FactoryInterface $productTranslationFactory |
||
130 | * @param FactoryInterface $productVariantFactory |
||
131 | * @param FactoryInterface $productVariantTranslationFactory |
||
132 | * @param FactoryInterface $channelPricingFactory |
||
133 | * @param FactoryInterface $productOptionFactory |
||
134 | * @param FactoryInterface $productOptionValueFactory |
||
135 | * @param FactoryInterface $productImageFactory |
||
136 | * @param ObjectManager $objectManager |
||
137 | * @param ProductVariantResolverInterface $defaultVariantResolver |
||
138 | * @param ImageUploaderInterface $imageUploader |
||
139 | * @param SlugGeneratorInterface $slugGenerator |
||
140 | * @param array $minkParameters |
||
141 | */ |
||
142 | public function __construct( |
||
175 | |||
176 | /** |
||
177 | * @Given the store has a product :productName |
||
178 | * @Given the store has a :productName product |
||
179 | * @Given I added a product :productName |
||
180 | * @Given /^the store(?:| also) has a product "([^"]+)" priced at ("[^"]+")$/ |
||
181 | * @Given /^the store(?:| also) has a product "([^"]+)" priced at ("[^"]+") in ("[^"]+" channel)$/ |
||
182 | */ |
||
183 | public function storeHasAProductPricedAt($productName, $price = 100, ChannelInterface $channel = null) |
||
184 | { |
||
185 | $product = $this->createProduct($productName, $price, $channel); |
||
186 | |||
187 | $this->saveProduct($product); |
||
188 | } |
||
189 | |||
190 | /** |
||
191 | * @Given /^(this product) is also priced at ("[^"]+") in ("[^"]+" channel)$/ |
||
192 | */ |
||
193 | public function thisProductIsAlsoPricedAtInChannel(ProductInterface $product, $price, ChannelInterface $channel) |
||
194 | { |
||
195 | $product->addChannel($channel); |
||
196 | |||
197 | /** @var ProductVariantInterface $productVariant */ |
||
198 | $productVariant = $this->defaultVariantResolver->getVariant($product); |
||
199 | $productVariant->addChannelPricing($this->createChannelPricingForChannel($price, $channel)); |
||
200 | |||
201 | $this->objectManager->flush(); |
||
202 | } |
||
203 | |||
204 | /** |
||
205 | * @Given the store( also) has a product :productName with code :code |
||
206 | * @Given the store( also) has a product :productName with code :code, created at :date |
||
207 | */ |
||
208 | public function storeHasProductWithCode($productName, $code, $date = null) |
||
209 | { |
||
210 | $product = $this->createProduct($productName); |
||
211 | $product->setCreatedAt(new \DateTime($date)); |
||
212 | $product->setCode($code); |
||
213 | |||
214 | $this->saveProduct($product); |
||
215 | } |
||
216 | |||
217 | /** |
||
218 | * @Given /^the store(?:| also) has a product "([^"]+)" priced at ("[^"]+") available in (channel "[^"]+") and (channel "[^"]+")$/ |
||
219 | */ |
||
220 | public function storeHasAProductPricedAtAvailableInChannels($productName, $price = 100, ...$channels) |
||
221 | { |
||
222 | $product = $this->createProduct($productName, $price); |
||
223 | /** @var ProductVariantInterface $productVariant */ |
||
224 | $productVariant = $this->defaultVariantResolver->getVariant($product); |
||
225 | |||
226 | foreach ($channels as $channel) { |
||
227 | $product->addChannel($channel); |
||
228 | if (!$productVariant->hasChannelPricingForChannel($channel)) { |
||
229 | $productVariant->addChannelPricing($this->createChannelPricingForChannel($price, $channel)); |
||
230 | } |
||
231 | } |
||
232 | |||
233 | $this->saveProduct($product); |
||
234 | } |
||
235 | |||
236 | /** |
||
237 | * @Given /^(this product) is named "([^"]+)" (in the "([^"]+)" locale)$/ |
||
238 | * @Given /^the (product "[^"]+") is named "([^"]+)" (in the "([^"]+)" locale)$/ |
||
239 | */ |
||
240 | public function thisProductIsNamedIn(ProductInterface $product, $name, $locale) |
||
241 | { |
||
242 | $this->addProductTranslation($product, $name, $locale); |
||
243 | |||
244 | $this->objectManager->flush(); |
||
245 | } |
||
246 | |||
247 | /** |
||
248 | * @Given /^the store has a product named "([^"]+)" in ("[^"]+" locale) and "([^"]+)" in ("[^"]+" locale)$/ |
||
249 | */ |
||
250 | public function theStoreHasProductNamedInAndIn($firstName, $firstLocale, $secondName, $secondLocale) |
||
251 | { |
||
252 | $product = $this->createProduct($firstName); |
||
253 | |||
254 | $names = [$firstName => $firstLocale, $secondName => $secondLocale]; |
||
255 | foreach ($names as $name => $locale) { |
||
256 | $this->addProductTranslation($product, $name, $locale); |
||
257 | } |
||
258 | |||
259 | $this->saveProduct($product); |
||
260 | } |
||
261 | |||
262 | /** |
||
263 | * @Given /^the store has(?:| a| an) "([^"]+)" configurable product$/ |
||
264 | * @Given /^the store has(?:| a| an) "([^"]+)" configurable product with "([^"]+)" slug$/ |
||
265 | */ |
||
266 | public function storeHasAConfigurableProduct($productName, $slug = null) |
||
267 | { |
||
268 | /** @var ChannelInterface|null $channel */ |
||
269 | $channel = null; |
||
270 | if ($this->sharedStorage->has('channel')) { |
||
271 | $channel = $this->sharedStorage->get('channel'); |
||
272 | } |
||
273 | |||
274 | /** @var ProductInterface $product */ |
||
275 | $product = $this->productFactory->createNew(); |
||
276 | $product->setCode(StringInflector::nameToUppercaseCode($productName)); |
||
277 | |||
278 | if (null !== $channel) { |
||
279 | $product->addChannel($channel); |
||
280 | |||
281 | foreach ($channel->getLocales() as $locale) { |
||
282 | $product->setFallbackLocale($locale->getCode()); |
||
283 | $product->setCurrentLocale($locale->getCode()); |
||
284 | |||
285 | $product->setName($productName); |
||
286 | $product->setSlug($slug ?: $this->slugGenerator->generate($productName)); |
||
287 | } |
||
288 | } |
||
289 | |||
290 | $this->saveProduct($product); |
||
291 | } |
||
292 | |||
293 | /** |
||
294 | * @Given the store has( also) :firstProductName and :secondProductName products |
||
295 | * @Given the store has( also) :firstProductName, :secondProductName and :thirdProductName products |
||
296 | * @Given the store has( also) :firstProductName, :secondProductName, :thirdProductName and :fourthProductName products |
||
297 | */ |
||
298 | public function theStoreHasProducts(...$productsNames) |
||
299 | { |
||
300 | foreach ($productsNames as $productName) { |
||
301 | $this->saveProduct($this->createProduct($productName)); |
||
302 | } |
||
303 | } |
||
304 | |||
305 | /** |
||
306 | * @Given /^(this channel) has "([^"]+)", "([^"]+)", "([^"]+)" and "([^"]+)" products$/ |
||
307 | */ |
||
308 | public function thisChannelHasProducts(ChannelInterface $channel, ...$productsNames) |
||
309 | { |
||
310 | foreach ($productsNames as $productName) { |
||
311 | $product = $this->createProduct($productName, 0, $channel); |
||
312 | |||
313 | $this->saveProduct($product); |
||
314 | } |
||
315 | } |
||
316 | |||
317 | /** |
||
318 | * @Given /^the (product "[^"]+") has(?:| a) "([^"]+)" variant priced at ("[^"]+")$/ |
||
319 | * @Given /^(this product) has "([^"]+)" variant priced at ("[^"]+")$/ |
||
320 | * @Given /^(this product) has "([^"]+)" variant priced at ("[^"]+") in ("([^"]+)" channel)$/ |
||
321 | */ |
||
322 | public function theProductHasVariantPricedAt( |
||
323 | ProductInterface $product, |
||
324 | $productVariantName, |
||
325 | $price, |
||
326 | ChannelInterface $channel = null |
||
327 | ) { |
||
328 | $this->createProductVariant( |
||
329 | $product, |
||
330 | $productVariantName, |
||
331 | $price, |
||
332 | StringInflector::nameToUppercaseCode($productVariantName), |
||
333 | (null !== $channel) ? $channel : $this->sharedStorage->get('channel') |
||
334 | ); |
||
335 | } |
||
336 | |||
337 | /** |
||
338 | * @Given /^the (product "[^"]+") has(?:| a| an) "([^"]+)" variant$/ |
||
339 | * @Given /^(this product) has(?:| a| an) "([^"]+)" variant$/ |
||
340 | * @Given /^(this product) has "([^"]+)", "([^"]+)" and "([^"]+)" variants$/ |
||
341 | */ |
||
342 | public function theProductHasVariants(ProductInterface $product, ...$variantNames) |
||
343 | { |
||
344 | $channel = $this->sharedStorage->get('channel'); |
||
345 | |||
346 | foreach ($variantNames as $name) { |
||
347 | $this->createProductVariant( |
||
348 | $product, |
||
349 | $name, |
||
350 | 0, |
||
351 | StringInflector::nameToUppercaseCode($name), |
||
352 | $channel |
||
353 | ); |
||
354 | } |
||
355 | } |
||
356 | |||
357 | /** |
||
358 | * @Given /^the (product "[^"]+")(?:| also) has a nameless variant with code "([^"]+)"$/ |
||
359 | * @Given /^(this product)(?:| also) has a nameless variant with code "([^"]+)"$/ |
||
360 | * @Given /^(it)(?:| also) has a nameless variant with code "([^"]+)"$/ |
||
361 | */ |
||
362 | public function theProductHasNamelessVariantWithCode(ProductInterface $product, $variantCode) |
||
363 | { |
||
364 | $channel = $this->sharedStorage->get('channel'); |
||
365 | |||
366 | $this->createProductVariant($product, null, 0, $variantCode, $channel); |
||
367 | } |
||
368 | |||
369 | /** |
||
370 | * @Given /^the (product "[^"]+")(?:| also) has(?:| a| an) "([^"]+)" variant with code "([^"]+)"$/ |
||
371 | * @Given /^(this product)(?:| also) has(?:| a| an) "([^"]+)" variant with code "([^"]+)"$/ |
||
372 | * @Given /^(it)(?:| also) has(?:| a| an) "([^"]+)" variant with code "([^"]+)"$/ |
||
373 | */ |
||
374 | public function theProductHasVariantWithCode(ProductInterface $product, $variantName, $variantCode) |
||
375 | { |
||
376 | $channel = $this->sharedStorage->get('channel'); |
||
377 | |||
378 | $this->createProductVariant($product, $variantName, 0, $variantCode, $channel); |
||
379 | } |
||
380 | |||
381 | /** |
||
382 | * @Given /^(this product) has "([^"]+)" variant priced at ("[^"]+") which does not require shipping$/ |
||
383 | */ |
||
384 | public function theProductHasVariantWhichDoesNotRequireShipping( |
||
385 | ProductInterface $product, |
||
386 | $productVariantName, |
||
387 | $price |
||
388 | ) { |
||
389 | $this->createProductVariant( |
||
390 | $product, |
||
391 | $productVariantName, |
||
392 | $price, |
||
393 | StringInflector::nameToUppercaseCode($productVariantName), |
||
394 | $this->sharedStorage->get('channel'), |
||
395 | null, |
||
396 | false |
||
397 | ); |
||
398 | } |
||
399 | |||
400 | /** |
||
401 | * @Given /^the (product "[^"]+") has(?:| also)(?:| a| an) "([^"]+)" variant$/ |
||
402 | * @Given /^the (product "[^"]+") has(?:| also)(?:| a| an) "([^"]+)" variant at position ([^"]+)$/ |
||
403 | * @Given /^(this product) has(?:| also)(?:| a| an) "([^"]+)" variant at position ([^"]+)$/ |
||
404 | */ |
||
405 | public function theProductHasVariantAtPosition( |
||
406 | ProductInterface $product, |
||
407 | $productVariantName, |
||
408 | $position = null |
||
409 | ) { |
||
410 | $this->createProductVariant( |
||
411 | $product, |
||
412 | $productVariantName, |
||
413 | 0, |
||
414 | StringInflector::nameToUppercaseCode($productVariantName), |
||
415 | $this->sharedStorage->get('channel'), |
||
416 | $position |
||
417 | ); |
||
418 | } |
||
419 | |||
420 | /** |
||
421 | * @Given /^(this variant) is also priced at ("[^"]+") in ("([^"]+)" channel)$/ |
||
422 | */ |
||
423 | public function thisVariantIsAlsoPricedAtInChannel(ProductVariantInterface $productVariant, $price, ChannelInterface $channel) |
||
424 | { |
||
425 | $productVariant->addChannelPricing($this->createChannelPricingForChannel( |
||
426 | $this->getPriceFromString(str_replace(['$', '€', '£'], '', $price)), |
||
427 | $channel |
||
428 | )); |
||
429 | |||
430 | $this->objectManager->flush(); |
||
431 | } |
||
432 | |||
433 | /** |
||
434 | * @Given /^(it|this product) has(?:| also) variant named "([^"]+)" in ("[^"]+" locale) and "([^"]+)" in ("[^"]+" locale)$/ |
||
435 | */ |
||
436 | public function itHasVariantNamedInAndIn(ProductInterface $product, $firstName, $firstLocale, $secondName, $secondLocale) |
||
437 | { |
||
438 | $productVariant = $this->createProductVariant( |
||
439 | $product, |
||
440 | $firstName, |
||
441 | 100, |
||
442 | StringInflector::nameToUppercaseCode($firstName), |
||
443 | $this->sharedStorage->get('channel') |
||
444 | ); |
||
445 | |||
446 | $names = [$firstName => $firstLocale, $secondName => $secondLocale]; |
||
447 | foreach ($names as $name => $locale) { |
||
448 | $this->addProductVariantTranslation($productVariant, $name, $locale); |
||
449 | } |
||
450 | |||
451 | $this->objectManager->flush(); |
||
452 | } |
||
453 | |||
454 | /** |
||
455 | * @Given /^(this product) has "([^"]+)" variant priced at ("[^"]+") identified by "([^"]+)"$/ |
||
456 | */ |
||
457 | public function theProductHasVariantPricedAtIdentifiedBy( |
||
458 | ProductInterface $product, |
||
459 | $productVariantName, |
||
460 | $price, |
||
461 | $code |
||
462 | ) { |
||
463 | $this->createProductVariant($product, $productVariantName, $price, $code, $this->sharedStorage->get('channel')); |
||
464 | } |
||
465 | |||
466 | /** |
||
467 | * @Given /^there is product "([^"]+)" available in ((?:this|that|"[^"]+") channel)$/ |
||
468 | * @Given /^the store has a product "([^"]+)" available in ("([^"]+)" channel)$/ |
||
469 | */ |
||
470 | public function thereIsProductAvailableInGivenChannel($productName, ChannelInterface $channel) |
||
471 | { |
||
472 | $product = $this->createProduct($productName, 0, $channel); |
||
473 | |||
474 | $this->saveProduct($product); |
||
475 | } |
||
476 | |||
477 | /** |
||
478 | * @Given /^([^"]+) belongs to ("[^"]+" tax category)$/ |
||
479 | */ |
||
480 | public function productBelongsToTaxCategory(ProductInterface $product, TaxCategoryInterface $taxCategory) |
||
481 | { |
||
482 | /** @var ProductVariantInterface $variant */ |
||
483 | $variant = $this->defaultVariantResolver->getVariant($product); |
||
484 | $variant->setTaxCategory($taxCategory); |
||
485 | |||
486 | $this->objectManager->flush(); |
||
487 | } |
||
488 | |||
489 | /** |
||
490 | * @Given /^(it) comes in the following variations:$/ |
||
491 | */ |
||
492 | public function itComesInTheFollowingVariations(ProductInterface $product, TableNode $table) |
||
493 | { |
||
494 | $channel = $this->sharedStorage->get('channel'); |
||
495 | |||
496 | foreach ($table->getHash() as $variantHash) { |
||
497 | /** @var ProductVariantInterface $variant */ |
||
498 | $variant = $this->productVariantFactory->createNew(); |
||
499 | |||
500 | $variant->setName($variantHash['name']); |
||
501 | $variant->setCode(StringInflector::nameToUppercaseCode($variantHash['name'])); |
||
502 | $variant->addChannelPricing($this->createChannelPricingForChannel( |
||
503 | $this->getPriceFromString(str_replace(['$', '€', '£'], '', $variantHash['price'])), |
||
504 | $channel |
||
505 | )); |
||
506 | |||
507 | $variant->setProduct($product); |
||
508 | $product->addVariant($variant); |
||
509 | } |
||
510 | |||
511 | $this->objectManager->flush(); |
||
512 | } |
||
513 | |||
514 | /** |
||
515 | * @Given /^("[^"]+" variant of product "[^"]+") belongs to ("[^"]+" tax category)$/ |
||
516 | */ |
||
517 | public function productVariantBelongsToTaxCategory( |
||
518 | ProductVariantInterface $productVariant, |
||
519 | TaxCategoryInterface $taxCategory |
||
520 | ) { |
||
521 | $productVariant->setTaxCategory($taxCategory); |
||
522 | $this->objectManager->flush($productVariant); |
||
523 | } |
||
524 | |||
525 | /** |
||
526 | * @Given /^(this product) has option "([^"]+)" with values "([^"]+)" and "([^"]+)"$/ |
||
527 | * @Given /^(this product) has option "([^"]+)" with values "([^"]+)", "([^"]+)" and "([^"]+)"$/ |
||
528 | */ |
||
529 | public function thisProductHasOptionWithValues(ProductInterface $product, $optionName, ...$values) |
||
530 | { |
||
531 | /** @var ProductOptionInterface $option */ |
||
532 | $option = $this->productOptionFactory->createNew(); |
||
533 | |||
534 | $option->setName($optionName); |
||
535 | $option->setCode(StringInflector::nameToUppercaseCode($optionName)); |
||
536 | |||
537 | $this->sharedStorage->set(sprintf('%s_option', $optionName), $option); |
||
538 | |||
539 | foreach ($values as $key => $value) { |
||
540 | $optionValue = $this->addProductOption($option, $value, StringInflector::nameToUppercaseCode($value)); |
||
541 | $this->sharedStorage->set(sprintf('%s_option_%s_value', $value, strtolower($optionName)), $optionValue); |
||
542 | } |
||
543 | |||
544 | $product->addOption($option); |
||
545 | $product->setVariantSelectionMethod(ProductInterface::VARIANT_SELECTION_MATCH); |
||
546 | |||
547 | $this->objectManager->persist($option); |
||
548 | $this->objectManager->flush(); |
||
549 | } |
||
550 | |||
551 | /** |
||
552 | * @Given /^there (?:is|are) (\d+) unit(?:|s) of (product "([^"]+)") available in the inventory$/ |
||
553 | */ |
||
554 | public function thereIsQuantityOfProducts($quantity, ProductInterface $product) |
||
555 | { |
||
556 | /** @var ProductVariantInterface $productVariant */ |
||
557 | $productVariant = $this->defaultVariantResolver->getVariant($product); |
||
558 | $productVariant->setOnHand($quantity); |
||
559 | |||
560 | $this->objectManager->flush(); |
||
561 | } |
||
562 | |||
563 | /** |
||
564 | * @Given /^the (product "([^"]+)") is out of stock$/ |
||
565 | */ |
||
566 | public function theProductIsOutOfStock(ProductInterface $product) |
||
567 | { |
||
568 | /** @var ProductVariantInterface $productVariant */ |
||
569 | $productVariant = $this->defaultVariantResolver->getVariant($product); |
||
570 | $productVariant->setTracked(true); |
||
571 | $productVariant->setOnHand(0); |
||
572 | |||
573 | $this->objectManager->flush(); |
||
574 | } |
||
575 | |||
576 | /** |
||
577 | * @When other customer has bought :quantity :product products by this time |
||
578 | */ |
||
579 | public function otherCustomerHasBoughtProductsByThisTime($quantity, ProductInterface $product) |
||
580 | { |
||
581 | /** @var ProductVariantInterface $productVariant */ |
||
582 | $productVariant = $this->defaultVariantResolver->getVariant($product); |
||
583 | $productVariant->setOnHand($productVariant->getOnHand() - $quantity); |
||
584 | |||
585 | $this->objectManager->flush(); |
||
586 | } |
||
587 | |||
588 | /** |
||
589 | * @Given /^(this product) is tracked by the inventory$/ |
||
590 | * @Given /^(?:|the )("[^"]+" product) is(?:| also) tracked by the inventory$/ |
||
591 | */ |
||
592 | public function thisProductIsTrackedByTheInventory(ProductInterface $product) |
||
593 | { |
||
594 | /** @var ProductVariantInterface $productVariant */ |
||
595 | $productVariant = $this->defaultVariantResolver->getVariant($product); |
||
596 | $productVariant->setTracked(true); |
||
597 | |||
598 | $this->objectManager->flush(); |
||
599 | } |
||
600 | |||
601 | /** |
||
602 | * @Given /^(this product) is available in "([^"]+)" ([^"]+) priced at ("[^"]+")$/ |
||
603 | */ |
||
604 | public function thisProductIsAvailableInSize(ProductInterface $product, $optionValueName, $optionName, $price) |
||
605 | { |
||
606 | /** @var ProductVariantInterface $variant */ |
||
607 | $variant = $this->productVariantFactory->createNew(); |
||
608 | |||
609 | $optionValue = $this->sharedStorage->get(sprintf('%s_option_%s_value', $optionValueName, $optionName)); |
||
610 | |||
611 | $variant->addOptionValue($optionValue); |
||
612 | $variant->addChannelPricing($this->createChannelPricingForChannel($price, $this->sharedStorage->get('channel'))); |
||
613 | $variant->setCode(sprintf('%s_%s', $product->getCode(), $optionValueName)); |
||
614 | $variant->setName($product->getName()); |
||
615 | |||
616 | $product->addVariant($variant); |
||
617 | $this->objectManager->flush(); |
||
618 | } |
||
619 | |||
620 | /** |
||
621 | * @Given the :product product's :optionValueName size belongs to :shippingCategory shipping category |
||
622 | */ |
||
623 | public function thisProductSizeBelongsToShippingCategory(ProductInterface $product, $optionValueName, ShippingCategoryInterface $shippingCategory) |
||
636 | |||
637 | /** |
||
638 | * @Given /^(this product) has (this product option)$/ |
||
639 | * @Given /^(this product) has (?:a|an) ("[^"]+" option)$/ |
||
640 | */ |
||
641 | public function thisProductHasThisProductOption(ProductInterface $product, ProductOptionInterface $option) |
||
642 | { |
||
643 | $product->addOption($option); |
||
644 | |||
645 | $this->objectManager->flush(); |
||
646 | } |
||
647 | |||
648 | /** |
||
649 | * @Given /^there are ([^"]+) units of ("[^"]+" variant of product "[^"]+") available in the inventory$/ |
||
650 | */ |
||
651 | public function thereAreItemsOfProductInVariantAvailableInTheInventory($quantity, ProductVariantInterface $productVariant) |
||
652 | { |
||
653 | $productVariant->setTracked(true); |
||
654 | $productVariant->setOnHand($quantity); |
||
655 | |||
656 | $this->objectManager->flush(); |
||
657 | } |
||
658 | |||
659 | /** |
||
660 | * @Given /^the ("[^"]+" product variant) is tracked by the inventory$/ |
||
661 | */ |
||
662 | public function theProductVariantIsTrackedByTheInventory(ProductVariantInterface $productVariant) |
||
663 | { |
||
664 | $productVariant->setTracked(true); |
||
665 | |||
666 | $this->objectManager->flush(); |
||
667 | } |
||
668 | |||
669 | /** |
||
670 | * @Given /^(this product)'s price is ("[^"]+")$/ |
||
671 | * @Given /^the (product "[^"]+") changed its price to ("[^"]+")$/ |
||
672 | * @Given /^(this product) price has been changed to ("[^"]+")$/ |
||
673 | */ |
||
674 | public function theProductChangedItsPriceTo(ProductInterface $product, $price) |
||
683 | |||
684 | /** |
||
685 | * @Given /^(this product)(?:| also) has an image "([^"]+)" with "([^"]+)" type$/ |
||
686 | * @Given /^the ("[^"]+" product)(?:| also) has an image "([^"]+)" with "([^"]+)" type$/ |
||
687 | * @Given /^(it)(?:| also) has an image "([^"]+)" with "([^"]+)" type$/ |
||
688 | */ |
||
689 | public function thisProductHasAnImageWithType(ProductInterface $product, $imagePath, $imageType) |
||
690 | { |
||
691 | $filesPath = $this->getParameter('files_path'); |
||
692 | |||
693 | /** @var ImageInterface $productImage */ |
||
694 | $productImage = $this->productImageFactory->createNew(); |
||
695 | $productImage->setFile(new UploadedFile($filesPath.$imagePath, basename($imagePath))); |
||
696 | $productImage->setType($imageType); |
||
697 | $this->imageUploader->upload($productImage); |
||
698 | |||
699 | $product->addImage($productImage); |
||
700 | |||
701 | $this->objectManager->flush($product); |
||
702 | } |
||
703 | |||
704 | /** |
||
705 | * @Given /^(this product) belongs to ("([^"]+)" shipping category)$/ |
||
706 | * @Given product :product shipping category has been changed to :shippingCategory |
||
707 | */ |
||
708 | public function thisProductBelongsToShippingCategory(ProductInterface $product, ShippingCategoryInterface $shippingCategory) |
||
709 | { |
||
710 | $product->getVariants()->first()->setShippingCategory($shippingCategory); |
||
711 | $this->objectManager->flush(); |
||
712 | } |
||
713 | |||
714 | /** |
||
715 | * @Given /^(this product) has been disabled$/ |
||
716 | */ |
||
717 | public function thisProductHasBeenDisabled(ProductInterface $product) |
||
722 | |||
723 | /** |
||
724 | * @param string $price |
||
725 | * |
||
726 | * @return int |
||
727 | */ |
||
728 | private function getPriceFromString($price) |
||
732 | |||
733 | /** |
||
734 | * @param string $productName |
||
735 | * @param int $price |
||
736 | * @param ChannelInterface|null $channel |
||
737 | * |
||
738 | * @return ProductInterface |
||
739 | */ |
||
740 | private function createProduct($productName, $price = 100, ChannelInterface $channel = null) |
||
777 | |||
778 | /** |
||
779 | * @param ProductOptionInterface $option |
||
780 | * @param string $value |
||
781 | * @param string $code |
||
782 | * |
||
783 | * @return ProductOptionValueInterface |
||
784 | */ |
||
785 | private function addProductOption(ProductOptionInterface $option, $value, $code) |
||
798 | |||
799 | /** |
||
800 | * @param ProductInterface $product |
||
801 | */ |
||
802 | private function saveProduct(ProductInterface $product) |
||
807 | |||
808 | /** |
||
809 | * @param string $name |
||
810 | * |
||
811 | * @return NodeElement |
||
812 | */ |
||
813 | private function getParameter($name) |
||
817 | |||
818 | /** |
||
819 | * @param ProductInterface $product |
||
820 | * @param $productVariantName |
||
821 | * @param int $price |
||
822 | * @param string $code |
||
823 | * @param ChannelInterface $channel |
||
|
|||
824 | * @param int $position |
||
825 | * @param bool $shippingRequired |
||
826 | * |
||
827 | * @return ProductVariantInterface |
||
828 | */ |
||
829 | private function createProductVariant( |
||
857 | |||
858 | /** |
||
859 | * @param ProductInterface $product |
||
860 | * @param string $name |
||
861 | * @param string $locale |
||
862 | */ |
||
863 | private function addProductTranslation(ProductInterface $product, $name, $locale) |
||
877 | |||
878 | /** |
||
879 | * @param ProductVariantInterface $productVariant |
||
880 | * @param string $name |
||
881 | * @param string $locale |
||
882 | */ |
||
883 | private function addProductVariantTranslation(ProductVariantInterface $productVariant, $name, $locale) |
||
892 | |||
893 | /** |
||
894 | * @param int $price |
||
895 | * @param ChannelInterface|null $channel |
||
896 | * |
||
897 | * @return ChannelPricingInterface |
||
898 | */ |
||
899 | private function createChannelPricingForChannel($price, ChannelInterface $channel = null) |
||
908 | } |
||
909 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.