Skip to content

Commit

Permalink
Merge pull request #108 from kamilkawasw/PERF-57
Browse files Browse the repository at this point in the history
adjust to Magento 2.4.7 changes
  • Loading branch information
AleksandrsKondratjevs authored Jul 14, 2024
2 parents 9f22b03 + 8990d89 commit 6716106
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/Model/Resolver/CartItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Framework\GraphQl\Query\Uid;
use Magento\Quote\Api\Data\CartItemInterface;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\Quote\Item as QuoteItem;
use Magento\QuoteGraphQl\Model\Cart\GetCartProducts;
use Magento\QuoteGraphQl\Model\CartItem\GetItemsData;
use Magento\QuoteGraphQl\Model\Resolver\CartItems as SourceCartItems;
use Magento\Store\Model\App\Emulation;
use Magento\Store\Model\StoreManagerInterface;
Expand All @@ -37,9 +38,9 @@
class CartItems extends SourceCartItems
{
/**
* @var GetCartProducts
* @var GetItemsData
*/
protected GetCartProducts $getCartProducts;
protected GetItemsData $getItemsData;

/**
* @var Uid
Expand Down Expand Up @@ -67,27 +68,27 @@ class CartItems extends SourceCartItems
protected DataPostProcessor $productPostProcessor;

/**
* @param GetCartProducts $getCartProducts
* @param GetItemsData $getItemsData
* @param Uid $uidEncoder
* @param Emulation $emulation
* @param HelperImage $helperImage
* @param StoreManagerInterface $storeManager
* @param DataPostProcessor $productPostProcessor
*/
public function __construct(
GetCartProducts $getCartProducts,
GetItemsData $getItemsData,
Uid $uidEncoder,
Emulation $emulation,
HelperImage $helperImage,
StoreManagerInterface $storeManager,
DataPostProcessor $productPostProcessor
) {
parent::__construct(
$getCartProducts,
$uidEncoder
$uidEncoder,
$getItemsData
);

$this->getCartProducts = $getCartProducts;
$this->getItemsData = $getItemsData;
$this->uidEncoder = $uidEncoder;
$this->emulation = $emulation;
$this->helperImage = $helperImage;
Expand Down Expand Up @@ -178,7 +179,8 @@ public function resolve(
*/
public function getCartProductsData(Quote $cart, ResolveInfo $info): array
{
$products = $this->getCartProducts->execute($cart);
$cartItems = $cart->getItems();
$products = $this->getCartProducts($cartItems);
$productsData = [];

$productsPostData = $this->productPostProcessor->process(
Expand Down Expand Up @@ -229,4 +231,17 @@ protected function getImageUrl(

return $image->getUrl();
}

/**
* @param CartItemInterface[] $cartItems
* @return array
*/
private function getCartProducts(array $cartItems): array
{
$itemsData = [];
foreach ($cartItems as $cartItem) {
$itemsData[] = $cartItem->getProduct();
}
return $itemsData;
}
}

0 comments on commit 6716106

Please sign in to comment.