/** * Assert prices on the product view Page * * @param CatalogProductBundle $product * @param CatalogProductView $catalogProductView * @return void */ protected function assertPrice(CatalogProductBundle $product, CatalogProductView $catalogProductView) { $priceData = $product->getDataFieldConfig('price')['source']->getPreset(); $priceBlock = $catalogProductView->getViewBlock()->getProductPriceBlock(); $priceLow = $product->getPriceView() == 'Price Range' ? $priceBlock->getPriceFrom() : $priceBlock->getRegularPrice(); \PHPUnit_Framework_Assert::assertEquals($priceData['price_from'], $priceLow, 'Bundle price From on product view page is not correct.'); if ($product->getPriceView() == 'Price Range') { \PHPUnit_Framework_Assert::assertEquals($priceData['price_to'], $priceBlock->getPriceTo(), 'Bundle price To on product view page is not correct.'); } }
/** * Verify product price on category view page * * @param CatalogProductBundle $bundle * @param CatalogCategoryView $catalogCategoryView * @return void */ protected function assertPrice(CatalogProductBundle $bundle, CatalogCategoryView $catalogCategoryView) { $priceData = $bundle->getDataFieldConfig('price')['source']->getPreset(); //Price from/to verification $priceBlock = $catalogCategoryView->getListProductBlock()->getProductPriceBlock($bundle->getName()); $priceLow = $bundle->getPriceView() == 'Price Range' ? $priceBlock->getPriceFrom() : $priceBlock->getRegularPrice(); \PHPUnit_Framework_Assert::assertEquals($priceData['price_from'], $priceLow, 'Bundle price From on category page is not correct.'); if ($bundle->getPriceView() == 'Price Range') { \PHPUnit_Framework_Assert::assertEquals($priceData['price_to'], $priceBlock->getPriceTo(), 'Bundle price To on category page is not correct.'); } }
/** * Fill bundle option on frontend add click "Add to cart" button * * @param CatalogProductBundle $product * @param CatalogProductView $catalogProductView * @return void */ public function addToCart(CatalogProductBundle $product, CatalogProductView $catalogProductView) { $fillData = $product->getDataFieldConfig('checkout_data')['source']->getPreset(); if (isset($fillData['bundle_options'])) { $this->fillBundleOptions($fillData['bundle_options']); } if (isset($fillData['custom_options'])) { $catalogProductView->getCustomOptionsBlock()->fillCustomOptions($product, $fillData['custom_options']); } $catalogProductView->getViewBlock()->clickAddToCart(); }
/** * 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'; $catalogProductView->getViewBlock()->clickCustomize(); $bundleData = $product->getData(); $this->productPriceType = $originalProduct !== null ? $originalProduct->getPriceType() : $product->getPriceType(); $fillData = $product->getDataFieldConfig('checkout_data')['source']->getPreset(); $bundleBlock = $catalogProductView->getBundleViewBlock()->getBundleBlock(); $bundleBlock->addToCart($product, $catalogProductView); $cartBlock = $checkoutCartView->getCartBlock(); $specialPrice = 0; if (isset($bundleData['group_price'])) { $specialPrice = $bundleData['group_price'][array_search($customerGroup, $bundleData['group_price'])]['price'] / 100; } $optionPrice = []; 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), $cartBlock->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($cartBlock->getCartItemUnitPrice($product), 2); \PHPUnit_Framework_Assert::assertEquals($sumOptionsPrice, $subTotal, 'Bundle unit price on frontend doesn\'t equal to fixture.'); }