/**
  * 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.');
 }
Exemplo n.º 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.');
 }
 /**
  * Assertion that commodity options are displayed correctly
  *
  * @param CatalogProductView $catalogProductView
  * @param FixtureInterface $product
  * @return void
  */
 public function processAssert(CatalogProductView $catalogProductView, FixtureInterface $product)
 {
     $this->product = $product;
     // TODO fix initialization url for frontend page
     // Open product view page
     $catalogProductView->init($this->product);
     $catalogProductView->open();
     // Prepare data
     $customOptions = $catalogProductView->getCustomOptionsBlock()->getOptions();
     foreach ($customOptions as &$option) {
         unset($option['value']);
     }
     unset($option);
     $compareOptions = $this->prepareOptionArray($this->product->getCustomOptions());
     $customOptions = $this->dataSortByKey($customOptions);
     $compareOptions = $this->dataSortByKey($compareOptions);
     \PHPUnit_Framework_Assert::assertEquals($customOptions, $compareOptions, 'Incorrect display of custom product options on the product page.');
 }
Exemplo n.º 4
0
 /**
  * @constructor
  * @param FixtureInterface $product
  */
 public function __construct(FixtureInterface $product)
 {
     /** @var CatalogProductSimple $product */
     $checkoutData = $product->getCheckoutData();
     $cartItem = isset($checkoutData['cartItem']) ? $checkoutData['cartItem'] : [];
     $customOptions = $product->hasData('custom_options') ? $product->getCustomOptions() : [];
     $checkoutCustomOptions = isset($checkoutData['options']['custom_options']) ? $checkoutData['options']['custom_options'] : [];
     foreach ($checkoutCustomOptions as $key => $checkoutCustomOption) {
         $attribute = str_replace('attribute_key_', '', $checkoutCustomOption['title']);
         $option = str_replace('option_key_', '', $checkoutCustomOption['value']);
         $checkoutCustomOptions[$key] = ['title' => isset($customOptions[$attribute]['title']) ? $customOptions[$attribute]['title'] : $attribute, 'value' => isset($customOptions[$attribute]['options'][$option]['title']) ? $customOptions[$attribute]['options'][$option]['title'] : $option];
     }
     $cartItem['options'] = isset($cartItem['options']) ? $cartItem['options'] + $checkoutCustomOptions : $checkoutCustomOptions;
     $this->data = $cartItem;
 }