Skip to content

Commit

Permalink
Fixed menu to respect store id.
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredsgenkins committed Dec 9, 2019
1 parent 5a35e51 commit 281ee7f
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/Model/Resolver/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
namespace ScandiPWA\MenuOrganizer\Model\Resolver;

use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Store\Model\StoreManagerInterface;
use ScandiPWA\MenuOrganizer\Model\MenuFactory;
use ScandiPWA\MenuOrganizer\Model\ResourceModel\Item\CollectionFactory as ItemCollectionFactory;
use ScandiPWA\MenuOrganizer\Model\ResourceModel\Menu as MenuResourceModel;
Expand Down Expand Up @@ -48,19 +51,27 @@ class Menu implements ResolverInterface
*/
protected $categoryRepository;

/**
* @var StoreManagerInterface
*/
protected $storeManager;

/**
* Menu constructor.
* @param StoreManagerInterface $storeManager
* @param MenuFactory $menuFactory
* @param MenuResourceModel $menuResourceModel
* @param ItemCollectionFactory $itemCollectionFactory
* @param CategoryRepositoryInterface $categoryRepository
*/
public function __construct(
StoreManagerInterface $storeManager,
MenuFactory $menuFactory,
MenuResourceModel $menuResourceModel,
ItemCollectionFactory $itemCollectionFactory,
CategoryRepositoryInterface $categoryRepository
)
{
) {
$this->storeManager = $storeManager;
$this->menuFactory = $menuFactory;
$this->menuResourceModel = $menuResourceModel;
$this->itemCollectionFactory = $itemCollectionFactory;
Expand All @@ -71,23 +82,27 @@ public function __construct(
* Menu organizer resolver (lines concerning menu id are changed from core scandipwa menumanager)
*
* @param Field $field
* @param \Magento\Framework\GraphQl\Query\Resolver\ContextInterface $context
* @param ContextInterface $context
* @param ResolveInfo $info
* @param array|null $value
* @param array|null $args
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @return array
*
* @throws NoSuchEntityException
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
)
{
) {
$identifier = $args['identifier'];

$menu = $this->menuFactory->create();
$menu = $this->menuFactory->create()->setStoreId(
$this->storeManager->getStore()->getId()
);

$this->menuResourceModel->load($menu, $identifier);

if ($menu->getId() === null) {
Expand All @@ -98,7 +113,8 @@ public function resolve(
$menu->getData(),
[
'items' => $this->getMenuItems($menu['menu_id'])
]);
]
);
}

/**
Expand Down

0 comments on commit 281ee7f

Please sign in to comment.