Skip to content

Commit fd3287d

Browse files
committed
Resolved cyclomatic complexity of AssertProductRegularPriceOnStorefront.php
1 parent aae2808 commit fd3287d

File tree

1 file changed

+59
-28
lines changed

1 file changed

+59
-28
lines changed

dev/tests/functional/tests/app/Magento/Wishlist/Test/Constraint/AssertProductRegularPriceOnStorefront.php

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,44 +44,29 @@ public function processAssert(
4444
$cmsIndex->getLinksBlock()->openLink('My Account');
4545
$customerAccountIndex->getAccountMenuBlock()->openMenuItem('My Wish List');
4646

47-
$isProductVisible = $wishlistIndex->getWishlistBlock()->getProductItemsBlock()->getItemProduct($product)
47+
$isProductVisible = $wishlistIndex->getWishlistBlock()
48+
->getProductItemsBlock()
49+
->getItemProduct($product)
4850
->isVisible();
4951
while (!$isProductVisible && $wishlistIndex->getTopToolbar()->nextPage()) {
50-
$isProductVisible = $wishlistIndex->getWishlistBlock()->getProductItemsBlock()->getItemProduct($product)
52+
$isProductVisible = $wishlistIndex->getWishlistBlock()
53+
->getProductItemsBlock()
54+
->getItemProduct($product)
5155
->isVisible();
5256
}
5357

54-
$productRegularPrice = 0;
5558
if ($product instanceof GroupedProduct) {
56-
$associatedProducts = $product->getAssociated();
57-
58-
/** @var \Magento\Catalog\Test\Fixture\CatalogProductSimple $associatedProduct */
59-
foreach ($associatedProducts['products'] as $key => $associatedProduct) {
60-
$qty = $associatedProducts['assigned_products'][$key]['qty'];
61-
$price = $associatedProduct->getPrice();
62-
$productRegularPrice += $qty * $price;
63-
}
59+
$productRegularPrice = $this->getGroupedProductRegularPrice($product);
6460
} elseif ($product instanceof BundleProduct) {
65-
$bundleSelection = (array)$product->getBundleSelections();
66-
foreach ($bundleSelection['products'] as $bundleOption) {
67-
$regularBundleProductPrice = 0;
68-
/** @var \Magento\Catalog\Test\Fixture\CatalogProductSimple $bundleProduct */
69-
foreach ($bundleOption as $bundleProduct) {
70-
$checkoutData = $bundleProduct->getCheckoutData();
71-
$bundleProductPrice = $checkoutData['qty'] * $checkoutData['cartItem']['price'];
72-
if (0 === $regularBundleProductPrice) {
73-
$regularBundleProductPrice = $bundleProductPrice;
74-
} else {
75-
$regularBundleProductPrice = max([$bundleProductPrice, $regularBundleProductPrice]);
76-
}
77-
}
78-
$productRegularPrice += $regularBundleProductPrice;
79-
}
61+
$productRegularPrice = $this->getBundleProductRegularPrice($product);
8062
} else {
81-
$productRegularPrice = (float)$product->getPrice();
63+
$productRegularPrice = (float) $product->getPrice();
8264
}
8365

84-
$productItem = $wishlistIndex->getWishlistBlock()->getProductItemsBlock()->getItemProduct($product);
66+
$productItem = $wishlistIndex->getWishlistBlock()
67+
->getProductItemsBlock()
68+
->getItemProduct($product);
69+
8570
$wishListProductRegularPrice = $product instanceof BundleProduct
8671
? (float)$productItem->getPrice()
8772
: (float)$productItem->getRegularPrice();
@@ -106,6 +91,52 @@ public function processAssert(
10691
);
10792
}
10893

94+
/**
95+
* Retrieve grouped product regular price
96+
*
97+
* @param GroupedProduct $product
98+
* @return float
99+
*/
100+
private function getGroupedProductRegularPrice(GroupedProduct $product)
101+
{
102+
$productRegularPrice = 0;
103+
$associatedProducts = $product->getAssociated();
104+
/** @var \Magento\Catalog\Test\Fixture\CatalogProductSimple $associatedProduct */
105+
foreach ($associatedProducts['products'] as $key => $associatedProduct) {
106+
$qty = $associatedProducts['assigned_products'][$key]['qty'];
107+
$price = $associatedProduct->getPrice();
108+
$productRegularPrice += $qty * $price;
109+
}
110+
return $productRegularPrice;
111+
}
112+
113+
/**
114+
* Retrieve bundle product regular price
115+
*
116+
* @param BundleProduct $product
117+
* @return float
118+
*/
119+
private function getBundleProductRegularPrice(BundleProduct $product)
120+
{
121+
$productRegularPrice = 0;
122+
$bundleSelection = (array) $product->getBundleSelections();
123+
foreach ($bundleSelection['products'] as $bundleOption) {
124+
$regularBundleProductPrice = 0;
125+
/** @var \Magento\Catalog\Test\Fixture\CatalogProductSimple $bundleProduct */
126+
foreach ($bundleOption as $bundleProduct) {
127+
$checkoutData = $bundleProduct->getCheckoutData();
128+
$bundleProductPrice = $checkoutData['qty'] * $checkoutData['cartItem']['price'];
129+
if (0 === $regularBundleProductPrice) {
130+
$regularBundleProductPrice = $bundleProductPrice;
131+
} else {
132+
$regularBundleProductPrice = max([$bundleProductPrice, $regularBundleProductPrice]);
133+
}
134+
}
135+
$productRegularPrice += $regularBundleProductPrice;
136+
}
137+
return $productRegularPrice;
138+
}
139+
109140
/**
110141
* Returns a string representation of the object.
111142
*

0 commit comments

Comments
 (0)