Skip to content

Commit 0fe805f

Browse files
Merge pull request #8371 from magento-l3/L3-PR-2023-06-23
L3 pr 2023 06 23
2 parents 70f8114 + 972ba07 commit 0fe805f

File tree

28 files changed

+858
-76
lines changed

28 files changed

+858
-76
lines changed

app/code/Magento/Bundle/Pricing/Adjustment/DefaultSelectionPriceListProvider.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ public function getPriceList(Product $bundleProduct, $searchMin, $useRegularPric
8585
[(int)$option->getOptionId()],
8686
$bundleProduct
8787
);
88-
$selectionsCollection->setFlag('has_stock_status_filter', true);
88+
89+
if ((int)$bundleProduct->getPriceType() !== Price::PRICE_TYPE_FIXED) {
90+
$selectionsCollection->setFlag('has_stock_status_filter', true);
91+
}
8992
$selectionsCollection->removeAttributeToSelect();
9093

9194
if (!$useRegularPrice) {

app/code/Magento/Bundle/Test/Unit/Pricing/Adjustment/DefaultSelectionPriceListProviderTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\Bundle\Test\Unit\Pricing\Adjustment;
99

1010
use Magento\Bundle\Model\Option;
11+
use Magento\Bundle\Model\Product\Price;
1112
use Magento\Bundle\Model\Product\Type;
1213
use Magento\Bundle\Model\ResourceModel\Option\Collection;
1314
use Magento\Bundle\Model\ResourceModel\Selection\Collection as SelectionCollection;
@@ -109,6 +110,8 @@ protected function setUp(): void
109110

110111
$this->product = $this->getMockBuilder(Product::class)
111112
->disableOriginalConstructor()
113+
->addMethods(['getPriceType'])
114+
->onlyMethods(['getTypeInstance', 'isSalable'])
112115
->getMock();
113116
$this->optionsCollection = $this->getMockBuilder(Collection::class)
114117
->disableOriginalConstructor()
@@ -142,6 +145,54 @@ public function testGetPriceList(): void
142145
{
143146
$optionId = 1;
144147

148+
$this->typeInstance->expects($this->any())
149+
->method('getOptionsCollection')
150+
->with($this->product)
151+
->willReturn($this->optionsCollection);
152+
$this->product->expects($this->any())
153+
->method('getTypeInstance')
154+
->willReturn($this->typeInstance);
155+
$this->product->expects($this->once())
156+
->method('getPriceType')->willReturn(Price::PRICE_TYPE_FIXED);
157+
$this->optionsCollection->expects($this->once())
158+
->method('getIterator')
159+
->willReturn(new \ArrayIterator([$this->option]));
160+
$this->option->expects($this->once())
161+
->method('getOptionId')
162+
->willReturn($optionId);
163+
$this->typeInstance->expects($this->once())
164+
->method('getSelectionsCollection')
165+
->with([$optionId], $this->product)
166+
->willReturn($this->selectionCollection);
167+
$this->option->expects($this->once())
168+
->method('isMultiSelection')
169+
->willReturn(true);
170+
$this->storeManager->expects($this->once())
171+
->method('getStore')
172+
->willReturn($this->store);
173+
$this->store->expects($this->once())
174+
->method('getWebsiteId')
175+
->willReturn(0);
176+
$this->websiteRepository->expects($this->once())
177+
->method('getDefault')
178+
->willReturn($this->website);
179+
$this->website->expects($this->once())
180+
->method('getId')
181+
->willReturn(1);
182+
$this->selectionCollection->expects($this->once())
183+
->method('getIterator')
184+
->willReturn(new \ArrayIterator([]));
185+
$this->selectionCollection->expects($this->never())
186+
->method('setFlag')
187+
->with('has_stock_status_filter', true);
188+
189+
$this->model->getPriceList($this->product, false, false);
190+
}
191+
192+
public function testGetPriceListForFixedPriceType(): void
193+
{
194+
$optionId = 1;
195+
145196
$this->typeInstance->expects($this->any())
146197
->method('getOptionsCollection')
147198
->with($this->product)

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class Product extends AbstractEntity
307307
ValidatorInterface::ERROR_INVALID_VARIATIONS_CUSTOM_OPTIONS => 'Value for \'%s\' sub attribute in \'%s\' attribute contains incorrect value, acceptable values are: \'dropdown\', \'checkbox\', \'radio\', \'text\'',
308308
ValidatorInterface::ERROR_INVALID_MEDIA_URL_OR_PATH => 'Wrong URL/path used for attribute %s',
309309
ValidatorInterface::ERROR_MEDIA_PATH_NOT_ACCESSIBLE => 'Imported resource (image) does not exist in the local media storage',
310-
ValidatorInterface::ERROR_MEDIA_URL_NOT_ACCESSIBLE => 'Imported resource (image) could not be downloaded from external resource due to timeout or access permissions',
310+
ValidatorInterface::ERROR_MEDIA_URL_NOT_ACCESSIBLE => 'Imported resource (image: %s) at row %s could not be downloaded from external resource due to timeout or access permissions',
311311
ValidatorInterface::ERROR_INVALID_WEIGHT => 'Product weight is invalid',
312312
ValidatorInterface::ERROR_DUPLICATE_URL_KEY => 'Url key: \'%s\' was already generated for an item with the SKU: \'%s\'. You need to specify the unique URL key manually',
313313
ValidatorInterface::ERROR_DUPLICATE_MULTISELECT_VALUES => 'Value for multiselect attribute %s contains duplicated values',
@@ -1899,7 +1899,11 @@ private function saveProductMediaGalleryPhase(
18991899
ValidatorInterface::ERROR_MEDIA_URL_NOT_ACCESSIBLE,
19001900
$rowNum,
19011901
null,
1902-
null,
1902+
sprintf(
1903+
$this->_messageTemplates[ValidatorInterface::ERROR_MEDIA_URL_NOT_ACCESSIBLE],
1904+
$columnImage,
1905+
$rowNum
1906+
),
19031907
ProcessingError::ERROR_LEVEL_NOT_CRITICAL
19041908
);
19051909
}

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext.php

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\CatalogSearch\Model\ResourceModel\Fulltext as FulltextResource;
1313
use Magento\Framework\App\ObjectManager;
1414
use Magento\Framework\Indexer\DimensionProviderInterface;
15+
use Magento\Framework\Indexer\SaveHandler\StackedActionsIndexerInterface;
1516
use Magento\Framework\Indexer\SaveHandler\IndexerInterface;
1617
use Magento\Store\Model\StoreDimensionProvider;
1718
use Magento\Indexer\Model\ProcessManager;
@@ -40,6 +41,13 @@ class Fulltext implements
4041
*/
4142
private const BATCH_SIZE = 1000;
4243

44+
/**
45+
* Deployment config path
46+
*
47+
* @var string
48+
*/
49+
private const DEPLOYMENT_CONFIG_INDEXER_BATCHES = 'indexer/batch_size/';
50+
4351
/**
4452
* @var array index structure
4553
*/
@@ -94,13 +102,6 @@ class Fulltext implements
94102
*/
95103
private $deploymentConfig;
96104

97-
/**
98-
* Deployment config path
99-
*
100-
* @var string
101-
*/
102-
private const DEPLOYMENT_CONFIG_INDEXER_BATCHES = 'indexer/batch_size/';
103-
104105
/**
105106
* @param FullFactory $fullActionFactory
106107
* @param IndexerHandlerFactory $indexerHandlerFactory
@@ -156,7 +157,7 @@ public function execute($entityIds)
156157
/**
157158
* @inheritdoc
158159
*
159-
* @throws \InvalidArgumentException
160+
* @throws \InvalidArgumentException|\Exception
160161
* @since 101.0.0
161162
*/
162163
public function executeByDimensions(array $dimensions, \Traversable $entityIds = null)
@@ -206,6 +207,7 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds =
206207
* @param IndexerInterface $saveHandler
207208
* @param array $dimensions
208209
* @param array $entityIds
210+
* @throws \Exception
209211
*/
210212
private function processBatch(
211213
IndexerInterface $saveHandler,
@@ -216,9 +218,24 @@ private function processBatch(
216218
$productIds = array_unique(
217219
array_merge($entityIds, $this->fulltextResource->getRelationsByChild($entityIds))
218220
);
221+
219222
if ($saveHandler->isAvailable($dimensions)) {
220-
$saveHandler->deleteIndex($dimensions, new \ArrayIterator($productIds));
221-
$saveHandler->saveIndex($dimensions, $this->fullAction->rebuildStoreIndex($storeId, $productIds));
223+
if (in_array(StackedActionsIndexerInterface::class, class_implements($saveHandler))) {
224+
try {
225+
$saveHandler->enableStackedActions();
226+
$saveHandler->deleteIndex($dimensions, new \ArrayIterator($productIds));
227+
$saveHandler->saveIndex($dimensions, $this->fullAction->rebuildStoreIndex($storeId, $productIds));
228+
$saveHandler->triggerStackedActions();
229+
$saveHandler->disableStackedActions();
230+
} catch (\Throwable $exception) {
231+
$saveHandler->disableStackedActions();
232+
$saveHandler->deleteIndex($dimensions, new \ArrayIterator($productIds));
233+
$saveHandler->saveIndex($dimensions, $this->fullAction->rebuildStoreIndex($storeId, $productIds));
234+
}
235+
} else {
236+
$saveHandler->deleteIndex($dimensions, new \ArrayIterator($productIds));
237+
$saveHandler->saveIndex($dimensions, $this->fullAction->rebuildStoreIndex($storeId, $productIds));
238+
}
222239
}
223240
}
224241

app/code/Magento/CatalogSearch/Test/Unit/Model/Indexer/FulltextTest.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\CatalogSearch\Model\Indexer\Fulltext;
1111
use Magento\CatalogSearch\Model\Indexer\Fulltext\Action\Full;
1212
use Magento\CatalogSearch\Model\Indexer\Fulltext\Action\FullFactory;
13+
use Magento\Elasticsearch\Model\Indexer\IndexerHandler;
1314
use Magento\Framework\Indexer\SaveHandler\IndexerInterface;
1415
use Magento\CatalogSearch\Model\Indexer\IndexerHandlerFactory;
1516
use Magento\CatalogSearch\Model\Indexer\Scope\State;
@@ -64,7 +65,7 @@ protected function setUp(): void
6465
['create']
6566
);
6667
$fullActionFactory->expects($this->any())->method('create')->willReturn($this->fullAction);
67-
$this->saveHandler = $this->getClassMock(IndexerInterface::class);
68+
$this->saveHandler = $this->getClassMock(IndexerHandler::class);
6869
$indexerHandlerFactory = $this->createPartialMock(
6970
IndexerHandlerFactory::class,
7071
['create']
@@ -116,6 +117,9 @@ public function testExecute()
116117
$this->fulltextResource->expects($this->exactly(2))
117118
->method('getRelationsByChild')
118119
->willReturn($ids);
120+
$this->saveHandler->expects($this->exactly(count($stores)))->method('enableStackedActions');
121+
$this->saveHandler->expects($this->exactly(count($stores)))->method('triggerStackedActions');
122+
$this->saveHandler->expects($this->exactly(count($stores)))->method('disableStackedActions');
119123
$this->saveHandler->expects($this->exactly(count($stores)))->method('deleteIndex');
120124
$this->saveHandler->expects($this->exactly(2))->method('saveIndex');
121125
$this->saveHandler->expects($this->exactly(2))->method('isAvailable')->willReturn(true);
@@ -133,6 +137,40 @@ function ($store) use ($ids) {
133137
$this->model->execute($ids);
134138
}
135139

140+
public function testExecuteWithStackedQueriesException()
141+
{
142+
$ids = [1, 2, 3];
143+
$stores = [0 => 'Store 1'];
144+
$this->setupDataProvider($stores);
145+
146+
$indexData = new \ArrayObject([]);
147+
$this->fulltextResource->expects($this->exactly(1))
148+
->method('getRelationsByChild')
149+
->willReturn($ids);
150+
$this->saveHandler->expects($this->exactly(count($stores)))->method('enableStackedActions');
151+
$this->saveHandler->expects($this->exactly(count($stores) + 1))->method('deleteIndex');
152+
$this->saveHandler->expects($this->exactly(count($stores) + 1))->method('saveIndex');
153+
$this->saveHandler->expects($this->exactly(count($stores)))
154+
->method('triggerStackedActions')
155+
->willThrowException(new \Exception('error'));
156+
$this->saveHandler->expects($this->exactly(count($stores)))->method('disableStackedActions');
157+
158+
$this->saveHandler->expects($this->exactly(2))->method('saveIndex');
159+
$this->saveHandler->expects($this->exactly(1))->method('isAvailable')->willReturn(true);
160+
$consecutiveStoreRebuildArguments = array_map(
161+
function ($store) use ($ids) {
162+
return [$store, $ids];
163+
},
164+
$stores
165+
);
166+
$this->fullAction->expects($this->exactly(2))
167+
->method('rebuildStoreIndex')
168+
->withConsecutive(...$consecutiveStoreRebuildArguments)
169+
->willReturn(new \ArrayObject([$indexData, $indexData]));
170+
171+
$this->model->execute($ids);
172+
}
173+
136174
/**
137175
* @param $stores
138176
*/

0 commit comments

Comments
 (0)