Skip to content

Commit e9d6e33

Browse files
authored
Merge pull request #507 from magento-lynx/graphql-api-enhancements
2 parents ec3f1e7 + cf01527 commit e9d6e33

11 files changed

+336
-55
lines changed

InventoryAdminUi/Test/Mftf/Test/AddProductToCartAfterCancelOrderConfigurableProductCustomStockTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
<fillField selector="{{StorefrontProductPageSection.qtyInput}}" userInput="{{101ProductQty.value}}" stepKey="fillQuantity"/>
116116
<click selector="{{StorefrontProductPageSection.addToCartBtn}}" stepKey="addToCart"/>
117117
<waitForElementVisible selector="{{StorefrontProductPageSection.errorMsg}}" stepKey="waitForErrorMessage"/>
118-
<see selector="{{StorefrontProductPageSection.errorMsg}}" userInput="The requested qty is not available" stepKey="verifyErrorMessage"/>
118+
<see selector="{{StorefrontProductPageSection.errorMsg}}" userInput="Not enough items for sale" stepKey="verifyErrorMessage"/>
119119
<!--Add configurable to cart with proper quantity-->
120120
<actionGroup ref="StorefrontAddConfigurableProductToTheCartActionGroup" stepKey="addConfigurableProductToCartWithProperQty">
121121
<argument name="urlKey" value="$configurableProduct.custom_attributes[url_key]$" />

InventoryAdminUi/Test/Mftf/Test/AddProductToCartAfterCancelOrderDownloadableProductCustomStockTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
<fillField selector="{{StorefrontProductPageSection.qtyInput}}" userInput="{{101ProductQty.value}}" stepKey="fillQuantity"/>
8484
<click selector="{{StorefrontProductPageSection.addToCartBtn}}" stepKey="addToCart"/>
8585
<waitForElementVisible selector="{{StorefrontProductPageSection.errorMsg}}" stepKey="waitForErrorMessage"/>
86-
<see selector="{{StorefrontProductPageSection.errorMsg}}" userInput="The requested qty is not available" stepKey="verifyErrorMessage"/>
86+
<see selector="{{StorefrontProductPageSection.errorMsg}}" userInput="Not enough items for sale" stepKey="verifyErrorMessage"/>
8787
<!--Add downloadable product with proper quantity.-->
8888
<actionGroup ref="StorefrontAddProductToCartWithQtyActionGroup" stepKey="addProductToCartWithProperQty">
8989
<argument name="productQty" value="{{defaultProductQty.value}}"/>

InventoryAdminUi/Test/Mftf/Test/AddProductToCartAfterCancelOrderSimpleProductCustomStockTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
<fillField selector="{{StorefrontProductPageSection.qtyInput}}" userInput="{{101ProductQty.value}}" stepKey="fillQuantity"/>
8888
<click selector="{{StorefrontProductPageSection.addToCartBtn}}" stepKey="addToCart"/>
8989
<waitForElementVisible selector="{{StorefrontProductPageSection.errorMsg}}" stepKey="waitForErrorMessage"/>
90-
<see selector="{{StorefrontProductPageSection.errorMsg}}" userInput="The requested qty is not available" stepKey="verifyErrorMessage"/>
90+
<see selector="{{StorefrontProductPageSection.errorMsg}}" userInput="Not enough items for sale" stepKey="verifyErrorMessage"/>
9191
<!--Add simple product with proper quantity.-->
9292
<actionGroup ref="StorefrontAddProductToCartWithQtyActionGroup" stepKey="addProductToCartWithProperQty">
9393
<argument name="productQty" value="{{defaultProductQty.value}}"/>

InventoryAdminUi/Test/Mftf/Test/AddProductToCartAfterOrderPlacementSimpleProductCustomStockTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<fillField selector="{{StorefrontProductPageSection.qtyInput}}" userInput="{{defaultProductQty.value}}" stepKey="fillQuantity"/>
8080
<click selector="{{StorefrontProductPageSection.addToCartBtn}}" stepKey="addToCart"/>
8181
<waitForElementVisible selector="{{StorefrontProductPageSection.errorMsg}}" stepKey="waitForErrorMessage"/>
82-
<see selector="{{StorefrontProductPageSection.errorMsg}}" userInput="The requested qty is not available" stepKey="verifyErrorMessage"/>
82+
<see selector="{{StorefrontProductPageSection.errorMsg}}" userInput="Not enough items for sale" stepKey="verifyErrorMessage"/>
8383
<!--Add simple product with proper quantity.-->
8484
<actionGroup ref="StorefrontAddProductToCartWithQtyActionGroup" stepKey="addProductToCartWithProperQty">
8585
<argument name="productQty" value="{{defaultProductQtyBoughtWith5Pieces.value}}"/>

InventoryGraphQl/Model/Resolver/StockStatusProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1515
use Magento\InventoryCatalog\Model\GetStockIdForCurrentWebsite;
1616
use Magento\InventorySalesApi\Api\AreProductsSalableInterface;
17+
use Magento\Catalog\Model\Product\Type;
1718

1819
/**
1920
* @inheritdoc
@@ -54,7 +55,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
5455
/* @var $product ProductInterface */
5556
$product = $value['model'];
5657

57-
$productSku = ($product->getTypeId() === "bundle") ? $value['sku'] : $product->getSku();
58+
$productSku = ($product->getTypeId() === TYPE::TYPE_BUNDLE || !empty($product->getOptions()))
59+
? $value['sku'] : $product->getSku();
5860
$stockId = $this->getStockIdForCurrentWebsite->execute();
5961
$result = $this->areProductsSalable->execute([$productSku], $stockId);
6062
$result = current($result);

InventorySales/Model/IsProductSalableForRequestedQtyCondition/IsSalableWithReservationsCondition.php

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,72 +7,34 @@
77

88
namespace Magento\InventorySales\Model\IsProductSalableForRequestedQtyCondition;
99

10-
use Magento\InventoryReservationsApi\Model\GetReservationsQuantityInterface;
10+
use Magento\CatalogInventory\Model\Config\Source\NotAvailableMessage;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
1112
use Magento\InventorySalesApi\Model\GetSalableQtyInterface;
1213
use Magento\InventorySalesApi\Api\IsProductSalableForRequestedQtyInterface;
1314
use Magento\InventorySalesApi\Model\GetStockItemDataInterface;
1415
use Magento\InventorySalesApi\Api\Data\ProductSalableResultInterface;
1516
use Magento\InventorySalesApi\Api\Data\ProductSalableResultInterfaceFactory;
1617
use Magento\InventorySalesApi\Api\Data\ProductSalabilityErrorInterfaceFactory;
17-
use Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface;
1818

1919
/**
2020
* @inheritdoc
2121
*/
2222
class IsSalableWithReservationsCondition implements IsProductSalableForRequestedQtyInterface
2323
{
24-
/**
25-
* @var GetStockItemDataInterface
26-
*/
27-
private $getStockItemData;
28-
29-
/**
30-
* @var GetReservationsQuantityInterface
31-
*/
32-
private $getReservationsQuantity;
33-
34-
/**
35-
* @var GetStockItemConfigurationInterface
36-
*/
37-
private $getStockItemConfiguration;
38-
39-
/**
40-
* @var ProductSalabilityErrorInterfaceFactory
41-
*/
42-
private $productSalabilityErrorFactory;
43-
44-
/**
45-
* @var ProductSalableResultInterfaceFactory
46-
*/
47-
private $productSalableResultFactory;
48-
49-
/**
50-
* @var GetSalableQtyInterface
51-
*/
52-
private $getProductQtyInStock;
53-
5424
/**
5525
* @param GetStockItemDataInterface $getStockItemData
56-
* @param GetReservationsQuantityInterface $getReservationsQuantity
57-
* @param GetStockItemConfigurationInterface $getStockItemConfiguration
5826
* @param ProductSalabilityErrorInterfaceFactory $productSalabilityErrorFactory
5927
* @param ProductSalableResultInterfaceFactory $productSalableResultFactory
6028
* @param GetSalableQtyInterface $getProductQtyInStock
29+
* @param ScopeConfigInterface $scopeConfig
6130
*/
6231
public function __construct(
63-
GetStockItemDataInterface $getStockItemData,
64-
GetReservationsQuantityInterface $getReservationsQuantity,
65-
GetStockItemConfigurationInterface $getStockItemConfiguration,
66-
ProductSalabilityErrorInterfaceFactory $productSalabilityErrorFactory,
67-
ProductSalableResultInterfaceFactory $productSalableResultFactory,
68-
GetSalableQtyInterface $getProductQtyInStock
32+
private readonly GetStockItemDataInterface $getStockItemData,
33+
private readonly ProductSalabilityErrorInterfaceFactory $productSalabilityErrorFactory,
34+
private readonly ProductSalableResultInterfaceFactory $productSalableResultFactory,
35+
private readonly GetSalableQtyInterface $getProductQtyInStock,
36+
private readonly ScopeConfigInterface $scopeConfig,
6937
) {
70-
$this->getStockItemData = $getStockItemData;
71-
$this->getReservationsQuantity = $getReservationsQuantity;
72-
$this->getStockItemConfiguration = $getStockItemConfiguration;
73-
$this->productSalabilityErrorFactory = $productSalabilityErrorFactory;
74-
$this->productSalableResultFactory = $productSalableResultFactory;
75-
$this->getProductQtyInStock = $getProductQtyInStock;
7638
}
7739

7840
/**
@@ -96,10 +58,20 @@ public function execute(string $sku, int $stockId, float $requestedQty): Product
9658
$isEnoughQty = bccomp((string)$qtyLeftInStock, (string)$requestedQty, 4) >= 0;
9759

9860
if (!$isEnoughQty) {
61+
$message = __('Not enough items for sale');
62+
if ((int)$this->scopeConfig->getValue(
63+
'cataloginventory/options/not_available_message'
64+
) === NotAvailableMessage::VALUE_ONLY_X_OF_Y) {
65+
$message = (__(sprintf(
66+
'Only %s of %s available',
67+
$qtyLeftInStock,
68+
$requestedQty
69+
)));
70+
}
9971
$errors = [
10072
$this->productSalabilityErrorFactory->create([
10173
'code' => 'is_salable_with_reservations-not_enough_qty',
102-
'message' => __('The requested qty is not available')
74+
'message' => $message
10375
])
10476
];
10577
return $this->productSalableResultFactory->create(['errors' => $errors]);

InventorySales/i18n/en_US.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"Condition have to implement IsProductSalableForRequestedQtyInterface.","Condition have to implement IsProductSalableForRequestedQtyInterface."
1414
"The requested sku is not assigned to given stock.","The requested sku is not assigned to given stock."
1515
"The requested sku is not assigned to given stock","The requested sku is not assigned to given stock"
16-
"The requested qty is not available","The requested qty is not available"
16+
"Not enough items for sale","Not enough items for sale"
1717
"Manage stock is enabled","Manage stock is enabled"
1818
"Condition must implement %1","Condition must implement %1"
1919
"""%field"" can not be empty.","""%field"" can not be empty."

InventorySalesAdminUi/Test/Mftf/Test/AdminAddSelectedProductToOrderTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<actionGroup ref="AssertAdminItemOrderedErrorActionGroup" stepKey="assertProductErrorRemains">
1313
<argument name="productName" value="$simpleProduct.name$"/>
1414
<argument name="messageType" value="error"/>
15+
<argument name="message" value="Not enough items for sale"/>
1516
</actionGroup>
1617
</test>
1718
</tests>

InventorySalesAdminUi/Test/Mftf/Test/AdminEditOrderWithOutOfStockConfigurableProductTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
</actionGroup>
140140

141141
<!-- Check error message is absent -->
142-
<dontSee selector="{{AdminOrderEditMessagesSection.error}}" userInput="The requested qty is not available" stepKey="verifyErrorMessageIsAbsent"/>
142+
<dontSee selector="{{AdminOrderEditMessagesSection.error}}" userInput="Not enough items for sale" stepKey="verifyErrorMessageIsAbsent"/>
143143

144144
<!-- Update customer address -->
145145
<actionGroup ref="FillOrderCustomerInformationActionGroup" stepKey="updateCustomerInformation">

InventorySalesAdminUi/Test/Mftf/Test/AdminEditOrderWithOutOfStockProductTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
</actionGroup>
7474

7575
<!-- Check error message is absent -->
76-
<dontSee selector="{{AdminOrderEditMessagesSection.error}}" userInput="The requested qty is not available" stepKey="verifyErrorMessageIsAbsent"/>
76+
<dontSee selector="{{AdminOrderEditMessagesSection.error}}" userInput="Not enough items for sale" stepKey="verifyErrorMessageIsAbsent"/>
7777

7878
<!-- Update customer address -->
7979
<actionGroup ref="FillOrderCustomerInformationActionGroup" stepKey="updateCustomerInformation">

0 commit comments

Comments
 (0)