-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
5343 Updated wishlist resolver and schema to support pagination #32
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,7 +182,8 @@ public function resolve( | |
|
||
/** @var Wishlist $wishlist */ | ||
$wishlist = $value['model']; | ||
$wishlistItems = $this->getWishListItems($wishlist); | ||
$wishlistCollection = $this->getWishlistCollection($wishlist, $args); | ||
$wishlistItems = $wishlistCollection->getItems(); | ||
$itemProductIds = []; | ||
|
||
foreach ($wishlistItems as $item) { | ||
|
@@ -225,13 +226,20 @@ public function resolve( | |
'buy_request' => $buyRequestOption->getValue() ?? '', | ||
'description' => $wishlistItem->getDescription(), | ||
'added_at' => $wishlistItem->getAddedAt(), | ||
'model' => $wishlistItem, | ||
'model' => $product, | ||
'product' => $itemProduct, | ||
'options' => $options | ||
]; | ||
} | ||
|
||
return $data; | ||
return [ | ||
'items' => $data, | ||
'page_info' => [ | ||
'current_page' => $wishlistCollection->getCurPage(), | ||
'page_size' => $wishlistCollection->getPageSize(), | ||
'total_pages' => $wishlistCollection->getLastPageNumber() | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
|
@@ -313,30 +321,39 @@ protected function getWishlistProducts( | |
$collection = $this->collectionFactory->create(); | ||
$collection->addIdFilter(array_values($itemProductIds)); | ||
|
||
$itemsNode = array_filter(iterator_to_array($info->fieldNodes), function ($node) { | ||
return $node->name->value === 'items_v2'; | ||
})[0]; | ||
|
||
$this->collectionProcessor->process( | ||
$collection, | ||
$this->searchCriteriaBuilder->create(), | ||
$this->getFieldsFromProductInfo($info, 'items/product') | ||
$this->getFieldsFromProductInfo($itemsNode, 'items/product') | ||
); | ||
|
||
$items = $collection->getItems(); | ||
|
||
return $this->productPostProcessor->process( | ||
$items, | ||
'items/product', | ||
$info | ||
$itemsNode | ||
); | ||
} | ||
|
||
/** | ||
* Get wish-list items | ||
* Get wishlist items collection | ||
* | ||
* @param Wishlist $wishlist | ||
* @return Item[] | ||
* @param array $args | ||
* @return \Magento\Wishlist\Model\ResourceModel\Item\Collection | ||
*/ | ||
protected function getWishListItems( | ||
Wishlist $wishlist | ||
): array { | ||
protected function getWishlistCollection( | ||
Wishlist $wishlist, | ||
array $args | ||
): \Magento\Wishlist\Model\ResourceModel\Item\Collection { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Import collection in head of file |
||
$currentPage = $args['currentPage'] ?? 1; | ||
$pageSize = $args['pageSize'] ?? 20; | ||
|
||
/** @var WishlistItemCollection $collection */ | ||
$collection = $this->wishlistItemsFactory->create(); | ||
$collection | ||
|
@@ -346,7 +363,15 @@ protected function getWishListItems( | |
}, $this->storeManager->getStores())) | ||
->setVisibilityFilter(); | ||
|
||
return $collection->getItems(); | ||
if ($currentPage > 0) { | ||
$collection->setCurPage($currentPage); | ||
} | ||
|
||
if ($pageSize > 0) { | ||
$collection->setPageSize($pageSize); | ||
} | ||
|
||
return $collection; | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,6 @@ | |
type="ScandiPWA\WishlistGraphQl\Model\Resolver\WishlistResolver"/> | ||
<preference for="Magento\WishlistGraphQl\Model\Resolver\WishlistItemsResolver" | ||
type="ScandiPWA\WishlistGraphQl\Model\Resolver\WishlistItemsResolver"/> | ||
<preference for="Magento\WishlistGraphQl\Model\Resolver\WishlistItems" | ||
type="ScandiPWA\WishlistGraphQl\Model\Resolver\WishlistItemsResolver"/> | ||
Comment on lines
+17
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How looks the original file? Do we really need to override it fully without extending it? |
||
</config> |
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.
Why like that? Do we really need to get the field out here?
Maybe move it into
getFieldsFromProductInfo
where semantically it can fit?