/** * Verify displayed product special price on product page(front-end) equals passed from fixture. * * @return string|null */ protected function verifySpecialPrice() { $fixtureProductSpecialPrice = $this->product->getSpecialPrice(); if (!$fixtureProductSpecialPrice) { return null; } $fixtureProductSpecialPrice = number_format($fixtureProductSpecialPrice, 2); $formProductSpecialPrice = $this->productView->getPriceBlock()->getSpecialPrice(); if ($fixtureProductSpecialPrice == $formProductSpecialPrice) { return null; } return "\nDisplayed product special price on product page(front-end) not equals passed from fixture. " . "Actual: {$formProductSpecialPrice}, expected: {$fixtureProductSpecialPrice}."; }
/** * Get product actual price. * * @param InjectableFixture $product * @return int */ protected function getProductActualPrice(InjectableFixture $product) { return $product->hasData('special_price') ? $product->getSpecialPrice() : $product->getPrice(); }
/** * Prepare product price from fixture. * * @param InjectableFixture $product * @return float */ protected function prepareFixturePrice(InjectableFixture $product) { /** @var CatalogProductSimple $product */ $customOptions = $product->getCustomOptions(); $checkoutData = $product->getCheckoutData(); $checkoutCustomOptions = isset($checkoutData['options']['custom_options']) ? $checkoutData['options']['custom_options'] : []; if (isset($checkoutData['cartItem'])) { $fixturePrice = $checkoutData['cartItem']['price']; } else { $fixturePrice = $product->getPrice(); $groupPrice = $product->getGroupPrice(); $specialPrice = $product->getSpecialPrice(); if ($groupPrice) { $groupPrice = reset($groupPrice); $fixturePrice = $groupPrice['price']; } if ($specialPrice) { $fixturePrice = $specialPrice; } foreach ($checkoutCustomOptions as $checkoutOption) { $attributeKey = str_replace('attribute_key_', '', $checkoutOption['title']); $optionKey = str_replace('option_key_', '', $checkoutOption['value']); $option = $customOptions[$attributeKey]['options'][$optionKey]; if ('Fixed' == $option['price_type']) { $fixturePrice += $option['price']; } else { $fixturePrice += $fixturePrice / 100 * $option['price']; } } } return $fixturePrice; }
/** * Verify product special price on product view page. * * @param InjectableFixture $product * @param View $productViewBlock * @return void */ public function assertPrice(InjectableFixture $product, View $productViewBlock) { \PHPUnit_Framework_Assert::assertEquals(number_format($product->getSpecialPrice(), 2), $productViewBlock->getPriceBlock()->getSpecialPrice(), $this->errorMessage); }