Skip to content

Commit 452710d

Browse files
author
Volodymyr Kublytskyi
authored
Merge pull request #2300 from magento-engcom/msi-core-changes-no-history
[EngCom] Various fixes in Magento 2 core to support MSI
2 parents ec80b7b + 85a9c2f commit 452710d

File tree

73 files changed

+1610
-199
lines changed

Some content is hidden

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

73 files changed

+1610
-199
lines changed

.travis.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ services:
1616
- elasticsearch
1717
language: php
1818
php:
19-
- 7.0
2019
- 7.1
2120
env:
2221
global:
@@ -33,16 +32,6 @@ env:
3332
- TEST_SUITE=integration INTEGRATION_INDEX=2
3433
- TEST_SUITE=integration INTEGRATION_INDEX=3
3534
- TEST_SUITE=functional
36-
matrix:
37-
exclude:
38-
- php: 7.0
39-
env: TEST_SUITE=static
40-
- php: 7.0
41-
env: TEST_SUITE=js GRUNT_COMMAND=spec
42-
- php: 7.0
43-
env: TEST_SUITE=js GRUNT_COMMAND=static
44-
- php: 7.0
45-
env: TEST_SUITE=functional
4635
cache:
4736
apt: true
4837
directories:
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\Ui\Component\Control;
9+
10+
use Magento\Framework\App\RequestInterface;
11+
use Magento\Framework\Escaper;
12+
use Magento\Framework\UrlInterface;
13+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
14+
15+
/**
16+
* Represents delete button with pre-configured options
17+
* Provide an ability to show confirmation message on click on the "Delete" button
18+
*
19+
* @api
20+
*/
21+
class DeleteButton implements ButtonProviderInterface
22+
{
23+
/**
24+
* @var RequestInterface
25+
*/
26+
private $request;
27+
28+
/**
29+
* @var UrlInterface
30+
*/
31+
private $urlBuilder;
32+
33+
/**
34+
* @var Escaper
35+
*/
36+
private $escaper;
37+
38+
/**
39+
* @var string
40+
*/
41+
private $confirmationMessage;
42+
43+
/**
44+
* @var string
45+
*/
46+
private $idFieldName;
47+
48+
/**
49+
* @var string
50+
*/
51+
private $deleteRoutePath;
52+
53+
/**
54+
* @var int
55+
*/
56+
private $sortOrder;
57+
58+
/**
59+
* @param RequestInterface $request
60+
* @param UrlInterface $urlBuilder
61+
* @param Escaper $escaper
62+
* @param string $confirmationMessage
63+
* @param string $idFieldName
64+
* @param string $deleteRoutePath
65+
* @param int $sortOrder
66+
*/
67+
public function __construct(
68+
RequestInterface $request,
69+
UrlInterface $urlBuilder,
70+
Escaper $escaper,
71+
string $confirmationMessage,
72+
string $idFieldName,
73+
string $deleteRoutePath,
74+
int $sortOrder
75+
) {
76+
$this->request = $request;
77+
$this->urlBuilder = $urlBuilder;
78+
$this->escaper = $escaper;
79+
$this->confirmationMessage = $confirmationMessage;
80+
$this->idFieldName = $idFieldName;
81+
$this->deleteRoutePath = $deleteRoutePath;
82+
$this->sortOrder = $sortOrder;
83+
}
84+
85+
/**
86+
* {@inheritdoc}
87+
*/
88+
public function getButtonData()
89+
{
90+
$data = [];
91+
$fieldId = $this->escaper->escapeJs($this->escaper->escapeHtml($this->request->getParam($this->idFieldName)));
92+
if (null !== $fieldId) {
93+
$url = $this->urlBuilder->getUrl($this->deleteRoutePath);
94+
$escapedMessage = $this->escaper->escapeJs($this->escaper->escapeHtml($this->confirmationMessage));
95+
$data = [
96+
'label' => __('Delete'),
97+
'class' => 'delete',
98+
'on_click' => "deleteConfirm('{$escapedMessage}', '{$url}', {data:{{$this->idFieldName}:{$fieldId}}})",
99+
'sort_order' => $this->sortOrder,
100+
];
101+
}
102+
return $data;
103+
}
104+
}

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\CatalogImportExport\Model\Import\Product\MediaGalleryProcessor;
1111
use Magento\CatalogImportExport\Model\Import\Product\ImageTypeProcessor;
1212
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface as ValidatorInterface;
13+
use Magento\CatalogImportExport\Model\StockItemImporterInterface;
1314
use Magento\Framework\App\Filesystem\DirectoryList;
1415
use Magento\Framework\App\ObjectManager;
1516
use Magento\Framework\Exception\LocalizedException;
@@ -535,6 +536,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
535536

536537
/**
537538
* @var \Magento\CatalogInventory\Model\ResourceModel\Stock\ItemFactory
539+
* @deprecated this variable isn't used anymore.
538540
*/
539541
protected $_stockResItemFac;
540542

@@ -703,6 +705,13 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
703705
*/
704706
private $catalogConfig;
705707

708+
/**
709+
* Stock Item Importer
710+
*
711+
* @var StockItemImporterInterface
712+
*/
713+
private $stockItemImporter;
714+
706715
/**
707716
* @var ImageTypeProcessor
708717
*/
@@ -751,12 +760,13 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
751760
* @param TransactionManagerInterface $transactionManager
752761
* @param Product\TaxClassProcessor $taxClassProcessor
753762
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
763+
* @param \Magento\Catalog\Model\Product\Url $productUrl
754764
* @param array $data
755765
* @param array $dateAttrCodes
756766
* @param CatalogConfig $catalogConfig
757767
* @param ImageTypeProcessor $imageTypeProcessor
758768
* @param MediaGalleryProcessor $mediaProcessor
759-
* @throws \Magento\Framework\Exception\LocalizedException
769+
* @param StockItemImporterInterface|null $stockItemImporter
760770
*
761771
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
762772
*/
@@ -801,7 +811,8 @@ public function __construct(
801811
array $dateAttrCodes = [],
802812
CatalogConfig $catalogConfig = null,
803813
ImageTypeProcessor $imageTypeProcessor = null,
804-
MediaGalleryProcessor $mediaProcessor = null
814+
MediaGalleryProcessor $mediaProcessor = null,
815+
StockItemImporterInterface $stockItemImporter = null
805816
) {
806817
$this->_eventManager = $eventManager;
807818
$this->stockRegistry = $stockRegistry;
@@ -835,7 +846,8 @@ public function __construct(
835846
$this->catalogConfig = $catalogConfig ?: ObjectManager::getInstance()->get(CatalogConfig::class);
836847
$this->imageTypeProcessor = $imageTypeProcessor ?: ObjectManager::getInstance()->get(ImageTypeProcessor::class);
837848
$this->mediaProcessor = $mediaProcessor ?: ObjectManager::getInstance()->get(MediaGalleryProcessor::class);
838-
849+
$this->stockItemImporter = $stockItemImporter ?: ObjectManager::getInstance()
850+
->get(StockItemImporterInterface::class);
839851
parent::__construct(
840852
$jsonHelper,
841853
$importExportData,
@@ -851,7 +863,6 @@ public function __construct(
851863
) ? $data['option_entity'] : $optionFactory->create(
852864
['data' => ['product_entity' => $this]]
853865
);
854-
855866
$this->_initAttributeSets()
856867
->_initTypeModels()
857868
->_initSkus()
@@ -2128,9 +2139,6 @@ protected function _saveProductWebsites(array $websiteData)
21282139
*/
21292140
protected function _saveStockItem()
21302141
{
2131-
/** @var $stockResource \Magento\CatalogInventory\Model\ResourceModel\Stock\Item */
2132-
$stockResource = $this->_stockResItemFac->create();
2133-
$entityTable = $stockResource->getMainTable();
21342142
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
21352143
$stockData = [];
21362144
$productIdsToReindex = [];
@@ -2158,6 +2166,7 @@ protected function _saveStockItem()
21582166
array_intersect_key($rowData, $this->defaultStockData),
21592167
$row
21602168
);
2169+
$row['sku'] = $sku;
21612170

21622171
if ($this->stockConfiguration->isQty(
21632172
$this->skuProcessor->getNewSku($sku)['type_id']
@@ -2185,7 +2194,7 @@ protected function _saveStockItem()
21852194

21862195
// Insert rows
21872196
if (!empty($stockData)) {
2188-
$this->_connection->insertOnDuplicate($entityTable, array_values($stockData));
2197+
$this->stockItemImporter->import($stockData);
21892198
}
21902199

21912200
$this->reindexProducts($productIdsToReindex);
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogImportExport\Model;
9+
10+
use Magento\CatalogInventory\Model\ResourceModel\Stock\Item;
11+
use Magento\CatalogInventory\Model\ResourceModel\Stock\ItemFactory;
12+
use Magento\Framework\Exception\CouldNotSaveException;
13+
use Psr\Log\LoggerInterface;
14+
15+
class StockItemImporter implements StockItemImporterInterface
16+
{
17+
/**
18+
* Stock Item Resource Factory
19+
*
20+
* @var ItemFactory $stockResourceItemFactory
21+
*/
22+
private $stockResourceItemFactory;
23+
24+
/**
25+
* @var LoggerInterface
26+
*/
27+
private $logger;
28+
29+
/**
30+
* StockItemImporter constructor
31+
*
32+
* @param ItemFactory $stockResourceItemFactory
33+
* @param LoggerInterface $logger
34+
*/
35+
public function __construct(
36+
ItemFactory $stockResourceItemFactory,
37+
LoggerInterface $logger
38+
) {
39+
$this->stockResourceItemFactory = $stockResourceItemFactory;
40+
$this->logger = $logger;
41+
}
42+
43+
/**
44+
* @inheritdoc
45+
*/
46+
public function import(array $stockData)
47+
{
48+
/** @var $stockItemResource Item */
49+
$stockItemResource = $this->stockResourceItemFactory->create();
50+
$entityTable = $stockItemResource->getMainTable();
51+
try {
52+
$stockImportData = array_map(
53+
function ($stockItemData) {
54+
unset($stockItemData['sku']);
55+
return $stockItemData;
56+
},
57+
array_values($stockData)
58+
);
59+
$stockItemResource->getConnection()->insertOnDuplicate($entityTable, $stockImportData);
60+
} catch (\Exception $e) {
61+
$this->logger->error($e->getMessage());
62+
throw new CouldNotSaveException(__('Invalid Stock data for insert'), $e);
63+
}
64+
}
65+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogImportExport\Model;
9+
10+
/**
11+
* Interface StockItemImporterInterface
12+
*
13+
* @api
14+
*/
15+
interface StockItemImporterInterface
16+
{
17+
/**
18+
* Handle Import of Stock Item Data
19+
*
20+
* @param array $stockData
21+
* @return void
22+
* @throws \Magento\Framework\Exception\CouldNotSaveException
23+
* @throws \Magento\Framework\Exception\InputException
24+
* @throws \Magento\Framework\Validation\ValidationException
25+
*/
26+
public function import(array $stockData);
27+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
99
<preference for="Magento\CatalogImportExport\Model\Export\RowCustomizerInterface" type="Magento\CatalogImportExport\Model\Export\RowCustomizer\Composite" />
10+
<preference for="Magento\CatalogImportExport\Model\StockItemImporterInterface" type="Magento\CatalogImportExport\Model\StockItemImporter" />
1011
<type name="Magento\ImportExport\Model\Import">
1112
<plugin name="catalogProductFlatIndexerImport" type="Magento\CatalogImportExport\Model\Indexer\Product\Flat\Plugin\Import" />
1213
<plugin name="invalidatePriceIndexerOnImport" type="Magento\CatalogImportExport\Model\Indexer\Product\Price\Plugin\Import" />
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogInventory\Api;
9+
10+
use Magento\CatalogInventory\Api\Data\StockItemInterface;
11+
use Magento\Framework\Exception\LocalizedException;
12+
13+
/**
14+
* @api
15+
*/
16+
interface RegisterProductSaleInterface
17+
{
18+
/**
19+
* Subtract product qtys from stock
20+
* Return array of items that require full save
21+
*
22+
* Method signature is unchanged for backward compatibility
23+
*
24+
* @param float[] $items
25+
* @param int $websiteId
26+
* @return StockItemInterface[]
27+
* @throws LocalizedException
28+
*/
29+
public function registerProductsSale($items, $websiteId = null);
30+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogInventory\Api;
9+
10+
/**
11+
* @api
12+
*/
13+
interface RevertProductSaleInterface
14+
{
15+
/**
16+
* Revert register product sale
17+
*
18+
* Method signature is unchanged for backward compatibility
19+
*
20+
* @param string[] $items
21+
* @param int $websiteId
22+
* @return bool
23+
*/
24+
public function revertProductsSale($items, $websiteId = null);
25+
}

0 commit comments

Comments
 (0)