From bf1e4c2dacf3cd343d4aaf19b584c7d4f4a89956 Mon Sep 17 00:00:00 2001 From: Adarsh Khatri Date: Fri, 8 Aug 2025 16:10:40 +1000 Subject: [PATCH 1/9] Follow OOTB for CartItemFactory --- app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php b/app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php index 65bafa584560a..7de91b4ffdaf7 100644 --- a/app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php @@ -25,12 +25,14 @@ class AddProductsToCart * @param AddProductsToCartService $addProductsToCartService * @param ScopeConfigInterface $scopeConfig * @param PrecursorInterface $cartItemPrecursor + * @param CartItemFactory $cartItemFactory */ public function __construct( private readonly GetCartForUser $getCartForUser, private readonly AddProductsToCartService $addProductsToCartService, private readonly ScopeConfigInterface $scopeConfig, - private readonly PrecursorInterface $cartItemPrecursor + private readonly PrecursorInterface $cartItemPrecursor, + private readonly CartItemFactory $cartItemFactory ) { } @@ -53,7 +55,7 @@ public function execute($context, ?array $args): array $cartItemsData = $this->cartItemPrecursor->process($cartItemsData, $context); $cartItems = []; foreach ($cartItemsData as $cartItemData) { - $cartItems[] = (new CartItemFactory())->create($cartItemData); + $cartItems[] = $this->cartItemFactory->create($cartItemData); } /** @var AddProductsToCartOutput $addProductsToCartOutput */ From 7a8427f7a5f9e4650874559460d97269e962fda0 Mon Sep 17 00:00:00 2001 From: Adarsh Khatri Date: Fri, 8 Aug 2025 16:13:59 +1000 Subject: [PATCH 2/9] Follow OOTB for CartItemFactory in Wishlists --- .../Model/Resolver/Wishlist/AddToCart.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/WishlistGraphQl/Model/Resolver/Wishlist/AddToCart.php b/app/code/Magento/WishlistGraphQl/Model/Resolver/Wishlist/AddToCart.php index b8a844dc9b644..320ae5e7c5eb6 100755 --- a/app/code/Magento/WishlistGraphQl/Model/Resolver/Wishlist/AddToCart.php +++ b/app/code/Magento/WishlistGraphQl/Model/Resolver/Wishlist/AddToCart.php @@ -76,6 +76,11 @@ class AddToCart implements ResolverInterface */ private $cartItemsRequestBuilder; + /** + * @var CartItemFactory + */ + private $cartItemFactory; + /** * @param WishlistResourceModel $wishlistResource * @param WishlistFactory $wishlistFactory @@ -86,6 +91,7 @@ class AddToCart implements ResolverInterface * @param CreateEmptyCartForCustomer $createEmptyCartForCustomer * @param AddProductsToCartService $addProductsToCart * @param CartItemsRequestBuilder $cartItemsRequestBuilder + * @param CartItemFactory $cartItemFactory */ public function __construct( WishlistResourceModel $wishlistResource, @@ -96,7 +102,8 @@ public function __construct( LocaleQuantityProcessor $quantityProcessor, CreateEmptyCartForCustomer $createEmptyCartForCustomer, AddProductsToCartService $addProductsToCart, - CartItemsRequestBuilder $cartItemsRequestBuilder + CartItemsRequestBuilder $cartItemsRequestBuilder, + CartItemFactory $cartItemFactory ) { $this->wishlistResource = $wishlistResource; $this->wishlistFactory = $wishlistFactory; @@ -107,6 +114,7 @@ public function __construct( $this->createEmptyCartForCustomer = $createEmptyCartForCustomer; $this->addProductsToCartService = $addProductsToCart; $this->cartItemsRequestBuilder = $cartItemsRequestBuilder; + $this->cartItemFactory = $cartItemFactory; } /** @@ -164,7 +172,7 @@ public function resolve( $item->getProduct()->setDisableAddToCart($disableAddToCart); $cartItemData = $this->cartItemsRequestBuilder->build($item); - $cartItem = (new CartItemFactory())->create($cartItemData); + $cartItem = $this->cartItemFactory->create($cartItemData); /** @var AddProductsToCartOutput $addProductsToCartOutput */ $addProductsToCartOutput = $this->addProductsToCartService->execute($maskedCartId, [$cartItem]); From 2504cba88b9c442454a61bf4533519172eebc2f1 Mon Sep 17 00:00:00 2001 From: Adarsh Khatri Date: Fri, 8 Aug 2025 16:22:01 +1000 Subject: [PATCH 3/9] Follow OOTB for CartItemFactory in wishlist --- .../WishlistGraphQl/Model/Resolver/Wishlist/AddToCart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/WishlistGraphQl/Model/Resolver/Wishlist/AddToCart.php b/app/code/Magento/WishlistGraphQl/Model/Resolver/Wishlist/AddToCart.php index 320ae5e7c5eb6..09df8311bc93c 100755 --- a/app/code/Magento/WishlistGraphQl/Model/Resolver/Wishlist/AddToCart.php +++ b/app/code/Magento/WishlistGraphQl/Model/Resolver/Wishlist/AddToCart.php @@ -103,7 +103,7 @@ public function __construct( CreateEmptyCartForCustomer $createEmptyCartForCustomer, AddProductsToCartService $addProductsToCart, CartItemsRequestBuilder $cartItemsRequestBuilder, - CartItemFactory $cartItemFactory + CartItemFactory $cartItemFactory = null ) { $this->wishlistResource = $wishlistResource; $this->wishlistFactory = $wishlistFactory; @@ -114,7 +114,7 @@ public function __construct( $this->createEmptyCartForCustomer = $createEmptyCartForCustomer; $this->addProductsToCartService = $addProductsToCart; $this->cartItemsRequestBuilder = $cartItemsRequestBuilder; - $this->cartItemFactory = $cartItemFactory; + $this->cartItemFactory = $cartItemFactory ?: ObjectManager::getInstance()->get(CartItemFactory::class); } /** From a4547aa547c0605291a03eb5a4bd2fc1e8297371 Mon Sep 17 00:00:00 2001 From: Adarsh Khatri Date: Fri, 8 Aug 2025 16:22:07 +1000 Subject: [PATCH 4/9] Follow OOTB for CartItemFactory --- app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php b/app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php index 7de91b4ffdaf7..0e5bfad218b23 100644 --- a/app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php @@ -20,6 +20,11 @@ class AddProductsToCart { + /** + * @var CartItemFactory + */ + private $cartItemFactory; + /** * @param GetCartForUser $getCartForUser * @param AddProductsToCartService $addProductsToCartService @@ -32,8 +37,9 @@ public function __construct( private readonly AddProductsToCartService $addProductsToCartService, private readonly ScopeConfigInterface $scopeConfig, private readonly PrecursorInterface $cartItemPrecursor, - private readonly CartItemFactory $cartItemFactory + private readonly CartItemFactory $cartItemFactory = null ) { + $this->cartItemFactory = $cartItemFactory ?: ObjectManager::getInstance()->get(CartItemFactory::class); } /** From 3554a421856bbf0390bff5432297c089870eb684 Mon Sep 17 00:00:00 2001 From: Adarsh Khatri Date: Fri, 8 Aug 2025 16:23:40 +1000 Subject: [PATCH 5/9] Follow OOTB for CartItemFactory in Wishlists --- .../WishlistGraphQl/Model/Resolver/Wishlist/AddToCart.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/WishlistGraphQl/Model/Resolver/Wishlist/AddToCart.php b/app/code/Magento/WishlistGraphQl/Model/Resolver/Wishlist/AddToCart.php index 09df8311bc93c..75d606db86a08 100755 --- a/app/code/Magento/WishlistGraphQl/Model/Resolver/Wishlist/AddToCart.php +++ b/app/code/Magento/WishlistGraphQl/Model/Resolver/Wishlist/AddToCart.php @@ -7,6 +7,7 @@ namespace Magento\WishlistGraphQl\Model\Resolver\Wishlist; +use Magento\Framework\App\ObjectManager; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; use Magento\Framework\GraphQl\Exception\GraphQlInputException; From 308ebb6fea0abd615b4c2a351c95988bd85daf07 Mon Sep 17 00:00:00 2001 From: Adarsh Khatri Date: Mon, 11 Aug 2025 09:01:28 +1000 Subject: [PATCH 6/9] Follow OOTB for CartItemFactory in Wishlists --- .../WishlistGraphQl/Model/Resolver/Wishlist/AddToCart.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/WishlistGraphQl/Model/Resolver/Wishlist/AddToCart.php b/app/code/Magento/WishlistGraphQl/Model/Resolver/Wishlist/AddToCart.php index 75d606db86a08..320ae5e7c5eb6 100755 --- a/app/code/Magento/WishlistGraphQl/Model/Resolver/Wishlist/AddToCart.php +++ b/app/code/Magento/WishlistGraphQl/Model/Resolver/Wishlist/AddToCart.php @@ -7,7 +7,6 @@ namespace Magento\WishlistGraphQl\Model\Resolver\Wishlist; -use Magento\Framework\App\ObjectManager; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; use Magento\Framework\GraphQl\Exception\GraphQlInputException; @@ -104,7 +103,7 @@ public function __construct( CreateEmptyCartForCustomer $createEmptyCartForCustomer, AddProductsToCartService $addProductsToCart, CartItemsRequestBuilder $cartItemsRequestBuilder, - CartItemFactory $cartItemFactory = null + CartItemFactory $cartItemFactory ) { $this->wishlistResource = $wishlistResource; $this->wishlistFactory = $wishlistFactory; @@ -115,7 +114,7 @@ public function __construct( $this->createEmptyCartForCustomer = $createEmptyCartForCustomer; $this->addProductsToCartService = $addProductsToCart; $this->cartItemsRequestBuilder = $cartItemsRequestBuilder; - $this->cartItemFactory = $cartItemFactory ?: ObjectManager::getInstance()->get(CartItemFactory::class); + $this->cartItemFactory = $cartItemFactory; } /** From 019af049e767d8b567554303cc34a87b02e7150f Mon Sep 17 00:00:00 2001 From: Adarsh Khatri Date: Mon, 11 Aug 2025 09:02:08 +1000 Subject: [PATCH 7/9] Follow OOTB for CartItemFactory --- .../Magento/QuoteGraphQl/Model/AddProductsToCart.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php b/app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php index 0e5bfad218b23..a7264cb44a5bc 100644 --- a/app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php @@ -19,12 +19,7 @@ use Magento\QuoteGraphQl\Model\CartItem\PrecursorInterface; class AddProductsToCart -{ - /** - * @var CartItemFactory - */ - private $cartItemFactory; - +{ /** * @param GetCartForUser $getCartForUser * @param AddProductsToCartService $addProductsToCartService @@ -37,9 +32,9 @@ public function __construct( private readonly AddProductsToCartService $addProductsToCartService, private readonly ScopeConfigInterface $scopeConfig, private readonly PrecursorInterface $cartItemPrecursor, - private readonly CartItemFactory $cartItemFactory = null + private readonly CartItemFactory $cartItemFactory ) { - $this->cartItemFactory = $cartItemFactory ?: ObjectManager::getInstance()->get(CartItemFactory::class); + $this->cartItemFactory = $cartItemFactory; } /** From e3cedf9e63d6387ada9fa6d338022f2f69b1adc5 Mon Sep 17 00:00:00 2001 From: Adarsh Khatri Date: Mon, 11 Aug 2025 09:02:45 +1000 Subject: [PATCH 8/9] Follow OOTB for CartItemFactory --- app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php b/app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php index a7264cb44a5bc..1b5773e426071 100644 --- a/app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php @@ -19,7 +19,7 @@ use Magento\QuoteGraphQl\Model\CartItem\PrecursorInterface; class AddProductsToCart -{ +{ /** * @param GetCartForUser $getCartForUser * @param AddProductsToCartService $addProductsToCartService From e29168b2d98a0fcbd1ea07c1ac54357ea0577eef Mon Sep 17 00:00:00 2001 From: Adarsh Khatri Date: Mon, 11 Aug 2025 09:03:41 +1000 Subject: [PATCH 9/9] Follow OOTB for CartItemFactory --- app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php b/app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php index 1b5773e426071..7de91b4ffdaf7 100644 --- a/app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/AddProductsToCart.php @@ -34,7 +34,6 @@ public function __construct( private readonly PrecursorInterface $cartItemPrecursor, private readonly CartItemFactory $cartItemFactory ) { - $this->cartItemFactory = $cartItemFactory; } /**