Skip to content

Commit 4d0a14a

Browse files
author
Dmytro Voskoboinikov
committed
Merge branch 'develop' into MAGETWO-64547
# Conflicts: # app/code/Magento/Bundle/etc/di.xml
2 parents 19cf025 + d03bc98 commit 4d0a14a

File tree

217 files changed

+4128
-2893
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

217 files changed

+4128
-2893
lines changed

app/code/Magento/Bundle/Model/CartItemProcessor.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,26 +84,28 @@ public function processOptions(CartItemInterface $cartItem)
8484
$productOptions = [];
8585
$bundleOptions = $cartItem->getBuyRequest()->getBundleOption();
8686
$bundleOptionsQty = $cartItem->getBuyRequest()->getBundleOptionQty();
87-
foreach ($bundleOptions as $optionId => $optionSelections) {
88-
if (empty($optionSelections)) {
89-
continue;
90-
}
91-
$optionSelections = is_array($optionSelections) ? $optionSelections : [$optionSelections];
92-
$optionQty = isset($bundleOptionsQty[$optionId]) ? $bundleOptionsQty[$optionId] : 1;
87+
if (is_array($bundleOptions)) {
88+
foreach ($bundleOptions as $optionId => $optionSelections) {
89+
if (empty($optionSelections)) {
90+
continue;
91+
}
92+
$optionSelections = is_array($optionSelections) ? $optionSelections : [$optionSelections];
93+
$optionQty = isset($bundleOptionsQty[$optionId]) ? $bundleOptionsQty[$optionId] : 1;
9394

94-
/** @var \Magento\Bundle\Api\Data\BundleOptionInterface $productOption */
95-
$productOption = $this->bundleOptionFactory->create();
96-
$productOption->setOptionId($optionId);
97-
$productOption->setOptionSelections($optionSelections);
98-
$productOption->setOptionQty($optionQty);
99-
$productOptions[] = $productOption;
100-
}
95+
/** @var \Magento\Bundle\Api\Data\BundleOptionInterface $productOption */
96+
$productOption = $this->bundleOptionFactory->create();
97+
$productOption->setOptionId($optionId);
98+
$productOption->setOptionSelections($optionSelections);
99+
$productOption->setOptionQty($optionQty);
100+
$productOptions[] = $productOption;
101+
}
101102

102-
$extension = $this->productOptionExtensionFactory->create()->setBundleOptions($productOptions);
103-
if (!$cartItem->getProductOption()) {
104-
$cartItem->setProductOption($this->productOptionFactory->create());
103+
$extension = $this->productOptionExtensionFactory->create()->setBundleOptions($productOptions);
104+
if (!$cartItem->getProductOption()) {
105+
$cartItem->setProductOption($this->productOptionFactory->create());
106+
}
107+
$cartItem->getProductOption()->setExtensionAttributes($extension);
105108
}
106-
$cartItem->getProductOption()->setExtensionAttributes($extension);
107109
return $cartItem;
108110
}
109111
}

app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Catalog\Api\Data\ProductInterface;
99
use Magento\CatalogInventory\Model\Indexer\Stock\Action\Full;
10+
use Magento\Framework\App\ObjectManager;
1011

1112
/**
1213
* Bundle Stock Status Indexer Resource Model
@@ -16,33 +17,31 @@
1617
class Stock extends \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\DefaultStock
1718
{
1819
/**
19-
* @var \Magento\Indexer\Model\ResourceModel\FrontendResource
20+
* @var \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher
2021
*/
21-
private $indexerStockFrontendResource;
22+
private $activeTableSwitcher;
2223

2324
/**
24-
* Class constructor
25-
*
25+
* Stock constructor.
2626
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
2727
* @param \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy
2828
* @param \Magento\Eav\Model\Config $eavConfig
2929
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
30-
* @param string $connectionName
31-
* @param null|\Magento\Indexer\Model\Indexer\StateFactory $stateFactory
32-
* @param null|\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource
30+
* @param null $connectionName
31+
* @param \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher|null $activeTableSwitcher
3332
*/
3433
public function __construct(
3534
\Magento\Framework\Model\ResourceModel\Db\Context $context,
3635
\Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy,
3736
\Magento\Eav\Model\Config $eavConfig,
3837
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
3938
$connectionName = null,
40-
\Magento\Indexer\Model\Indexer\StateFactory $stateFactory = null,
41-
\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null
39+
\Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher $activeTableSwitcher = null
4240
) {
43-
parent::__construct($context, $tableStrategy, $eavConfig, $scopeConfig, $connectionName, $stateFactory);
44-
$this->indexerStockFrontendResource = $indexerStockFrontendResource ?: ObjectManager::getInstance()
45-
->get(\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class);
41+
parent::__construct($context, $tableStrategy, $eavConfig, $scopeConfig, $connectionName);
42+
$this->activeTableSwitcher = $activeTableSwitcher ?: ObjectManager::getInstance()->get(
43+
\Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher::class
44+
);
4645
}
4746

4847
/**
@@ -67,8 +66,8 @@ protected function _prepareBundleOptionStockData($entityIds = null, $usePrimaryT
6766
$this->_cleanBundleOptionStockData();
6867
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
6968
$table = $this->getActionType() === Full::ACTION_TYPE
70-
? $this->getMainTable()
71-
: $this->indexerStockFrontendResource->getMainTable();
69+
? $this->activeTableSwitcher->getAdditionalTableName($this->getMainTable())
70+
: $this->getMainTable();
7271
$idxTable = $usePrimaryTable ? $table : $this->getIdxTable();
7372
$connection = $this->getConnection();
7473
$select = $connection->select()->from(

app/code/Magento/Bundle/Model/ResourceModel/Selection/Collection.php

Lines changed: 1 addition & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -44,99 +44,6 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
4444
*/
4545
private $websiteScopePriceJoined = false;
4646

47-
/**
48-
* @var \Magento\Indexer\Model\ResourceModel\FrontendResource
49-
*/
50-
private $indexerStockFrontendResource;
51-
52-
/**
53-
* Collection constructor.
54-
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
55-
* @param \Psr\Log\LoggerInterface $logger
56-
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
57-
* @param \Magento\Framework\Event\ManagerInterface $eventManager
58-
* @param \Magento\Eav\Model\Config $eavConfig
59-
* @param \Magento\Framework\App\ResourceConnection $resource
60-
* @param \Magento\Eav\Model\EntityFactory $eavEntityFactory
61-
* @param \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper
62-
* @param \Magento\Framework\Validator\UniversalFactory $universalFactory
63-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
64-
* @param \Magento\Framework\Module\Manager $moduleManager
65-
* @param \Magento\Catalog\Model\Indexer\Product\Flat\State $catalogProductFlatState
66-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
67-
* @param \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory
68-
* @param \Magento\Catalog\Model\ResourceModel\Url $catalogUrl
69-
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
70-
* @param \Magento\Customer\Model\Session $customerSession
71-
* @param \Magento\Framework\Stdlib\DateTime $dateTime
72-
* @param GroupManagementInterface $groupManagement
73-
* @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection
74-
* @param ProductLimitationFactory|null $productLimitationFactory
75-
* @param MetadataPool|null $metadataPool
76-
* @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $indexerFrontendResource
77-
* @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $categoryProductIndexerFrontend
78-
* @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $indexerStockFrontendResource
79-
*
80-
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
81-
* @SuppressWarnings(Magento.TypeDuplication)
82-
*/
83-
public function __construct(
84-
\Magento\Framework\Data\Collection\EntityFactory $entityFactory,
85-
\Psr\Log\LoggerInterface $logger,
86-
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
87-
\Magento\Framework\Event\ManagerInterface $eventManager,
88-
\Magento\Eav\Model\Config $eavConfig,
89-
\Magento\Framework\App\ResourceConnection $resource,
90-
\Magento\Eav\Model\EntityFactory $eavEntityFactory,
91-
\Magento\Catalog\Model\ResourceModel\Helper $resourceHelper,
92-
\Magento\Framework\Validator\UniversalFactory $universalFactory,
93-
\Magento\Store\Model\StoreManagerInterface $storeManager,
94-
\Magento\Framework\Module\Manager $moduleManager,
95-
\Magento\Catalog\Model\Indexer\Product\Flat\State $catalogProductFlatState,
96-
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
97-
\Magento\Catalog\Model\Product\OptionFactory $productOptionFactory,
98-
\Magento\Catalog\Model\ResourceModel\Url $catalogUrl,
99-
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
100-
\Magento\Customer\Model\Session $customerSession,
101-
\Magento\Framework\Stdlib\DateTime $dateTime,
102-
GroupManagementInterface $groupManagement,
103-
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
104-
ProductLimitationFactory $productLimitationFactory = null,
105-
MetadataPool $metadataPool = null,
106-
\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerFrontendResource = null,
107-
\Magento\Indexer\Model\ResourceModel\FrontendResource $categoryProductIndexerFrontend = null,
108-
\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null
109-
) {
110-
parent::__construct(
111-
$entityFactory,
112-
$logger,
113-
$fetchStrategy,
114-
$eventManager,
115-
$eavConfig,
116-
$resource,
117-
$eavEntityFactory,
118-
$resourceHelper,
119-
$universalFactory,
120-
$storeManager,
121-
$moduleManager,
122-
$catalogProductFlatState,
123-
$scopeConfig,
124-
$productOptionFactory,
125-
$catalogUrl,
126-
$localeDate,
127-
$customerSession,
128-
$dateTime,
129-
$groupManagement,
130-
$connection,
131-
$productLimitationFactory,
132-
$metadataPool,
133-
$indexerFrontendResource,
134-
$categoryProductIndexerFrontend
135-
);
136-
$this->indexerStockFrontendResource = $indexerStockFrontendResource ?: ObjectManager::getInstance()
137-
->get(\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class);
138-
}
139-
14047
/**
14148
* Initialize collection
14249
*
@@ -263,7 +170,7 @@ public function addQuantityFilter()
263170
{
264171
$this->getSelect()
265172
->joinInner(
266-
['stock' => $this->indexerStockFrontendResource->getMainTable()],
173+
['stock' => $this->getTable('cataloginventory_stock_status')],
267174
'selection.product_id = stock.product_id',
268175
[]
269176
)

app/code/Magento/Bundle/Test/Unit/Model/CartItemProcessorTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,22 @@ public function testProcessProductOptionsInvalidType()
180180
$cartItemMock->expects($this->once())->method('getProductType')->willReturn(Type::TYPE_SIMPLE);
181181
$this->assertSame($cartItemMock, $this->model->processOptions($cartItemMock));
182182
}
183+
184+
public function testProcessProductOptionsifBundleOptionsNotExists()
185+
{
186+
$buyRequestMock = new \Magento\Framework\DataObject(
187+
[]
188+
);
189+
$methods = ['getProductType', 'getBuyRequest'];
190+
$cartItemMock = $this->getMock(
191+
\Magento\Quote\Model\Quote\Item::class,
192+
$methods,
193+
[],
194+
'',
195+
false
196+
);
197+
$cartItemMock->expects($this->once())->method('getProductType')->willReturn(Type::TYPE_BUNDLE);
198+
$cartItemMock->expects($this->exactly(2))->method('getBuyRequest')->willReturn($buyRequestMock);
199+
$this->assertSame($cartItemMock, $this->model->processOptions($cartItemMock));
200+
}
183201
}

app/code/Magento/Bundle/Test/Unit/Model/ResourceModel/Selection/CollectionTest.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\Bundle\Test\Unit\Model\ResourceModel\Selection;
77

88
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
9-
use Magento\Indexer\Model\ResourceModel\FrontendResource;
109
use Magento\Store\Model\StoreManagerInterface;
1110
use Magento\Store\Api\Data\StoreInterface;
1211
use Magento\Framework\Validator\UniversalFactory;
@@ -17,15 +16,9 @@
1716

1817
/**
1918
* Class CollectionTest.
20-
* Unit test for \Magento\Indexer\Model\ResourceModel\FrontendResource.
2119
*/
2220
class CollectionTest extends \PHPUnit_Framework_TestCase
2321
{
24-
/**
25-
* @var \PHPUnit_Framework_MockObject_MockObject
26-
*/
27-
private $frontendResource;
28-
2922
/**
3023
* @var \PHPUnit_Framework_MockObject_MockObject
3124
*/
@@ -64,9 +57,6 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
6457
protected function setUp()
6558
{
6659
$objectManager = new ObjectManager($this);
67-
$this->frontendResource = $this->getMockBuilder(FrontendResource::class)
68-
->disableOriginalConstructor()
69-
->getMock();
7060
$this->storeManager = $this->getMockBuilder(StoreManagerInterface::class)
7161
->disableOriginalConstructor()
7262
->getMock();
@@ -114,17 +104,16 @@ protected function setUp()
114104
[
115105
'storeManager' => $this->storeManager,
116106
'universalFactory' => $this->universalFactory,
117-
'productLimitationFactory' => $factory,
118-
'indexerStockFrontendResource' => $this->frontendResource
107+
'productLimitationFactory' => $factory
119108
]
120109
);
121110
}
122111

123112
public function testAddQuantityFilter()
124113
{
125114
$tableName = 'cataloginventory_stock_status';
126-
$this->frontendResource->expects($this->once())
127-
->method('getMainTable')
115+
$this->entity->expects($this->once())
116+
->method('getTable')
128117
->willReturn($tableName);
129118
$this->select->expects($this->once())
130119
->method('joinInner')

app/code/Magento/Bundle/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
"magento/framework": "100.2.*",
1919
"magento/module-quote": "100.2.*",
2020
"magento/module-media-storage": "100.2.*",
21-
"magento/module-ui": "100.2.*",
22-
"magento/module-indexer": "100.2.*"
21+
"magento/module-ui": "100.2.*"
2322
},
2423
"suggest": {
2524
"magento/module-webapi": "100.2.*",

app/code/Magento/Bundle/etc/di.xml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,11 @@
155155
</type>
156156
<type name="Magento\CatalogInventory\Model\Indexer\Stock\Action\Full">
157157
<arguments>
158-
<argument name="memoryTablesMinRows" xsi:type="array">
158+
<argument name="batchRowsCount" xsi:type="array">
159159
<item name="bundle" xsi:type="number">136</item>
160160
</argument>
161161
</arguments>
162162
</type>
163-
<type name="Magento\Bundle\Model\ResourceModel\Selection\Collection">
164-
<arguments>
165-
<argument name="indexerStockFrontendResource" xsi:type="object">Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource</argument>
166-
</arguments>
167-
</type>
168-
<type name="Magento\Bundle\Model\ResourceModel\Indexer\Stock">
169-
<arguments>
170-
<argument name="indexerStockFrontendResource" xsi:type="object">Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource</argument>
171-
</arguments>
172-
</type>
173163
<type name="Magento\Framework\EntityManager\MetadataPool">
174164
<arguments>
175165
<argument name="metadata" xsi:type="array">

app/code/Magento/Catalog/Model/Indexer/Category/Product/AbstractAction.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Magento\Framework\DB\Query\Generator as QueryGenerator;
1212
use Magento\Framework\App\ResourceConnection;
1313
use Magento\Framework\EntityManager\MetadataPool;
14-
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Category\Product\FrontendResource as CategoryProductFrontend;
1514

1615
/**
1716
* Class AbstractAction
@@ -112,33 +111,24 @@ abstract class AbstractAction
112111
*/
113112
private $queryGenerator;
114113

115-
/**
116-
* @var \Magento\Indexer\Model\ResourceModel\FrontendResource|null
117-
*/
118-
private $categoryProductIndexerFrontend;
119-
120114
/**
121115
* @param ResourceConnection $resource
122116
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
123117
* @param \Magento\Catalog\Model\Config $config
124118
* @param QueryGenerator $queryGenerator
125-
* @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $categoryProductIndexerFrontend
126119
*/
127120
public function __construct(
128121
\Magento\Framework\App\ResourceConnection $resource,
129122
\Magento\Store\Model\StoreManagerInterface $storeManager,
130123
\Magento\Catalog\Model\Config $config,
131-
QueryGenerator $queryGenerator = null,
132-
\Magento\Indexer\Model\ResourceModel\FrontendResource $categoryProductIndexerFrontend = null
124+
QueryGenerator $queryGenerator = null
133125
) {
134126
$this->resource = $resource;
135127
$this->connection = $resource->getConnection();
136128
$this->storeManager = $storeManager;
137129
$this->config = $config;
138130
$this->queryGenerator = $queryGenerator ?: \Magento\Framework\App\ObjectManager::getInstance()
139131
->get(QueryGenerator::class);
140-
$this->categoryProductIndexerFrontend = $categoryProductIndexerFrontend
141-
?: \Magento\Framework\App\ObjectManager::getInstance()->get(CategoryProductFrontend::class);
142132
}
143133

144134
/**
@@ -185,7 +175,7 @@ protected function getTable($table)
185175
*/
186176
protected function getMainTable()
187177
{
188-
return $this->categoryProductIndexerFrontend->getMainTable();
178+
return $this->getTable(self::MAIN_INDEX_TABLE);
189179
}
190180

191181
/**

0 commit comments

Comments
 (0)