-
Notifications
You must be signed in to change notification settings - Fork 153
Conversation
*/ | ||
private function getOnlyXLeftQty(ProductInterface $product): ?float | ||
{ | ||
$stockItem = $this->stockRegistry->getStockItem($product->getId()); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job on tests!
@bartekszymanski thank you for the contribution. Please see several suggestions in the comments above. |
@@ -51,7 +54,7 @@ public function __construct( | |||
} | |||
|
|||
/** | |||
* @inheritdoc | |||
* {@inheritdoc} |
There was a problem hiding this comment.
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.
# Conflicts: # composer.lock
-- Update composer lock
# Conflicts: # composer.lock
-- Update composer lock
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