Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Return product stock data #125

Merged
merged 15 commits into from
Sep 11, 2018
Merged

Return product stock data #125

merged 15 commits into from
Sep 11, 2018

Conversation

bartekszymanski
Copy link
Contributor

@bartekszymanski bartekszymanski commented Jul 18, 2018

Description

  • Distinguish between "in-stock" and "out-of-stock" products on storefront (if "display out-of-stock products = Yes)

  • Show "Only X Left" or "Low Stock" on PDP or PLP when the product's stock is below the configured threshold (Catalog > Inventory > Stock Options)

Fixed Issues (if relevant)

#23: Return product stock data

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Jul 18, 2018

CLA assistant check
All committers have signed the CLA.

@bartekszymanski bartekszymanski self-assigned this Jul 18, 2018
*/
private function getOnlyXLeftQty(ProductInterface $product): ?float
{
$stockItem = $this->stockRegistry->getStockItem($product->getId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we check if 'only X left' feature is enabled before performing any additional calculations?

*/
declare(strict_types=1);

namespace Magento\CatalogInventoryGraphQl\Test\CatalogInventory;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GraphQL functional tests must be placed under dev/tests/api-functional/testsuite/Magento/GraphQl, otherwise they will not be picked up by the builds. This is the difference between Unit vs other types of tests.


interface ProductInterface {
only_x_left_in_stock: Float @doc(description: "Product stock only x left count") @resolver(class: "Magento\\CatalogInventoryGraphQl\\Model\\Resolver\\OnlyXLeftInStockResolver")
stock_status: Int @doc(description: "Stock status of the product") @resolver(class: "Magento\\CatalogInventoryGraphQl\\Model\\Resolver\\StockStatusProvider")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider changing the type of stock_status to enum. See example here

use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Store\Model\ScopeInterface;

class OnlyXLeftInStockResolver implements ResolverInterface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document all classes/interfaces/methods. Documentation in tests is optional.

use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\GraphQlAbstract;

class ProductStockStatusTest extends GraphQlAbstract
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job on tests!

@paliarush
Copy link
Contributor

@bartekszymanski thank you for the contribution. Please see several suggestions in the comments above.

@@ -51,7 +54,7 @@ public function __construct(
}

/**
* @inheritdoc
* {@inheritdoc}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was actually correct before. But not a big deal, can leave as is.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants