Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertConfigurableProductOutOfStockPage.php
Go to the documentation of this file.
1 <?php
8 
10 
12 {
18  protected function verify()
19  {
20  $errors = parent::verify();
21 
22  return array_filter($errors);
23  }
24 
30  protected function verifyPrice()
31  {
32  $priceBlock = $this->productView->getPriceBlock();
33  $fixturePrice = $this->getLowestConfigurablePrice();
34 
35  if ($fixturePrice === null) {
36  if ($priceBlock->isVisible()) {
37  return "Price block for '{$this->product->getName()}' product' is visible.";
38  }
39  } else {
40  if (!$priceBlock->isVisible()) {
41  return "Price block for '{$this->product->getName()}' product' is not visible.";
42  }
43 
44  $formPrice = $priceBlock->isOldPriceVisible() ? $priceBlock->getOldPrice() : $priceBlock->getPrice();
45 
46  if ($fixturePrice != $formPrice) {
47  return "Displayed product price on product page (front-end) not equals passed from fixture. "
48  . "Actual: {$formPrice}, expected: {$fixturePrice}.";
49  }
50  }
51 
52  return null;
53  }
54 
60  protected function getLowestConfigurablePrice()
61  {
62  $price = null;
63  $priceDataConfig = $this->product->getDataFieldConfig('price');
64  if (isset($priceDataConfig['source'])) {
65  $priceData = $priceDataConfig['source']->getPriceData();
66  if (isset($priceData['price_from'])) {
67  $price = $priceData['price_from'];
68  }
69  }
70 
71  if (null === $price) {
72  $configurableOptions = $this->product->getConfigurableAttributesData();
73  $products = $this->product->getDataFieldConfig('configurable_attributes_data')['source']->getProducts();
74  foreach ($configurableOptions['matrix'] as $key => $option) {
75  if ($products[$key]->getQuantityAndStockStatus()['is_in_stock'] !== 'Out of Stock') {
76  $price = $price === null ? $option['price'] : $price;
77  if ($price > $option['price']) {
78  $price = $option['price'];
79  }
80  }
81  }
82  }
83  return $price;
84  }
85 }
$price
$errors
Definition: overview.phtml:9