forked from magento/inventory
-
Notifications
You must be signed in to change notification settings - Fork 0
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 magento#3170 from magento-mpi/MC-34177
[Support] Product salability status is not updated for default stock after order is placed until it is shipped
- Loading branch information
Showing
10 changed files
with
691 additions
and
69 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
...i/Test/Mftf/Test/StorefrontCreateOrderAllQuantityGroupedProductOptionDefaultStockTest.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,97 @@ | ||
<?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="StorefrontCreateOrderAllQuantityGroupedProductOptionDefaultStockTest"> | ||
<annotations> | ||
<stories value="Grouped Product Default Stock."/> | ||
<title value="Place order with all quantity with grouped product option on default stock."/> | ||
<description value="Verify, grouped product option will change status after order placement with all it's quantity on default stock"/> | ||
<severity value="CRITICAL"/> | ||
<group value="msi"/> | ||
<group value="multi_mode"/> | ||
</annotations> | ||
<before> | ||
<!--Login to admin--> | ||
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> | ||
<!--Disable all custom sources--> | ||
<actionGroup ref="DisableAllSourcesActionGroup" stepKey="disableSource"/> | ||
<!--Create category--> | ||
<createData entity="ApiCategory" stepKey="createCategory"/> | ||
<!--Create grouped product--> | ||
<createData entity="ApiGroupedProduct" stepKey="groupedProduct"/> | ||
<!--Create simple product (1) with qty 10--> | ||
<createData entity="ApiSimplePrice10Qty10" stepKey="product1"> | ||
<requiredEntity createDataKey="createCategory"/> | ||
</createData> | ||
<!--Create simple product (2) with qty 10--> | ||
<createData entity="ApiSimplePrice10Qty10" stepKey="product2"> | ||
<requiredEntity createDataKey="createCategory"/> | ||
</createData> | ||
<!--Add simple product (1) to grouped product--> | ||
<createData entity="OneSimpleProductLink" stepKey="addProductOne"> | ||
<requiredEntity createDataKey="groupedProduct"/> | ||
<requiredEntity createDataKey="product1"/> | ||
</createData> | ||
<!--Add simple product (2) to grouped product--> | ||
<updateData entity="OneMoreSimpleProductLink" createDataKey="addProductOne" stepKey="addProductTwo"> | ||
<requiredEntity createDataKey="groupedProduct"/> | ||
<requiredEntity createDataKey="product2"/> | ||
</updateData> | ||
<!--Create customer--> | ||
<createData entity="MsiCustomer1" stepKey="customer"/> | ||
</before> | ||
<after> | ||
<!--Logout from admin--> | ||
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutOfAdmin"/> | ||
<!--Delete category--> | ||
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/> | ||
<!--Delete grouped product--> | ||
<deleteData createDataKey="groupedProduct" stepKey="deleteGroupedProduct"/> | ||
<!--Delete simple product (1)--> | ||
<deleteData createDataKey="product1" stepKey="deleteSimpleProduct1"/> | ||
<!--Delete simple product (2)--> | ||
<deleteData createDataKey="product2" stepKey="deleteSimpleProduct2"/> | ||
<!--Delete customer--> | ||
<deleteData createDataKey="customer" stepKey="deleteCustomer"/> | ||
</after> | ||
|
||
<!--Login To storefront as Customer--> | ||
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginToStorefront"> | ||
<argument name="Customer" value="$$customer$$"/> | ||
</actionGroup> | ||
<!--Navigate to group product PDP.--> | ||
<actionGroup ref="StorefrontOpenProductEntityPageActionGroup" stepKey="navigateToGroupedProductPDP"> | ||
<argument name="product" value="$groupedProduct$"/> | ||
</actionGroup> | ||
<!--Add grouped product to cart with all available quantity of product (1).--> | ||
<actionGroup ref="StorefrontAddGroupedProductWithTwoLinksToCartActionGroup" stepKey="addGroupedProductToCart"> | ||
<argument name="product" value="$groupedProduct$"/> | ||
<argument name="linkedProduct1Name" value="$product1.name$"/> | ||
<argument name="linkedProduct2Name" value="$product2.name$"/> | ||
<argument name="linkedProduct1Qty" value="{{Qty_10.qty}}"/> | ||
<argument name="linkedProduct2Qty" value="{{Qty_1.qty}}"/> | ||
</actionGroup> | ||
<!--Place order.--> | ||
<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="navigateToCheckoutPage"/> | ||
<click selector="{{CheckoutShippingSection.next}}" stepKey="clickNextButton"/> | ||
<actionGroup ref="ClickPlaceOrderActionGroup" stepKey="clickOnPlaceOrder"/> | ||
<!--Run queue consumer.--> | ||
<magentoCLI command="queue:consumers:start" arguments="inventory.reservations.updateSalabilityStatus" stepKey="startSalabilityUpdate" timeout="30"/> | ||
<!--Navigate to group product PDP.--> | ||
<actionGroup ref="StorefrontOpenProductEntityPageActionGroup" stepKey="navigateToGroupedProductPDPAfterOrderPlacement"> | ||
<argument name="product" value="$groupedProduct$"/> | ||
</actionGroup> | ||
<!--Verify that product1 is not present.--> | ||
<dontSee selector="{{StorefrontProductInfoMainSection.groupedProductsTable}}" userInput="$product1.name$" stepKey="dontSeeProduct1"/> | ||
<!--Verify that product2 is present.--> | ||
<actionGroup ref="AssertLinkPresenceOnGroupedProductPage" stepKey="verifySecondOptionIsStillPresentedOnPage"> | ||
<argument name="productName" value="$product2.name$"/> | ||
</actionGroup> | ||
</test> | ||
</tests> |
87 changes: 87 additions & 0 deletions
87
InventoryIndexer/Model/Queue/GetSalabilityDataForUpdate.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,87 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryIndexer\Model\Queue; | ||
|
||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\InventorySalesApi\Api\AreProductsSalableInterface; | ||
use Magento\InventorySalesApi\Model\GetStockItemDataInterface; | ||
|
||
/** | ||
* Get stock status changes for given reservation. | ||
*/ | ||
class GetSalabilityDataForUpdate | ||
{ | ||
/** | ||
* @var AreProductsSalableInterface | ||
*/ | ||
private $areProductsSalable; | ||
|
||
/** | ||
* @var GetStockItemDataInterface | ||
*/ | ||
private $getStockItemData; | ||
|
||
/** | ||
* @param AreProductsSalableInterface $areProductsSalable | ||
* @param GetStockItemDataInterface $getStockItemData | ||
*/ | ||
public function __construct( | ||
AreProductsSalableInterface $areProductsSalable, | ||
GetStockItemDataInterface $getStockItemData | ||
) { | ||
$this->areProductsSalable = $areProductsSalable; | ||
$this->getStockItemData = $getStockItemData; | ||
} | ||
|
||
/** | ||
* Get stock status changes for given reservation. | ||
* | ||
* @param ReservationData $reservationData | ||
* @return bool[] - ['sku' => bool] | ||
*/ | ||
public function execute(ReservationData $reservationData): array | ||
{ | ||
$salabilityData = $this->areProductsSalable->execute( | ||
$reservationData->getSkus(), | ||
$reservationData->getStock() | ||
); | ||
|
||
$data = []; | ||
foreach ($salabilityData as $isProductSalableResult) { | ||
$currentStatus = $this->isCurrentlySalable( | ||
$isProductSalableResult->getSku(), | ||
$reservationData->getStock() | ||
); | ||
if ($isProductSalableResult->isSalable() !== $currentStatus) { | ||
$data[$isProductSalableResult->getSku()] = $isProductSalableResult->isSalable(); | ||
} | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* Get current is_salable value. | ||
* | ||
* @param string $sku | ||
* @param int $stockId | ||
* | ||
* @return bool | ||
*/ | ||
private function isCurrentlySalable(string $sku, int $stockId): bool | ||
{ | ||
try { | ||
$data = $this->getStockItemData->execute($sku, $stockId); | ||
$isSalable = $data ? (bool)$data[GetStockItemDataInterface::IS_SALABLE] : false; | ||
} catch (LocalizedException $e) { | ||
$isSalable = false; | ||
} | ||
|
||
return $isSalable; | ||
} | ||
} |
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.