-
Notifications
You must be signed in to change notification settings - Fork 154
GraphQl-144: [Checkout] Add grouped product to Cart #369
GraphQl-144: [Checkout] Add grouped product to Cart #369
Conversation
{ | ||
/** | ||
* @param CartInterface $cart | ||
* @param ContextInterface $context |
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.
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.
@TomashKhamlai yes, good spot. Thanks.
namespace Magento\QuoteGraphQl\Model\Cart; | ||
|
||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; |
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.
Shall we keep it here?
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
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.
@TomashKhamlai makes sense. Thanks.
I removed the branch locally before checking this PR again. Please check the Try
for more details. |
Hello. When trying to run php/bin/magento setup:di:compile got an error: PHP Fatal error: Declaration of Magento\QuoteGraphQl\Model\Cart\AddProductsToCart::execute(Magento\Quote\Model\Quote $cart, array $cartItems): void must be compatible with Magento\QuoteGraphQl\Model\Cart\AddToCartHandlerInterface::execute(Magento\Quote\Api\Data\CartInterface $cart, array $cartItemData): void in /home/mykola/sites/magento/mag23-graphql/app/code/Magento/QuoteGraphQl/Model/Cart/AddProductsToCart.php on line 18 |
@galaoleksandr thanks. It's fixed now. |
@TomashKhamlai please re-check this issue, we are going to delivery functionality in the scope of the next release (pay attention need to resolve conflicts in scheme file) |
@@ -0,0 +1,156 @@ | |||
<?php |
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.
All functionality should be moved to GroupedProductGraphQl
*/ | ||
private function extractSubProducts(array $cartItemData): array | ||
{ | ||
$subProducts = $cartItemData['data']['grouped_products']; |
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.
Looks like we can use array_column
native function
->addFilter('sku', array_keys($subProducts) , 'in') | ||
->create(); | ||
|
||
$products = $this->productRepository->getList($searchCriteria)->getItems(); |
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.
We can use $procudctCollection->getData()
for performance improvement
We don't need whole
product object, just SKUs
/** | ||
* Add products to cart | ||
*/ | ||
class AddGroupedProductsToCart implements AddToCartHandlerInterface |
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.
Looks like a duplicate of a simple product handler
/** | ||
* @inheritdoc | ||
*/ | ||
class AddToCartHandlerResolver |
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 should be an interface with product type
and cart item data
(under the hood will list of handlers)
*/ | ||
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) | ||
{ | ||
$cartHash = $this->arrayManager->get('input/cart_id', $args); |
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.
Looks like arrayManager
is overhead for this operation
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.
Hi @ldusan84! Wee need to use schema this schema for the implementation https://github.com/magento/architecture/blob/master/design-documents/graph-ql/coverage/add-items-to-cart/AddGroupedProductToCart.graphqls
@lenaorobei @naydav please let me know if you are satisfied with the schema and we'll move on - https://github.com/magento/graphql-ce/blob/1d891c9c77823fefca3635517eac0ac465f91a4e/app/code/Magento/GroupedProductGraphQl/etc/schema.graphqls Thanks |
|
||
input AddGroupedProductsToCartInput { | ||
cart_id: String! | ||
cartItems: [GroupedProductCartItemInput!]! |
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.
cartItems: [GroupedProductCartItemInput!]! | |
cart_items: [GroupedProductCartItemInput!]! |
I believe there is typo in proposal. Let's keep snake_case for consistency.
cartItems: [GroupedProductCartItemInput!]! | ||
} | ||
|
||
input GroupedProductCartItemInput { |
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.
input GroupedProductCartItemInput {
data: CartItemInput!
}
@ldusan84 please see comments. Thanks. |
@lenaorobei thank you for the comments, can you do another quick check please? |
} | ||
|
||
input GroupedProductCartItemInput { | ||
data: [CartItemInput!]! |
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.
I think it should be data: CartItemInput!
. Please have a look at Magento/QuoteGraphQl/etc/schema.graphqls:34
for example.
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.
Yes I see what you mean, but in simple products case we can pick only one sku. For grouped products we can pick multiple with different quantities.
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.
The idea was to add separate groped items cart_items: [GroupedProductCartItemInput!]!
. They will be displayed in cart as simple products anyway.
|
||
input GroupedProductCartItemInput { | ||
data: [CartItemInput!]! | ||
parent_sku: String @doc(description: "Grouped product SKU.") |
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.
parent_sku: String @doc(description: "Grouped product SKU.") |
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.
@lenaorobei not sure about this one. How do we add grouped product without knowing it's sku or id?
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.
The idea was to add as a group of simples
, so no parent sku is required. In shopping cart it will be listed as multiple simple products.
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.
I think we need to know which grouped product is being added. Same as with configurable - https://github.com/magento/graphql-ce/blob/2.3-develop/app/code/Magento/ConfigurableProductGraphQl/etc/schema.graphqls#L51
Sorry to say that but we need to close this PR. As per additional investigation and conversation with PO it was decided that adding grouped product to cart scenarios can be covered using DevDocs will be updated in order to reflect this data. |
Hi @ldusan84, thank you for your contribution! |
Description (*)
Add grouped product to cart feature:
Fixed Issues (if relevant)
Manual testing scenarios (*)
Contribution checklist (*)