init
This commit is contained in:
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle\Option\Search;
|
||||
|
||||
class GridTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testToHtmlHasOnClick()
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getInstance()
|
||||
->loadArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
|
||||
/** @var $layout \Magento\Framework\View\LayoutInterface */
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\View\Layout::class,
|
||||
['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE]
|
||||
);
|
||||
$block = $layout->createBlock(
|
||||
\Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle\Option\Search\Grid::class,
|
||||
'block'
|
||||
);
|
||||
$block->setId('temp_id');
|
||||
|
||||
$html = $block->toHtml();
|
||||
|
||||
$regexpTemplate = '/\<script.*?\>.*?temp_id[^"]*\\.%s/is';
|
||||
$jsFuncs = ['doFilter', 'resetFilter'];
|
||||
foreach ($jsFuncs as $func) {
|
||||
$regexp = sprintf($regexpTemplate, $func);
|
||||
$this->assertMatchesRegularExpression($regexp, $html);
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle\Option;
|
||||
|
||||
class SearchTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
public function testToHtmlHasIndex()
|
||||
{
|
||||
/** @var $layout \Magento\Framework\View\LayoutInterface */
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\View\Layout::class
|
||||
);
|
||||
$block = $layout->createBlock(
|
||||
\Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle\Option\Search::class,
|
||||
'block2'
|
||||
);
|
||||
|
||||
$indexValue = 'magento_index_set_to_test';
|
||||
$block->setIndex($indexValue);
|
||||
|
||||
$html = $block->toHtml();
|
||||
$this->assertStringContainsString($indexValue, $html);
|
||||
}
|
||||
}
|
||||
+194
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Block\Catalog\Product\View\Type;
|
||||
|
||||
use Magento\Catalog\Api\Data\ProductInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class consist of basic logic for bundle options view
|
||||
*/
|
||||
abstract class AbstractBundleOptionsViewTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var ProductRepositoryInterface */
|
||||
private $productRepository;
|
||||
|
||||
/** @var SerializerInterface */
|
||||
private $serializer;
|
||||
|
||||
/** @var Registry */
|
||||
private $registry;
|
||||
|
||||
/** @var PageFactory */
|
||||
private $pageFactory;
|
||||
|
||||
/** @var ProductResource */
|
||||
private $productResource;
|
||||
|
||||
/** @var string */
|
||||
private $selectLabelXpath = "//fieldset[contains(@class, 'fieldset-bundle-options')]"
|
||||
. "//label/span[normalize-space(text()) = '%s']";
|
||||
|
||||
/** @var string */
|
||||
private $backToProductDetailButtonXpath = "//button[contains(@class, 'back customization')]";
|
||||
|
||||
/** @var string */
|
||||
private $titleXpath = "//fieldset[contains(@class, 'bundle-options')]//span[contains(text(), 'Customize %s')]";
|
||||
|
||||
/** @var string */
|
||||
private $singleOptionXpath = "//input[contains(@class, 'bundle-option') and contains(@type, 'hidden')]";
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
|
||||
$this->productRepository->cleanCache();
|
||||
$this->serializer = $this->objectManager->get(SerializerInterface::class);
|
||||
$this->registry = $this->objectManager->get(Registry::class);
|
||||
$this->pageFactory = $this->objectManager->get(PageFactory::class);
|
||||
$this->productResource = $this->objectManager->get(ProductResource::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->registry->unregister('product');
|
||||
$this->registry->unregister('current_product');
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process bundle options view with few selections
|
||||
*
|
||||
* @param string $sku
|
||||
* @param string $optionsSelectLabel
|
||||
* @param array $expectedSelectionsNames
|
||||
* @param bool $requiredOption
|
||||
* @return void
|
||||
*/
|
||||
protected function processMultiSelectionsView(
|
||||
string $sku,
|
||||
string $optionsSelectLabel,
|
||||
array $expectedSelectionsNames,
|
||||
bool $requiredOption = false
|
||||
): void {
|
||||
$product = $this->productRepository->get($sku);
|
||||
$result = $this->renderProductOptionsBlock($product);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath($this->backToProductDetailButtonXpath, $result),
|
||||
"'Back to product details' button doesn't exist on the page"
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(sprintf($this->selectLabelXpath, $optionsSelectLabel), $result),
|
||||
'Options select label does not exist on the page'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(sprintf($this->titleXpath, $product->getName()), $result),
|
||||
sprintf('Customize %s label does not exist on the page', $product->getName())
|
||||
);
|
||||
$selectPath = $requiredOption ? $this->getRequiredSelectXpath() : $this->getNotRequiredSelectXpath();
|
||||
foreach ($expectedSelectionsNames as $selection) {
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(sprintf($selectPath, $selection), $result),
|
||||
sprintf('Option for product named %s does not exist on the page', $selection)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process bundle options view with single selection
|
||||
*
|
||||
* @param string $sku
|
||||
* @param string $optionsSelectLabel
|
||||
* @return void
|
||||
*/
|
||||
protected function processSingleSelectionView(string $sku, string $optionsSelectLabel): void
|
||||
{
|
||||
$product = $this->productRepository->get($sku);
|
||||
$result = $this->renderProductOptionsBlock($product);
|
||||
$this->assertEquals(1, Xpath::getElementsCountForXpath($this->backToProductDetailButtonXpath, $result));
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(sprintf($this->selectLabelXpath, $optionsSelectLabel), $result),
|
||||
'Options select label does not exist on the page'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath($this->singleOptionXpath, $result),
|
||||
'Bundle product options select with single option does not display correctly'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register product
|
||||
*
|
||||
* @param ProductInterface $product
|
||||
* @return void
|
||||
*/
|
||||
private function registerProduct(ProductInterface $product): void
|
||||
{
|
||||
$this->registry->unregister('product');
|
||||
$this->registry->unregister('current_product');
|
||||
$this->registry->register('product', $product);
|
||||
$this->registry->register('current_product', $product);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render bundle product options block
|
||||
*
|
||||
* @param ProductInterface $product
|
||||
* @return string
|
||||
*/
|
||||
private function renderProductOptionsBlock(ProductInterface $product): string
|
||||
{
|
||||
$this->registerProduct($product);
|
||||
$page = $this->pageFactory->create();
|
||||
$page->addHandle(['default', 'catalog_product_view', 'catalog_product_view_type_bundle']);
|
||||
$page->getLayout()->generateXml();
|
||||
$block = $page->getLayout()->getBlock('product.info.bundle.options');
|
||||
|
||||
return $block->toHtml();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get required select Xpath
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getRequiredSelectXpath(): string;
|
||||
|
||||
/**
|
||||
* Get not required select Xpath
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getNotRequiredSelectXpath(): string;
|
||||
}
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Block\Catalog\Product\View\Type;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Check bundle product prices.
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation disabled
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class BundleProductPriceTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var Registry */
|
||||
private $registry;
|
||||
|
||||
/** @var ProductRepositoryInterface */
|
||||
private $productRepository;
|
||||
|
||||
/** @var SerializerInterface */
|
||||
private $json;
|
||||
|
||||
/** @var Bundle */
|
||||
private $block;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
|
||||
$this->productRepository->cleanCache();
|
||||
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(Bundle::class);
|
||||
$this->registry = $this->objectManager->get(Registry::class);
|
||||
$this->json = $this->objectManager->get(SerializerInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->registry->unregister('product');
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_multiselect_option.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDynamicBundleOptionPrices(): void
|
||||
{
|
||||
$expectedData = [
|
||||
'options_prices' => [
|
||||
[
|
||||
'oldPrice' => ['amount' => 10],
|
||||
'basePrice' => ['amount' => 10],
|
||||
'finalPrice' => ['amount' => 10],
|
||||
],
|
||||
[
|
||||
'oldPrice' => ['amount' => 20],
|
||||
'basePrice' => ['amount' => 20],
|
||||
'finalPrice' => ['amount' => 20],
|
||||
],
|
||||
[
|
||||
'oldPrice' => ['amount' => 30],
|
||||
'basePrice' => ['amount' => 30],
|
||||
'finalPrice' => ['amount' => 30],
|
||||
],
|
||||
],
|
||||
'bundle_prices' => [
|
||||
'oldPrice' => ['amount' => 0],
|
||||
'basePrice' => ['amount' => 0],
|
||||
'finalPrice' => ['amount' => 0],
|
||||
]
|
||||
];
|
||||
$this->processBundlePriceView('bundle_product', $expectedData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/product_with_multiple_options_1.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFixedBundleOptionPrices(): void
|
||||
{
|
||||
$expectedData = [
|
||||
'options_prices' => [
|
||||
[
|
||||
'oldPrice' => ['amount' => 2.75],
|
||||
'basePrice' => ['amount' => 2.75],
|
||||
'finalPrice' => ['amount' => 2.75],
|
||||
],
|
||||
[
|
||||
'oldPrice' => ['amount' => 6.75],
|
||||
'basePrice' => ['amount' => 6.75],
|
||||
'finalPrice' => ['amount' => 6.75],
|
||||
],
|
||||
],
|
||||
'bundle_prices' => [
|
||||
'oldPrice' => ['amount' => 12.75],
|
||||
'basePrice' => ['amount' => 10],
|
||||
'finalPrice' => ['amount' => 10],
|
||||
]
|
||||
];
|
||||
$this->processBundlePriceView('bundle-product', $expectedData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $productSku
|
||||
* @param array $expectedData
|
||||
* @return void
|
||||
*/
|
||||
private function processBundlePriceView(string $productSku, array $expectedData): void
|
||||
{
|
||||
$this->registerProduct($productSku);
|
||||
$jsonConfig = $this->json->unserialize($this->block->getJsonConfig());
|
||||
$this->assertEquals($expectedData['bundle_prices'], $jsonConfig['prices']);
|
||||
$this->assertOptionsConfig($expectedData['options_prices'], $jsonConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert options prices.
|
||||
*
|
||||
* @param array $expectedData
|
||||
* @param array $actualData
|
||||
* @return void
|
||||
*/
|
||||
private function assertOptionsConfig(array $expectedData, array $actualData): void
|
||||
{
|
||||
$optionConfig = $actualData['options'] ?? null;
|
||||
$this->assertNotNull($optionConfig);
|
||||
$optionConfig = reset($optionConfig);
|
||||
foreach (array_values($optionConfig['selections']) as $key => $selection) {
|
||||
$this->assertEquals($expectedData[$key], $selection['prices']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the product.
|
||||
*
|
||||
* @param string $productSku
|
||||
* @return void
|
||||
*/
|
||||
private function registerProduct(string $productSku): void
|
||||
{
|
||||
$product = $this->productRepository->get($productSku);
|
||||
$this->registry->unregister('product');
|
||||
$this->registry->register('product', $product);
|
||||
}
|
||||
}
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Block\Catalog\Product\View\Type;
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\Data\ProductInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class checks bundle product view behaviour
|
||||
*
|
||||
* @magentoDataFixture Magento/Bundle/_files/product.php
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppArea frontend
|
||||
* @see \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle
|
||||
*/
|
||||
class BundleTest extends TestCase
|
||||
{
|
||||
/** @var Bundle */
|
||||
private $block;
|
||||
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var ProductRepositoryInterface */
|
||||
private $productRepository;
|
||||
|
||||
/** @var LayoutInterface */
|
||||
private $layout;
|
||||
|
||||
/** @var SerializerInterface */
|
||||
private $json;
|
||||
|
||||
/** @var Registry */
|
||||
private $registry;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
|
||||
$this->productRepository->cleanCache();
|
||||
$this->layout = $this->objectManager->get(LayoutInterface::class);
|
||||
$this->block = $this->layout->createBlock(Bundle::class);
|
||||
$this->json = $this->objectManager->get(SerializerInterface::class);
|
||||
$this->registry = $this->objectManager->get(Registry::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->registry->unregister('product');
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for method \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle::getJsonConfig
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetJsonConfig(): void
|
||||
{
|
||||
$product = $this->updateProduct('bundle-product', ['price_type' => Price::PRICE_TYPE_DYNAMIC]);
|
||||
$this->registerProduct($product);
|
||||
$this->updateProduct('simple', ['special_price' => 5]);
|
||||
$config = $this->json->unserialize($this->block->getJsonConfig());
|
||||
$options = current($config['options']);
|
||||
$selection = current($options['selections']);
|
||||
$this->assertEquals(10, $selection['prices']['oldPrice']['amount']);
|
||||
$this->assertEquals(5, $selection['prices']['basePrice']['amount']);
|
||||
$this->assertEquals(5, $selection['prices']['finalPrice']['amount']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider isSalableForStockStatusProvider
|
||||
*
|
||||
* @param bool $isSalable
|
||||
* @param string $expectedValue
|
||||
* @return void
|
||||
*/
|
||||
public function testStockStatusView(bool $isSalable, string $expectedValue): void
|
||||
{
|
||||
$product = $this->productRepository->get('bundle-product');
|
||||
$product->setIsSalable($isSalable);
|
||||
$this->block->setTemplate('Magento_Bundle::catalog/product/view/type/bundle.phtml');
|
||||
$result = $this->renderBlockHtml($product);
|
||||
$this->assertEquals($expectedValue, trim(strip_tags($result)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function isSalableForStockStatusProvider(): array
|
||||
{
|
||||
return [
|
||||
'is_salable' => [
|
||||
'is_salable' => true,
|
||||
'expected_value' => 'In stock',
|
||||
],
|
||||
'is_not_salable' => [
|
||||
'is_salable' => false,
|
||||
'expected_value' => 'Out of stock',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider isSalableForCustomizeButtonProvider
|
||||
*
|
||||
* @param bool $isSalable
|
||||
* @param string $expectedValue
|
||||
* @return void
|
||||
*/
|
||||
public function testCustomizeButton(bool $isSalable, string $expectedValue): void
|
||||
{
|
||||
$product = $this->productRepository->get('bundle-product');
|
||||
$product->setSalable($isSalable);
|
||||
$this->block->setTemplate('Magento_Bundle::catalog/product/view/customize.phtml');
|
||||
$result = $this->renderBlockHtml($product);
|
||||
$this->assertEquals($expectedValue, trim(strip_tags($result)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function isSalableForCustomizeButtonProvider(): array
|
||||
{
|
||||
return [
|
||||
'is_salable' => [
|
||||
'is_salable' => true,
|
||||
'expected_value' => 'Customize and Add to Cart',
|
||||
],
|
||||
'is_not_salable' => [
|
||||
'is_salable' => false,
|
||||
'expected_value' => '',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/empty_bundle_product.php
|
||||
*
|
||||
* @param bool $isSalable
|
||||
* @param string $expectedValue
|
||||
* @return void
|
||||
*/
|
||||
public function testCustomizeButtonProductWithoutOptions(): void
|
||||
{
|
||||
$product = $this->productRepository->get('bundle-product');
|
||||
$product->setSalable(true);
|
||||
$this->block->setTemplate('Magento_Bundle::catalog/product/view/customize.phtml');
|
||||
$result = $this->renderBlockHtml($product);
|
||||
$this->assertEmpty(trim(strip_tags($result)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update product
|
||||
*
|
||||
* @param ProductInterface|string $productSku
|
||||
* @param array $data
|
||||
* @return ProductInterface
|
||||
*/
|
||||
private function updateProduct(string $productSku, array $data): ProductInterface
|
||||
{
|
||||
$product = $this->productRepository->get($productSku);
|
||||
$product->addData($data);
|
||||
|
||||
return $this->productRepository->save($product);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register product
|
||||
*
|
||||
* @param ProductInterface $product
|
||||
* @return void
|
||||
*/
|
||||
private function registerProduct(ProductInterface $product): void
|
||||
{
|
||||
$this->registry->unregister('product');
|
||||
$this->registry->register('product', $product);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render block output
|
||||
*
|
||||
* @param ProductInterface $product
|
||||
* @return string
|
||||
*/
|
||||
private function renderBlockHtml(ProductInterface $product): string
|
||||
{
|
||||
$this->registerProduct($product);
|
||||
|
||||
return $this->block->toHtml();
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Block\Catalog\Product\View\Type;
|
||||
|
||||
/**
|
||||
* Class checks checkbox bundle options appearance
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class CheckboxOptionViewTest extends AbstractBundleOptionsViewTest
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/bundle_product_checkbox_options.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNotRequiredSelectMultiSelectionsView(): void
|
||||
{
|
||||
$expectedSelectionsNames = ['Simple Product', 'Simple Product2'];
|
||||
$this->processMultiSelectionsView(
|
||||
'bundle-product-checkbox-options',
|
||||
'Checkbox Options',
|
||||
$expectedSelectionsNames
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/bundle_product_checkbox_required_options.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRequiredSelectMultiSelectionsView(): void
|
||||
{
|
||||
$expectedSelectionsNames = ['Simple Product', 'Simple Product2'];
|
||||
$this->processMultiSelectionsView(
|
||||
'bundle-product-checkbox-required-options',
|
||||
'Checkbox Options',
|
||||
$expectedSelectionsNames,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/bundle_product_checkbox_required_option.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testShowSingle(): void
|
||||
{
|
||||
$this->processSingleSelectionView('bundle-product-checkbox-required-option', 'Checkbox Options');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function getRequiredSelectXpath(): string
|
||||
{
|
||||
return "//input[@type='checkbox' and contains(@data-validate, 'validate-one-required-by-name')"
|
||||
. "and contains(@class, 'bundle-option')]/../label//span[normalize-space(text()) = '1 x %s']";
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function getNotRequiredSelectXpath(): string
|
||||
{
|
||||
return "//input[@type='checkbox' and not(contains(@data-validate, 'validate-one-required-by-name'))"
|
||||
. "and contains(@class, 'bundle-option')]/../label//span[normalize-space(text()) = '1 x %s']";
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Block\Catalog\Product\View\Type;
|
||||
|
||||
/**
|
||||
* Class checks dropdown bundle options appearance
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class DropDownOptionViewTest extends AbstractBundleOptionsViewTest
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/bundle_product_dropdown_options.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNotRequiredSelectMultiSelectionsView(): void
|
||||
{
|
||||
$expectedSelectionsNames = ['Simple Product', 'Simple Product2'];
|
||||
$this->processMultiSelectionsView(
|
||||
'bundle-product-dropdown-options',
|
||||
'Dropdown Options',
|
||||
$expectedSelectionsNames
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/bundle_product_dropdown_required_options.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRequiredSelectMultiSelectionsView(): void
|
||||
{
|
||||
$expectedSelectionsNames = ['Simple Product', 'Simple Product2'];
|
||||
$this->processMultiSelectionsView(
|
||||
'bundle-product-dropdown-required-options',
|
||||
'Dropdown Options',
|
||||
$expectedSelectionsNames,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/product.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testShowSingle(): void
|
||||
{
|
||||
$this->processSingleSelectionView('bundle-product', 'Bundle Product Items');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function getRequiredSelectXpath(): string
|
||||
{
|
||||
return "//select[contains(@id, 'bundle-option') and contains(@data-validate, 'required:true')]"
|
||||
. "/option/span[normalize-space(text()) = '%s']";
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function getNotRequiredSelectXpath(): string
|
||||
{
|
||||
return "//select[contains(@id, 'bundle-option') and not(contains(@data-validate, 'required:true'))]"
|
||||
. "/option/span[normalize-space(text()) = '%s']";
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Block\Catalog\Product\View\Type;
|
||||
|
||||
/**
|
||||
* Class checks multiselect bundle options appearance
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class MultiselectOptionViewTest extends AbstractBundleOptionsViewTest
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/bundle_product_multiselect_options.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNotRequiredSelectMultiSelectionsView(): void
|
||||
{
|
||||
$expectedSelectionsNames = ['Simple Product', 'Simple Product2'];
|
||||
$this->processMultiSelectionsView(
|
||||
'bundle-product-multiselect-options',
|
||||
'Multiselect Options',
|
||||
$expectedSelectionsNames
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/bundle_product_multiselect_required_options.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRequiredSelectMultiSelectionsView(): void
|
||||
{
|
||||
$expectedSelectionsNames = ['Simple Product', 'Simple Product2'];
|
||||
$this->processMultiSelectionsView(
|
||||
'bundle-product-multiselect-required-options',
|
||||
'Multiselect Options',
|
||||
$expectedSelectionsNames,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/bundle_product_multiselect_required_option.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testShowSingle(): void
|
||||
{
|
||||
$this->processSingleSelectionView('bundle-product-multiselect-required-option', 'Multiselect Options');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheridoc
|
||||
*/
|
||||
protected function getRequiredSelectXpath(): string
|
||||
{
|
||||
return "//select[contains(@id, 'bundle-option') and @multiple='multiple' "
|
||||
. "and contains(@data-validate, 'required:true')]/option/span[normalize-space(text()) = '1 x %s']";
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheridoc
|
||||
*/
|
||||
protected function getNotRequiredSelectXpath(): string
|
||||
{
|
||||
return "//select[contains(@id, 'bundle-option') and @multiple='multiple'"
|
||||
. "and not(contains(@data-validate, 'required:true'))]/option/span[normalize-space(text()) = '1 x %s']";
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Block\Catalog\Product\View\Type;
|
||||
|
||||
/**
|
||||
* Class checks radio buttons bundle options appearance
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class RadioOptionViewTest extends AbstractBundleOptionsViewTest
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/bundle_product_radio_options.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNotRequiredSelectMultiSelectionsView(): void
|
||||
{
|
||||
$expectedSelectionsNames = ['Simple Product', 'Simple Product2'];
|
||||
$this->processMultiSelectionsView('bundle-product-radio-options', 'Radio Options', $expectedSelectionsNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/bundle_product_radio_required_options.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRequiredSelectMultiSelectionsView(): void
|
||||
{
|
||||
$expectedSelectionsNames = ['Simple Product', 'Simple Product2'];
|
||||
$this->processMultiSelectionsView(
|
||||
'bundle-product-radio-required-options',
|
||||
'Radio Options',
|
||||
$expectedSelectionsNames,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/bundle_product_radio_required_option.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testShowSingle(): void
|
||||
{
|
||||
$this->processSingleSelectionView('bundle-product-radio-required-option', 'Radio Options');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function getRequiredSelectXpath(): string
|
||||
{
|
||||
return "//input[@type='radio' and contains(@data-validate, 'validate-one-required-by-name')"
|
||||
. "and contains(@class, 'bundle option')]/../label//span[normalize-space(text()) = '%s']";
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function getNotRequiredSelectXpath(): string
|
||||
{
|
||||
return "//input[@type='radio' and not(contains(@data-validate, 'validate-one-required-by-name'))"
|
||||
. "and contains(@class, 'bundle option')]/../label//span[normalize-space(text()) = '%s']";
|
||||
}
|
||||
}
|
||||
+209
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Block\Sales\Order\Items;
|
||||
|
||||
use Magento\Bundle\Test\Fixture\Option as BundleOptionFixture;
|
||||
use Magento\Bundle\Test\Fixture\OrderItem as OrderItemFixture;
|
||||
use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
|
||||
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
|
||||
use Magento\Config\Model\ResourceModel\Config as CoreConfig;
|
||||
use Magento\Customer\Api\AccountManagementInterface;
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Customer\Test\Fixture\Customer;
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
|
||||
use Magento\Sales\Model\Order\Address as OrderAddress;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Fixture\Config;
|
||||
use Magento\TestFramework\Fixture\DataFixture;
|
||||
use Magento\TestFramework\Fixture\DataFixtureStorage;
|
||||
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
|
||||
use Magento\TestFramework\Fixture\DbIsolation;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class RendererTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var DataFixtureStorage
|
||||
*/
|
||||
private $fixtures;
|
||||
/**
|
||||
* @var Session
|
||||
*/
|
||||
protected $session;
|
||||
|
||||
/** @var Renderer */
|
||||
private $block;
|
||||
|
||||
/**
|
||||
* @var CoreConfig
|
||||
*/
|
||||
protected $resourceConfig;
|
||||
|
||||
/**
|
||||
* @var AccountManagementInterface
|
||||
*/
|
||||
private $accountManagement;
|
||||
|
||||
/**
|
||||
* @var OrderSender
|
||||
*/
|
||||
private $orderSender;
|
||||
|
||||
/**
|
||||
* @defaultDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$layout = $this->objectManager->get(LayoutInterface::class);
|
||||
$this->block = $layout->createBlock(Renderer::class);
|
||||
$this->fixtures = Bootstrap::getObjectManager()->get(DataFixtureStorageManager::class)->getStorage();
|
||||
$this->resourceConfig = $this->objectManager->get(CoreConfig::class);
|
||||
$this->accountManagement = $this->objectManager->get(AccountManagementInterface::class);
|
||||
$this->orderSender = $this->objectManager->get(OrderSender::class);
|
||||
}
|
||||
|
||||
#[
|
||||
DbIsolation(false),
|
||||
Config('default/currency/options/base', 'USD', 'store', 'default'),
|
||||
Config('currency/options/default', 'EUR', 'store', 'default'),
|
||||
Config('currency/options/allow', 'USD, EUR', 'store', 'default'),
|
||||
DataFixture(ProductFixture::class, ['price' => 10], 'p1'),
|
||||
DataFixture(ProductFixture::class, ['price' => 20], 'p2'),
|
||||
DataFixture(BundleOptionFixture::class, ['product_links' => ['$p1$', '$p2$']], 'opt1'),
|
||||
DataFixture(BundleProductFixture::class, ['_options' => ['$opt1$']], 'bundle1'),
|
||||
DataFixture(OrderItemFixture::class, ['items' => [['sku' => '$bundle1.sku$']]], 'order'),
|
||||
]
|
||||
public function testOrderEmailContent(): void
|
||||
{
|
||||
$order = $this->objectManager->create(Order::class);
|
||||
|
||||
$incrementId = $this->fixtures->get('order')->getIncrementId();
|
||||
$order->loadByIncrementId($incrementId);
|
||||
|
||||
$storeManager = $this->objectManager->get(StoreManagerInterface::class);
|
||||
$currencyCode = $storeManager->getWebsite()->getDefaultStore()->getDefaultCurrency()->getCode();
|
||||
$storeId = $this->objectManager->get(StoreManagerInterface::class)->getStore()->getId();
|
||||
$order->setStoreId($storeId);
|
||||
$order->setOrderCurrencyCode($currencyCode);
|
||||
$order->save();
|
||||
|
||||
$priceBlockHtml = [];
|
||||
|
||||
$items = $order->getAllItems();
|
||||
foreach ($items as $item) {
|
||||
$item->setProductOptions([
|
||||
'bundle_options' => [
|
||||
[
|
||||
'value' => [
|
||||
['title' => '']
|
||||
],
|
||||
],
|
||||
],
|
||||
'bundle_selection_attributes' => '{"qty":5 ,"price":99}'
|
||||
]);
|
||||
$this->block->setItem($item);
|
||||
$priceBlockHtml[] = $this->block->getValueHtml($item);
|
||||
}
|
||||
|
||||
$this->assertStringContainsString("€99", $priceBlockHtml[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
#[
|
||||
DbIsolation(true),
|
||||
DataFixture(ProductFixture::class, ['price' => 10], 'p1'),
|
||||
DataFixture(ProductFixture::class, ['price' => 20], 'p2'),
|
||||
DataFixture(ProductFixture::class, ['price' => 30], 'p3'),
|
||||
DataFixture(BundleOptionFixture::class, ['product_links' => ['$p1$', '$p2$', '$p3$']], 'opt1'),
|
||||
DataFixture(BundleProductFixture::class, ['_options' => ['$opt1$']], 'bundle1'),
|
||||
DataFixture(OrderItemFixture::class, ['items' => [['sku' => '$bundle1.sku$']]], 'order'),
|
||||
DataFixture(Customer::class, ['email' => 'customer@example.com'], as: 'customer'),
|
||||
]
|
||||
public function testPlaceOrderWithOtherThanDefaultCurrencyValidateEmailHasSameCurrency(): void
|
||||
{
|
||||
$this->resourceConfig->saveConfig(
|
||||
'currency/options/default',
|
||||
'EUR',
|
||||
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
|
||||
0
|
||||
);
|
||||
|
||||
$this->resourceConfig->saveConfig(
|
||||
'currency/options/allow',
|
||||
'EUR',
|
||||
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
|
||||
0
|
||||
);
|
||||
|
||||
$this->resourceConfig->saveConfig(
|
||||
'currency/options/base',
|
||||
'USD',
|
||||
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
|
||||
0
|
||||
);
|
||||
|
||||
// Load customer data
|
||||
$customer = $this->fixtures->get('customer');
|
||||
$customerEmail = $customer->getEmail();
|
||||
|
||||
// Login to customer
|
||||
$this->accountManagement->authenticate($customerEmail, 'password');
|
||||
|
||||
// Including address data file
|
||||
$addressData = include __DIR__ . '/../../../../../Sales/_files/address_data.php';
|
||||
|
||||
// Setting the billing address
|
||||
$billingAddress = $this->objectManager->create(OrderAddress::class, ['data' => $addressData]);
|
||||
$billingAddress->setAddressType('billing');
|
||||
|
||||
// Setting the shipping address
|
||||
$shippingAddress = clone $billingAddress;
|
||||
$shippingAddress->setId(null)->setAddressType('shipping');
|
||||
|
||||
// Place the order
|
||||
$order = $this->objectManager->create(Order::class);
|
||||
$incrementId = $this->fixtures->get('order')->getIncrementId();
|
||||
$order->loadByIncrementId($incrementId);
|
||||
$storeManager = $this->objectManager->get(StoreManagerInterface::class);
|
||||
$currencyCodeSymbol = $storeManager->getWebsite()->getDefaultStore()->getDefaultCurrency()->getCurrencySymbol();
|
||||
$storeId = $this->objectManager->get(StoreManagerInterface::class)->getStore()->getId();
|
||||
$order->setStoreId($storeId);
|
||||
$order->setCustomerEmail($customerEmail);
|
||||
$order->setBillingAddress($billingAddress);
|
||||
$order->setShippingAddress($shippingAddress);
|
||||
$order->save();
|
||||
$this->orderSender->send($order);
|
||||
$this->assertTrue($order->getSendEmail());
|
||||
|
||||
/** @var TransportBuilderMock $transportBuilderMock */
|
||||
$transportBuilderMock = Bootstrap::getObjectManager()
|
||||
->get(TransportBuilderMock::class);
|
||||
$sentMessage = $transportBuilderMock->getSentMessage();
|
||||
|
||||
$this->assertNotNull($sentMessage);
|
||||
$this->assertStringContainsString($currencyCodeSymbol, $sentMessage->getBodyText());
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Controller\Adminhtml\Bundle\Product\Edit;
|
||||
|
||||
use Magento\Catalog\Controller\Adminhtml\Product\MassDeleteTest as CatalogMassDeleteTest;
|
||||
|
||||
/**
|
||||
* Test for mass bundle product deleting.
|
||||
*
|
||||
* @see \Magento\Bundle\Controller\Adminhtml\Bundle\Product\Edit\MassDelete
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class MassDeleteTest extends CatalogMassDeleteTest
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/bundle_product_checkbox_required_option.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteBundleProductViaMassAction(): void
|
||||
{
|
||||
$product = $this->productRepository->get('bundle-product-checkbox-required-option');
|
||||
$this->dispatchMassDeleteAction([$product->getId()]);
|
||||
$this->assertSuccessfulDeleteProducts(1);
|
||||
}
|
||||
}
|
||||
+252
@@ -0,0 +1,252 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Controller\Adminhtml\Product;
|
||||
|
||||
use Magento\Bundle\Model\Product\Type;
|
||||
use Magento\Bundle\Model\ResourceModel\Option\Collection as OptionCollection;
|
||||
use Magento\Bundle\Model\ResourceModel\Selection\Collection as SelectionCollection;
|
||||
use Magento\Catalog\Api\Data\ProductAttributeInterface;
|
||||
use Magento\Catalog\Api\Data\ProductInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
|
||||
use Magento\Eav\Model\Config;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
use Magento\TestFramework\TestCase\AbstractBackendController;
|
||||
|
||||
/**
|
||||
* Class determine basic logic for bundle product save tests
|
||||
*/
|
||||
abstract class AbstractBundleProductSaveTest extends AbstractBackendController
|
||||
{
|
||||
/** @var string */
|
||||
protected $productToDelete;
|
||||
|
||||
/** @var ProductRepositoryInterface */
|
||||
protected $productRepository;
|
||||
|
||||
/** @var Config */
|
||||
private $eavConfig;
|
||||
|
||||
/** @var ProductResource */
|
||||
private $productResource;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->productRepository = $this->_objectManager->get(ProductRepositoryInterface::class);
|
||||
$this->eavConfig = $this->_objectManager->get(Config::class);
|
||||
$this->productResource = $this->_objectManager->get(ProductResource::class);
|
||||
$this->productToDelete = $this->getStaticProductData()['sku'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
if ($this->productToDelete) {
|
||||
$this->productRepository->deleteById($this->productToDelete);
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve default product attribute set id.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getDefaultAttributeSetId(): int
|
||||
{
|
||||
return (int)$this->eavConfig->getEntityType(ProductAttributeInterface::ENTITY_TYPE_CODE)
|
||||
->getDefaultAttributeSetId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare request
|
||||
*
|
||||
* @param array $post
|
||||
* @param int|null $id
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareRequestData(array $post, ?int $id = null): array
|
||||
{
|
||||
$post = $this->preparePostParams($post);
|
||||
$this->setRequestparams($post, $id);
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare and assert bundle options
|
||||
*
|
||||
* @param array $bundleOptions
|
||||
* @return void
|
||||
*/
|
||||
protected function assertBundleOptions(array $bundleOptions): void
|
||||
{
|
||||
$mainProduct = $this->productRepository->get($this->getStaticProductData()['sku'], false, null, true);
|
||||
$optionsCollection = $mainProduct->getTypeInstance()->getOptionsCollection($mainProduct);
|
||||
$selectionCollection = $mainProduct->getTypeInstance()
|
||||
->getSelectionsCollection($optionsCollection->getAllIds(), $mainProduct);
|
||||
$this->assertOptionsData($bundleOptions, $optionsCollection, $selectionCollection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare post params before dispatch
|
||||
*
|
||||
* @param array $post
|
||||
* @return array
|
||||
*/
|
||||
private function preparePostParams(array $post): array
|
||||
{
|
||||
$post['product'] = $this->getStaticProductData();
|
||||
foreach ($post['bundle_options']['bundle_options'] as &$bundleOption) {
|
||||
$bundleOption = $this->prepareOptionByType($bundleOption['type'], $bundleOption);
|
||||
$productIdsBySkus = $this->productResource->getProductsIdsBySkus(
|
||||
array_column($bundleOption['bundle_selections'], 'sku')
|
||||
);
|
||||
foreach ($bundleOption['bundle_selections'] as &$bundleSelection) {
|
||||
$bundleSelection = $this->prepareSelection($productIdsBySkus, $bundleSelection);
|
||||
}
|
||||
}
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare option params
|
||||
*
|
||||
* @param string $type
|
||||
* @param array $option
|
||||
* @return array
|
||||
*/
|
||||
private function prepareOptionByType(string $type, array $option): array
|
||||
{
|
||||
$option['required'] = '1';
|
||||
$option['delete'] = '';
|
||||
$option['title'] = $option['title'] ?? $type . ' Option Title';
|
||||
|
||||
return $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare selection params
|
||||
*
|
||||
* @param array $productIdsBySkus
|
||||
* @param array $selection
|
||||
* @return array
|
||||
*/
|
||||
private function prepareSelection(array $productIdsBySkus, array $selection): array
|
||||
{
|
||||
$staticData = [
|
||||
'price' => '10.000000',
|
||||
'selection_qty' => '5.0000',
|
||||
'selection_can_change_qty' => '0'
|
||||
];
|
||||
$selection['product_id'] = $productIdsBySkus[$selection['sku']];
|
||||
$selection = array_merge($selection, $staticData);
|
||||
|
||||
return $selection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert bundle options data
|
||||
*
|
||||
* @param array $expectedOptions
|
||||
* @param OptionCollection $actualOptions
|
||||
* @param SelectionCollection $selectionCollection
|
||||
* @return void
|
||||
*/
|
||||
private function assertOptionsData(
|
||||
array $expectedOptions,
|
||||
OptionCollection $actualOptions,
|
||||
SelectionCollection $selectionCollection
|
||||
): void {
|
||||
$this->assertCount(count($expectedOptions['bundle_options']), $actualOptions);
|
||||
foreach ($expectedOptions['bundle_options'] as $expectedOption) {
|
||||
$optionToCheck = $actualOptions->getItemByColumnValue('title', $expectedOption['title']);
|
||||
$this->assertNotNull($optionToCheck->getId());
|
||||
$selectionToCheck = $selectionCollection->getItemsByColumnValue('option_id', $optionToCheck->getId());
|
||||
$this->assertCount(count($expectedOption['bundle_selections']), $selectionToCheck);
|
||||
$this->assertSelections($expectedOption['bundle_selections'], $selectionToCheck);
|
||||
unset($expectedOption['delete'], $expectedOption['bundle_selections']);
|
||||
foreach ($expectedOption as $key => $value) {
|
||||
$this->assertEquals($value, $optionToCheck->getData($key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert selections data
|
||||
*
|
||||
* @param array $expectedSelections
|
||||
* @param array $actualSelections
|
||||
* @return void
|
||||
*/
|
||||
private function assertSelections(array $expectedSelections, array $actualSelections): void
|
||||
{
|
||||
foreach ($expectedSelections as $expectedSelection) {
|
||||
$actualSelectionToCheck = $this->getSelectionByProductSku($expectedSelection['sku'], $actualSelections);
|
||||
$this->assertNotNull($actualSelectionToCheck);
|
||||
foreach ($expectedSelection as $key => $value) {
|
||||
$this->assertEquals($value, $actualSelectionToCheck->getData($key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get selection by product sku
|
||||
*
|
||||
* @param string $sku
|
||||
* @param array $actualSelections
|
||||
* @return ProductInterface
|
||||
*/
|
||||
private function getSelectionByProductSku(string $sku, array $actualSelections): ProductInterface
|
||||
{
|
||||
$item = null;
|
||||
foreach ($actualSelections as $selection) {
|
||||
if ($selection->getSku() === $sku) {
|
||||
$item = $selection;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set request parameters
|
||||
*
|
||||
* @param array $post
|
||||
* @param int|null $id
|
||||
* @return void
|
||||
*/
|
||||
private function setRequestParams(array $post, ?int $id): void
|
||||
{
|
||||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
|
||||
$params = ['type' => Type::TYPE_CODE, 'set' => $this->getDefaultAttributeSetId()];
|
||||
if ($id) {
|
||||
$params['id'] = $id;
|
||||
}
|
||||
$this->getRequest()->setParams($params);
|
||||
$this->getRequest()->setPostValue('product', $post['product']);
|
||||
$this->getRequest()->setPostValue('bundle_options', $post['bundle_options']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get main product data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getStaticProductData(): array;
|
||||
}
|
||||
+269
@@ -0,0 +1,269 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Controller\Adminhtml\Product;
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
|
||||
/**
|
||||
* Class checks dynamic bundle product save behavior
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class DynamicBundleProductTest extends AbstractBundleProductSaveTest
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
*
|
||||
* @dataProvider bundleProductDataProvider
|
||||
*
|
||||
* @param array $post
|
||||
* @return void
|
||||
*/
|
||||
public function testBundleProductSave(array $post): void
|
||||
{
|
||||
$post = $this->prepareRequestData($post);
|
||||
$this->dispatch('backend/catalog/product/save');
|
||||
$this->assertBundleOptions($post['bundle_options']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function bundleProductDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'with_dropdown_option' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'select',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'with_radio_buttons_option' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'radio',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'with_checkbox_option' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'checkbox',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'with_multiselect_option' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'multi',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
|
||||
*
|
||||
* @dataProvider multiOptionsDataProvider
|
||||
*
|
||||
* @param array $post
|
||||
* @return void
|
||||
*/
|
||||
public function testBundleProductSaveMultiOptions(array $post): void
|
||||
{
|
||||
$post = $this->prepareRequestData($post);
|
||||
$this->dispatch('backend/catalog/product/save');
|
||||
$this->assertBundleOptions($post['bundle_options']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function multiOptionsDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'with_two_options_few_selections' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'select',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
[
|
||||
'name' => 'Simple Product',
|
||||
'sku' => 'simple-1',
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'checkbox',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product',
|
||||
'sku' => 'simple-1',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
*
|
||||
* @dataProvider emptyOptionTitleDataProvider
|
||||
*
|
||||
* @param array $post
|
||||
* @return void
|
||||
*/
|
||||
public function testProductSaveMissedOptionTitle(array $post): void
|
||||
{
|
||||
$this->productToDelete = null;
|
||||
$post = $this->prepareRequestData($post);
|
||||
$this->dispatch('backend/catalog/product/save');
|
||||
$this->assertSessionMessages($this->equalTo(["The option couldn't be saved."]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function emptyOptionTitleDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'empty_option_title' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'title' => '',
|
||||
'type' => 'multi',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/bundle_product_checkbox_options.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
*
|
||||
* @dataProvider updateProductDataProvider
|
||||
*
|
||||
* @param array $post
|
||||
* @return void
|
||||
*/
|
||||
public function testUpdateProduct(array $post): void
|
||||
{
|
||||
$id = $this->productRepository->get('bundle-product-checkbox-options')->getId();
|
||||
$post = $this->prepareRequestData($post, (int)$id);
|
||||
$this->dispatch('backend/catalog/product/save');
|
||||
$this->assertBundleOptions($post['bundle_options']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function updateProductDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'update_existing_product' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'multi',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function getStaticProductData(): array
|
||||
{
|
||||
return [
|
||||
'sku' => 'bundle-test-product',
|
||||
'name' => 'test-bundle',
|
||||
'price' => '',
|
||||
'sku_type' => '0',
|
||||
'price_type' => Price::PRICE_TYPE_DYNAMIC,
|
||||
'weight_type' => '0',
|
||||
'shipment_type' => AbstractType::SHIPMENT_TOGETHER,
|
||||
'attribute_set_id' => $this->getDefaultAttributeSetId(),
|
||||
];
|
||||
}
|
||||
}
|
||||
+226
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Controller\Adminhtml\Product;
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
|
||||
/**
|
||||
* Class checks fixed bundle product save behavior
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class FixedBundleProductTest extends AbstractBundleProductSaveTest
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
*
|
||||
* @dataProvider fixedBundleProductDataProvider
|
||||
*
|
||||
* @param array $post
|
||||
* @return void
|
||||
*/
|
||||
public function testBundleProductSave(array $post): void
|
||||
{
|
||||
$post = $this->prepareRequestData($post);
|
||||
$this->dispatch('backend/catalog/product/save');
|
||||
$this->assertBundleOptions($post['bundle_options']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function fixedBundleProductDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'with_dropdown_option' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'select',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'with_radio_buttons_option' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'radio',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'with_checkbox_option' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'checkbox',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'with_multiselect_option' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'multi',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
|
||||
*
|
||||
* @dataProvider multiOptionsDataProvider
|
||||
*
|
||||
* @param array $post
|
||||
* @return void
|
||||
*/
|
||||
public function testBundleProductSaveMultiOptions(array $post): void
|
||||
{
|
||||
$post = $this->prepareRequestData($post);
|
||||
$this->dispatch('backend/catalog/product/save');
|
||||
$this->assertBundleOptions($post['bundle_options']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function multiOptionsDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'with_two_options_few_selections' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'select',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
[
|
||||
'name' => 'Simple Product',
|
||||
'sku' => 'simple-1',
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'checkbox',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product',
|
||||
'sku' => 'simple-1',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/bundle_product_checkbox_options.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
*
|
||||
* @dataProvider updateProductDataProvider
|
||||
*
|
||||
* @param array $post
|
||||
* @return void
|
||||
*/
|
||||
public function testUpdateProduct(array $post): void
|
||||
{
|
||||
$id = $this->productRepository->get('bundle-product-checkbox-options')->getId();
|
||||
$post = $this->prepareRequestData($post, (int)$id);
|
||||
$this->dispatch('backend/catalog/product/save');
|
||||
$this->assertBundleOptions($post['bundle_options']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function updateProductDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'update_existing_product' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'multi',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function getStaticProductData(): array
|
||||
{
|
||||
return [
|
||||
'sku' => 'bundle-test-product',
|
||||
'name' => 'test-bundle',
|
||||
'price' => '150',
|
||||
'sku_type' => '1',
|
||||
'price_type' => Price::PRICE_TYPE_FIXED,
|
||||
'weight_type' => '1',
|
||||
'shipment_type' => AbstractType::SHIPMENT_TOGETHER,
|
||||
'attribute_set_id' => $this->getDefaultAttributeSetId(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Bundle\Controller\Adminhtml;
|
||||
|
||||
use Magento\Bundle\Api\Data\OptionInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
use Magento\Framework\Data\Form\FormKey;
|
||||
use Magento\Framework\Message\MessageInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\AbstractBackendController;
|
||||
|
||||
/**
|
||||
* Provide tests for product admin controllers.
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ProductTest extends AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* Test bundle product duplicate won't remove bundle options from original product.
|
||||
*
|
||||
* @magentoDataFixture Magento/Catalog/_files/products_new.php
|
||||
* @return void
|
||||
*/
|
||||
public function testDuplicateProduct()
|
||||
{
|
||||
$params = $this->getRequestParamsForDuplicate();
|
||||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
|
||||
$this->getRequest()->setParams(['type' => Type::TYPE_BUNDLE]);
|
||||
$this->getRequest()->setPostValue($params);
|
||||
$this->dispatch('backend/catalog/product/save');
|
||||
$this->assertSessionMessages(
|
||||
$this->equalTo(
|
||||
[
|
||||
'You saved the product.',
|
||||
'You duplicated the product.',
|
||||
]
|
||||
),
|
||||
MessageInterface::TYPE_SUCCESS
|
||||
);
|
||||
$this->assertOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get necessary request post params for creating and duplicating bundle product.
|
||||
*
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
private function getRequestParamsForDuplicate()
|
||||
{
|
||||
$product = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class)->get('simple');
|
||||
return [
|
||||
'product' =>
|
||||
[
|
||||
'attribute_set_id' => '4',
|
||||
'gift_message_available' => '0',
|
||||
'use_config_gift_message_available' => '1',
|
||||
'stock_data' =>
|
||||
[
|
||||
'min_qty_allowed_in_shopping_cart' =>
|
||||
[
|
||||
[
|
||||
'record_id' => '0',
|
||||
'customer_group_id' => '32000',
|
||||
'min_sale_qty' => '',
|
||||
],
|
||||
],
|
||||
'min_qty' => '0',
|
||||
'max_sale_qty' => '10000',
|
||||
'notify_stock_qty' => '1',
|
||||
'min_sale_qty' => '1',
|
||||
'qty_increments' => '1',
|
||||
'use_config_manage_stock' => '1',
|
||||
'manage_stock' => '1',
|
||||
'use_config_min_qty' => '1',
|
||||
'use_config_max_sale_qty' => '1',
|
||||
'use_config_backorders' => '1',
|
||||
'backorders' => '0',
|
||||
'use_config_notify_stock_qty' => '1',
|
||||
'use_config_enable_qty_inc' => '1',
|
||||
'enable_qty_increments' => '0',
|
||||
'use_config_qty_increments' => '1',
|
||||
'use_config_min_sale_qty' => '1',
|
||||
'is_qty_decimal' => '0',
|
||||
'is_decimal_divided' => '0',
|
||||
],
|
||||
'status' => '1',
|
||||
'affect_product_custom_options' => '1',
|
||||
'name' => 'b1',
|
||||
'price' => '',
|
||||
'weight' => '',
|
||||
'url_key' => '',
|
||||
'special_price' => '',
|
||||
'quantity_and_stock_status' =>
|
||||
[
|
||||
'qty' => '',
|
||||
'is_in_stock' => '1',
|
||||
],
|
||||
'sku_type' => '0',
|
||||
'price_type' => '0',
|
||||
'weight_type' => '0',
|
||||
'website_ids' =>
|
||||
[
|
||||
1 => '1',
|
||||
],
|
||||
'sku' => 'b1',
|
||||
'meta_title' => 'b1',
|
||||
'meta_keyword' => 'b1',
|
||||
'meta_description' => 'b1 ',
|
||||
'tax_class_id' => '2',
|
||||
'product_has_weight' => '1',
|
||||
'visibility' => '4',
|
||||
'country_of_manufacture' => '',
|
||||
'page_layout' => '',
|
||||
'options_container' => 'container2',
|
||||
'custom_design' => '',
|
||||
'custom_layout' => '',
|
||||
'price_view' => '0',
|
||||
'shipment_type' => '0',
|
||||
'news_from_date' => '',
|
||||
'news_to_date' => '',
|
||||
'custom_design_from' => '',
|
||||
'custom_design_to' => '',
|
||||
'special_from_date' => '',
|
||||
'special_to_date' => '',
|
||||
'description' => '',
|
||||
'short_description' => '',
|
||||
'custom_layout_update' => '',
|
||||
'image' => '',
|
||||
'small_image' => '',
|
||||
'thumbnail' => '',
|
||||
],
|
||||
'bundle_options' =>
|
||||
[
|
||||
'bundle_options' =>
|
||||
[
|
||||
[
|
||||
'record_id' => '0',
|
||||
'type' => 'select',
|
||||
'required' => '1',
|
||||
'title' => 'test option title',
|
||||
'position' => '1',
|
||||
'option_id' => '',
|
||||
'delete' => '',
|
||||
'bundle_selections' =>
|
||||
[
|
||||
[
|
||||
'product_id' => $product->getId(),
|
||||
'name' => $product->getName(),
|
||||
'sku' => $product->getSku(),
|
||||
'price' => $product->getPrice(),
|
||||
'delete' => '',
|
||||
'selection_can_change_qty' => '',
|
||||
'selection_id' => '',
|
||||
'selection_price_type' => '0',
|
||||
'selection_price_value' => '',
|
||||
'selection_qty' => '1',
|
||||
'position' => '1',
|
||||
'option_id' => '',
|
||||
'record_id' => '1',
|
||||
'is_default' => '0',
|
||||
],
|
||||
],
|
||||
'bundle_button_proxy' =>
|
||||
[
|
||||
[
|
||||
'entity_id' => '1',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'affect_bundle_product_selections' => '1',
|
||||
'back' => 'duplicate',
|
||||
'form_key' => Bootstrap::getObjectManager()->get(FormKey::class)->getFormKey(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check options in created and duplicated products.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function assertOptions()
|
||||
{
|
||||
$createdOptions = $this->getProductOptions('b1');
|
||||
$createdOption = array_shift($createdOptions);
|
||||
$duplicatedOptions = $this->getProductOptions('b1-1');
|
||||
$duplicatedOption = array_shift($duplicatedOptions);
|
||||
$this->assertNotEmpty($createdOption);
|
||||
$this->assertNotEmpty($duplicatedOption);
|
||||
$optionFields = ['type', 'title', 'position', 'required', 'default_title'];
|
||||
foreach ($optionFields as $field) {
|
||||
$this->assertSame($createdOption->getData($field), $duplicatedOption->getData($field));
|
||||
}
|
||||
$createdLinks = $createdOption->getProductLinks();
|
||||
$createdLink = array_shift($createdLinks);
|
||||
$duplicatedLinks = $duplicatedOption->getProductLinks();
|
||||
$duplicatedLink = array_shift($duplicatedLinks);
|
||||
$this->assertNotEmpty($createdLink);
|
||||
$this->assertNotEmpty($duplicatedLink);
|
||||
$linkFields = [
|
||||
'entity_id',
|
||||
'sku',
|
||||
'position',
|
||||
'is_default',
|
||||
'price',
|
||||
'qty',
|
||||
'selection_can_change_quantity',
|
||||
'price_type',
|
||||
];
|
||||
foreach ($linkFields as $field) {
|
||||
$this->assertSame($createdLink->getData($field), $duplicatedLink->getData($field));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get options for given product.
|
||||
*
|
||||
* @param string $sku
|
||||
* @return OptionInterface[]
|
||||
*/
|
||||
private function getProductOptions(string $sku)
|
||||
{
|
||||
$product = Bootstrap::getObjectManager()->create(Product::class);
|
||||
$productId = $product->getResource()->getIdBySku($sku);
|
||||
$product->load($productId);
|
||||
|
||||
return $product->getExtensionAttributes()->getBundleProductOptions();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Catalog\Controller\Product (bundle product type)
|
||||
*/
|
||||
namespace Magento\Bundle\Controller;
|
||||
|
||||
class ProductTest extends \Magento\TestFramework\TestCase\AbstractController
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/product.php
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testViewAction()
|
||||
{
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $this->_objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('bundle-product');
|
||||
$this->dispatch('catalog/product/view/id/' . $product->getEntityId());
|
||||
$responseBody = $this->getResponse()->getBody();
|
||||
$this->assertStringContainsString('Bundle Product', $responseBody);
|
||||
$this->assertStringContainsString(
|
||||
'In stock',
|
||||
$responseBody,
|
||||
'Bundle Product Detailed Page does not contain In Stock field'
|
||||
);
|
||||
$addToCartCount = substr_count($responseBody, '<span>Add to Cart</span>');
|
||||
$this->assertEquals(1, $addToCartCount, '"Add to Cart" button should appear on the page exactly once.');
|
||||
$actualLinkCount = substr_count($responseBody, '>Bundle Product Items<');
|
||||
$this->assertEquals(1, $actualLinkCount, 'Bundle product options should appear on the page exactly once.');
|
||||
$this->assertStringNotContainsString('class="options-container-big"', $responseBody);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//*[@id="product-options-wrapper"]',
|
||||
$responseBody
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Pricing\Price;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* 'Final Price' model integration tests.
|
||||
*
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
class FinalPriceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ProductRepositoryInterface
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check minimal and maximal prices are calculated correctly for Bundle product selections with Tier Prices.
|
||||
*
|
||||
* @return void
|
||||
* @magentoDataFixture Magento/Bundle/_files/bundle_product_with_tier_price_selections.php
|
||||
*/
|
||||
public function testGetPriceForBundleSelectionsWithTierPrices(): void
|
||||
{
|
||||
$priceModel = $this->getPriceModel('bundle_with_tier_price_selections');
|
||||
$this->assertEquals(15.0, $priceModel->getMinimalPrice()->getValue());
|
||||
$this->assertEquals(45.0, $priceModel->getMaximalPrice()->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and retrieve Price Model for provided Product SKU.
|
||||
*
|
||||
* @param string $productSku
|
||||
* @return FinalPrice
|
||||
*/
|
||||
private function getPriceModel(string $productSku): FinalPrice
|
||||
{
|
||||
$bundleProduct = $this->productRepository->get($productSku);
|
||||
|
||||
return $this->objectManager->create(
|
||||
FinalPrice::class,
|
||||
[
|
||||
'saleableItem' => $bundleProduct,
|
||||
'quantity' => 0.,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)
|
||||
->setId(42)
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle_product')
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setPriceType(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC)
|
||||
->setShipmentType(0);
|
||||
|
||||
$productRepository->save($product);
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products_rollback.php');
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$registry = $objectManager->get(\Magento\Framework\Registry::class);
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle_product', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/CatalogRule/_files/catalog_rule_10_off_not_logged.php');
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product_rollback.php'
|
||||
);
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/CatalogRule/_files/catalog_rule_10_off_not_logged_rollback.php'
|
||||
);
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$productRepository
|
||||
->get('bundle_product')
|
||||
->setSpecialPrice(50)
|
||||
->save();
|
||||
|
||||
$productRepository
|
||||
->get('simple2')
|
||||
->setSpecialPrice(2.5)
|
||||
->save();
|
||||
|
||||
$productRepository
|
||||
->get('simple5')
|
||||
->setSpecialPrice(9.9)
|
||||
->save();
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product_rollback.php'
|
||||
);
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)
|
||||
->setId(42)
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle_product')
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setPriceType(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED)
|
||||
->setPrice(110.0)
|
||||
->setShipmentType(0);
|
||||
|
||||
$productRepository->save($product);
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products_rollback.php');
|
||||
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$registry = $objectManager->get(\Magento\Framework\Registry::class);
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle_product', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/PriceCalculator/fixed_bundle_product.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/CatalogRule/_files/catalog_rule_10_off_not_logged.php');
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/PriceCalculator/fixed_bundle_product_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/CatalogRule/_files/catalog_rule_10_off_not_logged_rollback.php'
|
||||
);
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/PriceCalculator/fixed_bundle_product.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$productRepository
|
||||
->get('bundle_product')
|
||||
->setSpecialPrice(50)
|
||||
->save();
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/PriceCalculator/fixed_bundle_product_rollback.php');
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
$product2 = $productRepository->get('simple2');
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Checkbox Options')
|
||||
->setSku('bundle-product-checkbox-options')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Checkbox Options',
|
||||
'default_title' => 'Checkbox Options',
|
||||
'type' => 'checkbox',
|
||||
'required' => 0,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
[
|
||||
'sku' => $product2->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
|
||||
$productRepository->save($bundleProduct);
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-checkbox-options', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Checkbox Required Option')
|
||||
->setSku('bundle-product-checkbox-required-option')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Checkbox Options',
|
||||
'default_title' => 'Checkbox Options',
|
||||
'type' => 'checkbox',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-checkbox-required-option', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
$product2 = $productRepository->get('simple2');
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Checkbox Required Options')
|
||||
->setSku('bundle-product-checkbox-required-options')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Checkbox Options',
|
||||
'default_title' => 'Checkbox Options',
|
||||
'type' => 'checkbox',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
[
|
||||
'sku' => $product2->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-checkbox-required-options', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
$product2 = $productRepository->get('simple2');
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Dropdown options')
|
||||
->setSku('bundle-product-dropdown-options')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Dropdown Options',
|
||||
'default_title' => 'Dropdown Options',
|
||||
'type' => 'select',
|
||||
'required' => 0,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
[
|
||||
'sku' => $product2->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-dropdown-options', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
$product2 = $productRepository->get('simple2');
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Dropdown Required options')
|
||||
->setSku('bundle-product-dropdown-required-options')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Dropdown Options',
|
||||
'default_title' => 'Dropdown Options',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => 'simple-1',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-dropdown-required-options', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
$product2 = $productRepository->get('simple2');
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Multiselect Options')
|
||||
->setSku('bundle-product-multiselect-options')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Multiselect Options',
|
||||
'default_title' => 'Multiselect Options',
|
||||
'type' => 'multi',
|
||||
'required' => 0,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
[
|
||||
'sku' => $product2->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-multiselect-options', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Multiselect Required Option')
|
||||
->setSku('bundle-product-multiselect-required-option')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Multiselect Options',
|
||||
'default_title' => 'Multiselect Options',
|
||||
'type' => 'multi',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-multiselect-required-option', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
$product2 = $productRepository->get('simple2');
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Multiselect Required Options')
|
||||
->setSku('bundle-product-multiselect-required-options')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Multiselect Options',
|
||||
'default_title' => 'Multiselect Options',
|
||||
'type' => 'multi',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
[
|
||||
'sku' => $product2->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-multiselect-required-options', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
$product2 = $productRepository->get('simple2');
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Radio Options')
|
||||
->setSku('bundle-product-radio-options')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Radio Options',
|
||||
'default_title' => 'Radio Options',
|
||||
'type' => 'radio',
|
||||
'required' => 0,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
[
|
||||
'sku' => $product2->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-radio-options', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Radio Required Option')
|
||||
->setSku('bundle-product-radio-required-option')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Radio Options',
|
||||
'default_title' => 'Radio Options',
|
||||
'type' => 'radio',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-radio-required-option', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
$product2 = $productRepository->get('simple2');
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Radio Required Options')
|
||||
->setSku('bundle-product-radio-required-options')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Radio Options',
|
||||
'default_title' => 'Radio Options',
|
||||
'type' => 'radio',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
[
|
||||
'sku' => $product2->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1,
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-radio-required-options', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Bundle\Api\Data\LinkInterfaceFactory;
|
||||
use Magento\Bundle\Api\Data\OptionInterfaceFactory;
|
||||
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\Model\Stock\Item;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var Item $stockItem */
|
||||
$stockItem = $objectManager->create(Item::class);
|
||||
$stockItem->load(10, 'product_id');
|
||||
|
||||
if (!$stockItem->getProductId()) {
|
||||
$stockItem->setProductId(10);
|
||||
}
|
||||
|
||||
$stockItem->setUseConfigManageStock(1);
|
||||
$stockItem->setQty(1000);
|
||||
$stockItem->setIsQtyDecimal(0);
|
||||
$stockItem->setIsInStock(1);
|
||||
$stockItem->save();
|
||||
|
||||
/** @var $product Product */
|
||||
$product = $objectManager->create(Product::class);
|
||||
$product->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product With Single dropdown option')
|
||||
->setSku('bundle-product-single-dropdown-option')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(1)
|
||||
->setPriceType(1)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(0)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
[
|
||||
'title' => 'Drop Down Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 0,
|
||||
'position' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
]
|
||||
)->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 1.00,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1,
|
||||
'option_id' => 1,
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
|
||||
if ($product->getBundleOptionsData()) {
|
||||
$options = [];
|
||||
foreach ($product->getBundleOptionsData() as $key => $optionData) {
|
||||
if (!$optionData['delete']) {
|
||||
$option = $objectManager->create(OptionInterfaceFactory::class)
|
||||
->create(['data' => $optionData]);
|
||||
$option->setSku($product->getSku());
|
||||
$option->setOptionId(null);
|
||||
|
||||
$links = [];
|
||||
$bundleLinks = $product->getBundleSelectionsData();
|
||||
if (!empty($bundleLinks[$key])) {
|
||||
foreach ($bundleLinks[$key] as $linkData) {
|
||||
if (!$linkData['delete']) {
|
||||
$link = $objectManager->create(LinkInterfaceFactory::class)
|
||||
->create(['data' => $linkData]);
|
||||
$linkProduct = $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;
|
||||
}
|
||||
}
|
||||
}
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
}
|
||||
$productRepository->save($product, true);
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-single-dropdown-option', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $exception) {
|
||||
$logger = $objectManager->get(LoggerInterface::class);
|
||||
$logger->log($exception->getCode(), $exception->getMessage());
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$productIds = range(10, 12, 1);
|
||||
foreach ($productIds as $productId) {
|
||||
/** @var \Magento\CatalogInventory\Model\Stock\Item $stockItem */
|
||||
$stockItem = $objectManager->create(\Magento\CatalogInventory\Model\Stock\Item::class);
|
||||
$stockItem->load($productId, 'product_id');
|
||||
|
||||
if (!$stockItem->getProductId()) {
|
||||
$stockItem->setProductId($productId);
|
||||
}
|
||||
$stockItem->setUseConfigManageStock(1);
|
||||
$stockItem->setQty(1000);
|
||||
$stockItem->setIsQtyDecimal(0);
|
||||
$stockItem->setIsInStock(1);
|
||||
$stockItem->save();
|
||||
}
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product With Two dropdown options')
|
||||
->setSku('bundle-product-two-dropdown-options')
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(1)
|
||||
->setPriceType(1)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(0)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
// "Drop-down" option
|
||||
[
|
||||
'title' => 'Drop Down Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 0,
|
||||
'position' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
[
|
||||
'title' => 'Drop Down Option 2',
|
||||
'default_title' => 'Option 2',
|
||||
'type' => 'select',
|
||||
'required' => 0,
|
||||
'position' => 2,
|
||||
'delete' => '',
|
||||
]
|
||||
]
|
||||
)->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 1.00,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 2.00,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_price_value' => 1.00,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 2
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 2.00,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 2
|
||||
]
|
||||
],
|
||||
]
|
||||
);
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
if ($product->getBundleOptionsData()) {
|
||||
$options = [];
|
||||
foreach ($product->getBundleOptionsData() as $key => $optionData) {
|
||||
if (!(bool)$optionData['delete']) {
|
||||
$option = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class)
|
||||
->create(['data' => $optionData]);
|
||||
$option->setSku($product->getSku());
|
||||
$option->setOptionId(null);
|
||||
|
||||
$links = [];
|
||||
$bundleLinks = $product->getBundleSelectionsData();
|
||||
if (!empty($bundleLinks[$key])) {
|
||||
foreach ($bundleLinks[$key] as $linkData) {
|
||||
if (!(bool)$linkData['delete']) {
|
||||
$link = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class)
|
||||
->create(['data' => $linkData]);
|
||||
$linkProduct = $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;
|
||||
}
|
||||
}
|
||||
}
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
}
|
||||
$productRepository->save($product, true);
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-two-dropdown-options', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Api\Data\LinkInterfaceFactory;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\CatalogInventory\Model\Stock\Item;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
use Magento\Bundle\Api\Data\OptionInterfaceFactory;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Catalog/_files/multiple_products_with_disabled_virtual_product.php'
|
||||
);
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$productIds = range(101, 104, 1);
|
||||
|
||||
foreach ($productIds as $productId) {
|
||||
/** @var Item $stockItem */
|
||||
$stockItem = $objectManager->create(Item::class);
|
||||
$stockItem->load($productId, 'product_id');
|
||||
|
||||
if (!$stockItem->getProductId()) {
|
||||
$stockItem->setProductId($productId);
|
||||
}
|
||||
$stockItem->setUseConfigManageStock(1);
|
||||
$stockItem->setIsQtyDecimal(0);
|
||||
if ($productId == 104) {
|
||||
$stockItem->setQty(0);
|
||||
$stockItem->setIsInStock(0);
|
||||
} else {
|
||||
$stockItem->setQty(1000);
|
||||
$stockItem->setIsInStock(1);
|
||||
}
|
||||
$stockItem->save();
|
||||
}
|
||||
|
||||
/** @var $product Product */
|
||||
$product = $objectManager->create(Product::class);
|
||||
$product->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setId(3)
|
||||
->setCategoryIds([565])
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle-product')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(1)
|
||||
->setPriceType(1)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(0)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
// Required "Drop-down" option 1
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
'position' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
// Required "Drop-down" option 2
|
||||
[
|
||||
'title' => 'Option 2',
|
||||
'default_title' => 'Option 2',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
'position' => 2,
|
||||
'delete' => '',
|
||||
]
|
||||
]
|
||||
)->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => 101,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
],
|
||||
[
|
||||
'product_id' => 102,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
],
|
||||
[
|
||||
'product_id' => 103,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
],
|
||||
[
|
||||
'product_id' => 104,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'product_id' => 101,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 2
|
||||
],
|
||||
[
|
||||
'product_id' => 102,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 2
|
||||
],
|
||||
[
|
||||
'product_id' => 103,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 2
|
||||
]
|
||||
]
|
||||
]
|
||||
);
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
|
||||
if ($product->getBundleOptionsData()) {
|
||||
$options = [];
|
||||
foreach ($product->getBundleOptionsData() as $key => $optionData) {
|
||||
if (!(bool)$optionData['delete']) {
|
||||
$option = $objectManager->create(OptionInterfaceFactory::class)
|
||||
->create(['data' => $optionData]);
|
||||
$option->setSku($product->getSku());
|
||||
$option->setOptionId(null);
|
||||
|
||||
$links = [];
|
||||
$bundleLinks = $product->getBundleSelectionsData();
|
||||
if (!empty($bundleLinks[$key])) {
|
||||
foreach ($bundleLinks[$key] as $linkData) {
|
||||
if (!(bool)$linkData['delete']) {
|
||||
$link = $objectManager->create(LinkInterfaceFactory::class)
|
||||
->create(['data' => $linkData]);
|
||||
$linkProduct = $productRepository->getById($linkData['product_id']);
|
||||
$link->setSku($linkProduct->getSku());
|
||||
$link->setQty($linkData['selection_qty']);
|
||||
$links[] = $link;
|
||||
}
|
||||
}
|
||||
$option->setProductLinks($links);
|
||||
$options[] = $option;
|
||||
}
|
||||
}
|
||||
}
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
}
|
||||
$product->save();
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Catalog/_files/multiple_products_with_disabled_virtual_product_rollback.php'
|
||||
);
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = Bootstrap::getObjectManager()->get(Registry::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
//delete bundle product
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product');
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $exception) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var StoreManagerInterface $storeManager */
|
||||
$storeManager = $objectManager->get(StoreManagerInterface::class);
|
||||
$defaultWebsiteId = $storeManager->getWebsite('base')->getId();
|
||||
/** @var ProductInterfaceFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
/** @var Magento\Catalog\Api\Data\ProductInterface $bundleProduct */
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$defaultWebsiteId])
|
||||
->setName('Bundle Product With Dynamic Price')
|
||||
->setSku('bundle_product_with_dynamic_price')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(
|
||||
[
|
||||
'use_config_manage_stock' => 0,
|
||||
'qty' => 100,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
]
|
||||
)
|
||||
->setSkuType(0)
|
||||
->setPriceView(0)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(null)
|
||||
->setWeightType(0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
],
|
||||
[
|
||||
'title' => 'Option 2',
|
||||
'default_title' => 'Option 2',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'selection_qty' => 1,
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'selection_qty' => 1,
|
||||
],
|
||||
]
|
||||
];
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, $bundleSelectionsData);
|
||||
$productRepository->save($bundleProduct);
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle_product_with_dynamic_price', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//product already deleted.
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products_rollback.php');
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Since the bundle product creation GUI doesn't allow to choose values for bundled products' custom options,
|
||||
* bundled items should not contain products with required custom options.
|
||||
* However, if to create such a bundle product, it will be always out of stock.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/simple_products_not_visible_individually.php');
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
$sampleProduct = $productRepository->get('simple_not_visible_1');
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId('bundle')
|
||||
->setId(3)
|
||||
->setAttributeSetId(4)
|
||||
->setWeight(2)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle-product-1')
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(0)
|
||||
->setPriceType(0)
|
||||
->setShipmentType(0)
|
||||
->setPrice(10.0)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
[
|
||||
'title' => 'Bundle Product Items',
|
||||
'default_title' => 'Bundle Product Items',
|
||||
'type' => 'select', 'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
]
|
||||
)
|
||||
->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => $sampleProduct->getId(),
|
||||
'selection_price_value' => 2.75,
|
||||
'selection_qty' => 2,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
if ($product->getBundleOptionsData()) {
|
||||
$options = [];
|
||||
foreach ($product->getBundleOptionsData() as $key => $optionData) {
|
||||
if (!(bool)$optionData['delete']) {
|
||||
$option = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class)
|
||||
->create(['data' => $optionData]);
|
||||
$option->setSku($product->getSku());
|
||||
$option->setOptionId(null);
|
||||
|
||||
$links = [];
|
||||
$bundleLinks = $product->getBundleSelectionsData();
|
||||
if (!empty($bundleLinks[$key])) {
|
||||
foreach ($bundleLinks[$key] as $linkData) {
|
||||
if (!(bool)$linkData['delete']) {
|
||||
/** @var \Magento\Bundle\Api\Data\LinkInterface$link */
|
||||
$link = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class)
|
||||
->create(['data' => $linkData]);
|
||||
$linkProduct = $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;
|
||||
}
|
||||
}
|
||||
}
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
}
|
||||
|
||||
$productRepository->save($product, true);
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Since the bundle product creation GUI doesn't allow to choose values for bundled products' custom options,
|
||||
* bundled items should not contain products with required custom options.
|
||||
* However, if to create such a bundle product, it will be always out of stock.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Catalog/_files/simple_products_not_visible_individually_rollback.php'
|
||||
);
|
||||
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-1', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/three_simple_products_with_tier_price.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
/** @var ProductInterfaceFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var StoreManagerInterface $storeManager */
|
||||
$storeManager = $objectManager->get(StoreManagerInterface::class);
|
||||
$defaultWebsiteId = $storeManager->getWebsite('base')->getId();
|
||||
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$defaultWebsiteId])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle_with_tier_price_selections')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(
|
||||
[
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 100,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
]
|
||||
)
|
||||
->setSkuType(0)
|
||||
->setPriceView(0)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(null)
|
||||
->setWeightType(0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
[
|
||||
'sku' => 'simple_1',
|
||||
'selection_qty' => 3,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple_2',
|
||||
'selection_qty' => 3,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple_3',
|
||||
'selection_qty' => 3,
|
||||
],
|
||||
]
|
||||
];
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, $bundleSelectionsData);
|
||||
$productRepository->save($bundleProduct);
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()
|
||||
->requireDataFixture('Magento/Catalog/_files/three_simple_products_with_tier_price_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
try {
|
||||
$product = $productRepository->get('bundle_with_tier_price_selections', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\CategoryLinkManagementInterface;
|
||||
use Magento\Catalog\Helper\DefaultCategory;
|
||||
use Magento\TestFramework\Catalog\Model\GetCategoryByName;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/product.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/bundle_product_dropdown_options.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/category.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var GetCategoryByName $getCategoryByName */
|
||||
$getCategoryByName = $objectManager->create(GetCategoryByName::class);
|
||||
$category = $getCategoryByName->execute('Category 1');
|
||||
/** @var CategoryLinkManagementInterface $categoryLinkManagement */
|
||||
$categoryLinkManagement = $objectManager->create(CategoryLinkManagementInterface::class);
|
||||
/** @var DefaultCategory $categoryHelper */
|
||||
$categoryHelper = $objectManager->get(DefaultCategory::class);
|
||||
$categoryLinkManagement->assignProductToCategories('bundle-product', [2, $category->getId()]);
|
||||
$categoryLinkManagement->assignProductToCategories(
|
||||
'bundle-product-dropdown-options',
|
||||
[$categoryHelper->getId(), $category->getId()]
|
||||
);
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/product_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/bundle_product_dropdown_options_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/category_rollback.php');
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Api\Data\LinkInterfaceFactory;
|
||||
use Magento\Bundle\Api\Data\OptionInterfaceFactory;
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\Data\ProductExtensionFactory;
|
||||
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductInterfaceFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$defaultWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var ProductExtensionFactory $extensionAttributesFactory */
|
||||
$extensionAttributesFactory = $objectManager->get(ProductExtensionFactory::class);
|
||||
/** @var OptionInterfaceFactory $optionFactory */
|
||||
$optionFactory = $objectManager->get(OptionInterfaceFactory::class);
|
||||
/** @var LinkInterfaceFactory $linkFactory */
|
||||
$linkFactory = $objectManager->get(LinkInterfaceFactory::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple1');
|
||||
$product2 = $productRepository->get('simple2');
|
||||
$product3 = $productRepository->get('simple3');
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$defaultWebsiteId])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle_product')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(
|
||||
[
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 100,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
]
|
||||
)
|
||||
->setSkuType(0)
|
||||
->setPriceView(0)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setWeightType(0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'multi',
|
||||
'required' => 1,
|
||||
],
|
||||
]
|
||||
)->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => $product->getId(),
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
[
|
||||
'product_id' => $product2->getId(),
|
||||
'sku' => $product2->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
[
|
||||
'product_id' => $product3->getId(),
|
||||
'sku' => $product3->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
$options = [];
|
||||
foreach ($bundleProduct->getBundleOptionsData() as $key => $optionData) {
|
||||
$option = $optionFactory->create(['data' => $optionData]);
|
||||
$option->setSku($bundleProduct->getSku());
|
||||
$option->setOptionId(null);
|
||||
$links = [];
|
||||
foreach ($bundleProduct->getBundleSelectionsData()[$key] as $linkData) {
|
||||
$link = $linkFactory->create(['data' => $linkData]);
|
||||
$links[] = $link;
|
||||
}
|
||||
$option->setProductLinks($links);
|
||||
$options[] = $option;
|
||||
}
|
||||
$extensionAttributes = $bundleProduct->getExtensionAttributes() ?: $extensionAttributesFactory->create();
|
||||
$extensionAttributes->setBundleProductOptions($options);
|
||||
$bundleProduct->setExtensionAttributes($extensionAttributes);
|
||||
$productRepository->save($bundleProduct);
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle_product', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\CategoryRepositoryInterface;
|
||||
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Api\Data\CategoryInterfaceFactory;
|
||||
use Magento\Catalog\Helper\DefaultCategory;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\CatalogRule\Api\CatalogRuleRepositoryInterface;
|
||||
use Magento\CatalogRule\Api\Data\RuleInterface;
|
||||
use Magento\CatalogRule\Api\Data\RuleInterfaceFactory;
|
||||
use Magento\CatalogRule\Model\Indexer\IndexBuilder;
|
||||
use Magento\CatalogRule\Model\Rule\Condition\Combine;
|
||||
use Magento\CatalogRule\Model\Rule\Condition\Product;
|
||||
use Magento\Customer\Model\Group;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/category_with_different_price_products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var CategoryInterfaceFactory $categoryFactory */
|
||||
$categoryFactory = $objectManager->get(CategoryInterfaceFactory::class);
|
||||
/** @var CategoryRepositoryInterface $categoryRepository */
|
||||
$categoryRepository = $objectManager->get(CategoryRepositoryInterface::class);
|
||||
/** @var DefaultCategory $categoryHelper */
|
||||
$categoryHelper = $objectManager->get(DefaultCategory::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var ProductInterfaceFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
|
||||
$product = $productRepository->get('simple1000');
|
||||
$product2 = $productRepository->get('simple1001');
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var RuleInterfaceFactory $catalogRuleFactory */
|
||||
$catalogRuleFactory = $objectManager->get(RuleInterfaceFactory::class);
|
||||
/** @var CatalogRuleRepositoryInterface $catalogRuleRepository */
|
||||
$catalogRuleRepository = $objectManager->get(CatalogRuleRepositoryInterface::class);
|
||||
/** @var IndexBuilder $indexBuilder */
|
||||
$indexBuilder = $objectManager->get(IndexBuilder::class);
|
||||
/** @var StoreManagerInterface $storeManager */
|
||||
$storeManager = $objectManager->get(StoreManagerInterface::class);
|
||||
$defaultWebsiteId = $storeManager->getWebsite('base')->getId();
|
||||
|
||||
$category = $categoryFactory->create();
|
||||
$category->isObjectNew(true);
|
||||
$category->setName('Category with bundle product and rule')
|
||||
->setParentId($categoryHelper->getId())
|
||||
->setIsActive(true)
|
||||
->setPosition(1);
|
||||
$category = $categoryRepository->save($category);
|
||||
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$defaultWebsiteId])
|
||||
->setName('Bundle Product')
|
||||
->setSku('dynamic_bundle_product_with_catalog_rule')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(
|
||||
[
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 100,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
]
|
||||
)
|
||||
->setSkuType(0)
|
||||
->setPriceView(0)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(null)
|
||||
->setWeightType(0)
|
||||
->setCategoryIds([$category->getId()])
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => $product2->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
]
|
||||
];
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, $bundleSelectionsData);
|
||||
$productRepository->save($bundleProduct);
|
||||
|
||||
$ruleData = [
|
||||
RuleInterface::NAME => 'Rule for bundle product',
|
||||
RuleInterface::IS_ACTIVE => 1,
|
||||
'website_ids' => [$defaultWebsiteId],
|
||||
'customer_group_ids' => Group::NOT_LOGGED_IN_ID,
|
||||
RuleInterface::DISCOUNT_AMOUNT => 50,
|
||||
RuleInterface::SIMPLE_ACTION => 'by_percent',
|
||||
'conditions' => [
|
||||
'1' => [
|
||||
'type' => Combine::class,
|
||||
'aggregator' => 'all',
|
||||
'value' => '1',
|
||||
],
|
||||
'1--1' => [
|
||||
'type' => Product::class,
|
||||
'attribute' => 'category_ids',
|
||||
'operator' => '==',
|
||||
'value' => $category->getId(),
|
||||
],
|
||||
],
|
||||
];
|
||||
$catalogRule = $catalogRuleFactory->create();
|
||||
$catalogRule->loadPost($ruleData);
|
||||
$catalogRuleRepository->save($catalogRule);
|
||||
$indexBuilder->reindexFull();
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\CategoryRepositoryInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\CatalogRule\Api\CatalogRuleRepositoryInterface;
|
||||
use Magento\CatalogRule\Model\Indexer\IndexBuilder;
|
||||
use Magento\CatalogRule\Model\ResourceModel\Rule\CollectionFactory;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Catalog\Model\GetCategoryByName;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Catalog/_files/category_with_different_price_products_rollback.php'
|
||||
);
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var CategoryRepositoryInterface $categoryRepository */
|
||||
$categoryRepository = $objectManager->get(CategoryRepositoryInterface::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
/** @var GetCategoryByName $getCategoryByName */
|
||||
$getCategoryByName = $objectManager->create(GetCategoryByName::class);
|
||||
/** @var CollectionFactory $ruleCollectionFactory */
|
||||
$ruleCollectionFactory = $objectManager->get(CollectionFactory::class);
|
||||
/** @var CatalogRuleRepositoryInterface $ruleRepository */
|
||||
$ruleRepository = $objectManager->get(CatalogRuleRepositoryInterface::class);
|
||||
/** @var IndexBuilder $indexBuilder */
|
||||
$indexBuilder = $objectManager->get(IndexBuilder::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('dynamic_bundle_product_with_catalog_rule', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//product already deleted.
|
||||
}
|
||||
|
||||
$category = $getCategoryByName->execute('Category with bundle product and rule');
|
||||
|
||||
try {
|
||||
$categoryRepository->delete($category);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//category already deleted.
|
||||
}
|
||||
|
||||
$ruleCollection = $ruleCollectionFactory->create();
|
||||
$ruleCollection->addFieldToFilter('name', 'Rule for bundle product');
|
||||
$ruleCollection->setPageSize(1);
|
||||
$catalogRule = $ruleCollection->getFirstItem();
|
||||
|
||||
try {
|
||||
$ruleRepository->delete($catalogRule);
|
||||
} catch (Exception $ex) {
|
||||
//Nothing to remove
|
||||
}
|
||||
|
||||
$indexBuilder->reindexFull();
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Api\Data\ProductTierPriceExtensionFactory;
|
||||
use Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$productIds = [10, 11, 12];
|
||||
foreach ($productIds as $productId) {
|
||||
/** @var \Magento\CatalogInventory\Model\Stock\Item $stockItem */
|
||||
$stockItem = $objectManager->create(\Magento\CatalogInventory\Model\Stock\Item::class);
|
||||
$stockItem->load($productId, 'product_id');
|
||||
|
||||
if (!$stockItem->getProductId()) {
|
||||
$stockItem->setProductId($productId);
|
||||
}
|
||||
$stockItem->setUseConfigManageStock(1);
|
||||
$stockItem->setQty(1000);
|
||||
$stockItem->setIsQtyDecimal(0);
|
||||
$stockItem->setIsInStock(1);
|
||||
$stockItem->save();
|
||||
}
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)
|
||||
->setId(3)
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle-product')
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(0)
|
||||
->setPrice(10.0)
|
||||
->setSpecialPrice(10)
|
||||
->setShipmentType(0)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
// Required "Drop-down" option
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
|
||||
]
|
||||
)->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 2.75,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 6.75,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
]
|
||||
]
|
||||
]
|
||||
);
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
if ($product->getBundleOptionsData()) {
|
||||
$options = [];
|
||||
foreach ($product->getBundleOptionsData() as $key => $optionData) {
|
||||
if (!(bool)$optionData['delete']) {
|
||||
$option = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class)
|
||||
->create(['data' => $optionData]);
|
||||
$option->setSku($product->getSku());
|
||||
$option->setOptionId(null);
|
||||
|
||||
$links = [];
|
||||
$bundleLinks = $product->getBundleSelectionsData();
|
||||
if (!empty($bundleLinks[$key])) {
|
||||
foreach ($bundleLinks[$key] as $linkData) {
|
||||
if (!(bool)$linkData['delete']) {
|
||||
$link = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class)
|
||||
->create(['data' => $linkData]);
|
||||
$linkProduct = $productRepository->getById($linkData['product_id']);
|
||||
$link->setSku($linkProduct->getSku());
|
||||
$link->setQty($linkData['selection_qty']);
|
||||
$link->setPrice($linkData['selection_price_value']);
|
||||
$links[] = $link;
|
||||
}
|
||||
}
|
||||
$option->setProductLinks($links);
|
||||
$options[] = $option;
|
||||
}
|
||||
}
|
||||
}
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
}
|
||||
$tierPriceFactory = $objectManager->get(ProductTierPriceInterfaceFactory::class);
|
||||
/** @var $tierPriceExtensionAttributesFactory */
|
||||
$tierPriceExtensionAttributesFactory = $objectManager->create(ProductTierPriceExtensionFactory::class);
|
||||
$tierPriceExtensionAttribute = $tierPriceExtensionAttributesFactory->create()->setPercentageValue(10);
|
||||
$tierPrices[] = $tierPriceFactory->create(
|
||||
[
|
||||
'data' => [
|
||||
'customer_group_id' => \Magento\Customer\Model\Group::CUST_GROUP_ALL,
|
||||
'qty' => 2
|
||||
]
|
||||
]
|
||||
)->setExtensionAttributes($tierPriceExtensionAttribute);
|
||||
$product->setTierPrices($tierPrices);
|
||||
$product->save();
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/product_with_multiple_options_rollback.php');
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/category_with_different_price_products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var ProductInterfaceFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
|
||||
/** @var StoreManagerInterface $storeManager */
|
||||
$storeManager = $objectManager->get(StoreManagerInterface::class);
|
||||
$defaultWebsiteId = $storeManager->getWebsite('base')->getId();
|
||||
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$defaultWebsiteId])
|
||||
->setName('Bundle Product')
|
||||
->setSku('dynamic_bundle_product_with_special_price')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(
|
||||
[
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 100,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
]
|
||||
)
|
||||
->setSkuType(0)
|
||||
->setPriceView(0)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(null)
|
||||
->setSpecialPrice(75)
|
||||
->setWeightType(0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
[
|
||||
'sku' => 'simple1000',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple1001',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
]
|
||||
];
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, $bundleSelectionsData);
|
||||
$productRepository->save($bundleProduct);
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user