/** * Assert prices on the product view page and shopping cart page. * * @param CatalogProductBundle $product * @param CatalogProductView $catalogProductView * @param CheckoutCart $checkoutCartView * @param CatalogProductBundle $originalProduct [optional] * @return void * * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function assertPrice(CatalogProductBundle $product, CatalogProductView $catalogProductView, CheckoutCart $checkoutCartView, CatalogProductBundle $originalProduct = null) { $customerGroup = 'NOT LOGGED IN'; $bundleData = $product->getData(); $this->productPriceType = $originalProduct !== null ? $originalProduct->getPriceType() : $product->getPriceType(); $catalogProductView->getViewBlock()->addToCart($product); $cartItem = $checkoutCartView->getCartBlock()->getCartItem($product); $specialPrice = 0; if (isset($bundleData['group_price'])) { $specialPrice = $bundleData['group_price'][array_search($customerGroup, $bundleData['group_price'])]['price'] / 100; } $optionPrice = []; $fillData = $product->getCheckoutData(); foreach ($fillData['bundle_options'] as $key => $data) { $subProductPrice = 0; foreach ($bundleData['bundle_selections']['products'][$key] as $productKey => $itemProduct) { if (strpos($itemProduct->getName(), $data['value']['name']) !== false) { $data['value']['key'] = $productKey; $subProductPrice = $itemProduct->getPrice(); } } $optionPrice[$key]['price'] = $this->productPriceType == 'Fixed' ? number_format($bundleData['bundle_selections']['bundle_options'][$key]['assigned_products'][$data['value']['key']]['data']['selection_price_value'], 2) : number_format($subProductPrice, 2); } foreach ($optionPrice as $index => $item) { $item['price'] -= $item['price'] * $specialPrice; \PHPUnit_Framework_Assert::assertEquals(number_format($item['price'], 2), $cartItem->getPriceBundleOptions($index + 1), 'Bundle item ' . ($index + 1) . ' options on frontend don\'t equal to fixture.'); } $sumOptionsPrice = $product->getDataFieldConfig('price')['source']->getPreset()['cart_price']; $subTotal = number_format($cartItem->getPrice(), 2); \PHPUnit_Framework_Assert::assertEquals($sumOptionsPrice, $subTotal, 'Bundle unit price on frontend doesn\'t equal to fixture.'); }
/** * Displayed bundle block on frontend with correct fixture product * * @param CatalogProductView $catalogProductView * @param CatalogProductBundle $product * @return string|null */ protected function displayedBundleBlock(CatalogProductView $catalogProductView, CatalogProductBundle $product) { $fields = $product->getData(); $bundleOptions = $fields['bundle_selections']['bundle_options']; if (!isset($bundleOptions)) { return 'Bundle options data on product page is not equals to fixture preset.'; } $catalogProductView->getViewBlock()->clickCustomize(); foreach ($bundleOptions as $index => $item) { foreach ($item['assigned_products'] as &$selection) { $selection = $selection['search_data']; } $result = $catalogProductView->getBundleViewBlock()->getBundleBlock()->displayedBundleItemOption($item, ++$index); if ($result !== true) { return $result; } } return null; }