init
This commit is contained in:
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Bundle\Model\Category;
|
||||
|
||||
use Magento\Catalog\Model\Category;
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
class ProductIndexerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
const DEFAULT_ROOT_CATEGORY = 2;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Indexer\IndexerInterface
|
||||
*/
|
||||
private $indexer;
|
||||
|
||||
/**
|
||||
* @var \Magento\Catalog\Model\ResourceModel\Product
|
||||
*/
|
||||
private $productResource;
|
||||
|
||||
/**
|
||||
* @var \Magento\Catalog\Model\ProductRepository
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
/**
|
||||
* @var \Magento\Catalog\Model\CategoryRepository
|
||||
*/
|
||||
private $categoryRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->indexer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Indexer\Model\Indexer::class
|
||||
);
|
||||
$this->indexer->load('catalog_category_product');
|
||||
|
||||
$this->productResource = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Catalog\Model\ResourceModel\Product::class
|
||||
);
|
||||
$this->productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Catalog\Model\ProductRepository::class
|
||||
);
|
||||
$this->categoryRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Catalog\Model\CategoryRepository::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/fixed_bundle_product.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/indexer_catalog_category.php
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testReindex()
|
||||
{
|
||||
$categories = $this->getCategories();
|
||||
|
||||
/** @var Category $categoryFourth */
|
||||
$categoryFourth = end($categories);
|
||||
/** @var \Magento\Catalog\Model\Product $bundleProduct */
|
||||
$bundleProduct = $this->productRepository->get('bundle_product');
|
||||
$bundleProduct->setCategoryIds([$categoryFourth->getId()]);
|
||||
$this->productRepository->save($bundleProduct);
|
||||
|
||||
/** @var Category $categoryThird */
|
||||
$categoryThird = $categories[2];
|
||||
$categoryThird->setIsAnchor(true);
|
||||
$this->categoryRepository->save($categoryThird);
|
||||
|
||||
$this->indexer->reindexAll();
|
||||
|
||||
$categories = [self::DEFAULT_ROOT_CATEGORY, $categoryThird->getId(), $categoryFourth->getId()];
|
||||
foreach ($categories as $categoryId) {
|
||||
$this->assertTrue((bool)$this->productResource->canBeShowInCategory($bundleProduct, $categoryId));
|
||||
}
|
||||
|
||||
$this->assertTrue(
|
||||
(bool)$this->productResource->canBeShowInCategory($bundleProduct, $categoryThird->getParentId())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/fixed_bundle_product.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/indexer_catalog_category.php
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testCategoryMove()
|
||||
{
|
||||
$categories = $this->getCategories();
|
||||
|
||||
/** @var Category $categoryFourth */
|
||||
$categoryFourth = end($categories);
|
||||
$bundleProduct = $this->productRepository->get('bundle_product');
|
||||
$bundleProduct->setCategoryIds([$categoryFourth->getId()]);
|
||||
$this->productRepository->save($bundleProduct);
|
||||
|
||||
/** @var Category $categorySecond */
|
||||
$categorySecond = $categories[1];
|
||||
$categorySecond->setIsAnchor(true);
|
||||
$this->categoryRepository->save($categorySecond);
|
||||
|
||||
/** @var Category $categoryThird */
|
||||
$categoryThird = $categories[2];
|
||||
$categoryThird->setIsAnchor(true);
|
||||
$this->categoryRepository->save($categoryThird);
|
||||
|
||||
$this->indexer->reindexAll();
|
||||
|
||||
/**
|
||||
* Move category from $categoryThird to $categorySecond
|
||||
*/
|
||||
$categoryFourth->move($categorySecond->getId(), null);
|
||||
|
||||
$categories = [self::DEFAULT_ROOT_CATEGORY, $categorySecond->getId(), $categoryFourth->getId()];
|
||||
|
||||
foreach ($categories as $categoryId) {
|
||||
$this->assertTrue((bool)$this->productResource->canBeShowInCategory($bundleProduct, $categoryId));
|
||||
}
|
||||
|
||||
$this->assertFalse(
|
||||
(bool)$this->productResource->canBeShowInCategory($bundleProduct, $categoryThird->getId())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product.php
|
||||
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/fixed_bundle_product.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/indexer_catalog_category.php
|
||||
* @depends testReindex
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testCategoryDelete()
|
||||
{
|
||||
$categories = $this->getCategories();
|
||||
$bundleProduct = $this->productRepository->get('bundle_product');
|
||||
|
||||
/** @var Category $categoryFourth */
|
||||
$categoryFourth = end($categories);
|
||||
$this->categoryRepository->delete($categoryFourth);
|
||||
|
||||
/** @var Category $categorySecond */
|
||||
$categorySecond = $categories[1];
|
||||
|
||||
$categories = [$categorySecond->getId(), $categoryFourth->getId()];
|
||||
|
||||
foreach ($categories as $categoryId) {
|
||||
$this->assertFalse((bool)$this->productResource->canBeShowInCategory($bundleProduct, $categoryId));
|
||||
}
|
||||
$this->assertTrue(
|
||||
(bool)$this->productResource->canBeShowInCategory(
|
||||
$bundleProduct,
|
||||
self::DEFAULT_ROOT_CATEGORY
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product.php
|
||||
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/fixed_bundle_product.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/indexer_catalog_category.php
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testCategoryCreate()
|
||||
{
|
||||
$this->testReindex();
|
||||
$categories = $this->getCategories();
|
||||
$bundleProduct = $this->productRepository->get('bundle_product');
|
||||
|
||||
/** @var Category $categorySecond */
|
||||
$categorySecond = $categories[1];
|
||||
$categorySecond->setIsAnchor(0);
|
||||
$this->categoryRepository->save($categorySecond);
|
||||
|
||||
/** @var Category $categoryFourth */
|
||||
$categoryFourth = end($categories);
|
||||
|
||||
/** @var Category $categorySixth */
|
||||
$categorySixth = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Catalog\Model\Category::class
|
||||
);
|
||||
$categorySixth->setName(
|
||||
'Category 6'
|
||||
)->setPath(
|
||||
$categoryFourth->getPath()
|
||||
)->setAvailableSortBy(
|
||||
'name'
|
||||
)->setDefaultSortBy(
|
||||
'name'
|
||||
)->setIsActive(
|
||||
true
|
||||
);
|
||||
$this->categoryRepository->save($categorySixth);
|
||||
|
||||
$bundleProduct->setCategoryIds([$categorySixth->getId()]);
|
||||
$bundleProduct->save();
|
||||
|
||||
$categories = [self::DEFAULT_ROOT_CATEGORY, $categorySixth->getId(), $categoryFourth->getId()];
|
||||
foreach ($categories as $categoryId) {
|
||||
$this->assertTrue((bool)$this->productResource->canBeShowInCategory($bundleProduct, $categoryId));
|
||||
}
|
||||
|
||||
$this->assertFalse(
|
||||
(bool)$this->productResource->canBeShowInCategory($bundleProduct, $categorySecond->getId())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds 4 categories
|
||||
*
|
||||
* @return Category[]
|
||||
*/
|
||||
private function getCategories()
|
||||
{
|
||||
$collectionFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory::class
|
||||
);
|
||||
|
||||
/** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $collection */
|
||||
$collection = $collectionFactory->create();
|
||||
|
||||
$collection
|
||||
->addAttributeToSelect('name')
|
||||
->addAttributeToFilter('name', ['in' => [
|
||||
'Category 1',
|
||||
'Category 2',
|
||||
'Category 3',
|
||||
'Category 4',
|
||||
]]);
|
||||
|
||||
return array_values($collection->getItems());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Model;
|
||||
|
||||
use Magento\Bundle\Api\Data\LinkInterface;
|
||||
use Magento\Bundle\Api\Data\OptionInterface;
|
||||
use Magento\Bundle\Api\Data\LinkInterfaceFactory;
|
||||
use Magento\Bundle\Api\Data\OptionInterfaceFactory;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\CatalogInventory\Api\StockRegistryInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Test option repository class
|
||||
*/
|
||||
class OptionRepositoryTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var OptionRepository
|
||||
*/
|
||||
private $optionRepository;
|
||||
|
||||
/**
|
||||
* @var ProductRepositoryInterface
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$this->optionRepository = $this->objectManager->get(OptionRepository::class);
|
||||
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/products.php
|
||||
* @magentoDataFixture Magento/Bundle/_files/empty_bundle_product.php
|
||||
*/
|
||||
public function testBundleProductIsSaleableAfterNewOptionSave()
|
||||
{
|
||||
$bundleProduct = $this->productRepository->get('bundle-product');
|
||||
|
||||
/** @var OptionInterface $newOption */
|
||||
$newOption = $this->objectManager->create(OptionInterfaceFactory::class)->create();
|
||||
/** @var LinkInterface $productLink */
|
||||
$productLink = $this->objectManager->create(LinkInterfaceFactory::class)->create();
|
||||
|
||||
$newOption->setTitle('new-option');
|
||||
$newOption->setRequired(true);
|
||||
$newOption->setType('select');
|
||||
$newOption->setSku($bundleProduct->getSku());
|
||||
|
||||
$productLink->setSku('simple');
|
||||
$productLink->setQty(1);
|
||||
$productLink->setIsDefault(true);
|
||||
$productLink->setCanChangeQuantity(0);
|
||||
|
||||
$newOption->setProductLinks([$productLink]);
|
||||
|
||||
$optionId = $this->optionRepository->save($bundleProduct, $newOption);
|
||||
$bundleProduct = $this->productRepository->get($bundleProduct->getSku(), false, null, true);
|
||||
|
||||
$this->assertNotNull($optionId, 'Bundle option was not saved correctly');
|
||||
$this->assertTrue($bundleProduct->isSaleable(), 'Bundle product should show as in stock once option is added');
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Model\Plugin\Frontend;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Interception\PluginList;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test bundle fronted product plugin adds children products ids to bundle product identities.
|
||||
*/
|
||||
class ProductIdentitiesExtenderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Check, product plugin is registered for storefront.
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
* @return void
|
||||
*/
|
||||
public function testProductIsRegistered(): void
|
||||
{
|
||||
$pluginInfo = Bootstrap::getObjectManager()->get(PluginList::class)
|
||||
->get(Product::class, []);
|
||||
$this->assertSame(
|
||||
ProductIdentitiesExtender::class,
|
||||
$pluginInfo['add_bundle_child_identities']['instance']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check plugin will add children ids to bundle product identities on storefront.
|
||||
*
|
||||
* @magentoDataFixture Magento/Bundle/_files/product.php
|
||||
* @magentoAppArea frontend
|
||||
* @return void
|
||||
*/
|
||||
public function testGetIdentitiesForBundleProductOnStorefront(): void
|
||||
{
|
||||
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
|
||||
$bundleProduct = $productRepository->get('bundle-product');
|
||||
$simpleProduct = $productRepository->get('simple');
|
||||
$expectedIdentities = [
|
||||
'cat_p_' . $bundleProduct->getId(),
|
||||
'cat_p',
|
||||
'cat_p_' . $simpleProduct->getId(),
|
||||
|
||||
];
|
||||
$this->assertEquals($expectedIdentities, $bundleProduct->getIdentities());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check plugin won't add children ids to bundle product identities in admin area.
|
||||
*
|
||||
* @magentoDataFixture Magento/Bundle/_files/product.php
|
||||
* @magentoAppArea adminhtml
|
||||
* @return void
|
||||
*/
|
||||
public function testGetIdentitiesForBundleProductInAdminArea(): void
|
||||
{
|
||||
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
|
||||
$bundleProduct = $productRepository->get('bundle-product');
|
||||
$expectedIdentities = [
|
||||
'cat_p_' . $bundleProduct->getId(),
|
||||
];
|
||||
$this->assertEquals($expectedIdentities, $bundleProduct->getIdentities());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Bundle\Model\Product;
|
||||
|
||||
/**
|
||||
* Abstract class for testing bundle prices
|
||||
* @codingStandardsIgnoreStart
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
abstract class BundlePriceAbstract extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** Fixed price type for product custom option */
|
||||
const CUSTOM_OPTION_PRICE_TYPE_FIXED = 'fixed';
|
||||
|
||||
/** Percent price type for product custom option */
|
||||
const CUSTOM_OPTION_PRICE_TYPE_PERCENT = 'percent';
|
||||
|
||||
/** @var \Magento\TestFramework\Helper\Bootstrap */
|
||||
protected $objectManager;
|
||||
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface */
|
||||
protected $productRepository;
|
||||
|
||||
/**
|
||||
* @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
|
||||
*/
|
||||
protected $productCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var \Magento\CatalogRule\Model\RuleFactory
|
||||
*/
|
||||
private $ruleFactory;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
$this->productCollectionFactory =
|
||||
$this->objectManager->create(\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class);
|
||||
|
||||
$scopeConfig = $this->objectManager->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class);
|
||||
$scopeConfig->setValue(
|
||||
\Magento\CatalogInventory\Model\Configuration::XML_PATH_SHOW_OUT_OF_STOCK,
|
||||
true,
|
||||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
|
||||
);
|
||||
$this->ruleFactory = $this->objectManager->get(\Magento\CatalogRule\Model\RuleFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get test cases
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getTestCases();
|
||||
|
||||
/**
|
||||
* @param array $strategyModifiers
|
||||
* @param string $productSku
|
||||
* @return void
|
||||
* @throws \Magento\Framework\Exception\NoSuchEntityException
|
||||
* @throws \Magento\Framework\Exception\InputException
|
||||
* @throws \Magento\Framework\Exception\StateException
|
||||
* @throws \Magento\Framework\Exception\CouldNotSaveException
|
||||
*/
|
||||
protected function prepareFixture($strategyModifiers, $productSku)
|
||||
{
|
||||
$this->ruleFactory->create()->clearPriceRulesData();
|
||||
|
||||
$bundleProduct = $this->productRepository->get($productSku);
|
||||
|
||||
foreach ($strategyModifiers as $modifier) {
|
||||
if (method_exists($this, $modifier['modifierName'])) {
|
||||
array_unshift($modifier['data'], $bundleProduct);
|
||||
$bundleProduct = call_user_func_array([$this, $modifier['modifierName']], $modifier['data']);
|
||||
} else {
|
||||
throw new \Magento\Framework\Exception\InputException(
|
||||
__('Modifier %s does not exists', $modifier['modifierName'])
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->productRepository->save($bundleProduct);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add simple product to bundle
|
||||
*
|
||||
* @param \Magento\Catalog\Model\Product $bundleProduct
|
||||
* @param array $optionsData
|
||||
* @return \Magento\Catalog\Model\Product
|
||||
*/
|
||||
protected function addSimpleProduct(\Magento\Catalog\Model\Product $bundleProduct, array $optionsData)
|
||||
{
|
||||
$options = [];
|
||||
|
||||
foreach ($optionsData as $optionData) {
|
||||
$links = [];
|
||||
$linksData = $optionData['links'];
|
||||
unset($optionData['links']);
|
||||
|
||||
$option = $this->objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class)
|
||||
->create(['data' => $optionData])
|
||||
->setSku($bundleProduct->getSku());
|
||||
|
||||
foreach ($linksData as $linkData) {
|
||||
$links[] = $this->objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class)
|
||||
->create(['data' => $linkData]);
|
||||
}
|
||||
|
||||
$option->setProductLinks($links);
|
||||
$options[] = $option;
|
||||
}
|
||||
|
||||
$extension = $bundleProduct->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$bundleProduct->setExtensionAttributes($extension);
|
||||
|
||||
return $bundleProduct;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Catalog\Model\Product $bundleProduct
|
||||
* @param array $optionsData
|
||||
* @return \Magento\Catalog\Model\Product
|
||||
*/
|
||||
protected function addCustomOption(\Magento\Catalog\Model\Product $bundleProduct, array $optionsData)
|
||||
{
|
||||
/** @var \Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory $customOptionFactory */
|
||||
$customOptionFactory = $this->objectManager
|
||||
->create(\Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory::class);
|
||||
|
||||
$options = [];
|
||||
foreach ($optionsData as $optionData) {
|
||||
$customOption = $customOptionFactory->create(
|
||||
[
|
||||
'data' => $optionData
|
||||
]
|
||||
);
|
||||
$customOption->setProductSku($bundleProduct->getSku());
|
||||
$customOption->setOptionId(null);
|
||||
|
||||
$options[] = $customOption;
|
||||
}
|
||||
|
||||
$bundleProduct->setOptions($options);
|
||||
$bundleProduct->setCanSaveCustomOptions(true);
|
||||
|
||||
return $bundleProduct;
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
+376
@@ -0,0 +1,376 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Bundle\Model\Product;
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class DynamicBundlePriceCalculatorTest extends BundlePriceAbstract
|
||||
{
|
||||
/**
|
||||
* @param array $strategyModifiers
|
||||
* @param array $expectedResults
|
||||
* @dataProvider getTestCases
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product.php
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testPriceForDynamicBundle(array $strategyModifiers, array $expectedResults)
|
||||
{
|
||||
$this->prepareFixture($strategyModifiers, 'bundle_product');
|
||||
$bundleProduct = $this->productRepository->get('bundle_product', false, null, true);
|
||||
|
||||
/** @var \Magento\Framework\Pricing\PriceInfo\Base $priceInfo */
|
||||
$priceInfo = $bundleProduct->getPriceInfo();
|
||||
$priceCode = \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE;
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedResults['minimalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMinimalPrice()->getValue(),
|
||||
'Failed to check minimal price on product'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expectedResults['maximalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMaximalPrice()->getValue(),
|
||||
'Failed to check maximal price on product'
|
||||
);
|
||||
|
||||
$priceInfoFromIndexer = $this->productCollectionFactory->create()
|
||||
->addFieldToFilter('sku', 'bundle_product')
|
||||
->addPriceData()
|
||||
->load()
|
||||
->getFirstItem();
|
||||
|
||||
$this->assertEquals($expectedResults['minimalPrice'], $priceInfoFromIndexer->getMinimalPrice());
|
||||
$this->assertEquals($expectedResults['maximalPrice'], $priceInfoFromIndexer->getMaxPrice());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $strategyModifiers
|
||||
* @param array $expectedResults
|
||||
* @dataProvider getTestCases
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoConfigFixture current_store catalog/price/scope 1
|
||||
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product.php
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testPriceForDynamicBundleInWebsiteScope(array $strategyModifiers, array $expectedResults)
|
||||
{
|
||||
$this->prepareFixture($strategyModifiers, 'bundle_product');
|
||||
$bundleProduct = $this->productRepository->get('bundle_product', false, null, true);
|
||||
|
||||
/** @var \Magento\Framework\Pricing\PriceInfo\Base $priceInfo */
|
||||
$priceInfo = $bundleProduct->getPriceInfo();
|
||||
$priceCode = \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE;
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedResults['minimalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMinimalPrice()->getValue(),
|
||||
'Failed to check minimal price on product'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expectedResults['maximalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMaximalPrice()->getValue(),
|
||||
'Failed to check maximal price on product'
|
||||
);
|
||||
|
||||
$priceInfoFromIndexer = $this->productCollectionFactory->create()
|
||||
->addFieldToFilter('sku', 'bundle_product')
|
||||
->addPriceData()
|
||||
->load()
|
||||
->getFirstItem();
|
||||
|
||||
$this->assertEquals($expectedResults['minimalPrice'], $priceInfoFromIndexer->getMinimalPrice());
|
||||
$this->assertEquals($expectedResults['maximalPrice'], $priceInfoFromIndexer->getMaxPrice());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for current test
|
||||
* @return array
|
||||
*/
|
||||
public function getTestCases()
|
||||
{
|
||||
return [
|
||||
'#1 Testing price for dynamic bundle product with one simple' => [
|
||||
'strategy' => $this->getBundleConfiguration1(),
|
||||
'expectedResults' => [
|
||||
// just price from simple1
|
||||
'minimalPrice' => 10,
|
||||
// just price from simple1
|
||||
'maximalPrice' => 10
|
||||
]
|
||||
],
|
||||
|
||||
'#2 Testing price for dynamic bundle product with three simples and different qty' => [
|
||||
'strategy' => $this->getBundleConfiguration2(),
|
||||
'expectedResults' => [
|
||||
// min price from simples 3*10 or 30
|
||||
'minimalPrice' => 30,
|
||||
// (3 * 10) + (2 * 20) + 30
|
||||
'maximalPrice' => 100
|
||||
]
|
||||
],
|
||||
|
||||
'#3 Testing price for dynamic bundle product with four simples and different price' => [
|
||||
'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
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle product with one simple
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration1()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle product with three simples and different qty
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration2()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 3,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 2,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple3',
|
||||
'qty' => 1,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle product with three simples and different price
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration3()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 1,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple3',
|
||||
'qty' => 1,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 3,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
'title' => 'Op2',
|
||||
'required' => false,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 3,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
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,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 3,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
'title' => 'Op2',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 3,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+376
@@ -0,0 +1,376 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Model\Product;
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation disabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoIndexerDimensionMode catalog_product_price website_and_customer_group
|
||||
* @group indexer_dimension
|
||||
*/
|
||||
class DynamicBundlePriceCalculatorWithDimensionTest extends BundlePriceAbstract
|
||||
{
|
||||
/**
|
||||
* @param array $strategyModifiers
|
||||
* @param array $expectedResults
|
||||
* @dataProvider getTestCases
|
||||
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product.php
|
||||
*/
|
||||
public function testPriceForDynamicBundle(array $strategyModifiers, array $expectedResults)
|
||||
{
|
||||
$this->prepareFixture($strategyModifiers, 'bundle_product');
|
||||
$bundleProduct = $this->productRepository->get('bundle_product', false, null, true);
|
||||
|
||||
/** @var \Magento\Framework\Pricing\PriceInfo\Base $priceInfo */
|
||||
$priceInfo = $bundleProduct->getPriceInfo();
|
||||
$priceCode = \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE;
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedResults['minimalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMinimalPrice()->getValue(),
|
||||
'Failed to check minimal price on product'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expectedResults['maximalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMaximalPrice()->getValue(),
|
||||
'Failed to check maximal price on product'
|
||||
);
|
||||
|
||||
$priceInfoFromIndexer = $this->productCollectionFactory->create()
|
||||
->addFieldToFilter('sku', 'bundle_product')
|
||||
->addPriceData()
|
||||
->load()
|
||||
->getFirstItem();
|
||||
|
||||
$this->assertEquals($expectedResults['minimalPrice'], $priceInfoFromIndexer->getMinimalPrice());
|
||||
$this->assertEquals($expectedResults['maximalPrice'], $priceInfoFromIndexer->getMaxPrice());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $strategyModifiers
|
||||
* @param array $expectedResults
|
||||
* @dataProvider getTestCases
|
||||
* @magentoConfigFixture current_store catalog/price/scope 1
|
||||
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product.php
|
||||
*/
|
||||
public function testPriceForDynamicBundleInWebsiteScope(array $strategyModifiers, array $expectedResults)
|
||||
{
|
||||
$this->prepareFixture($strategyModifiers, 'bundle_product');
|
||||
$bundleProduct = $this->productRepository->get('bundle_product', false, null, true);
|
||||
|
||||
/** @var \Magento\Framework\Pricing\PriceInfo\Base $priceInfo */
|
||||
$priceInfo = $bundleProduct->getPriceInfo();
|
||||
$priceCode = \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE;
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedResults['minimalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMinimalPrice()->getValue(),
|
||||
'Failed to check minimal price on product'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expectedResults['maximalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMaximalPrice()->getValue(),
|
||||
'Failed to check maximal price on product'
|
||||
);
|
||||
|
||||
$priceInfoFromIndexer = $this->productCollectionFactory->create()
|
||||
->addFieldToFilter('sku', 'bundle_product')
|
||||
->addPriceData()
|
||||
->load()
|
||||
->getFirstItem();
|
||||
|
||||
$this->assertEquals($expectedResults['minimalPrice'], $priceInfoFromIndexer->getMinimalPrice());
|
||||
$this->assertEquals($expectedResults['maximalPrice'], $priceInfoFromIndexer->getMaxPrice());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for current test
|
||||
* @return array
|
||||
*/
|
||||
public function getTestCases()
|
||||
{
|
||||
return [
|
||||
'#1 Testing price for dynamic bundle product with one simple' => [
|
||||
'strategy' => $this->getBundleConfiguration1(),
|
||||
'expectedResults' => [
|
||||
// just price from simple1
|
||||
'minimalPrice' => 10,
|
||||
// just price from simple1
|
||||
'maximalPrice' => 10
|
||||
]
|
||||
],
|
||||
|
||||
'#2 Testing price for dynamic bundle product with three simples and different qty' => [
|
||||
'strategy' => $this->getBundleConfiguration2(),
|
||||
'expectedResults' => [
|
||||
// min price from simples 3*10 or 30
|
||||
'minimalPrice' => 30,
|
||||
// (3 * 10) + (2 * 20) + 30
|
||||
'maximalPrice' => 100
|
||||
]
|
||||
],
|
||||
|
||||
'#3 Testing price for dynamic bundle product with four simples and different price' => [
|
||||
'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
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle product with one simple
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration1()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle product with three simples and different qty
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration2()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 3,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 2,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple3',
|
||||
'qty' => 1,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle product with three simples and different price
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration3()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 1,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple3',
|
||||
'qty' => 1,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 3,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
'title' => 'Op2',
|
||||
'required' => false,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 3,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
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,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 3,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
'title' => 'Op2',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 3,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+436
@@ -0,0 +1,436 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Bundle\Model\Product;
|
||||
|
||||
/**
|
||||
* @codingStandardsIgnoreStart
|
||||
* @magentoDataFixtureBeforeTransaction Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product_with_catalog_rule.php
|
||||
* @codingStandardsIgnoreEnd
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class DynamicBundleWithCatalogPriceRuleCalculatorTest extends BundlePriceAbstract
|
||||
{
|
||||
/**
|
||||
* @param array $strategyModifiers
|
||||
* @param array $expectedResults
|
||||
* @dataProvider getTestCases
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testPriceForDynamicBundle(array $strategyModifiers, array $expectedResults)
|
||||
{
|
||||
$this->prepareFixture($strategyModifiers, 'bundle_product');
|
||||
$bundleProduct = $this->productRepository->get('bundle_product', false, null, true);
|
||||
|
||||
/** @var \Magento\Framework\Pricing\PriceInfo\Base $priceInfo */
|
||||
$priceInfo = $bundleProduct->getPriceInfo();
|
||||
$priceCode = \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE;
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedResults['minimalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMinimalPrice()->getValue(),
|
||||
'Failed to check minimal price on product'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedResults['maximalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMaximalPrice()->getValue(),
|
||||
'Failed to check maximal price on product'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for current test
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function getTestCases()
|
||||
{
|
||||
return [
|
||||
'#1 Testing price for dynamic bundle with one required option' => [
|
||||
'strategy' => $this->getBundleProductConfiguration1(),
|
||||
'expectedResults' => [
|
||||
// 10 * 0.9
|
||||
'minimalPrice' => 9,
|
||||
|
||||
// 10 * 0.9
|
||||
'maximalPrice' => 9
|
||||
]
|
||||
],
|
||||
|
||||
'#3 Testing price for dynamic bundle with one non required option' => [
|
||||
'strategy' => $this->getBundleProductConfiguration3(),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 2 * 10
|
||||
'minimalPrice' => 18,
|
||||
|
||||
// 0.9 * 2 * 10
|
||||
'maximalPrice' => 18
|
||||
]
|
||||
],
|
||||
|
||||
'#4 Testing price for dynamic bundle with one required checkbox type option and 2 simples' => [
|
||||
'strategy' => $this->getBundleProductConfiguration4(),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 1 * 10
|
||||
'minimalPrice' => 9,
|
||||
|
||||
// 0.9 * 1 * 10 + 3 * 0.9 * 20
|
||||
'maximalPrice' => 63
|
||||
]
|
||||
],
|
||||
|
||||
'#5 Testing price for dynamic bundle with one required multi type option and 2 simples' => [
|
||||
'strategy' => $this->getBundleProductConfiguration5(),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 1 * 10
|
||||
'minimalPrice' => 9,
|
||||
|
||||
// 0.9 * 1 * 10 + 3 * 0.9 * 20
|
||||
'maximalPrice' => 63
|
||||
]
|
||||
],
|
||||
|
||||
'#6 Testing price for dynamic bundle with one required radio type option and 2 simples' => [
|
||||
'strategy' => $this->getBundleProductConfiguration6(),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 1 * 10
|
||||
'minimalPrice' => 9,
|
||||
|
||||
// 0.9 * 3 * 20
|
||||
'maximalPrice' => 54
|
||||
]
|
||||
],
|
||||
|
||||
'#7 Testing price for dynamic bundle with two required options' => [
|
||||
'strategy' => $this->getBundleProductConfiguration7(),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 1 * 10 + 0.9 * 1 * 10
|
||||
'minimalPrice' => 18,
|
||||
|
||||
// 3 * 0.9 * 20 + 1 * 0.9 * 10 + 3 * 0.9 * 20
|
||||
'maximalPrice' => 117
|
||||
]
|
||||
],
|
||||
|
||||
'#8 Testing price for dynamic bundle with one required option and one non required' => [
|
||||
'strategy' => $this->getBundleProductConfiguration8(),
|
||||
'expectedResults' => [
|
||||
// 1 * 0.9 * 10
|
||||
'minimalPrice' => 9,
|
||||
|
||||
// 3 * 0.9 * 20 + 1 * 0.9 * 10 + 3 * 0.9 * 20
|
||||
'maximalPrice' => 117
|
||||
]
|
||||
],
|
||||
|
||||
'#9 Testing price for dynamic bundle with two non required options' => [
|
||||
'strategy' => $this->getBundleProductConfiguration9(),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 1 * 10
|
||||
'minimalPrice' => 9,
|
||||
|
||||
// 3 * 0.9 * 20 + 1 * 0.9 * 10 + 3 * 0.9 * 20
|
||||
'maximalPrice' => 117
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with one required option
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleProductConfiguration1()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
],
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with one non required option
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleProductConfiguration3()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'type' => 'checkbox',
|
||||
'required' => false,
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 2,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with one required checkbox type option and 2 simples
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleProductConfiguration4()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'type' => 'checkbox',
|
||||
'required' => true,
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 3,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with one required multi type option and 2 simples
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleProductConfiguration5()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'multi',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 3,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with one required radio type option and 2 simples
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleProductConfiguration6()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'radio',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 3,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with two required options
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleProductConfiguration7()
|
||||
{
|
||||
$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]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with one required option and one non required
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleProductConfiguration8()
|
||||
{
|
||||
$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',
|
||||
'qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 3,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with two non required options
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleProductConfiguration9()
|
||||
{
|
||||
$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]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+349
@@ -0,0 +1,349 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Bundle\Model\Product;
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class DynamicBundleWithSpecialPriceCalculatorTest extends BundlePriceAbstract
|
||||
{
|
||||
/**
|
||||
* @param array $strategyModifiers
|
||||
* @param array $expectedResults
|
||||
* @dataProvider getTestCases
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product_with_special_price.php
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testPriceForDynamicBundle(array $strategyModifiers, array $expectedResults)
|
||||
{
|
||||
$this->prepareFixture($strategyModifiers, 'bundle_product');
|
||||
$bundleProduct = $this->productRepository->get('bundle_product', false, null, true);
|
||||
|
||||
/** @var \Magento\Framework\Pricing\PriceInfo\Base $priceInfo */
|
||||
$priceInfo = $bundleProduct->getPriceInfo();
|
||||
$priceCode = \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE;
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedResults['minimalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMinimalPrice()->getValue(),
|
||||
'Failed to check minimal price on product'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expectedResults['maximalPrice'],
|
||||
$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 maximal regular price on product'
|
||||
);
|
||||
}
|
||||
|
||||
$priceInfoFromIndexer = $this->productCollectionFactory->create()
|
||||
->addFieldToFilter('sku', 'bundle_product')
|
||||
->addPriceData()
|
||||
->load()
|
||||
->getFirstItem();
|
||||
|
||||
$this->assertEquals($expectedResults['minimalPrice'], $priceInfoFromIndexer->getMinimalPrice());
|
||||
$this->assertEquals($expectedResults['maximalPrice'], $priceInfoFromIndexer->getMaxPrice());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for current test
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function getTestCases()
|
||||
{
|
||||
return [
|
||||
'#1 Testing price for dynamic bundle with one required option and special price' => [
|
||||
'strategy' => $this->getBundleConfiguration1(),
|
||||
'expectedResults' => [
|
||||
// 0.5 * 10
|
||||
'minimalPrice' => 5,
|
||||
// 0.5 * 10
|
||||
'maximalPrice' => 5,
|
||||
]
|
||||
],
|
||||
|
||||
'#2 Testing price for dynamic bundle with one non required option and special price' => [
|
||||
'strategy' => $this->getBundleConfiguration2(),
|
||||
'expectedResults' => [
|
||||
// 0.5 * 2 * 10
|
||||
'minimalPrice' => 10,
|
||||
// 0.5 * 2 * 10
|
||||
'maximalPrice' => 10,
|
||||
]
|
||||
|
||||
],
|
||||
|
||||
'
|
||||
#3 Testing price for dynamic bundle
|
||||
with one required checkbox type option, two simples and special price
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration3(),
|
||||
'expectedResults' => [
|
||||
// 0.5 * 1 * 10
|
||||
'minimalPrice' => 5,
|
||||
// 0.5 * (1 * 10 + 3 * 30)
|
||||
'maximalPrice' => 50,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#4 Testing price for dynamic bundle
|
||||
with one required multi type option, two simples with special price
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration4(),
|
||||
'expectedResults' => [
|
||||
// 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 option, one non required and special price' => [
|
||||
'strategy' => $this->getBundleConfiguration5(),
|
||||
'expectedResults' => [
|
||||
// 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 one simple product with special price' => [
|
||||
'strategy' => $this->getBundleConfiguration6(),
|
||||
'expectedResults' => [
|
||||
// 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
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration1()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with one non required option and special price
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration2()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'type' => 'checkbox',
|
||||
'required' => false,
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 2,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with one required checkbox type option, two simples and special price
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration3()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple3',
|
||||
'qty' => 3,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with one required multi type option, two simples and special price
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration4()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple5',
|
||||
'qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 4,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
'title' => 'Op2',
|
||||
'required' => false,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple3',
|
||||
'qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple4',
|
||||
'qty' => 3,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with one simple product with special price
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration6()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'radio',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 4,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple5',
|
||||
'qty' => 1,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+654
@@ -0,0 +1,654 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Bundle\Model\Product;
|
||||
|
||||
use \Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory;
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class DynamicBundleWithTierPriceCalculatorTest extends BundlePriceAbstract
|
||||
{
|
||||
/** @var ProductTierPriceInterfaceFactory */
|
||||
private $tierPriceFactory;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->tierPriceFactory = $this->objectManager->create(ProductTierPriceInterfaceFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $strategyModifiers
|
||||
* @param array $expectedResults
|
||||
* @dataProvider getTestCases
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product.php
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testPriceForDynamicBundle(array $strategyModifiers, array $expectedResults)
|
||||
{
|
||||
$this->prepareFixture($strategyModifiers, 'bundle_product');
|
||||
$bundleProduct = $this->productRepository->get('bundle_product', false, null, true);
|
||||
|
||||
/** @var \Magento\Framework\Pricing\PriceInfo\Base $priceInfo */
|
||||
$priceInfo = $bundleProduct->getPriceInfo();
|
||||
$priceCode = \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE;
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedResults['minimalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMinimalPrice()->getValue(),
|
||||
'Failed to check minimal price on product'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expectedResults['maximalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMaximalPrice()->getValue(),
|
||||
'Failed to check maximal price on product'
|
||||
);
|
||||
|
||||
$priceInfoFromIndexer = $this->productCollectionFactory->create()
|
||||
->addFieldToFilter('sku', 'bundle_product')
|
||||
->addPriceData()
|
||||
->load()
|
||||
->getFirstItem();
|
||||
|
||||
$this->assertEquals($expectedResults['minimalPrice'], $priceInfoFromIndexer->getMinimalPrice());
|
||||
$this->assertEquals($expectedResults['maximalPrice'], $priceInfoFromIndexer->getMaxPrice());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for current test
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function getTestCases()
|
||||
{
|
||||
return [
|
||||
'
|
||||
#1 Testing product price for dynamic bundle
|
||||
with one required option and tier price
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration1(),
|
||||
'expectedResults' => [
|
||||
// 0.5 * 10
|
||||
'minimalPrice' => 5,
|
||||
// 0.5 * 10
|
||||
'maximalPrice' => 5,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#2 Testing product price for dynamic bundle
|
||||
with one non required option and tier price
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration2(),
|
||||
'expectedResults' => [
|
||||
// 0.5 * 2 * 10
|
||||
'minimalPrice' => 10,
|
||||
// 0.5 * 2 * 10
|
||||
'maximalPrice' => 10,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#3 Testing product price for dynamic bundle
|
||||
with one required checkbox type option and tier price
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration3(),
|
||||
'expectedResults' => [
|
||||
// 0.5 * 1 * 10
|
||||
'minimalPrice' => 5,
|
||||
// 0.5 * (1 * 10 + 3 * 20)
|
||||
'maximalPrice' => 35,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#4 Testing product price for dynamic bundle
|
||||
with one required multi type option and tier price
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration4(),
|
||||
'expectedResults' => [
|
||||
// 0.5 * 1 * 10
|
||||
'minimalPrice' => 5,
|
||||
// 0.5 * (1 * 10 + 3 * 20)
|
||||
'maximalPrice' => 35,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#5 Testing product price for dynamic bundle
|
||||
with one required radio type option and tier price
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration5(),
|
||||
'expectedResults' => [
|
||||
// 0.5 * 1 * 10
|
||||
'minimalPrice' => 5,
|
||||
// 0.5 * 3 * 20
|
||||
'maximalPrice' => 30,
|
||||
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#6 Testing product price for dynamic bundle
|
||||
with two required options and tier 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 product price for dynamic bundle
|
||||
with one required option, one non required option and tier price
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration7(),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (1 * 10)
|
||||
'minimalPrice' => 5,
|
||||
// 0.5 * (3 * 20 + 1 * 10 + 3 * 20)
|
||||
'maximalPrice' => 65,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#8 Testing product price for dynamic bundle
|
||||
with two non required options and tier price
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration8(),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (1 * 10)
|
||||
'minimalPrice' => 5,
|
||||
// 0.5 * (3 * 20 + 1 * 10 + 3 * 20)
|
||||
'maximalPrice' => 65,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#9 Testing product price for dynamic bundle
|
||||
with tier price and with simple with tier price
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration9(),
|
||||
'expectedResults' => [
|
||||
// 0.5 * 1 * 2.5
|
||||
'minimalPrice' => 1.25,
|
||||
// 0.5 * 3 * 20
|
||||
'maximalPrice' => 30,
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with one required option and tier price
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration1()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$tierPriceData = [
|
||||
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
|
||||
'qty' => 1,
|
||||
'value' => 50,
|
||||
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addTierPrice',
|
||||
'data' => [$tierPriceData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with one non required option and tier price
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration2()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'type' => 'checkbox',
|
||||
'required' => false,
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 2,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$tierPriceData = [
|
||||
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
|
||||
'qty' => 1,
|
||||
'value' => 50,
|
||||
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addTierPrice',
|
||||
'data' => [$tierPriceData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with one required checkbox type option and tier price
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration3()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 3,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$tierPriceData = [
|
||||
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
|
||||
'qty' => 1,
|
||||
'value' => 50,
|
||||
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addTierPrice',
|
||||
'data' => [$tierPriceData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with one required multi type option and tier price
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration4()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'multi',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 3,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$tierPriceData = [
|
||||
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
|
||||
'qty' => 1,
|
||||
'value' => 50,
|
||||
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addTierPrice',
|
||||
'data' => [$tierPriceData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with one required radio type option and tier price
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration5()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'radio',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 3,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$tierPriceData = [
|
||||
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
|
||||
'qty' => 1,
|
||||
'value' => 50,
|
||||
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addTierPrice',
|
||||
'data' => [$tierPriceData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with two required options and tier price
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration6()
|
||||
{
|
||||
$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,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$tierPriceData = [
|
||||
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
|
||||
'qty' => 1,
|
||||
'value' => 50,
|
||||
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addTierPrice',
|
||||
'data' => [$tierPriceData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with one required option, one non required option and tier 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',
|
||||
'qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 3,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$tierPriceData = [
|
||||
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
|
||||
'qty' => 1,
|
||||
'value' => 50,
|
||||
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addTierPrice',
|
||||
'data' => [$tierPriceData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with two non required options and tier 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,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$tierPriceData = [
|
||||
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
|
||||
'qty' => 1,
|
||||
'value' => 50,
|
||||
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addTierPrice',
|
||||
'data' => [$tierPriceData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic bundle with tier price and with simple with tier price
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration9()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'radio',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 3,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$tierPriceData = [
|
||||
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
|
||||
'qty' => 1,
|
||||
'value' => 50,
|
||||
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
|
||||
];
|
||||
|
||||
$tierPriceSimpleProductData = [
|
||||
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
|
||||
'qty' => 1,
|
||||
'value' => 2.5
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addTierPrice',
|
||||
'data' => [$tierPriceData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addTierPriceForSimple',
|
||||
'data' => ['simple1', $tierPriceSimpleProductData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Catalog\Model\Product $product
|
||||
* @param array $tirePriceData
|
||||
* @return \Magento\Catalog\Model\Product
|
||||
*/
|
||||
protected function addTierPrice(\Magento\Catalog\Model\Product $product, $tirePriceData)
|
||||
{
|
||||
$tierPrice = $this->tierPriceFactory->create([
|
||||
'data' => $tirePriceData
|
||||
]);
|
||||
$product->setTierPrices([$tierPrice]);
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Catalog\Model\Product $bundleProduct
|
||||
* @param string $sku
|
||||
* @param array $tirePriceData
|
||||
* @return \Magento\Catalog\Model\Product
|
||||
*/
|
||||
protected function addTierPriceForSimple(\Magento\Catalog\Model\Product $bundleProduct, $sku, $tirePriceData)
|
||||
{
|
||||
$simple = $this->productRepository->get($sku, false, null, true);
|
||||
$simple = $this->addTierPrice($simple, $tirePriceData);
|
||||
$this->productRepository->save($simple);
|
||||
|
||||
return $bundleProduct;
|
||||
}
|
||||
}
|
||||
+413
@@ -0,0 +1,413 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Bundle\Model\Product;
|
||||
|
||||
use \Magento\Bundle\Api\Data\LinkInterface;
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class FixedBundlePriceCalculatorTest extends BundlePriceAbstract
|
||||
{
|
||||
/**
|
||||
* @param array $strategyModifiers
|
||||
* @param array $expectedResults
|
||||
* @dataProvider getTestCases
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/fixed_bundle_product.php
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testPriceForFixedBundle(array $strategyModifiers, array $expectedResults)
|
||||
{
|
||||
$this->prepareFixture($strategyModifiers, 'bundle_product');
|
||||
$bundleProduct = $this->productRepository->get('bundle_product', false, null, true);
|
||||
|
||||
/** @var \Magento\Framework\Pricing\PriceInfo\Base $priceInfo */
|
||||
$priceInfo = $bundleProduct->getPriceInfo();
|
||||
$priceCode = \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE;
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedResults['minimalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMinimalPrice()->getValue(),
|
||||
'Failed to check minimal price on product'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expectedResults['maximalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMaximalPrice()->getValue(),
|
||||
'Failed to check maximal price on product'
|
||||
);
|
||||
|
||||
$priceInfoFromIndexer = $this->productCollectionFactory->create()
|
||||
->addIdFilter([42])
|
||||
->addPriceData()
|
||||
->load()
|
||||
->getFirstItem();
|
||||
|
||||
$this->assertEquals($expectedResults['minimalPrice'], $priceInfoFromIndexer->getMinimalPrice());
|
||||
$this->assertEquals($expectedResults['maximalPrice'], $priceInfoFromIndexer->getMaxPrice());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $strategyModifiers
|
||||
* @param array $expectedResults
|
||||
* @dataProvider getTestCases
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoConfigFixture current_store catalog/price/scope 1
|
||||
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/fixed_bundle_product.php
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testPriceForFixedBundleInWebsiteScope(array $strategyModifiers, array $expectedResults)
|
||||
{
|
||||
$this->prepareFixture($strategyModifiers, 'bundle_product');
|
||||
$bundleProduct = $this->productRepository->get('bundle_product', false, null, true);
|
||||
|
||||
/** @var \Magento\Framework\Pricing\PriceInfo\Base $priceInfo */
|
||||
$priceInfo = $bundleProduct->getPriceInfo();
|
||||
$priceCode = \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE;
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedResults['minimalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMinimalPrice()->getValue(),
|
||||
'Failed to check minimal price on product'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expectedResults['maximalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMaximalPrice()->getValue(),
|
||||
'Failed to check maximal price on product'
|
||||
);
|
||||
|
||||
$priceInfoFromIndexer = $this->productCollectionFactory->create()
|
||||
->addFieldToFilter('sku', 'bundle_product')
|
||||
->addPriceData()
|
||||
->load()
|
||||
->getFirstItem();
|
||||
|
||||
$this->assertEquals($expectedResults['minimalPrice'], $priceInfoFromIndexer->getMinimalPrice());
|
||||
$this->assertEquals($expectedResults['maximalPrice'], $priceInfoFromIndexer->getMaxPrice());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for current test
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function getTestCases()
|
||||
{
|
||||
return [
|
||||
'#1 Testing price for fixed bundle product with one simple' => [
|
||||
'strategy' => $this->getProductWithOneSimple(),
|
||||
'expectedResults' => [
|
||||
// 110 + 10 (price from simple1)
|
||||
'minimalPrice' => 120,
|
||||
// 110 + 10 (sum of simple price)
|
||||
'maximalPrice' => 120,
|
||||
]
|
||||
],
|
||||
|
||||
'#2 Testing price for fixed bundle product with three simples and different qty' => [
|
||||
'strategy' => $this->getProductWithDifferentQty(),
|
||||
'expectedResults' => [
|
||||
// 110 + 10 (min price from simples)
|
||||
'minimalPrice' => 120,
|
||||
// 110 + (3 * 10) + (2 * 10) + 10
|
||||
'maximalPrice' => 170,
|
||||
]
|
||||
],
|
||||
|
||||
'#3 Testing price for fixed bundle product with three simples and different price' => [
|
||||
'strategy' => $this->getProductWithDifferentPrice(),
|
||||
'expectedResults' => [
|
||||
// 110 + 10
|
||||
'minimalPrice' => 120,
|
||||
// 110 + 60
|
||||
'maximalPrice' => 170,
|
||||
]
|
||||
],
|
||||
|
||||
'#4 Testing price for fixed bundle product with three simples' => [
|
||||
'strategy' => $this->getProductWithSamePrice(),
|
||||
'expectedResults' => [
|
||||
// 110 + 10
|
||||
'minimalPrice' => 120,
|
||||
// 110 + 30
|
||||
'maximalPrice' => 140,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#5 Testing price for fixed bundle product
|
||||
with fixed sub items, fixed options and without any discounts
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration3(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 110 + 1 * 20 + 100
|
||||
'minimalPrice' => 230,
|
||||
|
||||
// 110 + 1 * 20 + 100
|
||||
'maximalPrice' => 230,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#6 Testing price for fixed bundle product
|
||||
with percent sub items, percent options and without any discounts
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration3(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 110 + 110 * 0.2 + 110 * 1
|
||||
'minimalPrice' => 242,
|
||||
|
||||
// 110 + 110 * 0.2 + 110 * 1
|
||||
'maximalPrice' => 242,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#7 Testing price for fixed bundle product
|
||||
with fixed sub items, percent options and without any discounts
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration3(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 110 + 1 * 20 + 110 * 1
|
||||
'minimalPrice' => 240,
|
||||
|
||||
// 110 + 1 * 20 + 110 * 1
|
||||
'maximalPrice' => 240,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#8 Testing price for fixed bundle product
|
||||
with percent sub items, fixed options and without any discounts
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration3(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 110 + 110 * 0.2 + 100
|
||||
'minimalPrice' => 232,
|
||||
|
||||
// 110 + 110 * 0.2 + 100
|
||||
'maximalPrice' => 232,
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with one simple
|
||||
* @return array
|
||||
*/
|
||||
private function getProductWithOneSimple()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'price' => 10,
|
||||
'qty' => 1,
|
||||
'price_type' => LinkInterface::PRICE_TYPE_FIXED,
|
||||
],
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with three simples and different qty
|
||||
* @return array
|
||||
*/
|
||||
private function getProductWithDifferentQty()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'price' => 10,
|
||||
'qty' => 3,
|
||||
'price_type' => LinkInterface::PRICE_TYPE_FIXED,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 10,
|
||||
'qty' => 2,
|
||||
'price_type' => LinkInterface::PRICE_TYPE_FIXED,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple3',
|
||||
'price' => 10,
|
||||
'qty' => 1,
|
||||
'price_type' => LinkInterface::PRICE_TYPE_FIXED,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with three simples and different price
|
||||
* @return array
|
||||
*/
|
||||
private function getProductWithSamePrice()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'price' => 10,
|
||||
'qty' => 1,
|
||||
'price_type' => LinkInterface::PRICE_TYPE_FIXED,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 10,
|
||||
'qty' => 1,
|
||||
'price_type' => LinkInterface::PRICE_TYPE_FIXED,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple3',
|
||||
'price' => 10,
|
||||
'qty' => 1,
|
||||
'price_type' => LinkInterface::PRICE_TYPE_FIXED,
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with three simples
|
||||
* @return array
|
||||
*/
|
||||
private function getProductWithDifferentPrice()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'price' => 10,
|
||||
'qty' => 1,
|
||||
'price_type' => LinkInterface::PRICE_TYPE_FIXED,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 20,
|
||||
'qty' => 1,
|
||||
'price_type' => LinkInterface::PRICE_TYPE_FIXED,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple3',
|
||||
'price' => 30,
|
||||
'qty' => 1,
|
||||
'price_type' => LinkInterface::PRICE_TYPE_FIXED,
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with required option, custom option and without any discounts
|
||||
* @param $selectionsPriceType
|
||||
* @param $customOptionsPriceType
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration3($selectionsPriceType, $customOptionsPriceType)
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 20,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
$customOptionsData = [
|
||||
[
|
||||
'price_type' => $customOptionsPriceType,
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'price' => 100,
|
||||
'sku' => '1-text',
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addCustomOption',
|
||||
'data' => [$customOptionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+416
@@ -0,0 +1,416 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Model\Product;
|
||||
|
||||
use \Magento\Bundle\Api\Data\LinkInterface;
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation disabled
|
||||
* @magentoIndexerDimensionMode catalog_product_price website_and_customer_group
|
||||
* @group indexer_dimension
|
||||
*/
|
||||
class FixedBundlePriceCalculatorWithDimensionTest extends BundlePriceAbstract
|
||||
{
|
||||
/**
|
||||
* @param array $strategyModifiers
|
||||
* @param array $expectedResults
|
||||
* @dataProvider getTestCases
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/fixed_bundle_product.php
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testPriceForFixedBundle(array $strategyModifiers, array $expectedResults)
|
||||
{
|
||||
$this->prepareFixture($strategyModifiers, 'bundle_product');
|
||||
$bundleProduct = $this->productRepository->get('bundle_product', false, null, true);
|
||||
|
||||
/** @var \Magento\Framework\Pricing\PriceInfo\Base $priceInfo */
|
||||
$priceInfo = $bundleProduct->getPriceInfo();
|
||||
$priceCode = \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE;
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedResults['minimalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMinimalPrice()->getValue(),
|
||||
'Failed to check minimal price on product'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expectedResults['maximalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMaximalPrice()->getValue(),
|
||||
'Failed to check maximal price on product'
|
||||
);
|
||||
|
||||
$priceInfoFromIndexer = $this->productCollectionFactory->create()
|
||||
->addIdFilter([42])
|
||||
->addPriceData()
|
||||
->load()
|
||||
->getFirstItem();
|
||||
|
||||
$this->assertEquals($expectedResults['minimalPrice'], $priceInfoFromIndexer->getMinimalPrice());
|
||||
$this->assertEquals($expectedResults['maximalPrice'], $priceInfoFromIndexer->getMaxPrice());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $strategyModifiers
|
||||
* @param array $expectedResults
|
||||
* @dataProvider getTestCases
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoConfigFixture current_store catalog/price/scope 1
|
||||
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/fixed_bundle_product.php
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testPriceForFixedBundleInWebsiteScope(array $strategyModifiers, array $expectedResults)
|
||||
{
|
||||
$this->prepareFixture($strategyModifiers, 'bundle_product');
|
||||
$bundleProduct = $this->productRepository->get('bundle_product', false, null, true);
|
||||
|
||||
/** @var \Magento\Framework\Pricing\PriceInfo\Base $priceInfo */
|
||||
$priceInfo = $bundleProduct->getPriceInfo();
|
||||
$priceCode = \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE;
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedResults['minimalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMinimalPrice()->getValue(),
|
||||
'Failed to check minimal price on product'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expectedResults['maximalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMaximalPrice()->getValue(),
|
||||
'Failed to check maximal price on product'
|
||||
);
|
||||
|
||||
$priceInfoFromIndexer = $this->productCollectionFactory->create()
|
||||
->addFieldToFilter('sku', 'bundle_product')
|
||||
->addPriceData()
|
||||
->load()
|
||||
->getFirstItem();
|
||||
|
||||
$this->assertEquals($expectedResults['minimalPrice'], $priceInfoFromIndexer->getMinimalPrice());
|
||||
$this->assertEquals($expectedResults['maximalPrice'], $priceInfoFromIndexer->getMaxPrice());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for current test
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function getTestCases()
|
||||
{
|
||||
return [
|
||||
'#1 Testing price for fixed bundle product with one simple' => [
|
||||
'strategy' => $this->getProductWithOneSimple(),
|
||||
'expectedResults' => [
|
||||
// 110 + 10 (price from simple1)
|
||||
'minimalPrice' => 120,
|
||||
// 110 + 10 (sum of simple price)
|
||||
'maximalPrice' => 120,
|
||||
]
|
||||
],
|
||||
|
||||
'#2 Testing price for fixed bundle product with three simples and different qty' => [
|
||||
'strategy' => $this->getProductWithDifferentQty(),
|
||||
'expectedResults' => [
|
||||
// 110 + 10 (min price from simples)
|
||||
'minimalPrice' => 120,
|
||||
// 110 + (3 * 10) + (2 * 10) + 10
|
||||
'maximalPrice' => 170,
|
||||
]
|
||||
],
|
||||
|
||||
'#3 Testing price for fixed bundle product with three simples and different price' => [
|
||||
'strategy' => $this->getProductWithDifferentPrice(),
|
||||
'expectedResults' => [
|
||||
// 110 + 10
|
||||
'minimalPrice' => 120,
|
||||
// 110 + 60
|
||||
'maximalPrice' => 170,
|
||||
]
|
||||
],
|
||||
|
||||
'#4 Testing price for fixed bundle product with three simples' => [
|
||||
'strategy' => $this->getProductWithSamePrice(),
|
||||
'expectedResults' => [
|
||||
// 110 + 10
|
||||
'minimalPrice' => 120,
|
||||
// 110 + 30
|
||||
'maximalPrice' => 140,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#5 Testing price for fixed bundle product
|
||||
with fixed sub items, fixed options and without any discounts
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration3(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 110 + 1 * 20 + 100
|
||||
'minimalPrice' => 230,
|
||||
|
||||
// 110 + 1 * 20 + 100
|
||||
'maximalPrice' => 230,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#6 Testing price for fixed bundle product
|
||||
with percent sub items, percent options and without any discounts
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration3(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 110 + 110 * 0.2 + 110 * 1
|
||||
'minimalPrice' => 242,
|
||||
|
||||
// 110 + 110 * 0.2 + 110 * 1
|
||||
'maximalPrice' => 242,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#7 Testing price for fixed bundle product
|
||||
with fixed sub items, percent options and without any discounts
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration3(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 110 + 1 * 20 + 110 * 1
|
||||
'minimalPrice' => 240,
|
||||
|
||||
// 110 + 1 * 20 + 110 * 1
|
||||
'maximalPrice' => 240,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#8 Testing price for fixed bundle product
|
||||
with percent sub items, fixed options and without any discounts
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration3(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 110 + 110 * 0.2 + 100
|
||||
'minimalPrice' => 232,
|
||||
|
||||
// 110 + 110 * 0.2 + 100
|
||||
'maximalPrice' => 232,
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with one simple
|
||||
* @return array
|
||||
*/
|
||||
private function getProductWithOneSimple()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'price' => 10,
|
||||
'qty' => 1,
|
||||
'price_type' => LinkInterface::PRICE_TYPE_FIXED,
|
||||
],
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with three simples and different qty
|
||||
* @return array
|
||||
*/
|
||||
private function getProductWithDifferentQty()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'price' => 10,
|
||||
'qty' => 3,
|
||||
'price_type' => LinkInterface::PRICE_TYPE_FIXED,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 10,
|
||||
'qty' => 2,
|
||||
'price_type' => LinkInterface::PRICE_TYPE_FIXED,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple3',
|
||||
'price' => 10,
|
||||
'qty' => 1,
|
||||
'price_type' => LinkInterface::PRICE_TYPE_FIXED,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with three simples and different price
|
||||
* @return array
|
||||
*/
|
||||
private function getProductWithSamePrice()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'price' => 10,
|
||||
'qty' => 1,
|
||||
'price_type' => LinkInterface::PRICE_TYPE_FIXED,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 10,
|
||||
'qty' => 1,
|
||||
'price_type' => LinkInterface::PRICE_TYPE_FIXED,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple3',
|
||||
'price' => 10,
|
||||
'qty' => 1,
|
||||
'price_type' => LinkInterface::PRICE_TYPE_FIXED,
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with three simples
|
||||
* @return array
|
||||
*/
|
||||
private function getProductWithDifferentPrice()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'price' => 10,
|
||||
'qty' => 1,
|
||||
'price_type' => LinkInterface::PRICE_TYPE_FIXED,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 20,
|
||||
'qty' => 1,
|
||||
'price_type' => LinkInterface::PRICE_TYPE_FIXED,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple3',
|
||||
'price' => 30,
|
||||
'qty' => 1,
|
||||
'price_type' => LinkInterface::PRICE_TYPE_FIXED,
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with required option, custom option and without any discounts
|
||||
* @param string $selectionsPriceType
|
||||
* @param string $customOptionsPriceType
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration3($selectionsPriceType, $customOptionsPriceType)
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 20,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
$customOptionsData = [
|
||||
[
|
||||
'price_type' => $customOptionsPriceType,
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'price' => 100,
|
||||
'sku' => '1-text',
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addCustomOption',
|
||||
'data' => [$customOptionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+812
@@ -0,0 +1,812 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Model\Product;
|
||||
|
||||
use \Magento\Bundle\Api\Data\LinkInterface;
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class FixedBundleWithCatalogPriceRuleCalculatorTest extends BundlePriceAbstract
|
||||
{
|
||||
/**
|
||||
* @param array $strategyModifiers
|
||||
* @param array $expectedResults
|
||||
* @dataProvider getTestCases
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/fixed_bundle_product_with_catalog_rule.php
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testPriceForFixedBundle(array $strategyModifiers, array $expectedResults)
|
||||
{
|
||||
$this->prepareFixture($strategyModifiers, 'bundle_product');
|
||||
$bundleProduct = $this->productRepository->get('bundle_product', false, null, true);
|
||||
|
||||
/** @var \Magento\Framework\Pricing\PriceInfo\Base $priceInfo */
|
||||
$priceInfo = $bundleProduct->getPriceInfo();
|
||||
$priceCode = \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE;
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedResults['minimalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMinimalPrice()->getValue(),
|
||||
'Failed to check minimal price on product'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedResults['maximalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMaximalPrice()->getValue(),
|
||||
'Failed to check maximal price on product'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for current test
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function getTestCases()
|
||||
{
|
||||
return [
|
||||
'
|
||||
#1 Testing price for fixed bundle product
|
||||
with catalog price rule and without sub items and options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration1(),
|
||||
'expectedResults' => [
|
||||
// 110 * 0.9
|
||||
'minimalPrice' => 99,
|
||||
|
||||
// 110 * 0.9
|
||||
'maximalPrice' => 99
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#2 Testing price for fixed bundle product
|
||||
with catalog price rule, fixed sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration2(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 1 * 20 + 100
|
||||
'minimalPrice' => 219,
|
||||
|
||||
// 0.9 * 110 + 1 * 20 + 100
|
||||
'maximalPrice' => 219
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#3 Testing price for fixed bundle product
|
||||
with catalog price rule, percent sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration2(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 0.9 * 110 * 0.2 + 0.9 * 110 * 1
|
||||
'minimalPrice' => 217.8,
|
||||
|
||||
// 0.9 * 110 + 0.9 * 110 * 0.2 + 0.9 * 110 * 1
|
||||
'maximalPrice' => 217.8
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#4 Testing price for fixed bundle product
|
||||
with catalog price rule, fixed sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration2(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 1 * 20 + 0.9 * 110 * 1
|
||||
'minimalPrice' => 218,
|
||||
|
||||
// 0.9 * 110 + 1 * 20 + 0.9 * 110 * 1
|
||||
'maximalPrice' => 218
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#5 Testing price for fixed bundle product
|
||||
with catalog price rule, percent sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration2(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 0.9 * 110 * 0.2 + 100
|
||||
'minimalPrice' => 218.8,
|
||||
|
||||
// 0.9 * 110 + 0.9 * 110 * 0.2 + 100
|
||||
'maximalPrice' => 218.8
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#6 Testing price for fixed bundle product
|
||||
with catalog price rule, fixed sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration3(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 100
|
||||
'minimalPrice' => 199,
|
||||
|
||||
// 0.9 * 110 + 2 * 20 + 100
|
||||
'maximalPrice' => 239
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#7 Testing price for fixed bundle product
|
||||
with catalog price rule, percent sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration3(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 0.9 * 110 * 1
|
||||
'minimalPrice' => 198,
|
||||
|
||||
// 0.9 * 110 + 2 * 0.9 * 110 * 0.2 + 1 * 0.9 * 110
|
||||
'maximalPrice' => 237.6
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#8 Testing price for fixed bundle product
|
||||
with catalog price rule, fixed sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration3(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 1 * 0.9 * 110
|
||||
'minimalPrice' => 198,
|
||||
|
||||
// 0.9 * 110 + 2 * 20 + 1 * 0.9 * 110
|
||||
'maximalPrice' => 238
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#9 Testing price for fixed bundle product
|
||||
with catalog price rule, percent sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration3(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 100
|
||||
'minimalPrice' => 199,
|
||||
|
||||
// 0.9 * 110 + 2 * 0.2 * 0.9 * 110 + 100
|
||||
'maximalPrice' => 238.6
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#10 Testing price for fixed bundle product
|
||||
with catalog price rule, fixed sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration4(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 3 * 10 + 100
|
||||
'minimalPrice' => 229,
|
||||
|
||||
// 0.9 * 110 + 3 * 10 + 1 * 40 + 100
|
||||
'maximalPrice' => 269
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#11 Testing price for fixed bundle product
|
||||
with catalog price rule, percent sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration4(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 3 * 0.9 * 110 * 0.1 + 0.9 * 110 * 1
|
||||
'minimalPrice' => 227.7,
|
||||
|
||||
// 0.9 * 110 + 3 * 0.9 * 110 * 0.1 + 1 * 0.9 * 110 * 0.4 + 0.9 * 110 * 1
|
||||
'maximalPrice' => 267.3
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#12 Testing price for fixed bundle product
|
||||
with catalog price rule, fixed sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration4(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 3 * 10 + 1 * 0.9 * 110
|
||||
'minimalPrice' => 228,
|
||||
|
||||
// 0.9 * 110 + 3 * 10 + 1 * 40 + 1 * 0.9 * 110
|
||||
'maximalPrice' => 268
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#13 Testing price for fixed bundle product
|
||||
with catalog price rule, percent sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration4(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 3 * 0.9 * 110 * 0.1 + 100
|
||||
'minimalPrice' => 228.7,
|
||||
|
||||
// 0.9 * 110 + 3 * 0.9 * 110 * 0.1 + 1 * 0.9 * 110 * 0.4 + 100
|
||||
'maximalPrice' => 268.3
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#14 Testing price for fixed bundle product
|
||||
with catalog price rule, fixed sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration5(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 1 * 40 + 100
|
||||
'minimalPrice' => 239,
|
||||
|
||||
// 0.9 * 110 + 1 * 40 + 3 * 15 + 100
|
||||
'maximalPrice' => 284
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#15 Testing price for fixed bundle product
|
||||
with catalog price rule, percent sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration5(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 1 * 0.9 * 110 * 0.4 + 1 * 0.9 * 110
|
||||
'minimalPrice' => 237.6,
|
||||
|
||||
// 0.9 * 110 + 1 * 0.9 * 110 * 0.4 + 3 * 0.9 * 110 * 0.15 + 0.9 * 110 * 1
|
||||
'maximalPrice' => 282.15
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#16 Testing price for fixed bundle product
|
||||
with catalog price rule, fixed sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration5(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 1 * 40 + 1 * 0.9 * 110
|
||||
'minimalPrice' => 238,
|
||||
|
||||
// 0.9 * 110 + 1 * 40 + 3 * 15 + 1 * 0.9 * 110
|
||||
'maximalPrice' => 283
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#17 Testing price for fixed bundle product
|
||||
with catalog price rule, percent sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration5(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 1 * 0.9 * 110 * 0.4 + 100
|
||||
'minimalPrice' => 238.6,
|
||||
|
||||
// 0.9 * 110 + 1 * 0.9 * 110 * 0.4 + 3 * 0.9 * 110 * 0.15 + 100
|
||||
'maximalPrice' => 283.15
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#18 Testing price for fixed bundle product
|
||||
with catalog price rule, fixed sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration6(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 1 * 40 + 100
|
||||
'minimalPrice' => 239,
|
||||
|
||||
// 0.9 * 110 + 3 * 15 + 100
|
||||
'maximalPrice' => 244
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#19 Testing price for fixed bundle product
|
||||
with catalog price rule, percent sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration6(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 1 * 0.9 * 110 * 0.4 + 1 * 0.9 * 110
|
||||
'minimalPrice' => 237.6,
|
||||
|
||||
// 0.9 * 110 + 3 * 0.9 * 110 * 0.15 + 1 * 0.9 * 110
|
||||
'maximalPrice' => 242.55
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#20 Testing price for fixed bundle product
|
||||
with catalog price rule, fixed sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration6(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 1 * 40 + 0.9 * 110 * 1
|
||||
'minimalPrice' => 238,
|
||||
|
||||
// 0.9 * 110 + 3 * 15 + 0.9 * 110 * 1
|
||||
'maximalPrice' => 243
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#21 Testing price for fixed bundle product
|
||||
with catalog price rule, percent sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration6(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 1 * 0.9 * 110 * 0.4 + 100
|
||||
'minimalPrice' => 238.6,
|
||||
|
||||
// 0.9 * 110 + 3 * 0.9 * 110 * 0.15 + 100
|
||||
'maximalPrice' => 243.55
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#22 Testing price for fixed bundle product
|
||||
with catalog price rule, fixed sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration7(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 1 * 40 + 1 * 20 + 100
|
||||
'minimalPrice' => 259,
|
||||
|
||||
// 0.9 * 110 + 3 * 15 + 1 * 20 + 3 * 10 + 100
|
||||
'maximalPrice' => 294
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#23 Testing price for fixed bundle product
|
||||
with catalog price rule, percent sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration7(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 1 * 0.9 * 110 * 0.4 + 1 * 0.9 * 110 * 0.2 + 0.9 * 110 * 1
|
||||
'minimalPrice' => 257.4,
|
||||
|
||||
// 0.9 * 110 + 3 * 0.9 * 110 * 0.15 + 1 * 0.9 * 110 * 0.2 + 3 * 0.9 * 110 * 0.1 + 0.9 * 110 * 1
|
||||
'maximalPrice' => 292.05
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#24 Testing price for fixed bundle product
|
||||
with catalog price rule, fixed sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration7(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 1 * 40 + 1 * 20 + 1 * 0.9 * 110
|
||||
'minimalPrice' => 258,
|
||||
|
||||
// 0.9 * 110 + 3 * 15 + 1 * 20 + 3 * 10 + 1 * 0.9 * 110
|
||||
'maximalPrice' => 293
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#25 Testing price for fixed bundle product
|
||||
with catalog price rule, percent sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration7(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.9 * 110 + 1 * 0.9 * 110 * 0.4 + 1 * 0.9 * 110 * 0.2 + 100
|
||||
'minimalPrice' => 258.4,
|
||||
|
||||
// 0.9 * 110 + 3 * 0.9 * 110 * 0.15 + 1 * 0.9 * 110 * 0.2 + 3 * 0.9 * 110 * 0.1 + 100
|
||||
'maximalPrice' => 293.05
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with catalog price rule and without sub items and options
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration1()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with catalog price rule, one required option and one custom option
|
||||
* @param string $selectionsPriceType
|
||||
* @param string $customOptionsPriceType
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration2($selectionsPriceType, $customOptionsPriceType)
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 20,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$customOptionsData = [
|
||||
[
|
||||
'price_type' => $customOptionsPriceType,
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'price' => 100,
|
||||
'sku' => '1-text',
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addCustomOption',
|
||||
'data' => [$customOptionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with catalog price rule, one non required option and one custom option
|
||||
* @param string $selectionsPriceType
|
||||
* @param string $customOptionsPriceType
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration3($selectionsPriceType, $customOptionsPriceType)
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'type' => 'checkbox',
|
||||
'required' => false,
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'price' => 20,
|
||||
'qty' => 2,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$customOptionsData = [
|
||||
[
|
||||
'price_type' => $customOptionsPriceType,
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'price' => 100,
|
||||
'sku' => '1-text',
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addCustomOption',
|
||||
'data' => [$customOptionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with catalog price rule, one checkbox type option with 2 simples and one custom option
|
||||
* @param string $selectionsPriceType
|
||||
* @param string $customOptionsPriceType
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration4($selectionsPriceType, $customOptionsPriceType)
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 40,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 10,
|
||||
'qty' => 3,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$customOptionsData = [
|
||||
[
|
||||
'price_type' => $customOptionsPriceType,
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'price' => 100,
|
||||
'sku' => '1-text',
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addCustomOption',
|
||||
'data' => [$customOptionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with catalog price rule, one multi type option with 2 simples and one custom option
|
||||
* @param string $selectionsPriceType
|
||||
* @param string $customOptionsPriceType
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration5($selectionsPriceType, $customOptionsPriceType)
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'multi',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 40,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 15,
|
||||
'qty' => 3,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$customOptionsData = [
|
||||
[
|
||||
'price_type' => $customOptionsPriceType,
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'price' => 100,
|
||||
'sku' => '1-text',
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addCustomOption',
|
||||
'data' => [$customOptionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with catalog price rule, one radio type option with 2 simples and one custom option
|
||||
* @param string $selectionsPriceType
|
||||
* @param string $customOptionsPriceType
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration6($selectionsPriceType, $customOptionsPriceType)
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'radio',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 40,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 15,
|
||||
'qty' => 3,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$customOptionsData = [
|
||||
[
|
||||
'price_type' => $customOptionsPriceType,
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'price' => 100,
|
||||
'sku' => '1-text',
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addCustomOption',
|
||||
'data' => [$customOptionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with catalog price rule, two required options and one custom option
|
||||
* @param string $selectionsPriceType
|
||||
* @param string $customOptionsPriceType
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration7($selectionsPriceType, $customOptionsPriceType)
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'radio',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 40,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 15,
|
||||
'qty' => 3,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
'title' => 'Op2',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 20,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 10,
|
||||
'qty' => 3,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$customOptionsData = [
|
||||
[
|
||||
'price_type' => $customOptionsPriceType,
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'price' => 100,
|
||||
'sku' => '1-text',
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addCustomOption',
|
||||
'data' => [$customOptionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+834
@@ -0,0 +1,834 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Bundle\Model\Product;
|
||||
|
||||
use \Magento\Bundle\Api\Data\LinkInterface;
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class FixedBundleWithSpecialPriceCalculatorTest extends BundlePriceAbstract
|
||||
{
|
||||
/**
|
||||
* @param array $strategyModifiers
|
||||
* @param array $expectedResults
|
||||
* @dataProvider getTestCases
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/fixed_bundle_product_with_special_price.php
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testPriceForFixedBundle(array $strategyModifiers, array $expectedResults)
|
||||
{
|
||||
if (empty($strategyModifiers)) {
|
||||
$this->markTestSkipped('Unskip after fixing https://github.com/magento-engcom/msi/issues/1398');
|
||||
}
|
||||
$this->prepareFixture($strategyModifiers, 'bundle_product');
|
||||
$bundleProduct = $this->productRepository->get('bundle_product', false, null, true);
|
||||
|
||||
/** @var \Magento\Framework\Pricing\PriceInfo\Base $priceInfo */
|
||||
$priceInfo = $bundleProduct->getPriceInfo();
|
||||
$priceCode = \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE;
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedResults['minimalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMinimalPrice()->getValue(),
|
||||
'Failed to check minimal price on product'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expectedResults['maximalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMaximalPrice()->getValue(),
|
||||
'Failed to check maximal price on product'
|
||||
);
|
||||
|
||||
$priceInfoFromIndexer = $this->productCollectionFactory->create()
|
||||
->addFieldToFilter('sku', 'bundle_product')
|
||||
->addPriceData()
|
||||
->load()
|
||||
->getFirstItem();
|
||||
|
||||
$this->assertEquals($expectedResults['minimalPrice'], $priceInfoFromIndexer->getMinimalPrice());
|
||||
$this->assertEquals($expectedResults['maximalPrice'], $priceInfoFromIndexer->getMaxPrice());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for current test
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function getTestCases()
|
||||
{
|
||||
return [
|
||||
'
|
||||
#1 Testing price for fixed bundle product
|
||||
with special price and without any sub items and options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration1(),
|
||||
'expectedResults' => [
|
||||
// 110 * 0.5
|
||||
'minimalPrice' => 55,
|
||||
|
||||
// 110 * 0.5
|
||||
'maximalPrice' => 55,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#2 Testing price for fixed bundle product
|
||||
with special price, fixed sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration2(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 20) + 100
|
||||
'minimalPrice' => 165,
|
||||
|
||||
// 0.5 * (110 + 1 * 20) + 100
|
||||
'maximalPrice' => 165,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#3 Testing price for fixed bundle product
|
||||
with special price, percent sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration2(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 110 * 0.2 + 110 * 1)
|
||||
'minimalPrice' => 121,
|
||||
|
||||
// 0.5 * (110 + 110 * 0.2 + 110 * 1)
|
||||
'maximalPrice' => 121,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#4 Testing price for fixed bundle product
|
||||
with special price, fixed sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration2(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 20 + 110 * 1)
|
||||
'minimalPrice' => 120,
|
||||
|
||||
// 0.5 * (110 + 1 * 20 + 110 * 1)
|
||||
'maximalPrice' => 120,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#5 Testing price for fixed bundle product
|
||||
with special price, percent sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration2(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 110 * 0.2) + 100
|
||||
'minimalPrice' => 166,
|
||||
|
||||
// 0.5 * (110 + 110 * 0.2) + 100
|
||||
'maximalPrice' => 166,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#6 Testing price for fixed bundle product
|
||||
with special price, fixed sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration3(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * 110 + 100
|
||||
'minimalPrice' => 155,
|
||||
|
||||
// 0.5 * (110 + 2 * 20) + 100
|
||||
'maximalPrice' => 175,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#7 Testing price for fixed bundle product
|
||||
with special price, percent sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration3(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 110 * 1)
|
||||
'minimalPrice' => 110,
|
||||
|
||||
// 0.5 * (110 + 2 * 110 * 0.2 + 1 * 110)
|
||||
'maximalPrice' => 132,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#8 Testing price for fixed bundle product
|
||||
with special price, fixed sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration3(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 110)
|
||||
'minimalPrice' => 110,
|
||||
|
||||
// 0.5 * (110 + 2 * 20 + 1 * 110)
|
||||
'maximalPrice' => 130,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#9 Testing price for fixed bundle product
|
||||
with special price, percent sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration3(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * 110 + 100
|
||||
'minimalPrice' => 155,
|
||||
|
||||
// 0.5 * (110 + 2 * 0.2 * 110) + 100
|
||||
'maximalPrice' => 177,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#10 Testing price for fixed bundle product
|
||||
with special price, fixed sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration4(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 3 * 10) + 100
|
||||
'minimalPrice' => 170,
|
||||
|
||||
// 0.5 * (110 + 3 * 10 + 1 * 40) + 100
|
||||
'maximalPrice' => 190,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#11 Testing price for fixed bundle product
|
||||
with special price, percent sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration4(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 3 * 110 * 0.1 + 110 * 1)
|
||||
'minimalPrice' => 126.5,
|
||||
|
||||
// 0.5 * (110 + 3 * 110 * 0.1 + 1 * 110 * 0.4 + 110 * 1)
|
||||
'maximalPrice' => 148.5,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#12 Testing price for fixed bundle product
|
||||
with special price, fixed sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration4(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 3 * 10 + 1 * 110)
|
||||
'minimalPrice' => 125,
|
||||
|
||||
// 0.5 * (110 + 3 * 10 + 1 * 40 + 1 * 110)
|
||||
'maximalPrice' => 145,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#13 Testing price for fixed bundle product
|
||||
with special price, percent sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration4(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 3 * 110 * 0.1) + 100
|
||||
'minimalPrice' => 171.5,
|
||||
|
||||
// 0.5 * (110 + 3 * 110 * 0.1 + 1 * 110 * 0.4) + 100
|
||||
'maximalPrice' => 193.5,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#14 Testing price for fixed bundle product
|
||||
with special price, fixed sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration5(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 40) + 100
|
||||
'minimalPrice' => 175,
|
||||
|
||||
// 0.5 * (110 + 1 * 40 + 3 * 15) + 100
|
||||
'maximalPrice' => 197.5,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#15 Testing price for fixed bundle product
|
||||
with special price, percent sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration5(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 110 * 0.4 + 1 * 110)
|
||||
'minimalPrice' => 132,
|
||||
|
||||
// 0.5 * (110 + 1 * 110 * 0.4 + 3 * 110 * 0.15 + 110 * 1)
|
||||
'maximalPrice' => 156.75,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#16 Testing price for fixed bundle product
|
||||
with special price, fixed sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration5(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 40 + 1 * 110)
|
||||
'minimalPrice' => 130,
|
||||
|
||||
// 0.5 * (110 + 1 * 40 + 3 * 15 + 1 * 110)
|
||||
'maximalPrice' => 152.5,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#17 Testing price for fixed bundle product
|
||||
with special price, percent sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration5(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 110 * 0.4) + 100
|
||||
'minimalPrice' => 177,
|
||||
|
||||
// 0.5 * (110 + 1 * 110 * 0.4 + 3 * 110 * 0.15) + 100
|
||||
'maximalPrice' => 201.75,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#18 Testing price for fixed bundle product
|
||||
with special price, fixed sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration6(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 40) + 100
|
||||
'minimalPrice' => 175,
|
||||
|
||||
// 0.5 * (110 + 3 * 15) + 100
|
||||
'maximalPrice' => 177.5,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#19 Testing price for fixed bundle product
|
||||
with special price, percent sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration6(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 110 * 0.4 + 1 * 110)
|
||||
'minimalPrice' => 132,
|
||||
|
||||
// 0.5 * (110 + 3 * 110 * 0.15 + 1 * 110)
|
||||
'maximalPrice' => 134.75,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#20 Testing price for fixed bundle product
|
||||
with special price, fixed sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration6(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 40 + 110 * 1)
|
||||
'minimalPrice' => 130,
|
||||
|
||||
// 0.5 * (110 + 3 * 15 + 110 * 1)
|
||||
'maximalPrice' => 132.5,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#21 Testing price for fixed bundle product
|
||||
with special price, percent sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration6(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 110 * 0.4) + 100
|
||||
'minimalPrice' => 177,
|
||||
|
||||
// 0.5 * (110 + 3 * 110 * 0.15) + 100
|
||||
'maximalPrice' => 179.75,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#22 Testing price for fixed bundle product
|
||||
with special price, fixed sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration7(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 40 + 1 * 20) + 100
|
||||
'minimalPrice' => 185,
|
||||
|
||||
// 0.5 * (110 + 3 * 15 + 1 * 20 + 3 * 10) + 100
|
||||
'maximalPrice' => 202.5,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#23 Testing price for fixed bundle product
|
||||
with special price, percent sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration7(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 110 * 0.4 + 1 * 110 * 0.2 + 110 * 1)
|
||||
'minimalPrice' => 143,
|
||||
|
||||
// 0.5 * (110 + 3 * 110 * 0.15 + 1 * 110 * 0.2 + 3 * 110 * 0.1 + 110 * 1)
|
||||
'maximalPrice' => 162.25,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#24 Testing price for fixed bundle product
|
||||
with special price, fixed sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration7(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 40 + 1 * 20 + 1 * 110)
|
||||
'minimalPrice' => 140,
|
||||
|
||||
// 0.5 * (110 + 3 * 15 + 1 * 20 + 3 * 10 + 1 * 110)
|
||||
'maximalPrice' => 157.5,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#25 Testing price for fixed bundle product
|
||||
with special price, percent sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration7(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 110 * 0.4 + 1 * 110 * 0.2) + 100
|
||||
'minimalPrice' => 188,
|
||||
|
||||
// 0.5 * (110 + 3 * 110 * 0.15 + 1 * 110 * 0.2 + 3 * 110 * 0.1) + 100
|
||||
'maximalPrice' => 207.25,
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with special price and without any sub items and options
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration1()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with required option, custom option and with special price
|
||||
* @param $selectionsPriceType
|
||||
* @param $customOptionsPriceType
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration2(
|
||||
$selectionsPriceType,
|
||||
$customOptionsPriceType
|
||||
) {
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 20,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$customOptionsData = [
|
||||
[
|
||||
'price_type' => $customOptionsPriceType,
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'price' => 100,
|
||||
'sku' => '1-text',
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addCustomOption',
|
||||
'data' => [$customOptionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with non required option, custom option and with special price
|
||||
* @param $selectionsPriceType
|
||||
* @param $customOptionsPriceType
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration3(
|
||||
$selectionsPriceType,
|
||||
$customOptionsPriceType
|
||||
) {
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'type' => 'checkbox',
|
||||
'required' => false,
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'price' => 20,
|
||||
'qty' => 2,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$customOptionsData = [
|
||||
[
|
||||
'price_type' => $customOptionsPriceType,
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'price' => 100,
|
||||
'sku' => '1-text',
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addCustomOption',
|
||||
'data' => [$customOptionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with checkbox type option, custom option and with special price
|
||||
* @param $selectionsPriceType
|
||||
* @param $customOptionsPriceType
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration4(
|
||||
$selectionsPriceType,
|
||||
$customOptionsPriceType
|
||||
) {
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 40,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 10,
|
||||
'qty' => 3,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$customOptionsData = [
|
||||
[
|
||||
'price_type' => $customOptionsPriceType,
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'price' => 100,
|
||||
'sku' => '1-text',
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addCustomOption',
|
||||
'data' => [$customOptionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with multi type option, custom option and with special price
|
||||
* @param $selectionsPriceType
|
||||
* @param $customOptionsPriceType
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration5(
|
||||
$selectionsPriceType,
|
||||
$customOptionsPriceType
|
||||
) {
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'multi',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 40,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 15,
|
||||
'qty' => 3,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$customOptionsData = [
|
||||
[
|
||||
'price_type' => $customOptionsPriceType,
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'price' => 100,
|
||||
'sku' => '1-text',
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addCustomOption',
|
||||
'data' => [$customOptionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with radio type option, custom option and with special price
|
||||
* @param $selectionsPriceType
|
||||
* @param $customOptionsPriceType
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration6(
|
||||
$selectionsPriceType,
|
||||
$customOptionsPriceType
|
||||
) {
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'radio',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 40,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 15,
|
||||
'qty' => 3,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$customOptionsData = [
|
||||
[
|
||||
'price_type' => $customOptionsPriceType,
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'price' => 100,
|
||||
'sku' => '1-text',
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addCustomOption',
|
||||
'data' => [$customOptionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with two required options, custom option and with special price
|
||||
* @param $selectionsPriceType
|
||||
* @param $customOptionsPriceType
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration7(
|
||||
$selectionsPriceType,
|
||||
$customOptionsPriceType
|
||||
) {
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'radio',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 40,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 15,
|
||||
'qty' => 3,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
'title' => 'Op2',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 20,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 10,
|
||||
'qty' => 3,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$customOptionsData = [
|
||||
[
|
||||
'price_type' => $customOptionsPriceType,
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'price' => 100,
|
||||
'sku' => '1-text',
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addCustomOption',
|
||||
'data' => [$customOptionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+929
@@ -0,0 +1,929 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Bundle\Model\Product;
|
||||
|
||||
use \Magento\Bundle\Api\Data\LinkInterface;
|
||||
use \Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory;
|
||||
|
||||
/**
|
||||
* Class FixedBundleWithTierPRiceCalculatorTest
|
||||
* @package Magento\Bundle\Model\Product
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class FixedBundleWithTierPriceCalculatorTest extends BundlePriceAbstract
|
||||
{
|
||||
/** @var ProductTierPriceInterfaceFactory */
|
||||
private $tierPriceFactory;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->tierPriceFactory = $this->objectManager->create(ProductTierPriceInterfaceFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $strategyModifiers
|
||||
* @param array $expectedResults
|
||||
* @dataProvider getTestCases
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/fixed_bundle_product.php
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testPriceForFixedBundle(array $strategyModifiers, array $expectedResults)
|
||||
{
|
||||
$this->prepareFixture($strategyModifiers, 'bundle_product');
|
||||
$bundleProduct = $this->productRepository->get('bundle_product', false, null, true);
|
||||
|
||||
if (empty($bundleProduct->getOptions())) {
|
||||
$this->markTestSkipped('Unskip after fixing https://github.com/magento-engcom/msi/issues/1398');
|
||||
}
|
||||
|
||||
/** @var \Magento\Framework\Pricing\PriceInfo\Base $priceInfo */
|
||||
$priceInfo = $bundleProduct->getPriceInfo();
|
||||
$priceCode = \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE;
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedResults['minimalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMinimalPrice()->getValue(),
|
||||
'Failed to check minimal price on product'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expectedResults['maximalPrice'],
|
||||
$priceInfo->getPrice($priceCode)->getMaximalPrice()->getValue(),
|
||||
'Failed to check maximal price on product'
|
||||
);
|
||||
|
||||
$priceInfoFromIndexer = $this->productCollectionFactory->create()
|
||||
->addFieldToFilter('sku', 'bundle_product')
|
||||
->addPriceData()
|
||||
->load()
|
||||
->getFirstItem();
|
||||
|
||||
$this->assertEquals($expectedResults['minimalPrice'], $priceInfoFromIndexer->getMinimalPrice());
|
||||
$this->assertEquals($expectedResults['maximalPrice'], $priceInfoFromIndexer->getMaxPrice());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases for current test
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function getTestCases()
|
||||
{
|
||||
return [
|
||||
'
|
||||
#1 Testing product price
|
||||
with tier price and without any sub items and options
|
||||
' => [
|
||||
'strategy' => $this->getBundleConfiguration1(),
|
||||
'expectedResults' => [
|
||||
// 110 * 0.5
|
||||
'minimalPrice' => 55,
|
||||
|
||||
// 110 * 0.5
|
||||
'maximalPrice' => 55,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#2 Testing product price
|
||||
with tier price, fixed sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration2(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 20) + 100
|
||||
'minimalPrice' => 165,
|
||||
|
||||
// 0.5 * (110 + 1 * 20) + 100
|
||||
'maximalPrice' => 165,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#3 Testing product price
|
||||
with tier price, percent sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration2(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 110 * 0.2 + 110 * 1)
|
||||
'minimalPrice' => 121,
|
||||
|
||||
// 0.5 * (110 + 110 * 0.2 + 110 * 1)
|
||||
'maximalPrice' => 121,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#4 Testing product price
|
||||
with tier price, fixed sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration2(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 20 + 110 * 1)
|
||||
'minimalPrice' => 120,
|
||||
|
||||
// 0.5 * (110 + 1 * 20 + 110 * 1)
|
||||
'maximalPrice' => 120,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#5 Testing product price
|
||||
with tier price, percent sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration2(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 110 * 0.2) + 100
|
||||
'minimalPrice' => 166,
|
||||
|
||||
// 0.5 * (110 + 110 * 0.2) + 100
|
||||
'maximalPrice' => 166,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#6 Testing product price
|
||||
with tier price, fixed sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration3(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * 110 + 100
|
||||
'minimalPrice' => 155,
|
||||
|
||||
// 0.5 * (110 + 2 * 20) + 100
|
||||
'maximalPrice' => 175,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#7 Testing product price
|
||||
with tier price, percent sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration3(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 110 * 1)
|
||||
'minimalPrice' => 110,
|
||||
|
||||
// 0.5 * (110 + 2 * 110 * 0.2 + 1 * 110)
|
||||
'maximalPrice' => 132,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#8 Testing product price
|
||||
with tier price, fixed sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration3(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 110)
|
||||
'minimalPrice' => 110,
|
||||
|
||||
// 0.5 * (110 + 2 * 20 + 1 * 110)
|
||||
'maximalPrice' => 130,
|
||||
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#9 Testing product price
|
||||
with tier price, percent sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration3(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * 110 + 100
|
||||
'minimalPrice' => 155,
|
||||
|
||||
// 0.5 * (110 + 2 * 0.2 * 110) + 100
|
||||
'maximalPrice' => 177,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#10 Testing product price
|
||||
with tier price, fixed sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration4(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 3 * 10) + 100
|
||||
'minimalPrice' => 170,
|
||||
|
||||
// 0.5 * (110 + 3 * 10 + 1 * 40) + 100
|
||||
'maximalPrice' => 190,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#11 Testing product price
|
||||
with tier price, percent sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration4(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 3 * 110 * 0.1 + 110 * 1)
|
||||
'minimalPrice' => 126.5,
|
||||
|
||||
// 0.5 * (110 + 3 * 110 * 0.1 + 1 * 110 * 0.4 + 110 * 1)
|
||||
'maximalPrice' => 148.5,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#12 Testing product price
|
||||
with tier price, fixed sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration4(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 3 * 10 + 1 * 110)
|
||||
'minimalPrice' => 125,
|
||||
|
||||
// 0.5 * (110 + 3 * 10 + 1 * 40 + 1 * 110)
|
||||
'maximalPrice' => 145,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#13 Testing product price
|
||||
with tier price, percent sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration4(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 3 * 110 * 0.1) + 100
|
||||
'minimalPrice' => 171.5,
|
||||
|
||||
// 0.5 * (110 + 3 * 110 * 0.1 + 1 * 110 * 0.4) + 100
|
||||
'maximalPrice' => 193.5,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#14 Testing product price
|
||||
with tier price, fixed sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration5(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 40) + 100
|
||||
'minimalPrice' => 175,
|
||||
|
||||
// 0.5 * (110 + 1 * 40 + 3 * 15) + 100
|
||||
'maximalPrice' => 197.5,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#15 Testing product price
|
||||
with tier price, percent sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration5(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 110 * 0.4 + 1 * 110)
|
||||
'minimalPrice' => 132,
|
||||
|
||||
// 0.5 * (110 + 1 * 110 * 0.4 + 3 * 110 * 0.15 + 110 * 1)
|
||||
'maximalPrice' => 156.75,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#16 Testing product price
|
||||
with tier price, fixed sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration5(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 40 + 1 * 110)
|
||||
'minimalPrice' => 130,
|
||||
|
||||
// 0.5 * (110 + 1 * 40 + 3 * 15 + 1 * 110)
|
||||
'maximalPrice' => 152.5,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#17 Testing product price
|
||||
with tier price, percent sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration5(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 110 * 0.4) + 100
|
||||
'minimalPrice' => 177,
|
||||
|
||||
// 0.5 * (110 + 1 * 110 * 0.4 + 3 * 110 * 0.15) + 100
|
||||
'maximalPrice' => 201.75,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#18 Testing product price
|
||||
with tier price, fixed sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration6(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 40) + 100
|
||||
'minimalPrice' => 175,
|
||||
|
||||
// 0.5 * (110 + 3 * 15) + 100
|
||||
'maximalPrice' => 177.5,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#19 Testing product price
|
||||
with tier price, percent sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration6(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 110 * 0.4 + 1 * 110)
|
||||
'minimalPrice' => 132,
|
||||
|
||||
// 0.5 * (110 + 3 * 110 * 0.15 + 1 * 110)
|
||||
'maximalPrice' => 134.75,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#20 Testing product price
|
||||
with tier price, fixed sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration6(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 40 + 110 * 1)
|
||||
'minimalPrice' => 130,
|
||||
|
||||
// 0.5 * (110 + 3 * 15 + 110 * 1)
|
||||
'maximalPrice' => 132.5,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#21 Testing product price
|
||||
with tier price, percent sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration6(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 110 * 0.4) + 100
|
||||
'minimalPrice' => 177,
|
||||
|
||||
// 0.5 * (110 + 3 * 110 * 0.15) + 100
|
||||
'maximalPrice' => 179.75,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#22 Testing product price
|
||||
with tier price, fixed sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration7(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 40 + 1 * 20) + 100
|
||||
'minimalPrice' => 185,
|
||||
|
||||
// 0.5 * (110 + 3 * 15 + 1 * 20 + 3 * 10) + 100
|
||||
'maximalPrice' => 202.5,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#23 Testing product price
|
||||
with tier price, percent sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration7(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 110 * 0.4 + 1 * 110 * 0.2 + 110 * 1)
|
||||
'minimalPrice' => 143,
|
||||
|
||||
// 0.5 * (110 + 3 * 110 * 0.15 + 1 * 110 * 0.2 + 3 * 110 * 0.1 + 110 * 1)
|
||||
'maximalPrice' => 162.25,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#24 Testing product price
|
||||
with tier price, fixed sub items and percent options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration7(
|
||||
LinkInterface::PRICE_TYPE_FIXED,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_PERCENT
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 40 + 1 * 20 + 1 * 110)
|
||||
'minimalPrice' => 140,
|
||||
|
||||
// 0.5 * (110 + 3 * 15 + 1 * 20 + 3 * 10 + 1 * 110)
|
||||
'maximalPrice' => 157.5,
|
||||
]
|
||||
],
|
||||
|
||||
'
|
||||
#25 Testing product price
|
||||
with tier price, percent sub items and fixed options
|
||||
' => [
|
||||
'strategy' => $this->getProductConfiguration7(
|
||||
LinkInterface::PRICE_TYPE_PERCENT,
|
||||
self::CUSTOM_OPTION_PRICE_TYPE_FIXED
|
||||
),
|
||||
'expectedResults' => [
|
||||
// 0.5 * (110 + 1 * 110 * 0.4 + 1 * 110 * 0.2) + 100
|
||||
'minimalPrice' => 188,
|
||||
|
||||
// 0.5 * (110 + 3 * 110 * 0.15 + 1 * 110 * 0.2 + 3 * 110 * 0.1) + 100
|
||||
'maximalPrice' => 207.25,
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product without sub items and options and with tier price
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleConfiguration1()
|
||||
{
|
||||
$tierPriceData = [
|
||||
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
|
||||
'qty' => 1,
|
||||
'value' => 50,
|
||||
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addTierPrice',
|
||||
'data' => [$tierPriceData]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with required option, custom option and with tier price
|
||||
* @param $selectionsPriceType
|
||||
* @param $customOptionsPriceType
|
||||
* @return array
|
||||
*/
|
||||
private function getProductConfiguration2($selectionsPriceType, $customOptionsPriceType)
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 20,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$customOptionsData = [
|
||||
[
|
||||
'price_type' => $customOptionsPriceType,
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'price' => 100,
|
||||
'sku' => '1-text',
|
||||
]
|
||||
];
|
||||
|
||||
$tierPriceData = [
|
||||
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
|
||||
'qty' => 1,
|
||||
'value' => 50,
|
||||
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addTierPrice',
|
||||
'data' => [$tierPriceData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addCustomOption',
|
||||
'data' => [$customOptionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with non required option, custom option and with tier price
|
||||
* @param $selectionsPriceType
|
||||
* @param $customOptionsPriceType
|
||||
* @return array
|
||||
*/
|
||||
private function getProductConfiguration3($selectionsPriceType, $customOptionsPriceType)
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'type' => 'checkbox',
|
||||
'required' => false,
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'price' => 20,
|
||||
'qty' => 2,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$customOptionsData = [
|
||||
[
|
||||
'price_type' => $customOptionsPriceType,
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'price' => 100,
|
||||
'sku' => '1-text',
|
||||
]
|
||||
];
|
||||
|
||||
$tierPriceData = [
|
||||
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
|
||||
'qty' => 1,
|
||||
'value' => 50,
|
||||
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addTierPrice',
|
||||
'data' => [$tierPriceData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addCustomOption',
|
||||
'data' => [$customOptionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with checkbox type option, custom option and with tier price
|
||||
* @param $selectionsPriceType
|
||||
* @param $customOptionsPriceType
|
||||
* @return array
|
||||
*/
|
||||
private function getProductConfiguration4($selectionsPriceType, $customOptionsPriceType)
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 40,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 10,
|
||||
'qty' => 3,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$customOptionsData = [
|
||||
[
|
||||
'price_type' => $customOptionsPriceType,
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'price' => 100,
|
||||
'sku' => '1-text',
|
||||
]
|
||||
];
|
||||
|
||||
$tierPriceData = [
|
||||
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
|
||||
'qty' => 1,
|
||||
'value' => 50,
|
||||
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addTierPrice',
|
||||
'data' => [$tierPriceData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addCustomOption',
|
||||
'data' => [$customOptionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with multi type option, custom option and with tier price
|
||||
* @param $selectionsPriceType
|
||||
* @param $customOptionsPriceType
|
||||
* @return array
|
||||
*/
|
||||
private function getProductConfiguration5($selectionsPriceType, $customOptionsPriceType)
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'multi',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 40,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 15,
|
||||
'qty' => 3,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$customOptionsData = [
|
||||
[
|
||||
'price_type' => $customOptionsPriceType,
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'price' => 100,
|
||||
'sku' => '1-text',
|
||||
]
|
||||
];
|
||||
|
||||
$tierPriceData = [
|
||||
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
|
||||
'qty' => 1,
|
||||
'value' => 50,
|
||||
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addTierPrice',
|
||||
'data' => [$tierPriceData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addCustomOption',
|
||||
'data' => [$customOptionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with radio type option, custom option and with tier price
|
||||
* @param $selectionsPriceType
|
||||
* @param $customOptionsPriceType
|
||||
* @return array
|
||||
*/
|
||||
private function getProductConfiguration6($selectionsPriceType, $customOptionsPriceType)
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'radio',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 40,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 15,
|
||||
'qty' => 3,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$customOptionsData = [
|
||||
[
|
||||
'price_type' => $customOptionsPriceType,
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'price' => 100,
|
||||
'sku' => '1-text',
|
||||
]
|
||||
];
|
||||
|
||||
$tierPriceData = [
|
||||
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
|
||||
'qty' => 1,
|
||||
'value' => 50,
|
||||
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addTierPrice',
|
||||
'data' => [$tierPriceData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addCustomOption',
|
||||
'data' => [$customOptionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed bundle product with two required options, custom option and with tier price
|
||||
* @param $selectionsPriceType
|
||||
* @param $customOptionsPriceType
|
||||
* @return array
|
||||
*/
|
||||
private function getProductConfiguration7($selectionsPriceType, $customOptionsPriceType)
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'Op1',
|
||||
'required' => true,
|
||||
'type' => 'radio',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 40,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 15,
|
||||
'qty' => 3,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
'title' => 'Op2',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 1,
|
||||
'price' => 20,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'price' => 10,
|
||||
'qty' => 3,
|
||||
'price_type' => $selectionsPriceType
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$customOptionsData = [
|
||||
[
|
||||
'price_type' => $customOptionsPriceType,
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'price' => 100,
|
||||
'sku' => '1-text',
|
||||
]
|
||||
];
|
||||
|
||||
$tierPriceData = [
|
||||
'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID,
|
||||
'qty' => 1,
|
||||
'value' => 50,
|
||||
'extension_attributes' => new \Magento\Framework\DataObject(['percentage_value' => 50])
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addTierPrice',
|
||||
'data' => [$tierPriceData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
[
|
||||
'modifierName' => 'addCustomOption',
|
||||
'data' => [$customOptionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Catalog\Model\Product $product
|
||||
* @param array $tirePriceData
|
||||
* @return \Magento\Catalog\Model\Product
|
||||
*/
|
||||
protected function addTierPrice(\Magento\Catalog\Model\Product $product, $tirePriceData)
|
||||
{
|
||||
$tierPrice = $this->tierPriceFactory->create([
|
||||
'data' => $tirePriceData
|
||||
]);
|
||||
$product->setTierPrices([$tierPrice]);
|
||||
|
||||
return $product;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,356 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Bundle\Model\Product;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Bundle\Model\Product\Type (bundle product type)
|
||||
*
|
||||
* @magentoDataFixture Magento/Bundle/_files/issaleable_product.php
|
||||
*/
|
||||
class IsSaleableTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
/**
|
||||
* @var \Magento\Catalog\Api\ProductRepositoryInterface
|
||||
*/
|
||||
protected $productRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->productRepository = $this->objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check bundle product is saleable if his status is enabled
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @covers \Magento\Bundle\Model\Product\Type::isSalable
|
||||
*/
|
||||
public function testIsSaleableOnEnabledStatus()
|
||||
{
|
||||
$bundleProduct = $this->productRepository->get('bundle-product');
|
||||
$bundleProduct->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
|
||||
|
||||
$this->assertTrue(
|
||||
$bundleProduct->isSalable(),
|
||||
'Bundle product supposed to be saleable'
|
||||
. ' if his status is enabled'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check bundle product is NOT saleable if his status is disabled
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @covers \Magento\Bundle\Model\Product\Type::isSalable
|
||||
*/
|
||||
public function testIsSaleableOnDisabledStatus()
|
||||
{
|
||||
$bundleProduct = $this->productRepository->get('bundle-product');
|
||||
$bundleProduct->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
|
||||
|
||||
$this->assertFalse(
|
||||
$bundleProduct->isSalable(),
|
||||
'Bundle product supposed to be non saleable'
|
||||
. ' if his status is disabled'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check bundle product is saleable if his status is enabled
|
||||
* and it has internal data is_salable = true
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @covers \Magento\Bundle\Model\Product\Type::isSalable
|
||||
*/
|
||||
public function testIsSaleableOnEnabledStatusAndIsSalableIsTrue()
|
||||
{
|
||||
$bundleProduct = $this->productRepository->get('bundle-product');
|
||||
$bundleProduct->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
|
||||
$bundleProduct->setData('is_salable', true);
|
||||
|
||||
$this->assertTrue(
|
||||
$bundleProduct->isSalable(),
|
||||
'Bundle product supposed to be saleable'
|
||||
. ' if his status is enabled and it has data is_salable = true'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check bundle product is NOT saleable if
|
||||
* his status is enabled but his data is_salable = false
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @covers \Magento\Bundle\Model\Product\Type::isSalable
|
||||
*/
|
||||
public function testIsSaleableOnEnabledStatusAndIsSalableIsFalse()
|
||||
{
|
||||
$bundleProduct = $this->productRepository->get('bundle-product');
|
||||
$bundleProduct->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
|
||||
$bundleProduct->setData('is_salable', false);
|
||||
|
||||
$this->assertFalse(
|
||||
$bundleProduct->isSalable(),
|
||||
'Bundle product supposed to be non saleable'
|
||||
. ' if his status is enabled but his data is_salable = false'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check bundle product is NOT saleable if it has no options
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @covers \Magento\Bundle\Model\Product\Type::isSalable
|
||||
*/
|
||||
public function testIsSaleableOnBundleWithoutOptions()
|
||||
{
|
||||
$optionRepository = $this->objectManager->create(\Magento\Bundle\Api\ProductOptionRepositoryInterface::class);
|
||||
$bundleProduct = $this->productRepository->get('bundle-product');
|
||||
|
||||
// TODO: make cleaner option deletion after fix MAGETWO-59465
|
||||
$ea = $bundleProduct->getExtensionAttributes();
|
||||
foreach ($ea->getBundleProductOptions() as $option) {
|
||||
$optionRepository->delete($option);
|
||||
}
|
||||
$ea->setBundleProductOptions([]);
|
||||
$bundleProduct->setExtensionAttributes($ea);
|
||||
|
||||
$bundleProduct = $this->productRepository->save($bundleProduct);
|
||||
|
||||
$this->assertFalse(
|
||||
$bundleProduct->isSalable(),
|
||||
'Bundle product supposed to be non saleable'
|
||||
. ' if it has no options'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check bundle product is NOT saleable if it has no selections
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @covers \Magento\Bundle\Model\Product\Type::isSalable
|
||||
*/
|
||||
public function testIsSaleableOnBundleWithoutSelections()
|
||||
{
|
||||
$bundleProduct = $this->productRepository->get('bundle-product', true, null, true);
|
||||
$bundleType = $bundleProduct->getTypeInstance();
|
||||
/** @var \Magento\Bundle\Model\LinkManagement $linkManager */
|
||||
$linkManager = $this->objectManager->create(\Magento\Bundle\Model\LinkManagement::class);
|
||||
|
||||
/** @var \Magento\Bundle\Model\Product\Type $bundleType */
|
||||
$options = $bundleType->getOptionsCollection($bundleProduct);
|
||||
$selections = $bundleType->getSelectionsCollection($options->getAllIds(), $bundleProduct);
|
||||
|
||||
foreach ($selections as $link) {
|
||||
/** @var \Magento\Bundle\Model\Selection $link */
|
||||
$linkManager->removeChild('bundle-product', $link->getOptionId(), $link->getSku());
|
||||
}
|
||||
|
||||
$bundleProduct = $this->productRepository->get('bundle-product', false, null, true);
|
||||
$this->assertFalse(
|
||||
$bundleProduct->isSalable(),
|
||||
'Bundle product supposed to be non saleable'
|
||||
. ' if it has no selections'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check bundle product is NOT saleable if
|
||||
* all his selections are not saleable
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @covers \Magento\Bundle\Model\Product\Type::isSalable
|
||||
*/
|
||||
public function testIsSaleableOnBundleWithoutSaleableSelections()
|
||||
{
|
||||
$productsSku = ['simple1', 'simple2', 'simple3', 'simple4', 'simple5'];
|
||||
foreach ($productsSku as $productSku) {
|
||||
$product = $this->productRepository->get($productSku);
|
||||
$product->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
|
||||
$this->productRepository->save($product);
|
||||
}
|
||||
|
||||
$bundleProduct = $this->productRepository->get('bundle-product');
|
||||
|
||||
$this->assertFalse(
|
||||
$bundleProduct->isSalable(),
|
||||
'Bundle product supposed to be non saleable'
|
||||
. ' if all his selections are not saleable'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check bundle product is NOT saleable if
|
||||
* it has at least one required option without saleable selections
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @covers \Magento\Bundle\Model\Product\Type::isSalable
|
||||
*/
|
||||
public function testIsSaleableOnBundleWithoutSaleableSelectionsOnRequiredOption()
|
||||
{
|
||||
$productsSku = ['simple1', 'simple2', 'simple3'];
|
||||
foreach ($productsSku as $productSku) {
|
||||
$product = $this->productRepository->get($productSku);
|
||||
$product->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
|
||||
$this->productRepository->save($product);
|
||||
}
|
||||
|
||||
$bundleProduct = $this->productRepository->get('bundle-product');
|
||||
|
||||
$this->assertFalse(
|
||||
$bundleProduct->isSalable(),
|
||||
'Bundle product supposed to be non saleable'
|
||||
. ' if it has at least one required option with no saleable selections'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check bundle product is NOT saleable if
|
||||
* there are not enough qty of selection on required option
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @covers \Magento\Bundle\Model\Product\Type::isSalable
|
||||
*/
|
||||
public function testIsSaleableOnBundleWithNotEnoughQtyOfSelection()
|
||||
{
|
||||
$this->setQtyForSelections(['simple1', 'simple2', 'simple3'], 1);
|
||||
|
||||
$bundleProduct = $this->productRepository->get('bundle-product');
|
||||
|
||||
$this->assertFalse(
|
||||
$bundleProduct->isSalable(),
|
||||
'Bundle product supposed to be non saleable'
|
||||
. ' if there are not enough qty of selections on required options'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check bundle product is saleable if
|
||||
* all his selections have selection_can_change_qty = 1
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @covers \Magento\Bundle\Model\Product\Type::isSalable
|
||||
*/
|
||||
public function testIsSaleableOnBundleWithSelectionCanChangeQty()
|
||||
{
|
||||
$this->setQtyForSelections(['simple1', 'simple2', 'simple3', 'simple4', 'simple5'], 1);
|
||||
$bundleProduct = $this->productRepository->get('bundle-product');
|
||||
$options = $bundleProduct->getExtensionAttributes()->getBundleProductOptions();
|
||||
|
||||
foreach ($options as $productOption) {
|
||||
$links = $productOption->getProductLinks();
|
||||
foreach ($links as $link) {
|
||||
$link->setSelectionCanChangeQuantity(1);
|
||||
}
|
||||
|
||||
$productOption->setProductLinks($links);
|
||||
}
|
||||
|
||||
$extension = $bundleProduct->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$bundleProduct->setExtensionAttributes($extension);
|
||||
|
||||
$bundleProduct = $this->productRepository->save($bundleProduct);
|
||||
|
||||
$this->assertTrue(
|
||||
$bundleProduct->isSalable(),
|
||||
'Bundle product supposed to be saleable'
|
||||
. ' if all his selections have selection_can_change_qty = 1'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check bundle product is not saleable if
|
||||
* all his options are not required and selections are not saleable
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @covers \Magento\Bundle\Model\Product\Type::isSalable
|
||||
*/
|
||||
public function testIsSaleableOnBundleWithoutRequiredOptions()
|
||||
{
|
||||
// making selections as not saleable
|
||||
$productsSku = ['simple1', 'simple2', 'simple3', 'simple4', 'simple5'];
|
||||
foreach ($productsSku as $productSku) {
|
||||
$product = $this->productRepository->get($productSku);
|
||||
$product->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
|
||||
$this->productRepository->save($product);
|
||||
}
|
||||
|
||||
$bundleProduct = $this->productRepository->get('bundle-product');
|
||||
|
||||
// setting all options as not required
|
||||
$options = $bundleProduct->getExtensionAttributes()->getBundleProductOptions();
|
||||
foreach ($options as $productOption) {
|
||||
$productOption->setRequired(false);
|
||||
}
|
||||
|
||||
$extension = $bundleProduct->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$bundleProduct->setExtensionAttributes($extension);
|
||||
$bundleProduct = $this->productRepository->save($bundleProduct);
|
||||
|
||||
$this->assertFalse(
|
||||
$bundleProduct->isSalable(),
|
||||
'Bundle product supposed to be not saleable'
|
||||
. ' if all his options are not required and selections are not saleable'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check bundle product is saleable if
|
||||
* it has at least one not required option with saleable selections
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @covers \Magento\Bundle\Model\Product\Type::isSalable
|
||||
*/
|
||||
public function testIsSaleableOnBundleWithOneSaleableSelection()
|
||||
{
|
||||
// making selections as not saleable except simple3
|
||||
$productsSku = ['simple1', 'simple2', 'simple4', 'simple5'];
|
||||
|
||||
foreach ($productsSku as $productSku) {
|
||||
$product = $this->productRepository->get($productSku);
|
||||
$product->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
|
||||
$this->productRepository->save($product);
|
||||
}
|
||||
|
||||
$bundleProduct = $this->productRepository->get('bundle-product');
|
||||
|
||||
// setting all options as not required
|
||||
$options = $bundleProduct->getExtensionAttributes()->getBundleProductOptions();
|
||||
foreach ($options as $productOption) {
|
||||
$productOption->setRequired(false);
|
||||
}
|
||||
|
||||
$extension = $bundleProduct->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$bundleProduct->setExtensionAttributes($extension);
|
||||
|
||||
$bundleProduct = $this->productRepository->save($bundleProduct);
|
||||
|
||||
$this->assertTrue(
|
||||
$bundleProduct->isSalable(),
|
||||
'Bundle product supposed to be saleable'
|
||||
. ' if it has at least one not required option with saleable selection'
|
||||
);
|
||||
}
|
||||
|
||||
private function setQtyForSelections($productsSku, $qty)
|
||||
{
|
||||
foreach ($productsSku as $productSku) {
|
||||
$product = $this->productRepository->get($productSku);
|
||||
$ea = $product->getExtensionAttributes();
|
||||
$ea->getStockItem()->setQty($qty);
|
||||
$this->productRepository->save($product);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Model\Product;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test for bundle product linksList model.
|
||||
*
|
||||
*/
|
||||
class LinksListTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var LinksList
|
||||
*/
|
||||
private $linksList;
|
||||
|
||||
/**
|
||||
* @inheridoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->linksList = Bootstrap::getObjectManager()->get(LinksList::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* verify get items with zero option selection price.
|
||||
*
|
||||
* @magentoDataFixture Magento/Bundle/_files//fixed_bundle_product_zero_price_option_selection.php
|
||||
* @return void
|
||||
*/
|
||||
public function testGetItemsWithZeroPrice(): void
|
||||
{
|
||||
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('bundle_product');
|
||||
$type = Bootstrap::getObjectManager()->get(Type::class);
|
||||
$optionsIds = $type->getOptionsIds($product);
|
||||
$links = $this->linksList->getItems($product, current($optionsIds));
|
||||
$link = current($links);
|
||||
self::assertEquals('simple1', $link->getSku());
|
||||
self::assertEquals(0, $link->getPrice());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Bundle\Model\Product;
|
||||
|
||||
/**
|
||||
* Integration test for Magento\Bundle\Model\OptionList
|
||||
*/
|
||||
class OptionListTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Catalog\Model\Product
|
||||
*/
|
||||
protected $product;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
/**
|
||||
* Set up
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/product.php
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testGetItems()
|
||||
{
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
$this->product = $productRepository->get('bundle-product');
|
||||
/**
|
||||
* @var \Magento\Bundle\Model\Product\OptionList $optionList
|
||||
*/
|
||||
$optionList = $this->objectManager->create(\Magento\Bundle\Model\Product\OptionList::class);
|
||||
$options = $optionList->getItems($this->product);
|
||||
$this->assertCount(1, $options);
|
||||
$this->assertEquals('Bundle Product Items', $options[0]->getTitle());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,585 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Model\Product;
|
||||
|
||||
use Magento\Bundle\Test\Fixture\Link as BundleSelectionFixture;
|
||||
use Magento\Bundle\Test\Fixture\Option as BundleOptionFixture;
|
||||
use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
|
||||
use Magento\Catalog\Api\Data\ProductInterface;
|
||||
use Magento\Catalog\Api\Data\TierPriceInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
|
||||
use Magento\Customer\Model\Group;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Catalog\Model\GetCategoryByName;
|
||||
use Magento\TestFramework\Catalog\Model\Product\Price\GetPriceIndexDataByProductId;
|
||||
use Magento\TestFramework\Fixture\DataFixture;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class to test bundle prices
|
||||
*
|
||||
* @magentoDbIsolation disabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoAppArea frontend
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class PriceTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var ProductRepositoryInterface */
|
||||
private $productRepository;
|
||||
|
||||
/** @var GetPriceIndexDataByProductId */
|
||||
private $getPriceIndexDataByProductId;
|
||||
|
||||
/** @var WebsiteRepositoryInterface */
|
||||
private $websiteRepository;
|
||||
|
||||
/** @var Price */
|
||||
private $priceModel;
|
||||
|
||||
/** @var SerializerInterface */
|
||||
private $json;
|
||||
|
||||
/** @var GetCategoryByName */
|
||||
private $getCategoryByName;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->priceModel = $this->objectManager->get(Price::class);
|
||||
$this->websiteRepository = $this->objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
|
||||
$this->productRepository->cleanCache();
|
||||
$this->getPriceIndexDataByProductId = $this->objectManager->get(GetPriceIndexDataByProductId::class);
|
||||
$this->json = $this->objectManager->get(SerializerInterface::class);
|
||||
$this->getCategoryByName = $this->objectManager->get(GetCategoryByName::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/product_with_tier_pricing.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetTierPrice(): void
|
||||
{
|
||||
$product = $this->productRepository->get('bundle-product');
|
||||
// Note that this is really not the "tier price" but the "tier discount percentage"
|
||||
// so it is expected to be increasing instead of decreasing
|
||||
$this->assertEquals(8.0, $this->priceModel->getTierPrice(2, $product));
|
||||
$this->assertEquals(20.0, $this->priceModel->getTierPrice(3, $product));
|
||||
$this->assertEquals(20.0, $this->priceModel->getTierPrice(4, $product));
|
||||
$this->assertEquals(30.0, $this->priceModel->getTierPrice(5, $product));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test calculation final price for bundle product with tire price in simple product
|
||||
* @magentoDataFixture Magento/Bundle/_files/product_with_simple_tier_pricing.php
|
||||
* @dataProvider getSelectionFinalTotalPriceWithSimpleTierPriceDataProvider
|
||||
*
|
||||
* @param float $bundleQty
|
||||
* @param float $selectionQty
|
||||
* @param float $finalPrice
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSelectionFinalTotalPriceWithSimpleTierPrice(
|
||||
float $bundleQty,
|
||||
float $selectionQty,
|
||||
float $finalPrice
|
||||
): void {
|
||||
$bundleProduct = $this->productRepository->get('bundle-product');
|
||||
$simpleProduct = $this->productRepository->get('simple');
|
||||
$simpleProduct->setCustomerGroupId(Group::CUST_GROUP_ALL);
|
||||
|
||||
$this->assertEquals(
|
||||
$finalPrice,
|
||||
$this->priceModel->getSelectionFinalTotalPrice(
|
||||
$bundleProduct,
|
||||
$simpleProduct,
|
||||
$bundleQty,
|
||||
$selectionQty,
|
||||
false
|
||||
),
|
||||
'Tier price calculation for Simple product is wrong'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSelectionFinalTotalPriceWithSimpleTierPriceDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[1, 1, 10],
|
||||
[2, 1, 8],
|
||||
[5, 1, 5],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed Bundle Product with catalog price rule
|
||||
* @magentoDataFixture Magento/Bundle/_files/fixed_bundle_product_without_discounts.php
|
||||
* @magentoDataFixture Magento/CatalogRule/_files/rule_apply_as_percentage_of_original_not_logged_user.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFixedBundleProductPriceWithCatalogRule(): void
|
||||
{
|
||||
$this->checkBundlePrices(
|
||||
'fixed_bundle_product_without_discounts',
|
||||
['price' => 50, 'final_price' => 45, 'min_price' => 45, 'max_price' => 75, 'tier_price' => null],
|
||||
['simple1' => 55, 'simple2' => 56.25, 'simple3' => 70]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed Bundle Product without discounts
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[
|
||||
DataFixture(ProductFixture::class, ['sku' => 'simple1', 'price' => 10], 'p1'),
|
||||
DataFixture(ProductFixture::class, ['sku' => 'simple2', 'price' => 20], 'p2'),
|
||||
DataFixture(ProductFixture::class, ['sku' => 'simple3', 'price' => 30], 'p3'),
|
||||
DataFixture(BundleSelectionFixture::class, ['sku' => '$p1.sku$', 'price' => 10, 'price_type' => 0], 'link1'),
|
||||
DataFixture(BundleSelectionFixture::class, ['sku' => '$p2.sku$', 'price' => 25, 'price_type' => 1], 'link2'),
|
||||
DataFixture(BundleSelectionFixture::class, ['sku' => '$p3.sku$', 'price' => 25, 'price_type' => 0], 'link3'),
|
||||
DataFixture(BundleOptionFixture::class, ['product_links' => ['$link1$', '$link2$', '$link3$']], 'opt1'),
|
||||
DataFixture(
|
||||
BundleProductFixture::class,
|
||||
['sku' => 'bundle1','price' => 50,'price_type' => 1,'_options' => ['$opt1$']],
|
||||
'bundle1'
|
||||
),
|
||||
]
|
||||
public function testFixedBundleProductPriceWithoutDiscounts(): void
|
||||
{
|
||||
$this->checkBundlePrices(
|
||||
'bundle1',
|
||||
['price' => 50, 'final_price' => 50, 'min_price' => 60, 'max_price' => 75, 'tier_price' => null],
|
||||
['simple1' => 60, 'simple2' => 62.5, 'simple3' => 75]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed Bundle Product with special price
|
||||
* @magentoDataFixture Magento/Bundle/_files/fixed_bundle_product_with_special_price.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFixedBundleProductPriceWithSpecialPrice(): void
|
||||
{
|
||||
$this->checkBundlePrices(
|
||||
'fixed_bundle_product_with_special_price',
|
||||
['price' => 50, 'final_price' => 40, 'min_price' => 48, 'max_price' => 60, 'tier_price' => null],
|
||||
['simple1' => 48, 'simple2' => 50, 'simple3' => 60]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed Bundle Product with tier price
|
||||
* @magentoDataFixture Magento/Bundle/_files/fixed_bundle_product_with_tier_price.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFixedBundleProductPriceWithTierPrice(): void
|
||||
{
|
||||
$this->checkBundlePrices(
|
||||
'fixed_bundle_product_with_tier_price',
|
||||
['price' => 50, 'final_price' => 50, 'min_price' => 60, 'max_price' => 75, 'tier_price' => 60],
|
||||
['simple1' => 45, 'simple2' => 46.88, 'simple3' => 56.25]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic Bundle Product without discount + options without discounts
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[
|
||||
DataFixture(ProductFixture::class, ['sku' => 'simple1000', 'price' => 10], 'p1'),
|
||||
DataFixture(ProductFixture::class, ['sku' => 'simple1001', 'price' => 20], 'p2'),
|
||||
DataFixture(BundleOptionFixture::class, ['product_links' => ['$p1$', '$p2$']], 'opt1'),
|
||||
DataFixture(
|
||||
BundleProductFixture::class,
|
||||
['sku' => 'bundle1', '_options' => ['$opt1$']],
|
||||
'bundle1'
|
||||
),
|
||||
]
|
||||
public function testDynamicBundleProductWithoutDiscountAndOptionsWithoutDiscounts(): void
|
||||
{
|
||||
$this->checkBundlePrices(
|
||||
'bundle1',
|
||||
['price' => 0, 'final_price' => 0, 'min_price' => 10, 'max_price' => 20, 'tier_price' => null],
|
||||
['simple1000' => 10, 'simple1001' => 20]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic Bundle Product without discount + options with special price
|
||||
* @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_without_discounts.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDynamicBundleProductWithoutDiscountsAndOptionsWithSpecialPrices(): void
|
||||
{
|
||||
$this->updateProducts($this->specialPricesForOptionsData());
|
||||
$this->checkBundlePrices(
|
||||
'dynamic_bundle_product_without_discounts',
|
||||
['price' => 0, 'final_price' => 0, 'min_price' => 8, 'max_price' => 15, 'tier_price' => null],
|
||||
['simple1000' => 8, 'simple1001' => 15]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic Bundle Product without discount + options with tier prices
|
||||
* @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_without_discounts.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDynamicBundleProductWithoutDiscountsAndOptionsWithTierPrices(): void
|
||||
{
|
||||
$this->updateProducts($this->tierPricesForOptionsData());
|
||||
$this->checkBundlePrices(
|
||||
'dynamic_bundle_product_without_discounts',
|
||||
['price' => 0, 'final_price' => 0, 'min_price' => 8, 'max_price' => 17, 'tier_price' => null],
|
||||
['simple1000' => 8, 'simple1001' => 17]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic Bundle Product without discounts + options with catalog rule
|
||||
* @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_without_discounts.php
|
||||
* @magentoDataFixture Magento/CatalogRule/_files/catalog_rule_for_category_999.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDynamicBundleProductWithoutDiscountsAndOptionsWithCatalogPriceRule(): void
|
||||
{
|
||||
$this->checkBundlePrices(
|
||||
'dynamic_bundle_product_without_discounts',
|
||||
['price' => 0, 'final_price' => 0, 'min_price' => 7.5, 'max_price' => 15, 'tier_price' => null],
|
||||
['simple1000' => 7.5, 'simple1001' => 15]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic Bundle Product with tier price + options without discounts
|
||||
* @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_with_tier_price.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDynamicBundleProductWithTierPriceAndOptionsWithoutDiscounts(): void
|
||||
{
|
||||
$this->checkBundlePrices(
|
||||
'dynamic_bundle_product_with_tier_price',
|
||||
['price' => 0,'final_price' => 0, 'min_price' => 10, 'max_price' => 20, 'tier_price' => 10],
|
||||
['simple1000' => 7.5, 'simple1001' => 15]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic Bundle Product with tier price + options with special prices
|
||||
* @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_with_tier_price.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDynamicBundleProductWithTierPriceAndOptionsWithSpecialPrices(): void
|
||||
{
|
||||
$this->updateProducts($this->specialPricesForOptionsData());
|
||||
$this->checkBundlePrices(
|
||||
'dynamic_bundle_product_with_tier_price',
|
||||
['price' => 0, 'final_price' => 0, 'min_price' => 8, 'max_price' => 15, 'tier_price' => 8],
|
||||
['simple1000' => 6, 'simple1001' => 11.25]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic Bundle Product with tier price + options with tier price
|
||||
* @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_with_tier_price.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDynamicBundleProductWithTierPriceAndOptionsWithTierPrices(): void
|
||||
{
|
||||
$this->updateProducts($this->tierPricesForOptionsData());
|
||||
$this->checkBundlePrices(
|
||||
'dynamic_bundle_product_with_tier_price',
|
||||
['price' => 0, 'final_price' => 0, 'min_price' => 8, 'max_price' => 17, 'tier_price' => 8],
|
||||
['simple1000' => 6, 'simple1001' => 12.75]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic Bundle Product with tier price + options with catalog rule
|
||||
* @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_with_tier_price.php
|
||||
* @magentoDataFixture Magento/CatalogRule/_files/catalog_rule_for_category_999.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDynamicBundleProductWithTierPriceAndOptionsWithCatalogPriceRule(): void
|
||||
{
|
||||
$this->checkBundlePrices(
|
||||
'dynamic_bundle_product_with_tier_price',
|
||||
['price' => 0, 'final_price' => 0, 'min_price' => 7.5, 'max_price' => 15, 'tier_price' => 7.5],
|
||||
['simple1000' => 5.63, 'simple1001' => 11.25]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic Bundle Product with special price + options without discounts
|
||||
* @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_with_special_price.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDynamicBundleProductWithSpecialPriceAndOptionsWithoutDiscounts(): void
|
||||
{
|
||||
$this->checkBundlePrices(
|
||||
'dynamic_bundle_product_with_special_price',
|
||||
['price' => 0, 'final_price' => 0, 'min_price' => 7.5, 'max_price' => 15, 'tier_price' => null],
|
||||
['simple1000' => 7.5, 'simple1001' => 15]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic Bundle Product with special price + options with special prices
|
||||
* @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_with_special_price.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDynamicBundleProductWithSpecialPriceAndOptionsWithSpecialPrices(): void
|
||||
{
|
||||
$this->updateProducts($this->specialPricesForOptionsData());
|
||||
$this->checkBundlePrices(
|
||||
'dynamic_bundle_product_with_special_price',
|
||||
['price' => 0, 'final_price' => 0, 'min_price' => 6, 'max_price' => 11.25, 'tier_price' => null],
|
||||
['simple1000' => 6, 'simple1001' => 11.25]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic Bundle Product with special price + options with tier prices
|
||||
* @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_with_special_price.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDynamicBundleProductWithSpecialPriceAndOptionsWithTierPrices(): void
|
||||
{
|
||||
$this->updateProducts($this->tierPricesForOptionsData());
|
||||
$this->checkBundlePrices(
|
||||
'dynamic_bundle_product_with_special_price',
|
||||
['price' => 0, 'final_price' => 0, 'min_price' => 6, 'max_price' => 12.75, 'tier_price' => null],
|
||||
['simple1000' => 6, 'simple1001' => 12.75]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic Bundle Product with special price + options with catalog price rule
|
||||
* @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_with_special_price.php
|
||||
* @magentoDataFixture Magento/CatalogRule/_files/catalog_rule_for_category_999.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDynamicBundleProductWithSpecialPriceAndOptionsWithCatalogPriceRule(): void
|
||||
{
|
||||
$this->checkBundlePrices(
|
||||
'dynamic_bundle_product_with_special_price',
|
||||
['price' => 0, 'final_price' => 0, 'min_price' => 5.625, 'max_price' => 11.25, 'tier_price' => null],
|
||||
['simple1000' => 5.63, 'simple1001' => 11.25]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic Bundle Product with catalog price rule + options without discounts
|
||||
* @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_with_catalog_rule.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDynamicBundleProductWithCatalogPriceRuleAndOptionsWithoutDiscounts(): void
|
||||
{
|
||||
$this->checkBundlePrices(
|
||||
'dynamic_bundle_product_with_catalog_rule',
|
||||
['price' => 0, 'final_price' => 0, 'min_price' => 10, 'max_price' => 20, 'tier_price' => null],
|
||||
['simple1000' => 10, 'simple1001' => 20]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic Bundle Product with catalog price rule + options with catalog price rule
|
||||
* @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_with_catalog_rule.php
|
||||
* @magentoDataFixture Magento/CatalogRule/_files/catalog_rule_for_category_999.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDynamicBundleProductWithCatalogPriceRuleAndOptionsWithCatalogPriceRule(): void
|
||||
{
|
||||
$this->checkBundlePrices(
|
||||
'dynamic_bundle_product_with_catalog_rule',
|
||||
['price' => 0, 'final_price' => 0, 'min_price' => 7.5, 'max_price' => 15, 'tier_price' => null],
|
||||
['simple1000' => 7.5, 'simple1001' => 15]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic Bundle Product with catalog price rule + options with special prices
|
||||
* @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_with_catalog_rule.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDynamicBundleProductWithCatalogPriceRuleAndOptionsWithSpecialPrices(): void
|
||||
{
|
||||
$this->updateProducts($this->specialPricesForOptionsData());
|
||||
$this->checkBundlePrices(
|
||||
'dynamic_bundle_product_with_catalog_rule',
|
||||
['price' => 0, 'final_price' => 0, 'min_price' => 8, 'max_price' => 15, 'tier_price' => null],
|
||||
['simple1000' => 8, 'simple1001' => 15]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic Bundle Product with catalog price rule + options with tier price
|
||||
* @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_with_catalog_rule.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDynamicBundleProductWithCatalogPriceRuleAndOptionsWithTierPrice(): void
|
||||
{
|
||||
$this->updateProducts($this->tierPricesForOptionsData());
|
||||
$this->checkBundlePrices(
|
||||
'dynamic_bundle_product_with_catalog_rule',
|
||||
['price' => 0, 'final_price' => 0, 'min_price' => 8, 'max_price' => 17, 'tier_price' => null],
|
||||
['simple1000' => 8, 'simple1001' => 17]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check bundle prices from index table and final bundle option price.
|
||||
*
|
||||
* @param string $sku
|
||||
* @param array $indexPrices
|
||||
* @param array $expectedPrices
|
||||
* @return void
|
||||
*/
|
||||
private function checkBundlePrices(string $sku, array $indexPrices, array $expectedPrices): void
|
||||
{
|
||||
$product = $this->productRepository->get($sku);
|
||||
$this->assertIndexTableData((int)$product->getId(), $indexPrices);
|
||||
$this->assertPriceWithChosenOption($product, $expectedPrices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts price data in index table.
|
||||
*
|
||||
* @param int $productId
|
||||
* @param array $expectedPrices
|
||||
* @return void
|
||||
*/
|
||||
private function assertIndexTableData(int $productId, array $expectedPrices): void
|
||||
{
|
||||
$data = $this->getPriceIndexDataByProductId->execute(
|
||||
$productId,
|
||||
Group::NOT_LOGGED_IN_ID,
|
||||
(int)$this->websiteRepository->get('base')->getId()
|
||||
);
|
||||
$data = reset($data);
|
||||
foreach ($expectedPrices as $column => $price) {
|
||||
$this->assertEquals($price, $data[$column]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert bundle final price with chosen option.
|
||||
*
|
||||
* @param ProductInterface $bundle
|
||||
* @param array $expectedPrices
|
||||
* @return void
|
||||
*/
|
||||
private function assertPriceWithChosenOption(ProductInterface $bundle, array $expectedPrices): void
|
||||
{
|
||||
$option = $bundle->getExtensionAttributes()->getBundleProductOptions()[0] ?? null;
|
||||
$this->assertNotNull($option);
|
||||
foreach ($option->getProductLinks() as $productLink) {
|
||||
$bundle->addCustomOption('bundle_selection_ids', $this->json->serialize([$productLink->getId()]));
|
||||
$bundle->addCustomOption('selection_qty_' . $productLink->getId(), 1);
|
||||
$this->assertEquals(
|
||||
round((float) $expectedPrices[$productLink->getSku()], 2),
|
||||
round((float) $this->priceModel->getFinalPrice(1, $bundle), 2)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update products.
|
||||
*
|
||||
* @param array $products
|
||||
* @return void
|
||||
*/
|
||||
private function updateProducts(array $products): void
|
||||
{
|
||||
foreach ($products as $sku => $updateData) {
|
||||
$product = $this->productRepository->get($sku);
|
||||
$product->addData($updateData);
|
||||
$this->productRepository->save($product);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function specialPricesForOptionsData(): array
|
||||
{
|
||||
return [
|
||||
'simple1000' => [
|
||||
'special_price' => 8,
|
||||
],
|
||||
'simple1001' => [
|
||||
'special_price' => 15,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function tierPricesForOptionsData(): array
|
||||
{
|
||||
return [
|
||||
'simple1000' => [
|
||||
'tier_price' => [
|
||||
[
|
||||
'website_id' => 0,
|
||||
'cust_group' => Group::CUST_GROUP_ALL,
|
||||
'price_qty' => 1,
|
||||
'value_type' => TierPriceInterface::PRICE_TYPE_FIXED,
|
||||
'price' => 8,
|
||||
],
|
||||
],
|
||||
],
|
||||
'simple1001' => [
|
||||
'tier_price' => [
|
||||
[
|
||||
'website_id' => 0,
|
||||
'cust_group' => Group::CUST_GROUP_ALL,
|
||||
'price_qty' => 1,
|
||||
'value_type' => TierPriceInterface::PRICE_TYPE_DISCOUNT,
|
||||
'website_price' => 20,
|
||||
'percentage_value' => 15,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Model\Product;
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation disabled
|
||||
* @magentoIndexerDimensionMode catalog_product_price website_and_customer_group
|
||||
* @group indexer_dimension
|
||||
* @magentoDataFixture Magento/Bundle/_files/product_with_tier_pricing.php
|
||||
*/
|
||||
class PriceWithDimensionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Bundle\Model\Product\Price
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
/**
|
||||
* Set up
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Bundle\Model\Product\Price::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tier price
|
||||
*/
|
||||
public function testGetTierPrice()
|
||||
{
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('bundle-product');
|
||||
// fixture
|
||||
|
||||
// Note that this is really not the "tier price" but the "tier discount percentage"
|
||||
// so it is expected to be increasing instead of decreasing
|
||||
$this->assertEquals(8.0, $this->_model->getTierPrice(2, $product));
|
||||
$this->assertEquals(20.0, $this->_model->getTierPrice(3, $product));
|
||||
$this->assertEquals(20.0, $this->_model->getTierPrice(4, $product));
|
||||
$this->assertEquals(30.0, $this->_model->getTierPrice(5, $product));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Model\Product;
|
||||
|
||||
use Magento\Bundle\Api\Data\LinkInterface;
|
||||
use Magento\Bundle\Api\Data\LinkInterfaceFactory;
|
||||
use Magento\Bundle\Api\Data\OptionInterfaceFactory;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Store\Model\Store;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Bundle\Model\Product\SaveHandler
|
||||
* The tested class used indirectly
|
||||
*
|
||||
* @magentoDataFixture Magento/Bundle/_files/product.php
|
||||
* @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
|
||||
* @magentoDbIsolation disabled
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
class SaveHandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var Store
|
||||
*/
|
||||
private $store;
|
||||
|
||||
/**
|
||||
* @var ProductRepositoryInterface
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->store = $this->objectManager->create(Store::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test option title on different stores
|
||||
*
|
||||
* @return void
|
||||
* @throws LocalizedException
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
public function testOptionTitlesOnDifferentStores(): void
|
||||
{
|
||||
/** @var OptionList $optionList */
|
||||
$optionList = $this->objectManager->create(OptionList::class);
|
||||
|
||||
$secondStoreId = $this->store->load('fixture_second_store')->getId();
|
||||
$thirdStoreId = $this->store->load('fixture_third_store')->getId();
|
||||
|
||||
$product = $this->productRepository->get('bundle-product', true, $secondStoreId, true);
|
||||
$options = $optionList->getItems($product);
|
||||
$title = $options[0]->getTitle();
|
||||
$newTitle = $title . ' ' . $this->store->load('fixture_second_store')->getCode();
|
||||
$options[0]->setTitle($newTitle);
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
$product->save();
|
||||
|
||||
$product = $this->productRepository->get('bundle-product', true, $thirdStoreId, true);
|
||||
$options = $optionList->getItems($product);
|
||||
$newTitle = $title . ' ' . $this->store->load('fixture_third_store')->getCode();
|
||||
$options[0]->setTitle($newTitle);
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
$product->save();
|
||||
|
||||
$product = $this->productRepository->get('bundle-product', false, $secondStoreId, true);
|
||||
$options = $optionList->getItems($product);
|
||||
$this->assertCount(1, $options);
|
||||
$this->assertEquals(
|
||||
$title . ' ' . $this->store->load('fixture_second_store')->getCode(),
|
||||
$options[0]->getTitle()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test option link of the same product
|
||||
*
|
||||
* @return void
|
||||
* @throws LocalizedException
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
public function testOptionLinksOfSameProduct(): void
|
||||
{
|
||||
/** @var OptionList $optionList */
|
||||
$optionList = $this->objectManager->create(OptionList::class);
|
||||
$product = $this->productRepository->get('bundle-product', true, 0, true);
|
||||
|
||||
//set the first option
|
||||
$options = $this->setBundleProductOptionData();
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
$product->save();
|
||||
|
||||
$product = $this->productRepository->get('bundle-product', true, 0, true);
|
||||
$options = $optionList->getItems($product);
|
||||
$this->assertCount(1, $options);
|
||||
|
||||
//set the second option with same product
|
||||
$newOption = $this->setBundleProductOptionData();
|
||||
array_push($options, current($newOption));
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
$product->save();
|
||||
$this->assertCount(2, $options);
|
||||
|
||||
//remove one option and verify the count
|
||||
array_pop($options);
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
$product->save();
|
||||
|
||||
$product = $this->productRepository->get('bundle-product', true, 0, true);
|
||||
$options = $optionList->getItems($product);
|
||||
$this->assertCount(1, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set product option link
|
||||
*
|
||||
* @param $bundleLinks
|
||||
* @param $option
|
||||
* @return array
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
private function setProductLink($bundleLinks, $option): array
|
||||
{
|
||||
$links = [];
|
||||
$options = [];
|
||||
if (!empty($bundleLinks)) {
|
||||
foreach ($bundleLinks as $linkData) {
|
||||
if (!(bool)$linkData['delete']) {
|
||||
/** @var LinkInterface $link */
|
||||
$link = $this->objectManager->create(LinkInterfaceFactory::class)
|
||||
->create(['data' => $linkData]);
|
||||
$linkProduct = $this->productRepository->getById($linkData['product_id']);
|
||||
$link->setSku($linkProduct->getSku());
|
||||
$link->setQty($linkData['selection_qty']);
|
||||
$link->setPrice($linkData['selection_price_value']);
|
||||
if (isset($linkData['selection_can_change_qty'])) {
|
||||
$link->setCanChangeQuantity($linkData['selection_can_change_qty']);
|
||||
}
|
||||
$links[] = $link;
|
||||
}
|
||||
}
|
||||
$option->setProductLinks($links);
|
||||
$options[] = $option;
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set product option
|
||||
*
|
||||
* @return array
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
private function setProductOption(): array
|
||||
{
|
||||
$options = [];
|
||||
$product = $this->productRepository->get('bundle-product', true);
|
||||
foreach ($product->getBundleOptionsData() as $optionData) {
|
||||
if (!(bool)$optionData['delete']) {
|
||||
$option = $this->objectManager->create(OptionInterfaceFactory::class)
|
||||
->create(['data' => $optionData]);
|
||||
$option->setSku($product->getSku());
|
||||
$option->setOptionId(null);
|
||||
|
||||
$bundleLinks = $product->getBundleSelectionsData();
|
||||
if (!empty($bundleLinks)) {
|
||||
$options = $this->setProductLink(current($bundleLinks), $option);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set bundle product option data
|
||||
*
|
||||
* @return array
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
private function setBundleProductOptionData(): array
|
||||
{
|
||||
$options = [];
|
||||
$product = $this->productRepository->get('bundle-product', true);
|
||||
$simpleProduct = $this->productRepository->get('simple');
|
||||
$product->setBundleOptionsData(
|
||||
[
|
||||
[
|
||||
'title' => 'Bundle Product Items',
|
||||
'default_title' => 'Bundle Product Items',
|
||||
'type' => 'select', 'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
]
|
||||
);
|
||||
$product->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => $simpleProduct->getId(),
|
||||
'selection_price_value' => 10,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
if ($product->getBundleOptionsData()) {
|
||||
$options = $this->setProductOption();
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Bundle\Model\Product;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Bundle\Model\Product\Type (bundle product type)
|
||||
*/
|
||||
class TypeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
/**
|
||||
* Full reindex
|
||||
*
|
||||
* @var \Magento\Framework\Indexer\IndexerInterface
|
||||
*/
|
||||
protected $indexer;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\ResourceConnection
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* Connection adapter
|
||||
*
|
||||
* @var \Magento\Framework\DB\Adapter\AdapterInterface
|
||||
*/
|
||||
protected $connectionMock;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
/** @var \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry */
|
||||
$indexerRegistry = $this->objectManager->create(\Magento\Framework\Indexer\IndexerRegistry::class);
|
||||
$this->indexer = $indexerRegistry->get('catalogsearch_fulltext');
|
||||
|
||||
$this->resource = $this->objectManager->get(\Magento\Framework\App\ResourceConnection::class);
|
||||
$this->connectionMock = $this->resource->getConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/product.php
|
||||
* @covers \Magento\Bundle\Model\Product\Type::getSearchableData
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testGetSearchableData()
|
||||
{
|
||||
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
/** @var \Magento\Catalog\Model\Product $bundleProduct */
|
||||
$bundleProduct = $productRepository->get('bundle-product');
|
||||
$bundleType = $bundleProduct->getTypeInstance();
|
||||
/** @var \Magento\Bundle\Model\Product\Type $bundleType */
|
||||
$searchableData = $bundleType->getSearchableData($bundleProduct);
|
||||
|
||||
$this->assertCount(1, $searchableData);
|
||||
$this->assertEquals('Bundle Product Items', $searchableData[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/product_with_multiple_options.php
|
||||
* @covers \Magento\Bundle\Model\Product\Type::getOptionsCollection
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testGetOptionsCollection()
|
||||
{
|
||||
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
/** @var \Magento\Catalog\Model\Product $bundleProduct */
|
||||
$bundleProduct = $productRepository->get('bundle-product');
|
||||
$bundleType = $bundleProduct->getTypeInstance();
|
||||
/** @var \Magento\Bundle\Model\Product\Type $bundleType */
|
||||
$options = $bundleType->getOptionsCollection($bundleProduct);
|
||||
$this->assertCount(5, $options->getItems());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/product.php
|
||||
* @covers \Magento\Bundle\Model\Product\Type::getParentIdsByChild()
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testGetParentIdsByChild()
|
||||
{
|
||||
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
/** @var \Magento\Catalog\Api\Data\ProductInterface $bundleProduct */
|
||||
$bundleProduct = $productRepository->get('bundle-product');
|
||||
/** @var \Magento\Catalog\Api\Data\ProductInterface $simpleProduct */
|
||||
$simpleProduct = $productRepository->get('simple');
|
||||
|
||||
/** @var \Magento\Bundle\Model\Product\Type $bundleType */
|
||||
$bundleType = $bundleProduct->getTypeInstance();
|
||||
$parentIds = $bundleType->getParentIdsByChild($simpleProduct->getId());
|
||||
$this->assertNotEmpty($parentIds);
|
||||
$this->assertEquals($bundleProduct->getId(), $parentIds[0]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,405 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* As far none class is present as separate bundle product,
|
||||
* this test is clone of \Magento\Catalog\Model\Product with product type "bundle"
|
||||
*/
|
||||
namespace Magento\Bundle\Model;
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Bundle\Model\Product\Type as BundleType;
|
||||
use Magento\Catalog\Api\Data\ProductInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\CatalogInventory\Api\Data\StockItemInterface;
|
||||
use Magento\CatalogInventory\Api\StockConfigurationInterface;
|
||||
use Magento\CatalogInventory\Api\StockItemCriteriaInterfaceFactory;
|
||||
use Magento\CatalogInventory\Api\StockItemRepositoryInterface;
|
||||
use Magento\CatalogInventory\Model\Stock;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Store\Api\StoreRepositoryInterface;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Entity;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class ProductTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Product
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$this->model = $this->objectManager->create(Product::class);
|
||||
$this->model->setTypeId(Type::TYPE_BUNDLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Retrieve ans set type instance of the product
|
||||
*
|
||||
* @see \Magento\Catalog\Model\Product::getTypeInstance
|
||||
* @see \Magento\Catalog\Model\Product::setTypeInstance
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSetTypeInstance()
|
||||
{
|
||||
// model getter
|
||||
$typeInstance = $this->model->getTypeInstance();
|
||||
$this->assertInstanceOf(BundleType::class, $typeInstance);
|
||||
$this->assertSame($typeInstance, $this->model->getTypeInstance());
|
||||
|
||||
// singleton getter
|
||||
$otherProduct = $this->objectManager->create(Product::class);
|
||||
$otherProduct->setTypeId(Type::TYPE_BUNDLE);
|
||||
$this->assertSame($typeInstance, $otherProduct->getTypeInstance());
|
||||
|
||||
// model setter
|
||||
$customTypeInstance = $this->objectManager->create(BundleType::class);
|
||||
$this->model->setTypeInstance($customTypeInstance);
|
||||
$this->assertSame($customTypeInstance, $this->model->getTypeInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
public function testCRUD()
|
||||
{
|
||||
$this->model->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId(4)
|
||||
->setName('Bundle Product')
|
||||
->setSku(uniqid())
|
||||
->setPrice(10)
|
||||
->setMetaTitle('meta title')
|
||||
->setMetaKeyword('meta keyword')
|
||||
->setMetaDescription('meta description')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED);
|
||||
$crud = new Entity($this->model, ['sku' => uniqid()]);
|
||||
$crud->testCrud();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Get product price model
|
||||
*
|
||||
* @see \Magento\Catalog\Model\Product::getPriceModel
|
||||
* @return void
|
||||
*/
|
||||
public function testGetPriceModel()
|
||||
{
|
||||
$this->model->setTypeId(Type::TYPE_BUNDLE);
|
||||
$type = $this->model->getPriceModel();
|
||||
$this->assertInstanceOf(Price::class, $type);
|
||||
$this->assertSame($type, $this->model->getPriceModel());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Check is product composite
|
||||
*
|
||||
* @see \Magento\Catalog\Model\Product::isComposite
|
||||
* @return void
|
||||
*/
|
||||
public function testIsComposite()
|
||||
{
|
||||
$this->assertTrue($this->model->isComposite());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a case when bundle product is should be available per multiple stores.
|
||||
*
|
||||
* @magentoDataFixture Magento/Bundle/_files/product_with_multiple_options.php
|
||||
* @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testMultipleStores()
|
||||
{
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
|
||||
$bundle = $productRepository->get('bundle-product');
|
||||
|
||||
/** @var StoreRepositoryInterface $storeRepository */
|
||||
$storeRepository = $this->objectManager->get(StoreRepositoryInterface::class);
|
||||
$store = $storeRepository->get('fixture_second_store');
|
||||
|
||||
self::assertNotEquals($store->getId(), $bundle->getStoreId());
|
||||
|
||||
/** @var StoreManagerInterface $storeManager */
|
||||
$storeManager = $this->objectManager->get(StoreManagerInterface::class);
|
||||
$storeManager->setCurrentStore($store->getId());
|
||||
|
||||
$bundle->setStoreId($store->getId())
|
||||
->setCopyFromView(true);
|
||||
$updatedBundle = $productRepository->save($bundle);
|
||||
|
||||
self::assertEquals($store->getId(), $updatedBundle->getStoreId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $selectionQty
|
||||
* @param float $qty
|
||||
* @param int $isInStock
|
||||
* @param bool $manageStock
|
||||
* @param int $backorders
|
||||
* @param bool $isSalable
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Bundle/_files/product.php
|
||||
* @dataProvider stockConfigDataProvider
|
||||
* @covers \Magento\Catalog\Model\Product::isSalable
|
||||
*/
|
||||
public function testIsSalable(
|
||||
float $selectionQty,
|
||||
float $qty,
|
||||
int $isInStock,
|
||||
bool $manageStock,
|
||||
int $backorders,
|
||||
bool $isSalable
|
||||
) {
|
||||
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
$child = $productRepository->get('simple');
|
||||
$childStockItem = $child->getExtensionAttributes()->getStockItem();
|
||||
$childStockItem->setQty($qty);
|
||||
$childStockItem->setIsInStock($isInStock);
|
||||
$childStockItem->setUseConfigManageStock(false);
|
||||
$childStockItem->setManageStock($manageStock);
|
||||
$childStockItem->setUseConfigBackorders(false);
|
||||
$childStockItem->setBackorders($backorders);
|
||||
$productRepository->save($child);
|
||||
|
||||
/** @var \Magento\Catalog\Model\Product $bundle */
|
||||
$bundle = $productRepository->get('bundle-product');
|
||||
foreach ($bundle->getExtensionAttributes()->getBundleProductOptions() as $productOption) {
|
||||
foreach ($productOption->getProductLinks() as $productLink) {
|
||||
$productLink->setCanChangeQuantity(0);
|
||||
$productLink->setQty($selectionQty);
|
||||
}
|
||||
}
|
||||
$bundle = $productRepository->save($bundle);
|
||||
|
||||
$this->assertEquals($isSalable, $bundle->isSalable());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function stockConfigDataProvider(): array
|
||||
{
|
||||
$qtyVars = [0, 10];
|
||||
$isInStockVars = [
|
||||
Stock::STOCK_OUT_OF_STOCK,
|
||||
Stock::STOCK_IN_STOCK,
|
||||
];
|
||||
$manageStockVars = [false, true];
|
||||
$backordersVars = [
|
||||
Stock::BACKORDERS_NO,
|
||||
Stock::BACKORDERS_YES_NONOTIFY,
|
||||
Stock::BACKORDERS_YES_NOTIFY,
|
||||
];
|
||||
$selectionQtyVars = [5, 10, 15];
|
||||
|
||||
$variations = [];
|
||||
foreach ($qtyVars as $qty) {
|
||||
foreach ($isInStockVars as $isInStock) {
|
||||
foreach ($manageStockVars as $manageStock) {
|
||||
foreach ($backordersVars as $backorders) {
|
||||
foreach ($selectionQtyVars as $selectionQty) {
|
||||
$variationName = "selectionQty: {$selectionQty}"
|
||||
. " qty: {$qty}"
|
||||
. " isInStock: {$isInStock}"
|
||||
. " manageStock: {$manageStock}"
|
||||
. " backorders: {$backorders}";
|
||||
$isSalable = $this->checkIsSalable(
|
||||
$selectionQty,
|
||||
$qty,
|
||||
$isInStock,
|
||||
$manageStock,
|
||||
$backorders
|
||||
);
|
||||
|
||||
$variations[$variationName] = [
|
||||
$selectionQty,
|
||||
$qty,
|
||||
$isInStock,
|
||||
$manageStock,
|
||||
$backorders,
|
||||
$isSalable
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $variations;
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Bundle/_files/bundle_product_with_dynamic_price.php
|
||||
* @dataProvider shouldUpdateBundleStockStatusIfChildProductsStockStatusChangedDataProvider
|
||||
* @param bool $isOption1Required
|
||||
* @param bool $isOption2Required
|
||||
* @param array $outOfStockConfig
|
||||
* @param array $inStockConfig
|
||||
* @throws NoSuchEntityException
|
||||
* @throws \Magento\Framework\Exception\CouldNotSaveException
|
||||
* @throws \Magento\Framework\Exception\InputException
|
||||
* @throws \Magento\Framework\Exception\StateException
|
||||
*/
|
||||
public function testShouldUpdateBundleStockStatusIfChildProductsStockStatusChanged(
|
||||
bool $isOption1Required,
|
||||
bool $isOption2Required,
|
||||
array $outOfStockConfig,
|
||||
array $inStockConfig
|
||||
): void {
|
||||
$sku = 'bundle_product_with_dynamic_price';
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
|
||||
/** @var ProductInterface $product */
|
||||
$product = $productRepository->get($sku, true, null, true);
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$options = $extension->getBundleProductOptions();
|
||||
$options[0]->setRequired($isOption1Required);
|
||||
$options[1]->setRequired($isOption2Required);
|
||||
$extension->setBundleProductOptions($options);
|
||||
$stockItem = $extension->getStockItem();
|
||||
$stockItem->setUseConfigManageStock(1);
|
||||
$product->setExtensionAttributes($extension);
|
||||
$productRepository->save($product);
|
||||
|
||||
$stockItem = $this->getStockItem((int) $product->getId());
|
||||
$this->assertNotNull($stockItem);
|
||||
$this->assertTrue($stockItem->getIsInStock());
|
||||
foreach ($outOfStockConfig as $childSku => $stockData) {
|
||||
$this->updateStockItem($childSku, $stockData);
|
||||
}
|
||||
|
||||
$stockItem = $this->getStockItem((int) $product->getId());
|
||||
$this->assertNotNull($stockItem);
|
||||
$this->assertFalse($stockItem->getIsInStock());
|
||||
foreach ($inStockConfig as $childSku => $stockData) {
|
||||
$this->updateStockItem($childSku, $stockData);
|
||||
}
|
||||
|
||||
$stockItem = $this->getStockItem((int) $product->getId());
|
||||
$this->assertNotNull($stockItem);
|
||||
$this->assertTrue($stockItem->getIsInStock());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function shouldUpdateBundleStockStatusIfChildProductsStockStatusChangedDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'all options are required' => [
|
||||
true,
|
||||
true,
|
||||
'out-of-stock' => [
|
||||
'simple1' => [
|
||||
'is_in_stock' => false
|
||||
],
|
||||
],
|
||||
'in-stock' => [
|
||||
'simple1' => [
|
||||
'is_in_stock' => true
|
||||
]
|
||||
]
|
||||
],
|
||||
'all options are optional' => [
|
||||
false,
|
||||
false,
|
||||
'out-of-stock' => [
|
||||
'simple1' => [
|
||||
'is_in_stock' => false
|
||||
],
|
||||
'simple2' => [
|
||||
'is_in_stock' => false
|
||||
],
|
||||
],
|
||||
'in-stock' => [
|
||||
'simple1' => [
|
||||
'is_in_stock' => true
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sku
|
||||
* @param array $data
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
private function updateStockItem(string $sku, array $data): void
|
||||
{
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get($sku, true, null, true);
|
||||
$extendedAttributes = $product->getExtensionAttributes();
|
||||
$stockItem = $extendedAttributes->getStockItem();
|
||||
$stockItem->setIsInStock($data['is_in_stock']);
|
||||
$extendedAttributes->setStockItem($stockItem);
|
||||
$product->setExtensionAttributes($extendedAttributes);
|
||||
$productRepository->save($product);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @return StockItemInterface|null
|
||||
*/
|
||||
private function getStockItem(int $productId): ?StockItemInterface
|
||||
{
|
||||
$criteriaFactory = $this->objectManager->create(StockItemCriteriaInterfaceFactory::class);
|
||||
$stockItemRepository = $this->objectManager->create(StockItemRepositoryInterface::class);
|
||||
$stockConfiguration = $this->objectManager->create(StockConfigurationInterface::class);
|
||||
$criteria = $criteriaFactory->create();
|
||||
$criteria->setScopeFilter($stockConfiguration->getDefaultScopeId());
|
||||
$criteria->setProductsFilter($productId);
|
||||
$stockItemCollection = $stockItemRepository->getList($criteria);
|
||||
$stockItems = $stockItemCollection->getItems();
|
||||
return reset($stockItems);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $selectionQty
|
||||
* @param float $qty
|
||||
* @param int $isInStock
|
||||
* @param bool $manageStock
|
||||
* @param int $backorders
|
||||
* @return bool
|
||||
* @see \Magento\Bundle\Model\ResourceModel\Selection\Collection::addQuantityFilter
|
||||
*/
|
||||
private function checkIsSalable(
|
||||
float $selectionQty,
|
||||
float $qty,
|
||||
int $isInStock,
|
||||
bool $manageStock,
|
||||
int $backorders
|
||||
): bool {
|
||||
return !$manageStock || ($isInStock && ($backorders || $selectionQty <= $qty));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Model;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Integration tests for \Magento\Bundle\Model\QuoteRecollectProcessor class.
|
||||
*/
|
||||
class QuoteRecollectProcessorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var GetQuoteByReservedOrderId
|
||||
*/
|
||||
private $getQuoteByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @var ProductRepositoryInterface
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
/**
|
||||
* @var PrepareBundleLinks
|
||||
*/
|
||||
private $prepareBundleLinks;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->getQuoteByReservedOrderId = $objectManager->get(GetQuoteByReservedOrderId::class);
|
||||
$this->productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$this->prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that quote marked to recollect after bundle product options or selections changed.
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Bundle/_files/quote_with_fixed_bundle_product.php
|
||||
* @dataProvider getBundleOptionsDataProvider
|
||||
* @param array $optionsData
|
||||
* @param array $selectionsData
|
||||
* @param string $expectedTriggerRecollect
|
||||
* @return void
|
||||
*/
|
||||
public function testMarkQuoteRecollectAfterChangeBundleOptions(
|
||||
array $optionsData,
|
||||
array $selectionsData,
|
||||
string $expectedTriggerRecollect
|
||||
): void {
|
||||
$quote = $this->getQuoteByReservedOrderId->execute('test_cart_with_fixed_bundle');
|
||||
$this->assertFalse((bool)$quote->getTriggerRecollect());
|
||||
$this->updateBundleProduct('fixed_bundle_product_without_discounts', $optionsData, $selectionsData);
|
||||
$updatedQuote = $this->getQuoteByReservedOrderId->execute('test_cart_with_fixed_bundle');
|
||||
$this->assertEquals($expectedTriggerRecollect, $updatedQuote->getTriggerRecollect());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getBundleOptionsDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'product option changed' => [
|
||||
[
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'radio',
|
||||
'required' => 0,
|
||||
'delete' => '',
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 10,
|
||||
'selection_price_type' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
],
|
||||
'1',
|
||||
],
|
||||
'product link changed' => [
|
||||
[
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'radio',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'selection_qty' => 2,
|
||||
'selection_price_value' => 15,
|
||||
'selection_price_type' => 1,
|
||||
'selection_can_change_qty' => 0,
|
||||
],
|
||||
],
|
||||
'1',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates bundle product options and selections.
|
||||
*
|
||||
* @param string $sku
|
||||
* @param array $optionsData
|
||||
* @param array $selectionsData
|
||||
* @return void
|
||||
*/
|
||||
private function updateBundleProduct(string $sku, array $optionsData, array $selectionsData): void
|
||||
{
|
||||
$product = $this->productRepository->get($sku);
|
||||
$option = current($product->getExtensionAttributes()->getBundleProductOptions());
|
||||
$optionsData[0]['option_id'] = $option->getId();
|
||||
$updatedProduct = $this->prepareBundleLinks->execute($product, $optionsData, [$selectionsData]);
|
||||
$this->productRepository->save($updatedProduct);
|
||||
}
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Bundle\Model\ResourceModel\Indexer;
|
||||
|
||||
use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Indexer\Product\Price;
|
||||
use Magento\Customer\Model\Group;
|
||||
use Magento\Framework\Indexer\ActionInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Catalog\Model\Product\Price\GetPriceIndexDataByProductId;
|
||||
use Magento\CatalogInventory\Model\Indexer\Stock;
|
||||
use Magento\TestFramework\Fixture\DataFixture;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class PriceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var ActionInterface
|
||||
*/
|
||||
private $indexer;
|
||||
|
||||
/**
|
||||
* @var GetPriceIndexDataByProductId
|
||||
*/
|
||||
private $getPriceIndexDataByProductId;
|
||||
|
||||
/**
|
||||
* @var ProductRepositoryInterface
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
/**
|
||||
* @var WebsiteRepositoryInterface
|
||||
*/
|
||||
private $websiteRepository;
|
||||
|
||||
/**
|
||||
* @var Stock
|
||||
*/
|
||||
private $stockIndexer;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->indexer = $this->objectManager->get(Price::class);
|
||||
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
|
||||
$this->getPriceIndexDataByProductId = $this->objectManager->get(GetPriceIndexDataByProductId::class);
|
||||
$this->websiteRepository = $this->objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$this->stockIndexer = $this->objectManager->get(Stock::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get bundle index price if enabled show out off stock
|
||||
*
|
||||
* @magentoDbIsolation disabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Bundle/_files/bundle_product_with_dynamic_price.php
|
||||
* @magentoConfigFixture default_store cataloginventory/options/show_out_of_stock 1
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExecuteRowWithShowOutOfStock(): void
|
||||
{
|
||||
|
||||
$expectedPrices = [
|
||||
'price' => 0,
|
||||
'final_price' => 0,
|
||||
'min_price' => 15.99,
|
||||
'max_price' => 15.99,
|
||||
'tier_price' => null
|
||||
];
|
||||
$product = $this->productRepository->get('simple1');
|
||||
$product->setStockData(['qty' => 0]);
|
||||
$this->productRepository->save($product);
|
||||
$this->stockIndexer->executeRow($product->getId());
|
||||
$bundleProduct = $this->productRepository->get('bundle_product_with_dynamic_price');
|
||||
$this->indexer->executeRow($bundleProduct->getId());
|
||||
$this->assertIndexTableData($bundleProduct->getId(), $expectedPrices);
|
||||
}
|
||||
|
||||
#[
|
||||
DataFixture(
|
||||
BundleProductFixture::class,
|
||||
['sku' => 'bundle1', 'extension_attributes' => ['website_ids' => []]]
|
||||
),
|
||||
]
|
||||
public function testExecuteForBundleWithoutWebsites(): void
|
||||
{
|
||||
$bundleProduct = $this->productRepository->get('bundle1');
|
||||
$this->indexer->executeRow($bundleProduct->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts price data in index table.
|
||||
*
|
||||
* @param int $productId
|
||||
* @param array $expectedPrices
|
||||
* @return void
|
||||
*/
|
||||
private function assertIndexTableData(int $productId, array $expectedPrices): void
|
||||
{
|
||||
$data = $this->getPriceIndexDataByProductId->execute(
|
||||
$productId,
|
||||
Group::NOT_LOGGED_IN_ID,
|
||||
(int)$this->websiteRepository->get('base')->getId()
|
||||
);
|
||||
$data = reset($data);
|
||||
foreach ($expectedPrices as $column => $price) {
|
||||
$this->assertEquals($price, $data[$column]);
|
||||
}
|
||||
}
|
||||
}
|
||||
+201
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Bundle\Model\ResourceModel\Indexer;
|
||||
|
||||
use Magento\Bundle\Test\Fixture\Link as BundleSelectionFixture;
|
||||
use Magento\Bundle\Test\Fixture\Option as BundleOptionFixture;
|
||||
use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
|
||||
use Magento\CatalogInventory\Model\ResourceModel\Stock\Status as StockStatusResource;
|
||||
use Magento\TestFramework\Fixture\DataFixture;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class StockTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\CatalogInventory\Model\Indexer\Stock\Processor
|
||||
*/
|
||||
protected $processor;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->processor = Bootstrap::getObjectManager()->get(
|
||||
\Magento\CatalogInventory\Model\Indexer\Stock\Processor::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation disabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Bundle/_files/product_in_category.php
|
||||
*/
|
||||
public function testReindexAll()
|
||||
{
|
||||
$this->processor->reindexAll();
|
||||
|
||||
$categoryFactory = Bootstrap::getObjectManager()->get(
|
||||
\Magento\Catalog\Model\CategoryFactory::class
|
||||
);
|
||||
/** @var \Magento\Catalog\Block\Product\ListProduct $listProduct */
|
||||
$listProduct = Bootstrap::getObjectManager()->get(
|
||||
\Magento\Catalog\Block\Product\ListProduct::class
|
||||
);
|
||||
|
||||
$category = $categoryFactory->create()->load(2);
|
||||
$layer = $listProduct->getLayer();
|
||||
$layer->setCurrentCategory($category);
|
||||
$productCollection = $layer->getProductCollection();
|
||||
$productCollection->joinField(
|
||||
'qty',
|
||||
'cataloginventory_stock_status',
|
||||
'qty',
|
||||
'product_id=entity_id',
|
||||
'{{table}}.stock_id=1',
|
||||
'left'
|
||||
);
|
||||
|
||||
$this->assertCount(3, $productCollection);
|
||||
|
||||
$expectedResult = [
|
||||
'Simple Product' => 22,
|
||||
'Custom Design Simple Product' => 24,
|
||||
'Bundle Product' => 0
|
||||
];
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
foreach ($productCollection as $product) {
|
||||
$this->assertEquals($expectedResult[$product->getName()], $product->getQty());
|
||||
}
|
||||
}
|
||||
|
||||
#[
|
||||
DataFixture(
|
||||
ProductFixture::class,
|
||||
['sku' => 'simple1', 'stock_item' => ['use_config_manage_stock' => 0, 'use_config_backorders' => 0]],
|
||||
's1'
|
||||
),
|
||||
DataFixture(
|
||||
ProductFixture::class,
|
||||
['sku' => 'simple2', 'stock_item' => ['use_config_manage_stock' => 0, 'use_config_backorders' => 0]],
|
||||
's2'
|
||||
),
|
||||
DataFixture(
|
||||
ProductFixture::class,
|
||||
['sku' => 'simple3', 'stock_item' => ['use_config_manage_stock' => 0, 'use_config_backorders' => 0]],
|
||||
's3'
|
||||
),
|
||||
DataFixture(
|
||||
ProductFixture::class,
|
||||
['sku' => 'simple4', 'stock_item' => ['use_config_manage_stock' => 0, 'use_config_backorders' => 0]],
|
||||
's4'
|
||||
),
|
||||
DataFixture(
|
||||
BundleSelectionFixture::class,
|
||||
['sku' => '$s1.sku$', 'qty' => 2, 'can_change_quantity' => 0],
|
||||
'link1'
|
||||
),
|
||||
DataFixture(
|
||||
BundleSelectionFixture::class,
|
||||
['sku' => '$s2.sku$', 'qty' => 2, 'can_change_quantity' => 0],
|
||||
'link2'
|
||||
),
|
||||
DataFixture(
|
||||
BundleSelectionFixture::class,
|
||||
['sku' => '$s3.sku$', 'qty' => 2, 'can_change_quantity' => 1],
|
||||
'link3'
|
||||
),
|
||||
DataFixture(
|
||||
BundleSelectionFixture::class,
|
||||
['sku' => '$s4.sku$', 'qty' => 2, 'can_change_quantity' => 0],
|
||||
'link4'
|
||||
),
|
||||
DataFixture(BundleOptionFixture::class, ['product_links' => ['$link1$', '$link2$']], 'opt1'),
|
||||
DataFixture(BundleOptionFixture::class, ['product_links' => ['$link3$']], 'opt2'),
|
||||
DataFixture(BundleOptionFixture::class, ['product_links' => ['$link4$'], 'required' => false], 'opt3'),
|
||||
DataFixture(BundleProductFixture::class, ['sku' => 'bundle1', '_options' => ['$opt1$', '$opt2$', '$opt3$']]),
|
||||
]
|
||||
/**
|
||||
* @dataProvider reindexRowDataProvider
|
||||
* @param array $stockItems
|
||||
* @param bool $expectedStockStatus
|
||||
* @return void
|
||||
*/
|
||||
public function testReindexRow(array $stockItems, bool $expectedStockStatus): void
|
||||
{
|
||||
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
|
||||
foreach ($stockItems as $sku => $stockItem) {
|
||||
$child = $productRepository->get($sku);
|
||||
$child->setStockData($stockItem);
|
||||
$productRepository->save($child);
|
||||
}
|
||||
$bundle = $productRepository->get('bundle1');
|
||||
$this->processor->reindexRow($bundle->getId());
|
||||
|
||||
$stockStatusResource = Bootstrap::getObjectManager()->get(StockStatusResource::class);
|
||||
$stockStatus = $stockStatusResource->getProductsStockStatuses($bundle->getId(), 0);
|
||||
self::assertEquals($expectedStockStatus, (bool) $stockStatus[$bundle->getId()]);
|
||||
}
|
||||
|
||||
public function reindexRowDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
[
|
||||
'simple1' => ['manage_stock' => true, 'backorders' => false, 'qty' => 2],
|
||||
'simple2' => ['manage_stock' => true, 'backorders' => false, 'qty' => 2],
|
||||
'simple3' => ['manage_stock' => true, 'backorders' => false, 'qty' => 2],
|
||||
'simple4' => ['manage_stock' => true, 'backorders' => false, 'qty' => 2],
|
||||
],
|
||||
true,
|
||||
],
|
||||
[
|
||||
[
|
||||
'simple1' => ['manage_stock' => true, 'backorders' => false, 'qty' => 1],
|
||||
'simple3' => ['manage_stock' => true, 'backorders' => false, 'qty' => 1],
|
||||
'simple4' => ['manage_stock' => true, 'backorders' => false, 'qty' => 1],
|
||||
],
|
||||
true,
|
||||
],
|
||||
[
|
||||
[
|
||||
'simple1' => ['manage_stock' => true, 'backorders' => false, 'qty' => 1],
|
||||
'simple2' => ['manage_stock' => true, 'backorders' => false, 'qty' => 1],
|
||||
],
|
||||
false,
|
||||
],
|
||||
[
|
||||
[
|
||||
'simple3' => ['manage_stock' => true, 'backorders' => false, 'qty' => 0],
|
||||
],
|
||||
false,
|
||||
],
|
||||
[
|
||||
[
|
||||
'simple4' => ['manage_stock' => true, 'backorders' => false, 'qty' => 0],
|
||||
],
|
||||
true,
|
||||
],
|
||||
[
|
||||
[
|
||||
'simple1' => ['manage_stock' => false, 'backorders' => false, 'qty' => 0],
|
||||
'simple2' => ['manage_stock' => false, 'backorders' => false, 'qty' => 0],
|
||||
'simple3' => ['manage_stock' => false, 'backorders' => false, 'qty' => 0],
|
||||
],
|
||||
true,
|
||||
],
|
||||
[
|
||||
[
|
||||
'simple1' => ['manage_stock' => true, 'backorders' => true, 'qty' => 0],
|
||||
'simple2' => ['manage_stock' => true, 'backorders' => true, 'qty' => 0],
|
||||
'simple3' => ['manage_stock' => true, 'backorders' => true, 'qty' => 0],
|
||||
],
|
||||
true,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Model\ResourceModel\Option;
|
||||
|
||||
use Magento\Bundle\Test\Fixture\Link as BundleSelectionFixture;
|
||||
use Magento\Bundle\Test\Fixture\Option as BundleOptionFixture;
|
||||
use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
|
||||
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
|
||||
use Magento\Store\Api\StoreRepositoryInterface;
|
||||
use Magento\Store\Test\Fixture\Group as StoreGroupFixture;
|
||||
use Magento\Store\Test\Fixture\Store as StoreFixture;
|
||||
use Magento\Store\Test\Fixture\Website as WebsiteFixture;
|
||||
use Magento\TestFramework\Fixture\DataFixture;
|
||||
use Magento\TestFramework\Fixture\DbIsolation;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AreBundleOptionsSalableTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var AreBundleOptionsSalable
|
||||
*/
|
||||
private $areBundleOptionsSalable;
|
||||
|
||||
/**
|
||||
* @var ProductRepositoryInterface
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
/**
|
||||
* @var StoreRepositoryInterface
|
||||
*/
|
||||
private $storeRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->areBundleOptionsSalable = Bootstrap::getObjectManager()->create(AreBundleOptionsSalable::class);
|
||||
$this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
|
||||
$this->storeRepository = Bootstrap::getObjectManager()->get(StoreRepositoryInterface::class);
|
||||
}
|
||||
|
||||
#[
|
||||
DbIsolation(false),
|
||||
DataFixture(WebsiteFixture::class, as: 'website2'),
|
||||
DataFixture(StoreGroupFixture::class, ['website_id' => '$website2.id$'], 'group2'),
|
||||
DataFixture(StoreFixture::class, ['store_group_id' => '$group2.id$', 'code' => 'store2'], 'store2'),
|
||||
DataFixture(ProductFixture::class, ['sku' => 'simple1', 'website_ids' => [1, '$website2.id']], 's1'),
|
||||
DataFixture(ProductFixture::class, ['sku' => 'simple2', 'website_ids' => [1, '$website2.id']], 's2'),
|
||||
DataFixture(ProductFixture::class, ['sku' => 'simple3', 'website_ids' => [1, '$website2.id']], 's3'),
|
||||
DataFixture(BundleSelectionFixture::class, ['sku' => '$s1.sku$'], 'link1'),
|
||||
DataFixture(BundleSelectionFixture::class, ['sku' => '$s2.sku$'], 'link2'),
|
||||
DataFixture(BundleSelectionFixture::class, ['sku' => '$s3.sku$'], 'link3'),
|
||||
DataFixture(BundleOptionFixture::class, ['product_links' => ['$link1$', '$link2$']], 'opt1'),
|
||||
DataFixture(BundleOptionFixture::class, ['product_links' => ['$link3$'], 'required' => false], 'opt2'),
|
||||
DataFixture(
|
||||
BundleProductFixture::class,
|
||||
['sku' => 'bundle1', '_options' => ['$opt1$', '$opt2$'], 'website_ids' => [1, '$website2.id']]
|
||||
),
|
||||
]
|
||||
/**
|
||||
* @dataProvider executeDataProvider
|
||||
* @param string $storeCodeForChange
|
||||
* @param array $disabledChildren
|
||||
* @param string $storeCodeForCheck
|
||||
* @param bool $expectedResult
|
||||
* @return void
|
||||
*/
|
||||
public function testExecute(
|
||||
string $storeCodeForChange,
|
||||
array $disabledChildren,
|
||||
string $storeCodeForCheck,
|
||||
bool $expectedResult
|
||||
): void {
|
||||
$storeForChange = $this->storeRepository->get($storeCodeForChange);
|
||||
foreach ($disabledChildren as $childSku) {
|
||||
$child = $this->productRepository->get($childSku, true, $storeForChange->getId(), true);
|
||||
$child->setStatus(ProductStatus::STATUS_DISABLED);
|
||||
$this->productRepository->save($child);
|
||||
}
|
||||
|
||||
$bundle = $this->productRepository->get('bundle1');
|
||||
$storeForCheck = $this->storeRepository->get($storeCodeForCheck);
|
||||
$result = $this->areBundleOptionsSalable->execute((int) $bundle->getId(), (int) $storeForCheck->getId());
|
||||
self::assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function executeDataProvider(): array
|
||||
{
|
||||
return [
|
||||
['default', ['simple1'], 'default', true],
|
||||
['default', ['simple3'], 'default', true],
|
||||
['default', ['simple1', 'simple2'], 'default', false],
|
||||
['default', ['simple1', 'simple2'], 'store2', true],
|
||||
['store2', ['simple1', 'simple2', 'simple3'], 'store2', false],
|
||||
['store2', ['simple1', 'simple2', 'simple3'], 'default', true],
|
||||
['admin', ['simple1', 'simple2'], 'default', false],
|
||||
['admin', ['simple1', 'simple2'], 'store2', false],
|
||||
];
|
||||
}
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2023 Adobe
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Model\ResourceModel\Selection;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class CollectionTest extends \Magento\Bundle\Model\Product\BundlePriceAbstract
|
||||
{
|
||||
/**
|
||||
* @var CollectionFactory
|
||||
*/
|
||||
protected $collectionFactory;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->collectionFactory = Bootstrap::getObjectManager()->create(CollectionFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoIndexerDimensionMode catalog_product_price website
|
||||
* @magentoDataFixture Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product.php
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation disabled
|
||||
* @group indexer_dimension
|
||||
* @dataProvider getTestCases
|
||||
*/
|
||||
public function testAddPriceDataWithIndexerDimensionMode(array $strategy, int $expectedCount)
|
||||
{
|
||||
$this->prepareFixture($strategy, 'bundle_product');
|
||||
|
||||
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('bundle_product', false, null, true);
|
||||
|
||||
/** @var Collection $collection */
|
||||
$collection = $this->collectionFactory->create();
|
||||
$collection->setStoreId(0);
|
||||
$collection->addPriceFilter($product, true);
|
||||
$items = $collection->getItems();
|
||||
|
||||
$this->assertCount($expectedCount, $items);
|
||||
}
|
||||
|
||||
public function getTestCases()
|
||||
{
|
||||
return [
|
||||
'Dynamic bundle product with three Simple products' => [
|
||||
'variation' => $this->getBundleConfiguration(),
|
||||
'expectedCount' => 1
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function getBundleConfiguration()
|
||||
{
|
||||
$optionsData = [
|
||||
[
|
||||
'title' => 'op1',
|
||||
'required' => true,
|
||||
'type' => 'checkbox',
|
||||
'links' => [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'qty' => 3,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'qty' => 2,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple3',
|
||||
'qty' => 1,
|
||||
'price' => 100,
|
||||
'price_type' => 0,
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
'modifierName' => 'addSimpleProduct',
|
||||
'data' => [$optionsData]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Model\Sales\AdminOrder;
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Quote\Model\Quote\Address\Rate;
|
||||
use Magento\Quote\Model\Quote\Item as QuoteItem;
|
||||
use Magento\Sales\Model\AdminOrder\Create;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\Item as OrderItem;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Reorder with Bundle product integration tests.
|
||||
*
|
||||
* @see Create
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ReorderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var Create
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->model =$this->objectManager->get(Create::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Custom Price after reordering with Bundle product.
|
||||
*
|
||||
* @return void
|
||||
* @magentoDataFixture Magento/Bundle/_files/order_item_with_bundle_and_options.php
|
||||
*/
|
||||
public function testReorderBundleProductWithCustomPrice(): void
|
||||
{
|
||||
$customPrice = 300;
|
||||
/** @var $order Order */
|
||||
$order = $this->objectManager->create(Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
$this->model->initFromOrder($order);
|
||||
|
||||
/** @var QuoteItem[] $quoteItems */
|
||||
$quoteItems = $this->model->getQuote()->getAllItems();
|
||||
$firstQuoteItem = array_shift($quoteItems);
|
||||
self::assertNull($firstQuoteItem->getParentItemId());
|
||||
self::assertEquals($customPrice, (int)$firstQuoteItem->getCustomPrice());
|
||||
foreach ($quoteItems as $quoteItem) {
|
||||
self::assertEquals($firstQuoteItem->getId(), $quoteItem->getParentItemId());
|
||||
self::assertEquals(0, (int)$quoteItem->getCustomPrice());
|
||||
}
|
||||
|
||||
$customerMock = $this->getMockBuilder(\Magento\Customer\Model\Data\Customer::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(
|
||||
[
|
||||
'getGroupId',
|
||||
'getEmail',
|
||||
'_getExtensionAttributes'
|
||||
]
|
||||
)->getMock();
|
||||
$customerMock->method('getGroupId')
|
||||
->willReturn(1);
|
||||
$customerMock->method('getEmail')
|
||||
->willReturn('customer@example.com');
|
||||
$customerMock->method('_getExtensionAttributes')
|
||||
->willReturn(null);
|
||||
$this->model->getQuote()->setCustomer($customerMock);
|
||||
|
||||
$shippingMethod = 'freeshipping_freeshipping';
|
||||
/** @var Rate $rate */
|
||||
$rate = $this->objectManager->create(Rate::class);
|
||||
$rate->setCode($shippingMethod);
|
||||
$this->model->getQuote()->getShippingAddress()->addShippingRate($rate);
|
||||
$this->model->setPaymentData(['method' => 'checkmo']);
|
||||
$this->model->setIsValidate(true)->importPostData(['shipping_method' => $shippingMethod]);
|
||||
$newOrder = $this->model->createOrder();
|
||||
|
||||
/** @var OrderItem[] $orderItems */
|
||||
$orderItems = $newOrder->getAllItems();
|
||||
$firstOrderItem = array_shift($orderItems);
|
||||
self::assertNull($firstOrderItem->getParentItemId());
|
||||
self::assertEquals($customPrice, (int)$firstOrderItem->getPrice());
|
||||
foreach ($orderItems as $orderItem) {
|
||||
self::assertEquals($firstOrderItem->getId(), $orderItem->getParentItemId());
|
||||
self::assertEquals(0, (int)$orderItem->getPrice());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user