/** * Assert prices on the shopping cart * * @param FixtureInterface $product * @param CheckoutCart $checkoutCart * @return void * * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function assertOnShoppingCart(FixtureInterface $product, CheckoutCart $checkoutCart) { $checkoutCart->open(); /** @var CatalogProductSimple $product */ $customOptions = $product->getCustomOptions(); $checkoutData = $product->getCheckoutData(); $checkoutCartItem = isset($checkoutData['cartItem']) ? $checkoutData['cartItem'] : []; $checkoutCustomOptions = isset($checkoutData['options']['custom_options']) ? $checkoutData['options']['custom_options'] : []; $fixturePrice = $product->getPrice(); $specialPrice = $product->getSpecialPrice(); $cartItem = $checkoutCart->getCartBlock()->getCartItem($product); $formPrice = $cartItem->getPrice(); if ($specialPrice) { $fixturePrice = $specialPrice; } if (isset($checkoutCartItem['price'])) { $fixturePrice = $checkoutCartItem['price']; } $fixtureActualPrice = $fixturePrice; 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']) { $fixtureActualPrice += $option['price']; } else { $fixtureActualPrice += $fixturePrice / 100 * $option['price']; } } \PHPUnit_Framework_Assert::assertEquals($fixtureActualPrice, $formPrice, 'Product price in shopping cart is not correct.'); }
/** * Assert that duplicated product is found by sku and has correct product type, product template, * product status disabled and out of stock * * @param FixtureInterface $product * @param CatalogProductIndex $productGrid * @return void */ public function processAssert(FixtureInterface $product, CatalogProductIndex $productGrid) { $config = $product->getDataConfig(); $filter = ['name' => $product->getName(), 'visibility' => $product->getVisibility(), 'status' => 'Disabled', 'sku' => $product->getSku() . '-1', 'type' => ucfirst($config['create_url_params']['type']) . ' Product', 'price_to' => number_format($product->getPrice(), 2)]; $productGrid->open()->getProductGrid()->search($filter); $filter['price_to'] = '$' . $filter['price_to']; \PHPUnit_Framework_Assert::assertTrue($productGrid->getProductGrid()->isRowVisible($filter, false), 'Product duplicate is absent in Products grid.'); }
/** * Get configurable product price * * @param FixtureInterface $product * @throws \Exception * @return int */ protected function getProductPrice(FixtureInterface $product) { $price = $product->getPrice(); if (!$this->productsIsConfigured) { return $price; } if (!$product instanceof ConfigurableProduct) { throw new \Exception("Product '{$product->getName}()' is not configurable product."); } $checkoutData = $product->getCheckoutData(); if ($checkoutData === null) { return 0; } $attributesData = $product->getConfigurableAttributesData()['attributes_data']; foreach ($checkoutData['options']['configurable_options'] as $option) { $itemOption = $attributesData[$option['title']]['options'][$option['value']]; $itemPrice = $itemOption['is_percent'] == 'No' ? $itemOption['pricing_value'] : $product->getPrice() / 100 * $itemOption['pricing_value']; $price += $itemPrice; } return $price; }
/** * Verify displayed product price on product page(front-end) equals passed from fixture * * @return string|null */ protected function verifyPrice() { if ($this->product->hasData('price') == false) { return null; } $priceBlock = $this->productView->getPriceBlock(); $formPrice = $priceBlock->isOldPriceVisible() ? $priceBlock->getOldPrice() : $priceBlock->getPrice(); $fixturePrice = number_format($this->product->getPrice(), 2, '.', ''); if ($fixturePrice != $formPrice) { return "Displayed product price on product page(front-end) not equals passed from fixture. " . "Actual: {$fixturePrice}, expected: {$formPrice}."; } return null; }
/** * Get configurable product price * * @param FixtureInterface $product * @throws \Exception * @return int */ protected function getProductPrice(FixtureInterface $product) { $price = $product->getPrice(); if (!$this->productsIsConfigured) { return $price; } if (!$product instanceof ConfigurableProduct) { throw new \Exception("Product '{$product->getName}()' is not configurable product."); } $checkoutData = $product->getCheckoutData(); if ($checkoutData === null) { return 0; } return $price; }
/** * Preparation options before comparing * * @param FixtureInterface $product * @param int|null $actualPrice * @return array * * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function prepareOptions(FixtureInterface $product, $actualPrice = null) { $result = []; $customOptions = $product->hasData('custom_options') ? $product->getDataFieldConfig('custom_options')['source']->getCustomOptions() : null; $actualPrice = $actualPrice ? $actualPrice : $product->getPrice(); foreach ($customOptions as $customOption) { $skippedField = isset($this->skippedFieldOptions[$customOption['type']]) ? $this->skippedFieldOptions[$customOption['type']] : []; foreach ($customOption['options'] as &$option) { // recalculate percent price if ('Percent' == $option['price_type']) { $option['price'] = $actualPrice * $option['price'] / 100; $option['price'] = round($option['price'], 2); } $option = array_diff_key($option, array_flip($skippedField)); } $result[$customOption['title']] = $customOption; } return $result; }
/** * Get product price. * * @param FixtureInterface $product * @return int */ protected function getProductPrice(FixtureInterface $product) { return isset($product->getCheckoutData()['cartItem']['price']) ? $product->getCheckoutData()['cartItem']['price'] : $product->getPrice(); }
/** * Verify product price on category view page * * @param FixtureInterface $product * @param CatalogCategoryView $catalogCategoryView * @return void */ protected function assertPrice(FixtureInterface $product, CatalogCategoryView $catalogCategoryView) { $price = $catalogCategoryView->getListProductBlock()->getProductPriceBlock($product->getName())->getRegularPrice(); \PHPUnit_Framework_Assert::assertEquals(number_format($product->getPrice(), 2), $price, 'Product regular price on category page is not correct.'); }