Skip to content

Commit aa2a910

Browse files
author
Oleksandr Dubovyk
committed
Merge remote-tracking branch 'mainline/2.2-develop' into chaika-pr22
2 parents 1ec57c4 + 03f7ded commit aa2a910

File tree

209 files changed

+16976
-177
lines changed

Some content is hidden

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

209 files changed

+16976
-177
lines changed

app/code/Magento/CatalogInventory/Model/Indexer/Stock/AbstractAction.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Magento\Framework\App\ObjectManager;
1212
use Magento\Framework\App\ResourceConnection;
13+
use Magento\Framework\EntityManager\MetadataPool;
1314

1415
/**
1516
* Abstract action reindex class
@@ -70,25 +71,33 @@ abstract class AbstractAction
7071
*/
7172
private $cacheCleaner;
7273

74+
/**
75+
* @var MetadataPool
76+
*/
77+
private $metadataPool;
78+
7379
/**
7480
* @param ResourceConnection $resource
7581
* @param \Magento\CatalogInventory\Model\ResourceModel\Indexer\StockFactory $indexerFactory
7682
* @param \Magento\Catalog\Model\Product\Type $catalogProductType
7783
* @param \Magento\Framework\Indexer\CacheContext $cacheContext
7884
* @param \Magento\Framework\Event\ManagerInterface $eventManager
85+
* @param MetadataPool|null $metadataPool
7986
*/
8087
public function __construct(
8188
ResourceConnection $resource,
8289
\Magento\CatalogInventory\Model\ResourceModel\Indexer\StockFactory $indexerFactory,
8390
\Magento\Catalog\Model\Product\Type $catalogProductType,
8491
\Magento\Framework\Indexer\CacheContext $cacheContext,
85-
\Magento\Framework\Event\ManagerInterface $eventManager
92+
\Magento\Framework\Event\ManagerInterface $eventManager,
93+
MetadataPool $metadataPool = null
8694
) {
8795
$this->_resource = $resource;
8896
$this->_indexerFactory = $indexerFactory;
8997
$this->_catalogProductType = $catalogProductType;
9098
$this->cacheContext = $cacheContext;
9199
$this->eventManager = $eventManager;
100+
$this->metadataPool = $metadataPool ?: ObjectManager::getInstance()->get(MetadataPool::class);
92101
}
93102

94103
/**
@@ -154,10 +163,15 @@ protected function _getTable($entityName)
154163
public function getRelationsByChild($childIds)
155164
{
156165
$connection = $this->_getConnection();
157-
$select = $connection->select()
158-
->from($this->_getTable('catalog_product_relation'), 'parent_id')
159-
->where('child_id IN(?)', $childIds);
160-
166+
$linkField = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class)
167+
->getLinkField();
168+
$select = $connection->select()->from(
169+
['cpe' => $this->_getTable('catalog_product_entity')],
170+
'entity_id'
171+
)->join(
172+
['relation' => $this->_getTable('catalog_product_relation')],
173+
'relation.parent_id = cpe.' . $linkField
174+
)->where('child_id IN(?)', $childIds);
161175
return $connection->fetchCol($select);
162176
}
163177

@@ -230,7 +244,8 @@ protected function _reindexRows($productIds = [])
230244
if (!is_array($productIds)) {
231245
$productIds = [$productIds];
232246
}
233-
247+
$parentIds = $this->getRelationsByChild($productIds);
248+
$productIds = $parentIds ? array_unique(array_merge($parentIds, $productIds)) : $productIds;
234249
$this->getCacheCleaner()->clean($productIds, function () use ($productIds) {
235250
$this->doReindex($productIds);
236251
});
@@ -248,13 +263,10 @@ private function doReindex($productIds = [])
248263
{
249264
$connection = $this->_getConnection();
250265

251-
$parentIds = $this->getRelationsByChild($productIds);
252-
$processIds = $parentIds ? array_merge($parentIds, $productIds) : $productIds;
253-
254266
// retrieve product types by processIds
255267
$select = $connection->select()
256268
->from($this->_getTable('catalog_product_entity'), ['entity_id', 'type_id'])
257-
->where('entity_id IN(?)', $processIds);
269+
->where('entity_id IN(?)', $productIds);
258270
$pairs = $connection->fetchPairs($select);
259271

260272
$byType = [];
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogInventory\Model\Plugin;
7+
8+
use Magento\Catalog\Model\Product\Action as ProductAction;
9+
10+
/**
11+
* Plugin for Magento\Catalog\Model\Product\Action
12+
*/
13+
class ReindexUpdatedProducts
14+
{
15+
/**
16+
* @var \Magento\CatalogInventory\Model\Indexer\Stock\Processor
17+
*/
18+
private $indexerProcessor;
19+
20+
/**
21+
* @param \Magento\CatalogInventory\Model\Indexer\Stock\Processor $indexerProcessor
22+
*/
23+
public function __construct(\Magento\CatalogInventory\Model\Indexer\Stock\Processor $indexerProcessor)
24+
{
25+
$this->indexerProcessor = $indexerProcessor;
26+
}
27+
28+
/**
29+
* Reindex on product attribute mass change
30+
*
31+
* @param ProductAction $subject
32+
* @param ProductAction $action
33+
* @param array $productIds
34+
* @return ProductAction
35+
*
36+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
37+
*/
38+
public function afterUpdateAttributes(
39+
ProductAction $subject,
40+
ProductAction $action,
41+
$productIds
42+
) {
43+
$this->indexerProcessor->reindexList(array_unique($productIds));
44+
return $action;
45+
}
46+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
<type name="Magento\Catalog\Model\Product">
7979
<plugin name="catalogInventoryAfterLoad" type="Magento\CatalogInventory\Model\Plugin\AfterProductLoad"/>
8080
</type>
81+
<type name="Magento\Catalog\Model\Product\Action">
82+
<plugin name="ReindexUpdatedProducts" type="Magento\CatalogInventory\Model\Plugin\ReindexUpdatedProducts"/>
83+
</type>
8184
<type name="Magento\CatalogInventory\Setup\UpgradeData">
8285
<arguments>
8386
<argument name="indexerProcessor" xsi:type="object">Magento\CatalogInventory\Model\Indexer\Stock\Processor</argument>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Signifyd\Api;
7+
8+
/**
9+
* Signifyd case creation interface
10+
*
11+
* Interface of service for new Signifyd case creation and registering it on Magento side.
12+
* Implementation should send request to Signifyd API and create new entity in Magento.
13+
*
14+
* @api
15+
* @since 100.2.0
16+
*/
17+
interface CaseCreationServiceInterface
18+
{
19+
/**
20+
* Create new case for order with specified id.
21+
*
22+
* @param int $orderId
23+
* @return bool
24+
* @throws \Magento\Framework\Exception\NotFoundException If order does not exists
25+
* @throws \Magento\Framework\Exception\AlreadyExistsException If case for $orderId already exists
26+
* @since 100.2.0
27+
*/
28+
public function createForOrder($orderId);
29+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Signifyd\Api;
7+
8+
/**
9+
* Signifyd management interface
10+
* Allows to performs operations with Signifyd cases.
11+
*
12+
* @api
13+
* @since 100.2.0
14+
*/
15+
interface CaseManagementInterface
16+
{
17+
/**
18+
* Creates new Case entity linked to order id.
19+
*
20+
* @param int $orderId
21+
* @return \Magento\Signifyd\Api\Data\CaseInterface
22+
* @throws \Magento\Framework\Exception\NotFoundException If order does not exists
23+
* @throws \Magento\Framework\Exception\AlreadyExistsException If case for $orderId already exists
24+
* @since 100.2.0
25+
*/
26+
public function create($orderId);
27+
28+
/**
29+
* Gets Case entity associated with order id.
30+
*
31+
* @param int $orderId
32+
* @return \Magento\Signifyd\Api\Data\CaseInterface|null
33+
* @since 100.2.0
34+
*/
35+
public function getByOrderId($orderId);
36+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Signifyd\Api;
7+
8+
/**
9+
* Signifyd Case repository interface
10+
*
11+
* @api
12+
* @since 100.2.0
13+
*/
14+
interface CaseRepositoryInterface
15+
{
16+
/**
17+
* Saves case entity.
18+
*
19+
* @param \Magento\Signifyd\Api\Data\CaseInterface $case
20+
* @return \Magento\Signifyd\Api\Data\CaseInterface
21+
* @since 100.2.0
22+
*/
23+
public function save(\Magento\Signifyd\Api\Data\CaseInterface $case);
24+
25+
/**
26+
* Gets case entity by order id.
27+
*
28+
* @param int $id
29+
* @return \Magento\Signifyd\Api\Data\CaseInterface
30+
* @since 100.2.0
31+
*/
32+
public function getById($id);
33+
34+
/**
35+
* Gets entity by Signifyd case id.
36+
*
37+
* @param int $caseId
38+
* @return \Magento\Signifyd\Api\Data\CaseInterface|null
39+
* @since 100.2.0
40+
*/
41+
public function getByCaseId($caseId);
42+
43+
/**
44+
* Deletes case entity.
45+
*
46+
* @param \Magento\Signifyd\Api\Data\CaseInterface $case
47+
* @return bool
48+
* @since 100.2.0
49+
*/
50+
public function delete(\Magento\Signifyd\Api\Data\CaseInterface $case);
51+
52+
/**
53+
* Gets list of case entities.
54+
*
55+
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
56+
* @return \Magento\Signifyd\Api\Data\CaseSearchResultsInterface
57+
* @since 100.2.0
58+
*/
59+
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria);
60+
}

0 commit comments

Comments
 (0)