-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #217 from magento-l3/L3-PR-2022-04-19
L3-PR-2022-04-19
- Loading branch information
Showing
11 changed files
with
485 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...ntoryAdminUi/Test/Mftf/Test/AdminAssertNoteIsDisplayedForAddSourcesToDefaultStockTest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
|
||
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> | ||
<test name="AdminAssertNoteIsDisplayedForAssignSourcesForDefaultStockTest"> | ||
<annotations> | ||
<stories value="Assign new sources to the default stock"/> | ||
<title value="Assert that a note is displayed for Assign Sources for Default Stock"/> | ||
<description value="User shouldn't be able to assign new sources to the default stock"/> | ||
<testCaseId value="AC-2761"/> | ||
<useCaseId value="ACP2E-545"/> | ||
<severity value="AVERAGE"/> | ||
<group value="msi"/> | ||
<group value="multi_mode"/> | ||
</annotations> | ||
|
||
<before> | ||
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> | ||
</before> | ||
|
||
<after> | ||
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutOfAdmin"/> | ||
</after> | ||
|
||
<amOnPage url="{{AdminManageStockPage.url}}" stepKey="amOnStockListPage"/> | ||
<click selector="{{AdminGridRow.editByValue(_defaultStock.name)}}" stepKey="clickEditDefaultStock"/> | ||
<waitForPageLoad time="20" stepKey="waitFroDefaultStockEditPageLoad"/> | ||
|
||
<!-- Check that Assign Sources button is disabled --> | ||
<assertElementContainsAttribute stepKey="seeAssignSourceButtonIsDisabled"> | ||
<expectedResult selector="{{AdminEditStockSourcesSection.assignSources}}" attribute="disabled" type="string"></expectedResult> | ||
</assertElementContainsAttribute> | ||
|
||
<grabTextFrom selector="{{AdminEditStockGeneralSection.disabledAddingSourcesNotice}}" stepKey="grabNote"/> | ||
<assertEquals stepKey="assertNotification"> | ||
<actualResult type="const">$grabNote</actualResult> | ||
<expectedResult type="const">"Assign sources is disabled for default stock"</expectedResult> | ||
</assertEquals> | ||
</test> | ||
</tests> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
InventoryIndexer/Test/Api/SourceItemsSaveInterfaceTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryIndexer\Test\Api; | ||
|
||
use Magento\CatalogInventory\Model\Stock; | ||
use Magento\Framework\Webapi\Rest\Request; | ||
use Magento\InventoryApi\Api\Data\SourceItemInterface; | ||
use Magento\InventoryIndexer\Model\ResourceModel\GetStockItemData; | ||
use Magento\InventorySalesApi\Model\GetStockItemDataInterface; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\TestCase\WebapiAbstract; | ||
|
||
class SourceItemsSaveInterfaceTest extends WebapiAbstract | ||
{ | ||
private const RESOURCE_PATH = '/V1/inventory/source-items'; | ||
private const SERVICE_NAME_SAVE = 'inventoryApiSourceItemsSaveV1'; | ||
|
||
/** | ||
* @var GetStockItemData | ||
*/ | ||
private $getStockItemData; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->getStockItemData = Bootstrap::getObjectManager()->get(GetStockItemData::class); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Catalog/_files/products.php | ||
* @magentoApiDataFixture Magento_InventoryApi::Test/_files/stock_with_source_link.php | ||
* @magentoApiDataFixture Magento/Catalog/_files/reindex_catalog_inventory_stock.php | ||
* @magentoApiDataFixture Magento_InventoryIndexer::Test/_files/reindex_inventory_rollback.php | ||
*/ | ||
public function testProductSalabilityShouldChangeAfterUpdatingSourceItemDefaultStock(): void | ||
{ | ||
$sku = 'simple'; | ||
$sourceCode = 'default'; | ||
$stockId = Stock::DEFAULT_STOCK_ID; | ||
$stockData = $this->getStockItemData->execute($sku, $stockId); | ||
$this->assertTrue((bool)$stockData[GetStockItemDataInterface::IS_SALABLE]); | ||
$this->saveSourceItems( | ||
[ | ||
[ | ||
SourceItemInterface::SOURCE_CODE => $sourceCode, | ||
SourceItemInterface::SKU => $sku, | ||
SourceItemInterface::QUANTITY => 0, | ||
SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, | ||
], | ||
] | ||
); | ||
$stockData = $this->getStockItemData->execute($sku, $stockId); | ||
$this->assertFalse((bool)$stockData[GetStockItemDataInterface::IS_SALABLE]); | ||
$this->saveSourceItems( | ||
[ | ||
[ | ||
SourceItemInterface::SOURCE_CODE => $sourceCode, | ||
SourceItemInterface::SKU => $sku, | ||
SourceItemInterface::QUANTITY => 10, | ||
SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, | ||
], | ||
] | ||
); | ||
$stockData = $this->getStockItemData->execute($sku, $stockId); | ||
$this->assertTrue((bool)$stockData[GetStockItemDataInterface::IS_SALABLE]); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento_InventorySalesApi::Test/_files/websites_with_stores.php | ||
* @magentoApiDataFixture Magento_InventoryApi::Test/_files/sources.php | ||
* @magentoApiDataFixture Magento_InventoryApi::Test/_files/stocks.php | ||
* @magentoApiDataFixture Magento_InventoryApi::Test/_files/stock_source_links.php | ||
* @magentoApiDataFixture Magento_InventorySalesApi::Test/_files/stock_website_sales_channels.php | ||
* @magentoApiDataFixture Magento_InventoryApi::Test/_files/products.php | ||
* @magentoApiDataFixture Magento_InventoryApi::Test/_files/source_items.php | ||
* @magentoApiDataFixture Magento_InventoryApi::Test/_files/assign_products_to_websites.php | ||
* @magentoApiDataFixture Magento_InventoryIndexer::Test/_files/reindex_inventory.php | ||
*/ | ||
public function testProductSalabilityShouldChangeAfterUpdatingSourceItemCustomStock(): void | ||
{ | ||
$sku = 'SKU-2'; | ||
$sourceCode = 'us-1'; | ||
$stockId = 20; | ||
$stockData = $this->getStockItemData->execute($sku, $stockId); | ||
$this->assertTrue((bool)$stockData[GetStockItemDataInterface::IS_SALABLE]); | ||
$this->saveSourceItems( | ||
[ | ||
[ | ||
SourceItemInterface::SOURCE_CODE => $sourceCode, | ||
SourceItemInterface::SKU => $sku, | ||
SourceItemInterface::QUANTITY => 0, | ||
SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, | ||
], | ||
] | ||
); | ||
$stockData = $this->getStockItemData->execute($sku, $stockId); | ||
$this->assertFalse((bool)$stockData[GetStockItemDataInterface::IS_SALABLE]); | ||
$this->saveSourceItems( | ||
[ | ||
[ | ||
SourceItemInterface::SOURCE_CODE => $sourceCode, | ||
SourceItemInterface::SKU => $sku, | ||
SourceItemInterface::QUANTITY => 10, | ||
SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, | ||
], | ||
] | ||
); | ||
$stockData = $this->getStockItemData->execute($sku, $stockId); | ||
$this->assertTrue((bool)$stockData[GetStockItemDataInterface::IS_SALABLE]); | ||
} | ||
|
||
/** | ||
* @param array $sourceItems | ||
* @return void | ||
*/ | ||
private function saveSourceItems(array $sourceItems): void | ||
{ | ||
$serviceInfo = [ | ||
'rest' => [ | ||
'resourcePath' => self::RESOURCE_PATH, | ||
'httpMethod' => Request::HTTP_METHOD_POST, | ||
], | ||
'soap' => [ | ||
'service' => self::SERVICE_NAME_SAVE, | ||
'operation' => self::SERVICE_NAME_SAVE . 'Execute', | ||
], | ||
]; | ||
$this->_webApiCall($serviceInfo, ['sourceItems' => $sourceItems]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventorySales\Model; | ||
|
||
use Magento\Framework\App\ResourceConnection; | ||
use Magento\Inventory\Model\ResourceModel\SourceItem; | ||
use Magento\Inventory\Model\ResourceModel\StockSourceLink; | ||
use Magento\Inventory\Model\ResourceModel\Source; | ||
use Magento\InventoryApi\Api\Data\SourceInterface; | ||
use Magento\InventoryApi\Api\Data\SourceItemInterface; | ||
use Magento\InventoryApi\Api\Data\StockSourceLinkInterface; | ||
use Zend_Db_Expr; | ||
|
||
/** | ||
* Service which returns aggregated quantity of a product across all active sources in the provided stock | ||
*/ | ||
class GetProductAvailableQty | ||
{ | ||
/** | ||
* @var ResourceConnection | ||
*/ | ||
private $resourceConnection; | ||
|
||
/** | ||
* @param ResourceConnection $resourceConnection | ||
*/ | ||
public function __construct(ResourceConnection $resourceConnection) | ||
{ | ||
$this->resourceConnection = $resourceConnection; | ||
} | ||
|
||
/** | ||
* Get available quantity for given SKU and Stock | ||
* | ||
* @param string $sku | ||
* @param int $stockId | ||
* @return float | ||
*/ | ||
public function execute(string $sku, int $stockId): float | ||
{ | ||
$connection = $this->resourceConnection->getConnection(); | ||
$select = $connection->select()->from( | ||
['issl' => $this->resourceConnection->getTableName(StockSourceLink::TABLE_NAME_STOCK_SOURCE_LINK)], | ||
[] | ||
)->joinInner( | ||
['is' => $this->resourceConnection->getTableName(Source::TABLE_NAME_SOURCE)], | ||
sprintf('issl.%s = is.%s', StockSourceLinkInterface::SOURCE_CODE, SourceInterface::SOURCE_CODE), | ||
[] | ||
)->joinInner( | ||
['isi' => $this->resourceConnection->getTableName(SourceItem::TABLE_NAME_SOURCE_ITEM)], | ||
sprintf('issl.%s = isi.%s', StockSourceLinkInterface::SOURCE_CODE, SourceItemInterface::SOURCE_CODE), | ||
[] | ||
)->where( | ||
sprintf('issl.%s = ?', StockSourceLinkInterface::STOCK_ID), | ||
$stockId | ||
)->where( | ||
sprintf('is.%s = ?', SourceInterface::ENABLED), | ||
1 | ||
)->where( | ||
sprintf('isi.%s = ?', SourceItemInterface::SKU), | ||
$sku | ||
)->where( | ||
sprintf('isi.%s = ?', SourceItemInterface::STATUS), | ||
SourceItemInterface::STATUS_IN_STOCK | ||
)->columns( | ||
['quantity' => new Zend_Db_Expr(sprintf('SUM(isi.%s)', SourceItemInterface::QUANTITY))] | ||
); | ||
|
||
return (float) $connection->fetchOne($select); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.