Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
module-catalog-inventory-graph-ql
Model
Resolver
StockStatusProvider.php
Go to the documentation of this file.
1
<?php
6
declare(strict_types=1);
7
8
namespace
Magento\CatalogInventoryGraphQl\Model\Resolver
;
9
10
use
Magento\Catalog\Api\Data\ProductInterface
;
11
use
Magento\CatalogInventory\Api\Data\StockStatusInterface
;
12
use
Magento\CatalogInventory\Api\StockStatusRepositoryInterface
;
13
use
Magento\Framework\GraphQl\Exception\GraphQlInputException
;
14
use
Magento\Framework\GraphQl\Schema\Type\ResolveInfo
;
15
use
Magento\Framework\GraphQl\Config\Element\Field
;
16
use
Magento\Framework\GraphQl\Query\ResolverInterface
;
17
21
class
StockStatusProvider
implements
ResolverInterface
22
{
26
private
$stockStatusRepository;
27
31
public
function
__construct
(
StockStatusRepositoryInterface
$stockStatusRepository)
32
{
33
$this->stockStatusRepository =
$stockStatusRepository
;
34
}
35
39
public
function
resolve
(
Field
$field, $context,
ResolveInfo
$info
, array
$value
=
null
, array $args =
null
)
40
{
41
if
(!array_key_exists(
'model'
,
$value
) || !
$value
[
'model'
] instanceof
ProductInterface
) {
42
throw
new
GraphQlInputException
(
__
(
'"model" value should be specified'
));
43
}
44
45
/* @var $product ProductInterface */
46
$product
=
$value
[
'model'
];
47
48
$stockStatus = $this->stockStatusRepository->get(
$product
->getId());
49
$productStockStatus = (int)$stockStatus->getStockStatus();
50
51
return
$productStockStatus ===
StockStatusInterface::STATUS_IN_STOCK
?
'IN_STOCK'
:
'OUT_OF_STOCK'
;
52
}
53
}
Magento\Framework\GraphQl\Query\ResolverInterface
Definition:
ResolverInterface.php:18
Magento\CatalogInventory\Api\StockStatusRepositoryInterface
Definition:
StockStatusRepositoryInterface.php:17
Magento\Framework\GraphQl\Schema\Type\ResolveInfo
Definition:
ResolveInfo.php:13
Magento\CatalogInventoryGraphQl\Model\Resolver\StockStatusProvider
Definition:
StockStatusProvider.php:21
__
__()
Definition:
__.php:13
$stockStatusRepository
$stockStatusRepository
Definition:
products_rollback.php:22
Magento\CatalogInventoryGraphQl\Model\Resolver\StockStatusProvider\resolve
resolve(Field $field, $context, ResolveInfo $info, array $value=null, array $args=null)
Definition:
StockStatusProvider.php:39
Magento\CatalogInventory\Api\Data\StockStatusInterface\STATUS_IN_STOCK
const STATUS_IN_STOCK
Definition:
StockStatusInterface.php:26
Magento\Framework\GraphQl\Config\Element\Field
Definition:
Field.php:15
$value
$value
Definition:
gender.phtml:16
Magento\CatalogInventoryGraphQl\Model\Resolver\StockStatusProvider\__construct
__construct(StockStatusRepositoryInterface $stockStatusRepository)
Definition:
StockStatusProvider.php:31
Magento\CatalogInventory\Api\Data\StockStatusInterface
Definition:
StockStatusInterface.php:19
$product
$product
Definition:
bundle_product_with_not_visible_children.php:22
$info
foreach( $_productCollection as $_product)() ?>" class $info
Definition:
listing.phtml:52
Magento\Catalog\Api\Data\ProductInterface
Definition:
ProductInterface.php:14
Magento\CatalogInventoryGraphQl\Model\Resolver
Definition:
OnlyXLeftInStockResolver.php:8
Magento\Framework\GraphQl\Exception\GraphQlInputException
Definition:
GraphQlInputException.php:16