/**
  * Assert prices on the shopping cart
  *
  * @param FixtureInterface $product
  * @param CheckoutCart $checkoutCart
  * @return void
  */
 protected function assertOnShoppingCart(FixtureInterface $product, CheckoutCart $checkoutCart)
 {
     $customOptions = $product->getCustomOptions();
     $checkoutData = $product->getCheckoutData();
     $checkoutCustomOptions = isset($checkoutData['custom_options']) ? $checkoutData['custom_options'] : [];
     $fixturePrice = $product->getPrice();
     $groupPrice = $product->getGroupPrice();
     $specialPrice = $product->getSpecialPrice();
     $cartItem = $checkoutCart->getCartBlock()->getCartItem($product);
     $formPrice = $cartItem->getPrice();
     if ($groupPrice) {
         $groupPrice = reset($groupPrice);
         $fixturePrice = $groupPrice['price'];
     }
     if ($specialPrice) {
         $fixturePrice = $specialPrice;
     }
     $fixtureActualPrice = $fixturePrice;
     foreach ($checkoutCustomOptions as $checkoutOption) {
         $attributeKey = $checkoutOption['title'];
         $optionKey = $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(number_format($fixtureActualPrice, 2), $formPrice, 'Product price in shopping cart is not correct.');
 }
Beispiel #2
0
 /**
  * Assert prices on the shopping cart
  *
  * @param FixtureInterface $product
  * @param CheckoutCart $checkoutCart
  * @return void
  */
 protected function assertOnShoppingCart(FixtureInterface $product, CheckoutCart $checkoutCart)
 {
     $cartBlock = $checkoutCart->getCartBlock();
     $productName = $product->getName();
     $productOptions = $product->getCustomOptions();
     $priceComparing = $product->getPrice();
     if ($groupPrice = $product->getGroupPrice()) {
         $groupPrice = reset($groupPrice);
         $priceComparing = $groupPrice['price'];
     }
     if ($specialPrice = $product->getSpecialPrice()) {
         $priceComparing = $specialPrice;
     }
     if (!empty($productOptions)) {
         $productOption = reset($productOptions);
         $optionsData = reset($productOption['options']);
         $optionName = $cartBlock->getCartItemOptionsNameByProductName($productName);
         $optionValue = $cartBlock->getCartItemOptionsValueByProductName($productName);
         \PHPUnit_Framework_Assert::assertTrue(trim($optionName) === $productOption['title'] && trim($optionValue) === $optionsData['title'], 'In the cart wrong option product.');
         if ($optionsData['price_type'] === 'Percent') {
             $priceComparing = $priceComparing * (1 + $optionsData['price'] / 100);
         } else {
             $priceComparing += $optionsData['price'];
         }
     }
     $price = $checkoutCart->getCartBlock()->getProductPriceByName($productName);
     \PHPUnit_Framework_Assert::assertEquals(number_format($priceComparing, 2), $price, 'Product price in shopping cart is not correct.');
 }
 /**
  * Checking the special product price
  *
  * @param array $price
  * @return array
  */
 protected function assertSpecialPrice(array $price)
 {
     $priceComparing = false;
     if ($specialPrice = $this->product->getSpecialPrice()) {
         $priceComparing = $specialPrice;
     }
     if ($groupPrice = $this->product->getGroupPrice()) {
         $groupPrice = reset($groupPrice);
         $priceComparing = $groupPrice['price'];
     }
     if ($priceComparing && isset($price['price_special_price']) && number_format($priceComparing, 2) !== $price['price_special_price']) {
         return ['special_price' => '- product special price on product view page is not correct.'];
     }
     return [];
 }
Beispiel #4
0
 /**
  * Checking the special product price
  *
  * @param CatalogProductView $catalogProductView
  * @return array
  */
 protected function verifySpecialPrice(CatalogProductView $catalogProductView)
 {
     $priceBlock = $catalogProductView->getViewBlock()->getProductPriceBlock();
     $price = $priceBlock->isVisible() ? $priceBlock->getPrice() : ['price_special_price' => null];
     $priceComparing = false;
     if ($specialPrice = $this->product->getSpecialPrice()) {
         $priceComparing = $specialPrice;
     }
     if ($groupPrice = $this->product->getGroupPrice()) {
         $groupPrice = reset($groupPrice);
         $priceComparing = $groupPrice['price'];
     }
     if ($priceComparing && isset($price['price_special_price']) && number_format($priceComparing, 2) !== $price['price_special_price']) {
         return ['special_price' => '- product special price on product view page is not correct.'];
     }
     return [];
 }
 /**
  * Preparation options before comparing
  *
  * @param array $options
  * @return array
  */
 protected function prepareOptionArray(array $options)
 {
     $result = [];
     $productPrice = $this->product->hasData('group_price') ? $this->product->getGroupPrice()[0]['price'] : $this->product->getPrice();
     $placeholder = ['Yes' => true, 'No' => false];
     foreach ($options as $option) {
         $result[$option['title']]['is_require'] = $placeholder[$option['is_require']];
         $result[$option['title']]['title'] = $option['title'];
         $result[$option['title']]['price'] = [];
         foreach ($option['options'] as $optionValue) {
             if ($optionValue['price_type'] === 'Percent') {
                 $optionValue['price'] = $productPrice / 100 * $optionValue['price'];
             }
             $result[$option['title']]['price'][] = number_format($optionValue['price'], 2);
         }
     }
     return $result;
 }