diff --git a/src/Model/Resolver/MenuItems.php b/src/Model/Resolver/MenuItems.php index e9de38f..8b9483e 100644 --- a/src/Model/Resolver/MenuItems.php +++ b/src/Model/Resolver/MenuItems.php @@ -11,6 +11,7 @@ namespace ScandiPWA\CatalogGraphQl\Model\Resolver; use Magento\Catalog\Model\Category; +use Magento\Cms\Model\BlockFactory; use Magento\Catalog\Api\CategoryRepositoryInterface; use Magento\Catalog\Helper\Category as CategoryHelper; use Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory; @@ -47,22 +48,30 @@ class MenuItems implements ResolverInterface */ protected $categoryRepository; + /** + * @var BlockFactory + */ + protected BlockFactory $blockFactory; + /** * @param CategoryHelper $catalogCategory * @param StateDependentCollectionFactory $categoryCollectionFactory * @param StoreManagerInterface $storeManager * @param CategoryRepositoryInterface $categoryRepository + * @param BlockFactory $blockFactory */ public function __construct( CategoryHelper $catalogCategory, StateDependentCollectionFactory $categoryCollectionFactory, StoreManagerInterface $storeManager, - CategoryRepositoryInterface $categoryRepository + CategoryRepositoryInterface $categoryRepository, + BlockFactory $blockFactory, ) { $this->catalogCategory = $catalogCategory; $this->collectionFactory = $categoryCollectionFactory; $this->storeManager = $storeManager; $this->categoryRepository = $categoryRepository; + $this->blockFactory = $blockFactory; } /** @@ -125,7 +134,7 @@ protected function getCategoryTree($storeId, $rootId) /** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $collection */ $collection = $this->collectionFactory->create(); $collection->setStoreId($storeId); - $collection->addAttributeToSelect('name'); + $collection->addAttributeToSelect(['name', 'description', 'landing_page']); $collection->addFieldToFilter('path', ['like' => '1/' . $rootId . '/%']); //load only from store root $collection->addAttributeToFilter('include_in_menu', 1); $collection->addIsActiveFilter(); @@ -143,11 +152,18 @@ protected function getCategoryTree($storeId, $rootId) * Convert category to array * * @param \Magento\Catalog\Model\Category $category - * @param int $itemId * @return array */ protected function getCategoryAsArray($category) { + $landingPageId = $category->getData('landing_page'); + $landingPageContent = ''; + + if ($landingPageId) { + $landingPageBlock = $this->blockFactory->create()->load($landingPageId); + $landingPageContent = $landingPageBlock->getContent(); + } + return [ 'title' => $category->getName(), 'item_id' => $category->getId(), @@ -158,7 +174,9 @@ protected function getCategoryAsArray($category) // For correct placeholders on FE // Default value is Products because if // display mode wasn't changed it returns null - 'display_mode' => $this->getCategoryDisplayMode($category) ?? Category::DM_PRODUCT + 'display_mode' => $this->getCategoryDisplayMode($category) ?? Category::DM_PRODUCT, + 'category_banner' => $landingPageContent, + 'category_description' => $category->getDescription() ?? '', ]; } diff --git a/src/etc/schema.graphqls b/src/etc/schema.graphqls index c213a89..ada9ccb 100755 --- a/src/etc/schema.graphqls +++ b/src/etc/schema.graphqls @@ -97,6 +97,8 @@ type MenuItem { category_id: Int position: Int display_mode: String + category_banner: String + category_description: String } type CurrencyConfig {