diff --git a/src/Model/Resolver/Inventory/StockCount.php b/src/Model/Resolver/Inventory/StockCount.php deleted file mode 100644 index f7fc0ad..0000000 --- a/src/Model/Resolver/Inventory/StockCount.php +++ /dev/null @@ -1,61 +0,0 @@ - - * @copyright Copyright (c) 2019 Scandiweb, Ltd (https://scandiweb.com) - */ -declare(strict_types=1); - -namespace ScandiPWA\CatalogGraphQl\Model\Resolver\Inventory; - -use Magento\Catalog\Api\Data\ProductInterface; -use Magento\CatalogInventory\Api\StockStatusRepositoryInterface; -use Magento\Framework\Exception\LocalizedException; -use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; -use Magento\Framework\GraphQl\Config\Element\Field; -use Magento\Framework\GraphQl\Query\ResolverInterface; - -/** - * @inheritdoc - */ -class StockCount implements ResolverInterface { - /** - * @var StockStatusRepositoryInterface - */ - private $stockStatusRepository; - - /** - * @param StockStatusRepositoryInterface $stockStatusRepository - */ - public function __construct(StockStatusRepositoryInterface $stockStatusRepository) - { - $this->stockStatusRepository = $stockStatusRepository; - } - - /** - * @inheritdoc - */ - public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) - { - if (!array_key_exists('model', $value) || !$value['model'] instanceof ProductInterface) { - throw new LocalizedException(__('"model" value should be specified')); - } - - /* @var $product ProductInterface */ - $product = $value['model']; - - $stockStatus = $this->stockStatusRepository->get($product->getId()); - $stockItem = $stockStatus->getStockItem(); - - return [ - 'in_stock' => $stockItem->getIsInStock(), - 'qty' => $stockItem->getQty(), - 'min_sale_qty' => $stockItem->getMinSaleQty(), - 'max_sale_qty' => $stockItem->getMaxSaleQty(), - 'qty_increments' => $stockItem->getQtyIncrements() === false ? 1 : $stockItem->getQtyIncrements() - ]; - } -} diff --git a/src/Model/Variant/Collection.php b/src/Model/Variant/Collection.php index 307006f..1e4e93c 100755 --- a/src/Model/Variant/Collection.php +++ b/src/Model/Variant/Collection.php @@ -62,9 +62,6 @@ class Collection /** @var DataPostProcessor */ protected $dataPostProcessor; - /** @var DataPostProcessor\Stocks */ - protected $stocksPostProcessor; - /** @var ProductCollectionFactory */ protected $collectionFactory; @@ -87,7 +84,6 @@ class Collection * @param CollectionProcessorInterface $collectionProcessor * @param CollectionPostProcessor $collectionPostProcessor * @param DataPostProcessor $dataPostProcessor - * @param DataPostProcessor\Stocks $stocksPostProcessor * @param ResourceConnection $connection * @param StockFilter $stockFilter * @param StoreManagerInterface $storeManager @@ -100,7 +96,6 @@ public function __construct( CollectionProcessorInterface $collectionProcessor, CollectionPostProcessor $collectionPostProcessor, DataPostProcessor $dataPostProcessor, - DataPostProcessor\Stocks $stocksPostProcessor, ResourceConnection $connection, StockFilter $stockFilter, StoreManagerInterface $storeManager @@ -111,7 +106,6 @@ public function __construct( $this->collectionProcessor = $collectionProcessor; $this->collectionPostProcessor = $collectionPostProcessor; $this->dataPostProcessor = $dataPostProcessor; - $this->stocksPostProcessor = $stocksPostProcessor; $this->collectionFactory = $collectionFactory; $this->connection = $connection; $this->stockFilter = $stockFilter; @@ -445,14 +439,6 @@ protected function fetchPlp($info) : array { $products = $collection->getItems(); - // Populate stock status (use same post processor as for non-plp variants) - $stockStatusCallback = $this->stocksPostProcessor->process( - $products, - 'variants_plp/product', - $info, - ['isSingleProduct' => false] - ); - // Populate attributes (use more simple logic) $productsData = []; $productAttributes = []; @@ -489,9 +475,6 @@ protected function fetchPlp($info) : array { ]; } - // Set stock status - $stockStatusCallback($product); - $productsData[$product->getId()] = $product->getData() + [ 'model' => $product, 's_attributes' => $productAttributes[$productId] diff --git a/src/etc/schema.graphqls b/src/etc/schema.graphqls index 3f9e2c1..c15ce79 100755 --- a/src/etc/schema.graphqls +++ b/src/etc/schema.graphqls @@ -38,7 +38,6 @@ type CategoryTree { interface ProductInterface { qty: Float @doc(description: "Qty field for checkout order view") - stock_item: ProductStockItem @resolver(class: "ScandiPWA\\CatalogGraphQl\\Model\\Resolver\\Inventory\\StockCount") url: String @resolver(class: "ScandiPWA\\CatalogGraphQl\\Model\\Resolver\\Product\\Url") } @@ -63,14 +62,6 @@ type ProductPrice @doc(description: "Represents a product price.") { discount: ProductDiscount @doc(description: "The price discount. Represents the difference between the regular and final price.") } -type ProductStockItem { - in_stock: Boolean @doc(description: "Product in stock status") - qty: Float @doc(description: "Product quantity available in stock") - min_sale_qty: Int @doc(description: "Minimal amount of item that can be bought") - max_sale_qty: Int @doc(description: "Maximal amount of item that can be bought") - qty_increments: Int @doc(description: "Increment for number of items that can be bought") -} - extends type Breadcrumb { category_url: String @doc(description: "Trimmed URL rewrite") category_is_active: Boolean @doc(description: "Is category active")