Skip to content

Commit e708f7a

Browse files
Merge pull request #330 from magento-cia/pre-release-develop-sync-03062023
Sync of pre-release with develop
2 parents d0b553f + 9aac2ba commit e708f7a

File tree

114 files changed

+1425
-200
lines changed

Some content is hidden

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

114 files changed

+1425
-200
lines changed

.github/CONTRIBUTING.md

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

33
Contributions to the Magento Inventory codebase are done using the fork & pull model.
44
This contribution model has contributors maintaining their own fork of the Magento Inventory repository.
5-
The forked repository is then used to submit a request to the base repository to pull a set of changes.
5+
The forked repository is then used to submit a request to the base repository to "pull" a set of changes.
66
For more information on pull requests please refer to [GitHub Help](https://help.github.com/articles/about-pull-requests/).
77

88
Contributions can take the form of new components or features, changes to existing features, tests, documentation (such as developer guides, user guides, examples, or specifications), bug fixes or optimizations.
@@ -33,7 +33,7 @@ This will allow you to collaborate with the Magento 2 development team, fork the
3333
1. Search current [listed issues](https://github.com/magento/inventory/issues) (open or closed) for similar proposals of intended contribution before starting work on a new contribution.
3434
2. Review the [Contributor License Agreement](https://opensource.adobe.com/cla.html) if this is your first time contributing.
3535
3. Create and test your work.
36-
4. Fork the Magento Inventory repository according to the [Fork a Repository instructions](https://devdocs.magento.com/guides/v2.4/contributor-guide/contributing.html#fork) and when you are ready to send us a pull request – follow the [Create a Pull Request instructions](https://devdocs.magento.com/guides/v2.4/contributor-guide/contributing.html#pull_request).
36+
4. Fork the Magento Inventory repository according to the [Fork a Repository instructions](https://developer.adobe.com/commerce/contributor/guides/code-contributions/) and when you are ready to send us a pull request – follow the [Create a Pull Request instructions](https://developer.adobe.com/commerce/contributor/guides/code-contributions/).
3737
5. Once your contribution is received the Magento Inventory development team will review the contribution and collaborate with you as needed.
3838

3939
## Code of Conduct

Inventory/Model/ResourceModel/SourceItem/SaveMultiple.php

Lines changed: 100 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\Inventory\Model\ResourceModel\SourceItem;
99

1010
use Magento\Framework\App\ResourceConnection;
11+
use Magento\Framework\DB\Adapter\AdapterInterface;
1112
use Magento\Inventory\Model\ResourceModel\SourceItem as SourceItemResourceModel;
1213
use Magento\InventoryApi\Api\Data\SourceItemInterface;
1314

@@ -46,27 +47,13 @@ public function execute(array $sourceItems)
4647
$connection = $this->resourceConnection->getConnection();
4748
$tableName = $this->resourceConnection->getTableName(SourceItemResourceModel::TABLE_NAME_SOURCE_ITEM);
4849

49-
$columnsSql = $this->buildColumnsSqlPart([
50-
SourceItemInterface::SOURCE_CODE,
51-
SourceItemInterface::SKU,
52-
SourceItemInterface::QUANTITY,
53-
SourceItemInterface::STATUS
54-
]);
55-
$valuesSql = $this->buildValuesSqlPart($sourceItems);
56-
$onDuplicateSql = $this->buildOnDuplicateSqlPart([
57-
SourceItemInterface::QUANTITY,
58-
SourceItemInterface::STATUS,
59-
]);
60-
$bind = $this->getSqlBindData($sourceItems);
61-
62-
$insertSql = sprintf(
63-
'INSERT INTO `%s` (%s) VALUES %s %s',
64-
$tableName,
65-
$columnsSql,
66-
$valuesSql,
67-
$onDuplicateSql
68-
);
69-
$connection->query($insertSql, $bind);
50+
[$newItems, $existingItems] = $this->separateExistingAndNewItems($sourceItems);
51+
if (count($newItems)) {
52+
$this->insertNewItems($newItems, $connection, $tableName);
53+
}
54+
if (count($existingItems)) {
55+
$this->updateExistentItems($existingItems, $connection, $tableName);
56+
}
7057
}
7158

7259
/**
@@ -129,4 +116,96 @@ private function buildOnDuplicateSqlPart(array $fields): string
129116
$sql = 'ON DUPLICATE KEY UPDATE ' . implode(', ', $processedFields);
130117
return $sql;
131118
}
119+
120+
/**
121+
* Separate and return new and existing Source Items by mapping provided Items with stored ones.
122+
*
123+
* @param array $sourceItems
124+
* @return array
125+
*/
126+
private function separateExistingAndNewItems(array $sourceItems): array
127+
{
128+
$connection = $this->resourceConnection->getConnection();
129+
$tableName = $this->resourceConnection->getTableName(SourceItemResourceModel::TABLE_NAME_SOURCE_ITEM);
130+
131+
$skus = [];
132+
$stock = [];
133+
foreach ($sourceItems as $sourceItem) {
134+
$skus[] = $sourceItem->getSku();
135+
$stock[] = $sourceItem->getSourceCode();
136+
}
137+
138+
$storedSourceItems = $connection->fetchAll(
139+
$connection->select()
140+
->from($tableName, ['source_item_id', 'source_code', 'sku'])
141+
->where('sku IN (?)', $skus)->where('source_code IN (?)', $stock)
142+
);
143+
144+
$exisingSourceItems = [];
145+
foreach ($sourceItems as $key => $sourceItem) {
146+
foreach ($storedSourceItems as $storedSourceItem) {
147+
if ($sourceItem->getSku() === $storedSourceItem['sku'] &&
148+
$sourceItem->getSourceCode() === $storedSourceItem['source_code']) {
149+
unset($sourceItems[$key]);
150+
$exisingSourceItems[$storedSourceItem['source_item_id']] = $sourceItem;
151+
}
152+
}
153+
}
154+
return [$sourceItems, $exisingSourceItems];
155+
}
156+
157+
/**
158+
* Insert new Source Items.
159+
*
160+
* @param array $sourceItems
161+
* @param AdapterInterface $connection
162+
* @param string $tableName
163+
* @return void
164+
*/
165+
private function insertNewItems(array $sourceItems, AdapterInterface $connection, string $tableName): void
166+
{
167+
$columnsSql = $this->buildColumnsSqlPart([
168+
SourceItemInterface::SOURCE_CODE,
169+
SourceItemInterface::SKU,
170+
SourceItemInterface::QUANTITY,
171+
SourceItemInterface::STATUS
172+
]);
173+
$valuesSql = $this->buildValuesSqlPart($sourceItems);
174+
$onDuplicateSql = $this->buildOnDuplicateSqlPart([
175+
SourceItemInterface::QUANTITY,
176+
SourceItemInterface::STATUS,
177+
]);
178+
$bind = $this->getSqlBindData($sourceItems);
179+
180+
$insertSql = sprintf(
181+
'INSERT INTO `%s` (%s) VALUES %s %s',
182+
$tableName,
183+
$columnsSql,
184+
$valuesSql,
185+
$onDuplicateSql
186+
);
187+
$connection->query($insertSql, $bind);
188+
}
189+
190+
/**
191+
* Update existing Source Items.
192+
*
193+
* @param array $sourceItems
194+
* @param AdapterInterface $connection
195+
* @param string $tableName
196+
* @return void
197+
*/
198+
private function updateExistentItems(array $sourceItems, AdapterInterface $connection, string $tableName): void
199+
{
200+
foreach ($sourceItems as $sourceItemId => $sourceItem) {
201+
$bind = [
202+
SourceItemInterface::SOURCE_CODE => $sourceItem->getSourceCode(),
203+
SourceItemInterface::SKU => $sourceItem->getSku(),
204+
SourceItemInterface::QUANTITY => $sourceItem->getQuantity(),
205+
SourceItemInterface::STATUS => $sourceItem->getStatus()
206+
];
207+
208+
$connection->update($tableName, $bind, ['source_item_id = ?' => $sourceItemId]);
209+
}
210+
}
132211
}

Inventory/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
The `Inventory` module is part of the new inventory infrastructure,
44
which replaces the legacy `CatalogInventory` module with new and expanded features and APIs for Inventory Management.
55

6-
The [Inventory Management overview](https://devdocs.magento.com/guides/v2.4/inventory/index.html)
6+
The [Inventory Management overview](https://developer.adobe.com/commerce/webapi/rest/inventory/index.html)
77
describes the MSI (Multi-Source Inventory) project in more detail.
88

99
All Inventory Management modules follow the
1010
[Single Responsibility Principle](https://en.wikipedia.org/wiki/Single_responsibility_principle).
11-
[Inventory management architecture](https://devdocs.magento.com/guides/v2.4/inventory/architecture.html)
11+
[Inventory management architecture](https://developer.adobe.com/commerce/php/architecture/modules/inventory-management/)
1212
provides additional insight about the overall structure of these modules.
1313

1414
## Installation details
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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\Inventory\Test\Integration\Model\ResourceModel\SourceItem;
9+
10+
use Magento\Framework\App\ResourceConnection;
11+
use Magento\Framework\DB\Adapter\AdapterInterface;
12+
use Magento\Framework\ObjectManagerInterface;
13+
use Magento\Inventory\Model\ResourceModel\SourceItem\SaveMultiple;
14+
use Magento\Inventory\Model\SourceItem;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
use PHPUnit\Framework\TestCase;
17+
18+
class SaveMultipleTest extends TestCase
19+
{
20+
/**
21+
* @var SaveMultiple
22+
*/
23+
private $subject;
24+
25+
/**
26+
* @var AdapterInterface
27+
*/
28+
private $connection;
29+
30+
/**
31+
* @var ObjectManagerInterface
32+
*/
33+
private $objectManager;
34+
35+
protected function setUp(): void
36+
{
37+
$this->objectManager = Bootstrap::getObjectManager();
38+
$this->subject = $this->objectManager->get(SaveMultiple::class);
39+
$resourceConnection = $this->objectManager->get(ResourceConnection::class);
40+
$this->connection = $resourceConnection->getConnection();
41+
}
42+
43+
/**
44+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
45+
*/
46+
public function testExecuteUpdateSourceItemAutoIncrement()
47+
{
48+
$tableStatus = $this->connection->showTableStatus('inventory_source_item');
49+
$initialAutoIncrement = $tableStatus['Auto_increment'];
50+
51+
$sourceItem = $this->objectManager->create(SourceItem::class);
52+
$sourceItem->setData([
53+
'sku' => 'simple',
54+
'source_code' => 'default',
55+
'quantity' => 700.0000,
56+
'status' => 1,
57+
]);
58+
59+
$this->subject->execute([$sourceItem]);
60+
$tableStatus = $this->connection->showTableStatus('inventory_source_item');
61+
$this->assertSame($tableStatus['Auto_increment'], $initialAutoIncrement);
62+
}
63+
}

InventoryAdminUi/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
The `InventoryAdminUi` module extends the Magento Admin UI to add Inventory Management functionality.
44

55
This module is part of the new inventory infrastructure. The
6-
[Inventory Management overview](https://devdocs.magento.com/guides/v2.4/inventory/index.html)
6+
[Inventory Management overview](https://developer.adobe.com/commerce/webapi/rest/inventory/index.html)
77
describes the MSI (Multi-Source Inventory) project in more detail.
88

99
## Installation details

InventoryAdminUi/Test/Mftf/ActionGroup/AdminCreateNewStockActionGroup.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<click selector="{{AdminEditStockSourcesSection.doneButton}}" stepKey="clickDoneButton" />
3030
<click selector="{{AdminEditStockGeneralSection.saveAndContinueDropdown}}" stepKey="clickSaveAndContinueDropdown" />
3131
<click selector="{{AdminEditStockGeneralSection.saveAndCloseButton}}" stepKey="clickSaveAndClose" />
32+
<waitForElementVisible selector="{{AdminManageStockGridBody.stockSavedSuccessfulMessage}}" stepKey="waitForVerifyTheStockCreatedSuccessfullyMessageVisible"/>
3233
<seeElement selector="{{AdminManageStockGridBody.stockSavedSuccessfulMessage}}" stepKey="verifyTheStockCreatedSuccessfully"/>
3334
<waitForPageLoad stepKey="waitForStoreGroupPageLoad1" />
3435
</actionGroup>

InventoryAdminUi/Test/Mftf/Section/AdminSourceSelectionFormSection/AdminSourceSelectionFormSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<element name="sourceSelectionAlgorithmToggle" type="button" selector=".action-toggle.primary.save"/>
1212
<element name="selectSourcePriority" type="button" selector=".item[data-ui-id='source-selection-algorithms-button-item-0']"/>
1313
<element name="selectDistancePriority" type="button" selector=".item[title='Distance Priority']"/>
14+
<element name="selectSourcePriority1" type="button" selector=".item[title='Source Priority']"/>
1415
<element name="proceedToShipment" type="button" selector="#save[data-ui-id='save-button']"/>
1516
<element name="sourceSelection" type="select" selector="select[name='sourceCode']"/>
1617
</section>

InventoryAdminUi/Test/Mftf/Suite/InventoryMultiModeSuite.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Suite/etc/suiteSchema.xsd">
1010
<suite name="InventoryMultiModeSuite">
1111
<before>
12+
<magentoCLI command="config:set {{EnableFlatRateConfigData.path}} {{EnableFlatRateConfigData.value}}" stepKey="enableFlatRate"/>
13+
1214
<actionGroup ref="AdminDisableWYSIWYGActionGroup" stepKey="disableWYSYWYG"/>
1315
<magentoCLI command="config:set {{TurnOnManageStockConfig.path}} {{TurnOnManageStockConfig.value}}" stepKey="enableStockManagement"/>
1416
<magentoCron groups="index" stepKey="reindex"/>
@@ -24,6 +26,8 @@
2426
<group name="single_mode"/>
2527
</exclude>
2628
<after>
29+
<magentoCLI command="config:set {{DisableFlatRateConfigData.path}} {{DisableFlatRateConfigData.value}}" stepKey="disableFlatRate"/>
30+
2731
<actionGroup ref="AdminEnableWYSIWYGActionGroup" stepKey="enableWYSYWYG"/>
2832
<magentoCLI command="config:set {{TurnOffManageStockConfig.path}} {{TurnOffManageStockConfig.value}}" stepKey="disableStockManagement"/>
2933
<magentoCron groups="index" stepKey="reindex"/>

InventoryAdminUi/Test/Mftf/Test/AdminAssignMultipleSourcesToProductTest.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
<severity value="MAJOR"/>
1818
<group value="msi"/>
1919
<group value="multi_mode"/>
20-
<skip>
21-
<issueId value="ACQE-4167"/>
22-
</skip>
2320
</annotations>
2421

2522
<before>

InventoryAdminUi/Test/Mftf/Test/AdminCacheValidationWhenSimpleProductIsSoldOutOnMultipleStockModeTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878

7979
<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart"/>
8080

81-
<fillField selector="{{CheckoutShippingSection.email}}" userInput="{{MsiCustomer1.email}}" stepKey="enterEmail"/>
81+
<fillField selector="{{CheckoutShippingSection.emailAddress}}" userInput="{{MsiCustomer1.email}}" stepKey="enterEmail"/>
8282
<waitForPageLoad stepKey="waitForPageLoad14"/>
8383
<fillField selector="#shipping-new-address-form input[name=firstname]" userInput="{{MsiCustomer1.firstname}}" stepKey="enterFirstName"/>
8484
<waitForPageLoad stepKey="waitForPageLoad15"/>

0 commit comments

Comments
 (0)