From b5d49661ca52db5ec4a1fa26c85dc8452fbf17aa Mon Sep 17 00:00:00 2001
From: Michail Slabko <mslabko@magento.com>
Date: Fri, 11 Nov 2016 17:36:01 +0200
Subject: [PATCH] MAGETWO-55729: [Customer] Optimize performance for bundled
 products with lots of product options

- MAGETWO-60826: Wrong Regular price for dynamic bundle
---
 .../ResourceModel/Selection/Collection.php    |   2 +-
 .../Model/Product/BundlePriceAbstract.php     |   6 +-
 .../DynamicBundlePriceCalculatorTest.php      | 128 +++++-
 ...ndleWithCatalogPriceRuleCalculatorTest.php |  55 ---
 ...icBundleWithSpecialPriceCalculatorTest.php | 374 +++---------------
 .../dynamic_bundle_product.php                |   4 +-
 ...amic_bundle_product_with_special_price.php |  29 ++
 ...le_product_with_special_price_rollback.php |   7 +
 8 files changed, 214 insertions(+), 391 deletions(-)
 create mode 100644 dev/tests/integration/testsuite/Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product_with_special_price.php
 create mode 100644 dev/tests/integration/testsuite/Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product_with_special_price_rollback.php

diff --git a/app/code/Magento/Bundle/Model/ResourceModel/Selection/Collection.php b/app/code/Magento/Bundle/Model/ResourceModel/Selection/Collection.php
index d255dfc4620..e5c370fd5b6 100644
--- a/app/code/Magento/Bundle/Model/ResourceModel/Selection/Collection.php
+++ b/app/code/Magento/Bundle/Model/ResourceModel/Selection/Collection.php
@@ -197,7 +197,7 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
         if ($product->getPriceType() == \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC) {
             $this->addPriceData();
             if ($useRegularPrice) {
-                $minimalPriceExpression = 'minimal_price';
+                $minimalPriceExpression = 'price';
             } else {
                 $this->getCatalogRuleProcessor()->addPriceData($this, 'selection.product_id');
                 $minimalPriceExpression = 'LEAST(minimal_price, IFNULL(catalog_rule_price, minimal_price))';
diff --git a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/BundlePriceAbstract.php b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/BundlePriceAbstract.php
index e69de8d62ef..a6f5653b276 100644
--- a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/BundlePriceAbstract.php
+++ b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/BundlePriceAbstract.php
@@ -38,7 +38,7 @@ abstract class BundlePriceAbstract extends \PHPUnit_Framework_TestCase
     /**
      * @param array $strategyModifiers
      * @param string $productSku
-     * @return \Magento\Catalog\Api\Data\ProductInterface
+     * @return void
      * @throws \Magento\Framework\Exception\NoSuchEntityException
      * @throws \Magento\Framework\Exception\InputException
      * @throws \Magento\Framework\Exception\StateException
@@ -54,12 +54,12 @@ abstract class BundlePriceAbstract extends \PHPUnit_Framework_TestCase
                 $bundleProduct = call_user_func_array([$this, $modifier['modifierName']], $modifier['data']);
             } else {
                 throw new \Magento\Framework\Exception\InputException(
-                    sprintf('Modifier %s does not exists', $modifier['modifierName'])
+                    __('Modifier %s does not exists', $modifier['modifierName'])
                 );
             }
         }
 
-        return $this->productRepository->save($bundleProduct);
+        $this->productRepository->save($bundleProduct);
     }
 
     /**
diff --git a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/DynamicBundlePriceCalculatorTest.php b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/DynamicBundlePriceCalculatorTest.php
index 0206bfa38f0..b97fb29b2ba 100644
--- a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/DynamicBundlePriceCalculatorTest.php
+++ b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/DynamicBundlePriceCalculatorTest.php
@@ -77,7 +77,7 @@ class DynamicBundlePriceCalculatorTest extends BundlePriceAbstract
     {
         return [
             '#1 Testing price for dynamic bundle product with one simple' => [
-                'strategy' => $this->getProductWithOneSimple(),
+                'strategy' => $this->getBundleConfiguration1(),
                 'expectedResults' => [
                     // just price from simple1
                     'minimalPrice' => 10,
@@ -87,7 +87,7 @@ class DynamicBundlePriceCalculatorTest extends BundlePriceAbstract
             ],
 
             '#2 Testing price for dynamic bundle product with three simples and different qty' => [
-                'strategy' => $this->getProductWithDifferentQty(),
+                'strategy' => $this->getBundleConfiguration2(),
                 'expectedResults' => [
                     // min price from simples 3*10 or 30
                     'minimalPrice' => 30,
@@ -97,14 +97,34 @@ class DynamicBundlePriceCalculatorTest extends BundlePriceAbstract
             ],
 
             '#3 Testing price for dynamic bundle product with four simples and different price' => [
-                'strategy' => $this->getProductWithDifferentPrice(),
+                'strategy' => $this->getBundleConfiguration3(),
                 'expectedResults' => [
                     //  10
                     'minimalPrice' => 10,
                     // 10 + 20 + 30
                     'maximalPrice' => 60
                 ]
-            ]
+            ],
+
+            '#4 Testing price for dynamic bundle with two non required options' => [
+                'strategy' => $this->getBundleConfiguration4(),
+                'expectedResults' => [
+                    // 1 * 10
+                    'minimalPrice' => 10,
+                    // 3 * 20 + 1 * 10 + 3 * 20
+                    'maximalPrice' => 130
+                ]
+            ],
+
+            '#5 Testing price for dynamic bundle with two required options' => [
+                'strategy' => $this->getBundleConfiguration5(),
+                'expectedResults' => [
+                    // 1 * 10 + 1 * 10
+                    'minimalPrice' => 20,
+                    // 3 * 20 + 1 * 10 + 3 * 20
+                    'maximalPrice' => 130
+                ]
+            ],
         ];
     }
 
@@ -113,7 +133,7 @@ class DynamicBundlePriceCalculatorTest extends BundlePriceAbstract
      *
      * @return array
      */
-    private function getProductWithOneSimple()
+    private function getBundleConfiguration1()
     {
         $optionsData = [
             [
@@ -142,7 +162,7 @@ class DynamicBundlePriceCalculatorTest extends BundlePriceAbstract
      *
      * @return array
      */
-    private function getProductWithDifferentQty()
+    private function getBundleConfiguration2()
     {
         $optionsData = [
             [
@@ -179,7 +199,7 @@ class DynamicBundlePriceCalculatorTest extends BundlePriceAbstract
      *
      * @return array
      */
-    private function getProductWithDifferentPrice()
+    private function getBundleConfiguration3()
     {
         $optionsData = [
             [
@@ -210,4 +230,98 @@ class DynamicBundlePriceCalculatorTest extends BundlePriceAbstract
             ],
         ];
     }
+
+    /**
+     * Dynamic bundle with two non required options and special price
+     * @return array
+     */
+    private function getBundleConfiguration4()
+    {
+        $optionsData = [
+            [
+                'title' => 'Op1',
+                'required' => false,
+                'type' => 'radio',
+                'links' => [
+                    [
+                        'sku' => 'simple1',
+                        'qty' => 1,
+                    ],
+                    [
+                        'sku' => 'simple2',
+                        'qty' => 3,
+                    ],
+                ]
+            ],
+            [
+                'title' => 'Op2',
+                'required' => false,
+                'type' => 'checkbox',
+                'links' => [
+                    [
+                        'sku' => 'simple1',
+                        'qty' => 1,
+                    ],
+                    [
+                        'sku' => 'simple2',
+                        'qty' => 3,
+                    ],
+                ]
+            ]
+        ];
+
+        return [
+            [
+                'modifierName' => 'addSimpleProduct',
+                'data' => [$optionsData]
+            ],
+        ];
+    }
+
+    /**
+     * Dynamic bundle with two required options
+     * @return array
+     */
+    private function getBundleConfiguration5()
+    {
+        $optionsData = [
+            [
+                'title' => 'Op1',
+                'required' => true,
+                'type' => 'radio',
+                'links' => [
+                    [
+                        'sku' => 'simple1',
+                        'qty' => 1,
+                    ],
+                    [
+                        'sku' => 'simple2',
+                        'qty' => 3,
+                    ],
+                ]
+            ],
+            [
+                'title' => 'Op2',
+                'required' => true,
+                'type' => 'checkbox',
+                'links' => [
+                    [
+                        'sku' => 'simple1',
+                        'qty' => 1,
+                    ],
+                    [
+                        'sku' => 'simple2',
+                        'qty' => 3,
+                    ],
+                ]
+            ]
+        ];
+
+        return [
+            [
+                'modifierName' => 'addSimpleProduct',
+                'data' => [$optionsData]
+            ],
+        ];
+    }
 }
diff --git a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/DynamicBundleWithCatalogPriceRuleCalculatorTest.php b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/DynamicBundleWithCatalogPriceRuleCalculatorTest.php
index 80ad5e6a857..5a85dfa3104 100644
--- a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/DynamicBundleWithCatalogPriceRuleCalculatorTest.php
+++ b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/DynamicBundleWithCatalogPriceRuleCalculatorTest.php
@@ -59,17 +59,6 @@ class DynamicBundleWithCatalogPriceRuleCalculatorTest extends BundlePriceAbstrac
                 ]
             ],
 
-            '#2 Testing price for dynamic bundle with one required option and special price' => [
-                'strategy' => $this->getBundleProductConfiguration2(),
-                'expectedResults' => [
-                    // 0.5 * 10 * 0.9
-                    'minimalPrice' => 4.5,
-
-                    // 0.5 * 10 * 0.9
-                    'maximalPrice' => 4.5
-                ]
-            ],
-
             '#3 Testing price for dynamic bundle with one non required option' => [
                 'strategy' => $this->getBundleProductConfiguration3(),
                 'expectedResults' => [
@@ -177,38 +166,6 @@ class DynamicBundleWithCatalogPriceRuleCalculatorTest extends BundlePriceAbstrac
         ];
     }
 
-    /**
-     * Dynamic bundle with one required option and special price
-     * @return array
-     */
-    private function getBundleProductConfiguration2()
-    {
-        $optionsData = [
-            [
-                'title' => 'Op1',
-                'required' => true,
-                'type' => 'checkbox',
-                'links' => [
-                    [
-                        'sku' => 'simple1',
-                        'qty' => 1,
-                    ],
-                ]
-            ]
-        ];
-
-        return [
-            [
-                'modifierName' => 'addSpecialPrice',
-                'data' => [50]
-            ],
-            [
-                'modifierName' => 'addSimpleProduct',
-                'data' => [$optionsData]
-            ],
-        ];
-    }
-
     /**
      * Dynamic bundle with one non required option
      * @return array
@@ -473,16 +430,4 @@ class DynamicBundleWithCatalogPriceRuleCalculatorTest extends BundlePriceAbstrac
             ],
         ];
     }
-
-    /**
-     * @param \Magento\Catalog\Model\Product $bundleProduct
-     * @param int $discount
-     * @return \Magento\Catalog\Model\Product
-     */
-    protected function addSpecialPrice(\Magento\Catalog\Model\Product $bundleProduct, $discount)
-    {
-        $bundleProduct->setSpecialPrice($discount);
-
-        return $bundleProduct;
-    }
 }
diff --git a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/DynamicBundleWithSpecialPriceCalculatorTest.php b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/DynamicBundleWithSpecialPriceCalculatorTest.php
index 10a63007f65..1001cf39c62 100644
--- a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/DynamicBundleWithSpecialPriceCalculatorTest.php
+++ b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/DynamicBundleWithSpecialPriceCalculatorTest.php
@@ -7,7 +7,7 @@
 namespace Magento\Bundle\Model\Product;
 
 /**
- * @magentoDataFixture Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product.php
+ * @magentoDataFixture Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product_with_special_price.php
  * @magentoAppArea frontend
  */
 class DynamicBundleWithSpecialPriceCalculatorTest extends BundlePriceAbstract
@@ -38,6 +38,24 @@ class DynamicBundleWithSpecialPriceCalculatorTest extends BundlePriceAbstract
             $priceInfo->getPrice($priceCode)->getMaximalPrice()->getValue(),
             'Failed to check maximal price on product'
         );
+
+        if (isset($expectedResults['regularMinimalPrice'])) {
+            $priceCode = \Magento\Catalog\Pricing\Price\RegularPrice::PRICE_CODE;
+            $this->assertEquals(
+                $expectedResults['regularMinimalPrice'],
+                $priceInfo->getPrice($priceCode)->getMinimalPrice()->getValue(),
+                'Failed to check minimal regular price on product'
+            );
+        }
+
+        if (isset($expectedResults['regularMaximalPrice'])) {
+            $priceCode = \Magento\Catalog\Pricing\Price\RegularPrice::PRICE_CODE;
+            $this->assertEquals(
+                $expectedResults['regularMaximalPrice'],
+                $priceInfo->getPrice($priceCode)->getMaximalPrice()->getValue(),
+                'Failed to check minimal regular price on product'
+            );
+        }
     }
 
     /**
@@ -48,10 +66,7 @@ class DynamicBundleWithSpecialPriceCalculatorTest extends BundlePriceAbstract
     public function getTestCases()
     {
         return [
-            '
-                #1 Testing price for dynamic bundle 
-                with one required option and special price
-            ' => [
+            '#1 Testing price for dynamic bundle with one required option and special price' => [
                 'strategy' => $this->getBundleConfiguration1(),
                 'expectedResults' => [
                     // 0.5 * 10
@@ -61,10 +76,7 @@ class DynamicBundleWithSpecialPriceCalculatorTest extends BundlePriceAbstract
                 ]
             ],
 
-            '
-                #2 Testing price for dynamic bundle 
-                with one non required option and special price
-            ' => [
+            '#2 Testing price for dynamic bundle with one non required option and special price' => [
                 'strategy' => $this->getBundleConfiguration2(),
                 'expectedResults' => [
                     // 0.5 * 2 * 10
@@ -82,8 +94,8 @@ class DynamicBundleWithSpecialPriceCalculatorTest extends BundlePriceAbstract
                 'expectedResults' => [
                     // 0.5 * 1 * 10
                     'minimalPrice' => 5,
-                    // 0.5 * (1 * 10 + 3 * 20)
-                    'maximalPrice' => 35
+                    // 0.5 * (1 * 10 + 3 * 30)
+                    'maximalPrice' => 50
                 ]
             ],
 
@@ -93,93 +105,41 @@ class DynamicBundleWithSpecialPriceCalculatorTest extends BundlePriceAbstract
             ' => [
                 'strategy' => $this->getBundleConfiguration4(),
                 'expectedResults' => [
-                    'minimalPrice' => 9.99,
-                    'maximalPrice' => 21.97
+                    // 0.5 * (min (1 * 9.9, 2.5 * 4))
+                    'minimalPrice' => 4.95,
+                    // 0.5 * ( 1 * 9.9 +  2.5 * 4)
+                    'maximalPrice' => 9.95
                 ]
             ],
 
-            '
-                #5 Testing price for dynamic bundle 
-                with one required radio type option, two simples and special price
-            ' => [
+            '#5 Testing price for dynamic bundle with one required option, one non required and special price' => [
                 'strategy' => $this->getBundleConfiguration5(),
                 'expectedResults' => [
-                    // 0.5 * 1 * 10
-                    'minimalPrice' => 5,
-                    // 0.5 * 3 * 20
-                    'maximalPrice' => 30
+                    // 0.5 * (3 * 2.5)
+                    'minimalPrice' => 3.75,
+                    // 0.5 * (3 * 13 + 1 * 30 + 1 * 10)
+                    'maximalPrice' => 39.5,
+                    // 1 * 10
+                    'regularMinimalPrice' => '10',
+                    // 3 * 20 + (30 * 1 + 13 * 3)
+                    'regularMaximalPrice' => '129',
                 ]
             ],
 
-            '
-                #6 Testing price for dynamic bundle 
-                with two required options and special price
-            ' => [
+            '#6 Testing price for dynamic bundle with one simple product with special price' => [
                 'strategy' => $this->getBundleConfiguration6(),
                 'expectedResults' => [
-                    // 0.5 * (1 * 10 + 1 * 10)
-                    'minimalPrice' => 10,
-                    // 0.5 * (3 * 20 + 1 * 10 + 3 * 20)
-                    'maximalPrice' => 65
-                ]
-            ],
-
-            '
-                #7 Testing price for dynamic bundle 
-                with one required option, one non required and special price
-            ' => [
-                'strategy' => $this->getBundleConfiguration7(),
-                'expectedResults' => [
-                    // 0.5 * (1 * 10)
-                    'minimalPrice' => 5,
-                    // 0.5 * (3 * 20 + 1 * 10 + 3 * 20)
-                    'maximalPrice' => 65
-                ]
-            ],
-
-            '
-                #8 Testing price for dynamic bundle 
-                with two non required options and special price
-            ' => [
-                'strategy' => $this->getBundleConfiguration8(),
-                'expectedResults' => [
-                    // 0.5 * (1 * 10)
-                    'minimalPrice' => 5,
-                    // 0.5 * (3 * 20 + 1 * 10 + 3 * 20)
-                    'maximalPrice' => 65
-                ]
-            ],
-
-            '
-                #9 Testing price for dynamic bundle 
-                with one simple product with special price
-            ' => [
-                'strategy' => $this->getBundleConfiguration9(),
-                'expectedResults' => [
-                    // 1 * 3.5
-                    'minimalPrice' => 3.5,
-                    // 1 * 20
-                    'maximalPrice' => 20
-                ]
-            ],
-
-            '
-                #10 Testing price for dynamic bundle
-                with special price and with one simple product with special price
-            ' => [
-                'strategy' => $this->getBundleConfiguration10(),
-                'expectedResults' => [
-                    // 0.5 * 1 * 3.5
-                    'minimalPrice' => 1.75,
-                    // 0.5 * 3 * 20
-                    'maximalPrice' => 30
+                    // 0.5 * min(4 * 2.5, 1 * 9.9)
+                    'minimalPrice' => 4.95,
+                    // 0.5 * max(4 * 2.5, 1 * 9.9)
+                    'maximalPrice' => 5
                 ]
             ],
         ];
     }
 
     /**
-     * Dynamic bundle with one required option and special price
+     * Dynamic bundle with one required option
      * @return array
      */
     private function getBundleConfiguration1()
@@ -199,10 +159,6 @@ class DynamicBundleWithSpecialPriceCalculatorTest extends BundlePriceAbstract
         ];
 
         return [
-            [
-                'modifierName' => 'addSpecialPrice',
-                'data' => [50]
-            ],
             [
                 'modifierName' => 'addSimpleProduct',
                 'data' => [$optionsData]
@@ -231,10 +187,6 @@ class DynamicBundleWithSpecialPriceCalculatorTest extends BundlePriceAbstract
         ];
 
         return [
-            [
-                'modifierName' => 'addSpecialPrice',
-                'data' => [50]
-            ],
             [
                 'modifierName' => 'addSimpleProduct',
                 'data' => [$optionsData]
@@ -259,7 +211,7 @@ class DynamicBundleWithSpecialPriceCalculatorTest extends BundlePriceAbstract
                         'qty' => 1,
                     ],
                     [
-                        'sku' => 'simple2',
+                        'sku' => 'simple3',
                         'qty' => 3,
                     ],
                 ]
@@ -267,10 +219,6 @@ class DynamicBundleWithSpecialPriceCalculatorTest extends BundlePriceAbstract
         ];
 
         return [
-            [
-                'modifierName' => 'addSpecialPrice',
-                'data' => [50]
-            ],
             [
                 'modifierName' => 'addSimpleProduct',
                 'data' => [$optionsData]
@@ -291,26 +239,18 @@ class DynamicBundleWithSpecialPriceCalculatorTest extends BundlePriceAbstract
                 'type' => 'checkbox',
                 'links' => [
                     [
-                        'sku' => 'simple1',
+                        'sku' => 'simple5',
                         'qty' => 1,
                     ],
                     [
                         'sku' => 'simple2',
-                        'qty' => 2,
+                        'qty' => 4,
                     ],
                 ]
             ]
         ];
 
         return [
-            [
-                'modifierName' => 'addSpecialPriceForSimple',
-                'data' => ['simple1', 9.99]
-            ],
-            [
-                'modifierName' => 'addSpecialPriceForSimple',
-                'data' => ['simple2', 5.99]
-            ],
             [
                 'modifierName' => 'addSimpleProduct',
                 'data' => [$optionsData]
@@ -319,46 +259,10 @@ class DynamicBundleWithSpecialPriceCalculatorTest extends BundlePriceAbstract
     }
 
     /**
-     * Dynamic bundle with one required radio type option, two simples and special price
+     * Dynamic bundle with one required option, one non required and special price
      * @return array
      */
     private function getBundleConfiguration5()
-    {
-        $optionsData = [
-            [
-                'title' => 'Op1',
-                'required' => true,
-                'type' => 'radio',
-                'links' => [
-                    [
-                        'sku' => 'simple1',
-                        'qty' => 1,
-                    ],
-                    [
-                        'sku' => 'simple2',
-                        'qty' => 3,
-                    ],
-                ]
-            ]
-        ];
-
-        return [
-            [
-                'modifierName' => 'addSpecialPrice',
-                'data' => [50]
-            ],
-            [
-                'modifierName' => 'addSimpleProduct',
-                'data' => [$optionsData]
-            ],
-        ];
-    }
-
-    /**
-     * Dynamic bundle with two required options and special price
-     * @return array
-     */
-    private function getBundleConfiguration6()
     {
         $optionsData = [
             [
@@ -378,66 +282,15 @@ class DynamicBundleWithSpecialPriceCalculatorTest extends BundlePriceAbstract
             ],
             [
                 'title' => 'Op2',
-                'required' => true,
-                'type' => 'checkbox',
-                'links' => [
-                    [
-                        'sku' => 'simple1',
-                        'qty' => 1,
-                    ],
-                    [
-                        'sku' => 'simple2',
-                        'qty' => 3,
-                    ],
-                ]
-            ]
-        ];
-
-        return [
-            [
-                'modifierName' => 'addSpecialPrice',
-                'data' => [50]
-            ],
-            [
-                'modifierName' => 'addSimpleProduct',
-                'data' => [$optionsData]
-            ],
-        ];
-    }
-
-    /**
-     * Dynamic bundle with one required option, one non required and special price
-     * @return array
-     */
-    private function getBundleConfiguration7()
-    {
-        $optionsData = [
-            [
-                'title' => 'Op1',
                 'required' => false,
-                'type' => 'radio',
-                'links' => [
-                    [
-                        'sku' => 'simple1',
-                        'qty' => 1,
-                    ],
-                    [
-                        'sku' => 'simple2',
-                        'qty' => 3,
-                    ],
-                ]
-            ],
-            [
-                'title' => 'Op2',
-                'required' => true,
                 'type' => 'checkbox',
                 'links' => [
                     [
-                        'sku' => 'simple1',
+                        'sku' => 'simple3',
                         'qty' => 1,
                     ],
                     [
-                        'sku' => 'simple2',
+                        'sku' => 'simple4',
                         'qty' => 3,
                     ],
                 ]
@@ -445,10 +298,6 @@ class DynamicBundleWithSpecialPriceCalculatorTest extends BundlePriceAbstract
         ];
 
         return [
-            [
-                'modifierName' => 'addSpecialPrice',
-                'data' => [50]
-            ],
             [
                 'modifierName' => 'addSimpleProduct',
                 'data' => [$optionsData]
@@ -456,62 +305,12 @@ class DynamicBundleWithSpecialPriceCalculatorTest extends BundlePriceAbstract
         ];
     }
 
-    /**
-     * Dynamic bundle with two non required options and special price
-     * @return array
-     */
-    private function getBundleConfiguration8()
-    {
-        $optionsData = [
-            [
-                'title' => 'Op1',
-                'required' => false,
-                'type' => 'radio',
-                'links' => [
-                    [
-                        'sku' => 'simple1',
-                        'qty' => 1,
-                    ],
-                    [
-                        'sku' => 'simple2',
-                        'qty' => 3,
-                    ],
-                ]
-            ],
-            [
-                'title' => 'Op2',
-                'required' => false,
-                'type' => 'checkbox',
-                'links' => [
-                    [
-                        'sku' => 'simple1',
-                        'qty' => 1,
-                    ],
-                    [
-                        'sku' => 'simple2',
-                        'qty' => 3,
-                    ],
-                ]
-            ]
-        ];
-
-        return [
-            [
-                'modifierName' => 'addSpecialPrice',
-                'data' => [50]
-            ],
-            [
-                'modifierName' => 'addSimpleProduct',
-                'data' => [$optionsData]
-            ],
-        ];
-    }
 
     /**
      * Dynamic bundle with one simple product with special price
      * @return array
      */
-    private function getBundleConfiguration9()
+    private function getBundleConfiguration6()
     {
         $optionsData = [
             [
@@ -519,94 +318,23 @@ class DynamicBundleWithSpecialPriceCalculatorTest extends BundlePriceAbstract
                 'required' => true,
                 'type' => 'radio',
                 'links' => [
-                    [
-                        'sku' => 'simple1',
-                        'qty' => 1,
-                    ],
                     [
                         'sku' => 'simple2',
-                        'qty' => 1,
+                        'qty' => 4,
                     ],
-                ]
-            ]
-        ];
-
-        return [
-            [
-                'modifierName' => 'addSpecialPriceForSimple',
-                'data' => ['simple1', 3.5]
-            ],
-            [
-                'modifierName' => 'addSimpleProduct',
-                'data' => [$optionsData]
-            ],
-        ];
-    }
-
-    /**
-     * Dynamic bundle with special price and with one simple product with special price
-     * @return array
-     */
-    private function getBundleConfiguration10()
-    {
-        $optionsData = [
-            [
-                'title' => 'Op1',
-                'required' => true,
-                'type' => 'radio',
-                'links' => [
                     [
-                        'sku' => 'simple1',
+                        'sku' => 'simple5',
                         'qty' => 1,
                     ],
-                    [
-                        'sku' => 'simple2',
-                        'qty' => 3,
-                    ],
                 ]
             ]
         ];
 
         return [
-            [
-                'modifierName' => 'addSpecialPriceForSimple',
-                'data' => ['simple1', 3.5]
-            ],
-            [
-                'modifierName' => 'addSpecialPrice',
-                'data' => [50]
-            ],
             [
                 'modifierName' => 'addSimpleProduct',
                 'data' => [$optionsData]
             ],
         ];
     }
-
-    /**
-     * @param \Magento\Catalog\Model\Product $bundleProduct
-     * @param int $discount
-     * @return \Magento\Catalog\Model\Product
-     */
-    protected function addSpecialPrice(\Magento\Catalog\Model\Product $bundleProduct, $discount)
-    {
-        $bundleProduct->setSpecialPrice($discount);
-
-        return $bundleProduct;
-    }
-
-    /**
-     * @param \Magento\Catalog\Model\Product $bundleProduct
-     * @param string $sku
-     * @param int $price
-     * @return \Magento\Catalog\Model\Product
-     */
-    protected function addSpecialPriceForSimple(\Magento\Catalog\Model\Product $bundleProduct, $sku, $price)
-    {
-        $simple = $this->productRepository->get($sku, false, null, true);
-        $simple->setSpecialPrice($price);
-        $this->productRepository->save($simple);
-
-        return $bundleProduct;
-    }
 }
diff --git a/dev/tests/integration/testsuite/Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product.php b/dev/tests/integration/testsuite/Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product.php
index 9918cb0c743..e05a72fe17d 100644
--- a/dev/tests/integration/testsuite/Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product.php
+++ b/dev/tests/integration/testsuite/Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product.php
@@ -15,12 +15,12 @@ $product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)
     ->setId(42)
     ->setAttributeSetId(4)
     ->setWebsiteIds([1])
-    ->setName('Spherical Bundle Product in a Vacuum')
+    ->setName('Bundle Product')
     ->setSku('bundle_product')
     ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
     ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
     ->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
-    ->setPriceView(1)
+    ->setPriceView(0)
     ->setPriceType(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC)
     ->setShipmentType(0);
 
diff --git a/dev/tests/integration/testsuite/Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product_with_special_price.php b/dev/tests/integration/testsuite/Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product_with_special_price.php
new file mode 100644
index 00000000000..37f8295e43c
--- /dev/null
+++ b/dev/tests/integration/testsuite/Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product_with_special_price.php
@@ -0,0 +1,29 @@
+<?php
+/**
+ * Copyright © 2016 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+
+require __DIR__ . '/dynamic_bundle_product.php';
+
+$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
+/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
+$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
+
+/** @var $product \Magento\Catalog\Model\Product */
+$productRepository
+    ->get('bundle_product')
+    ->setSpecialPrice(50)
+    ->save();
+
+$productRepository->save($product);
+
+$productRepository
+    ->get('simple2')
+    ->setSpecialPrice(2.5)
+    ->save();
+
+$productRepository
+    ->get('simple5')
+    ->setSpecialPrice(9.9)
+    ->save();
diff --git a/dev/tests/integration/testsuite/Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product_with_special_price_rollback.php b/dev/tests/integration/testsuite/Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product_with_special_price_rollback.php
new file mode 100644
index 00000000000..50cb07079c2
--- /dev/null
+++ b/dev/tests/integration/testsuite/Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product_with_special_price_rollback.php
@@ -0,0 +1,7 @@
+<?php
+/**
+ * Copyright © 2016 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+
+require __DIR__ . '/dynamic_bundle_product_rollback.php';
-- 
GitLab