Skip to content

Commit 320a285

Browse files
committed
Update product stock fixture
1 parent 4e89e48 commit 320a285

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

app/code/Magento/Catalog/Test/Fixture/ProductStock.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
<?php
2+
/**
3+
* Copyright 2023 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained from
13+
* Adobe.
14+
*/
15+
declare(strict_types=1);
16+
217
namespace Magento\Catalog\Test\Fixture;
318

419
use Magento\CatalogInventory\Api\StockRegistryInterface;
520
use Magento\Framework\DataObject;
621
use Magento\Framework\DataObjectFactory;
22+
use Magento\TestFramework\Fixture\Api\DataMerger;
723
use Magento\TestFramework\Fixture\DataFixtureInterface;
824

925
class ProductStock implements DataFixtureInterface
@@ -23,24 +39,33 @@ class ProductStock implements DataFixtureInterface
2339
*/
2440
protected StockRegistryInterface $stockRegistry;
2541

42+
/**
43+
* @var DataMerger
44+
*/
45+
protected DataMerger $dataMerger;
46+
2647
/**
2748
* @param DataObjectFactory $dataObjectFactory
2849
* @param StockRegistryInterface $stockRegistry
50+
* @param DataMerger $dataMerger
2951
*/
3052
public function __construct(
3153
DataObjectFactory $dataObjectFactory,
32-
StockRegistryInterface $stockRegistry
54+
StockRegistryInterface $stockRegistry,
55+
DataMerger $dataMerger
3356
) {
3457
$this->dataObjectFactory = $dataObjectFactory;
3558
$this->stockRegistry = $stockRegistry;
59+
$this->dataMerger = $dataMerger;
3660
}
3761

3862
/**
3963
* {@inheritdoc}
40-
* @param array $data Parameters. Same format as ReduceProductStock::DEFAULT_DATA
64+
* @param array $data Parameters. Same format as ProductStock::DEFAULT_DATA
4165
*/
4266
public function apply(array $data = []): ?DataObject
4367
{
68+
$data = $this->dataMerger->merge(self::DEFAULT_DATA, $data);
4469
$stockItem = $this->stockRegistry->getStockItem($data['prod_id']);
4570
$stockItem->setData('is_in_stock', 1);
4671
$stockItem->setData('qty', 90);

app/code/Magento/QuoteGraphQl/Model/CartItem/ProductStock.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(
5353
* @param Item $cartItem
5454
* @return bool
5555
*/
56-
public function getProductAvailability($cartItem):bool
56+
public function getProductAvailability($cartItem): bool
5757
{
5858
$requestedQty = 0;
5959
$previousQty = 0;
@@ -74,14 +74,14 @@ public function getProductAvailability($cartItem):bool
7474
if ($totalRequestedQty) {
7575
$requiredItemQty = $requiredItemQty * $totalRequestedQty;
7676
}
77-
if ($this->isStockAvailable($productId, $requiredItemQty)) {
77+
if (!$this->isStockAvailable($productId, $requiredItemQty)) {
7878
return false;
7979
}
8080
}
8181
} else {
8282
$requiredItemQty = $requestedQty + $previousQty;
8383
$productId = (int) $cartItem->getProduct()->getId();
84-
if ($this->isStockAvailable($productId, $requiredItemQty)) {
84+
if (!$this->isStockAvailable($productId, $requiredItemQty)) {
8585
return false;
8686
}
8787
}
@@ -98,6 +98,6 @@ public function getProductAvailability($cartItem):bool
9898
private function isStockAvailable(int $productId, float $requiredQuantity): bool
9999
{
100100
$stock = $this->stockStatusRepository->get($productId);
101-
return ($stock->getQty() < $requiredQuantity) ? true : false;
101+
return $stock->getQty() >= $requiredQuantity;
102102
}
103103
}

0 commit comments

Comments
 (0)