Skip to content

Commit c931e1c

Browse files
Merge branch 'release/2.28.0'
2 parents f794888 + 9dabc14 commit c931e1c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+520
-99
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
## [2.28.0] - 2025-03-25
11+
### Added
12+
- Auto populate node title ([#325](https://github.com/SnowdogApps/magento2-menu/pull/325))
13+
- Add missing $escaper and $viewModels declarations ([#350](https://github.com/SnowdogApps/magento2-menu/pull/350))
14+
- Import categories by store view ([#352](https://github.com/SnowdogApps/magento2-menu/pull/352))
15+
- Add external vue providers config option
16+
### Changed
17+
- Bump cross-spawn from 7.0.3 to 7.0.6 ([#349](https://github.com/SnowdogApps/magento2-menu/pull/349))
18+
- Improve graphql performance
19+
1020
## [2.27.2] - 2024-11-08
1121
### Fixed
1222
- Issue when saving nodes w/ db prefix ([#345](https://github.com/SnowdogApps/magento2-menu/pull/345))
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Snowdog\Menu\Controller\Adminhtml\Node;
5+
6+
use Magento\Backend\App\Action;
7+
use Magento\Backend\App\Action\Context;
8+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Framework\App\Action\HttpPostActionInterface;
10+
use Magento\Framework\Controller\ResultFactory;
11+
use Magento\Framework\Controller\ResultInterface;
12+
use Magento\Framework\Exception\NoSuchEntityException;
13+
14+
class ProductName extends Action implements HttpPostActionInterface
15+
{
16+
/**
17+
* @inheritDoc
18+
*/
19+
const ADMIN_RESOURCE = 'Snowdog_Menu::menus';
20+
21+
/**
22+
* @var \Magento\Catalog\Api\ProductRepositoryInterface
23+
*/
24+
private $productRepository;
25+
26+
public function __construct(
27+
Context $context,
28+
ProductRepositoryInterface $productRepository
29+
) {
30+
parent::__construct($context);
31+
$this->productRepository = $productRepository;
32+
}
33+
34+
public function execute()
35+
{
36+
$storeId = (int) $this->_request->getParam('store_id', 0);
37+
$productId = $this->_request->getParam('product_id');
38+
if (empty($productId)) {
39+
return $this->getMissingProductIdResult();
40+
}
41+
42+
try {
43+
$product = $this->productRepository->getById($productId, false, $storeId);
44+
} catch (NoSuchEntityException $e) {
45+
return $this->getProductNotFoundResult();
46+
}
47+
48+
$result = $this->resultFactory->create(ResultFactory::TYPE_JSON);
49+
50+
return $result->setData(['product_name' => $product->getName()]);
51+
}
52+
53+
private function getMissingProductIdResult(): ResultInterface
54+
{
55+
return $this->resultFactory
56+
->create(ResultFactory::TYPE_JSON)
57+
->setHttpResponseCode(400)
58+
->setData(['message' => __('Missing required product_id param')]);
59+
}
60+
61+
private function getProductNotFoundResult(): ResultInterface
62+
{
63+
return $this->resultFactory
64+
->create(ResultFactory::TYPE_JSON)
65+
->setHttpResponseCode(404)
66+
->setData(['message' => __('Product not found')]);
67+
}
68+
}

Model/GraphQl/Resolver/DataProvider/Node.php

+13-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Snowdog\Menu\Model\GraphQl\Resolver\DataProvider;
66

7-
use Magento\Framework\Exception\LocalizedException;
7+
use Exception;
88
use Magento\Framework\Exception\NoSuchEntityException;
99
use Snowdog\Menu\Api\Data\NodeInterface;
1010
use Snowdog\Menu\Api\NodeRepositoryInterface;
@@ -124,6 +124,7 @@ private function convertData(NodeInterface $node): array
124124
*/
125125
private function loadModels($nodes, $storeId): void
126126
{
127+
$modelsToLoadByType = [];
127128
/** @var NodeInterface $node */
128129
foreach ($nodes as $node) {
129130
$type = $node->getType();
@@ -133,12 +134,18 @@ private function loadModels($nodes, $storeId): void
133134
if (!in_array($type, TypeModel::TYPES)) {
134135
continue;
135136
}
137+
$modelsToLoadByType[$type][] = $node->getContent();
138+
}
139+
140+
foreach ($modelsToLoadByType as $type => $ids) {
141+
if (!is_array($ids)) {
142+
continue;
143+
}
136144
try {
137-
$model = $this->typeModel->getModel($type, $node->getContent(), $storeId);
138-
} catch (NoSuchEntityException|LocalizedException $e) {
139-
$model = null;
145+
$this->loadedModels[$type] = $this->typeModel->getModels($type, $ids ?? [], $storeId);
146+
} catch (Exception $e) {
147+
continue;
140148
}
141-
$this->loadedModels[$type][$node->getContent()] = $model;
142149
}
143150
}
144151

@@ -152,8 +159,7 @@ private function getUrlKey(NodeInterface $node): ?string
152159
if (!isset($this->loadedModels[$node->getType()][$node->getContent()])) {
153160
return null;
154161
}
155-
$currentModel = $this->loadedModels[$node->getType()][$node->getContent()];
156-
return $this->typeModel->getModelUrlKey($node->getType(), $currentModel);
162+
return $this->loadedModels[$node->getType()][$node->getContent()];
157163
} elseif ($node->getType() == self::NODE_TYPE_CUSTOM_URL) {
158164
return $node->getContent();
159165
} else {

Model/GraphQl/Resolver/DataProvider/Node/TypeModel.php

+11-45
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,34 @@
11
<?php
2+
declare(strict_types=1);
23

34
namespace Snowdog\Menu\Model\GraphQl\Resolver\DataProvider\Node;
45

5-
use Magento\Catalog\Api\CategoryRepositoryInterface;
66
use Magento\Catalog\Api\Data\CategoryInterface;
77
use Magento\Catalog\Api\Data\ProductInterface;
8-
use Magento\Catalog\Api\ProductRepositoryInterface;
98
use Magento\Cms\Api\Data\PageInterface;
10-
use Magento\Cms\Api\PageRepositoryInterface;
11-
use Magento\Framework\Exception\LocalizedException;
12-
use Magento\Framework\Exception\NoSuchEntityException;
139

1410
class TypeModel
1511
{
1612
const TYPES = ["category", "product", "cms_page"];
17-
18-
/**
19-
* @var ProductRepositoryInterface
20-
*/
21-
private $productRepository;
22-
/**
23-
* @var CategoryRepositoryInterface
24-
*/
25-
private $categoryRepository;
13+
2614
/**
27-
* @var PageRepositoryInterface
15+
* @var \Snowdog\Menu\Model\ResourceModel\NodeType\AbstractNode[]
2816
*/
29-
private $pageRepository;
17+
private $typeModels = [];
3018

3119
public function __construct(
32-
ProductRepositoryInterface $productRepository,
33-
CategoryRepositoryInterface $categoryRepository,
34-
PageRepositoryInterface $pageRepository
20+
array $typeModels = []
3521
) {
36-
$this->productRepository = $productRepository;
37-
$this->categoryRepository = $categoryRepository;
38-
$this->pageRepository = $pageRepository;
22+
$this->typeModels = $typeModels;
3923
}
4024

41-
/**
42-
* @param $type
43-
* @param $modelId
44-
* @param $storeId
45-
* @return ProductInterface|CategoryInterface|PageInterface|null
46-
* @throws LocalizedException
47-
* @throws NoSuchEntityException
48-
*/
49-
public function getModel($type, $modelId, $storeId)
25+
public function getModels($type, $modelIds, $storeId)
5026
{
51-
$model = null;
52-
switch ($type) {
53-
case "product":
54-
$model = $this->productRepository->getById($modelId, false, $storeId);
55-
break;
56-
case "category":
57-
$model = $this->categoryRepository->get($modelId, $storeId);
58-
break;
59-
case "cms_page":
60-
$model = $this->pageRepository->getById($modelId);
61-
break;
62-
default:
63-
break;
27+
if (isset($this->typeModels[$type])) {
28+
return $this->typeModels[$type]->fetchData($storeId, $modelIds);
6429
}
65-
return $model;
30+
31+
return [];
6632
}
6733

6834
public function getModelUrlKey($type, $model): ?string

Model/VueProvider.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,23 @@ class VueProvider
1313
*/
1414
private $components;
1515

16+
/**
17+
* 3rd party extensions have to provide full path
18+
*
19+
* @var array
20+
*/
21+
private $externalComponents;
22+
1623
/**
1724
* @param array $components
25+
* @param array $externalComponents
1826
*/
1927
public function __construct(
20-
array $components = []
28+
array $components = [],
29+
array $externalComponents = []
2130
) {
2231
$this->components = $components;
32+
$this->externalComponents = $externalComponents;
2333
}
2434

2535
/**
@@ -31,6 +41,9 @@ public function getComponents(): array
3141
foreach ($this->components as $component) {
3242
$data[] = sprintf(self::COMPONENT_PATH, $component);
3343
}
44+
foreach ($this->externalComponents as $externalComponent) {
45+
$data[] = $externalComponent;
46+
}
3447

3548
return $data;
3649
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Snowdog\Menu\Plugin\Model\ResourceModel\Category;
6+
7+
use Magento\Catalog\Model\ResourceModel\Category\Tree;
8+
use Magento\Framework\App\RequestInterface;
9+
10+
class TreePlugin
11+
{
12+
private RequestInterface $request;
13+
14+
public function __construct(
15+
RequestInterface $request
16+
) {
17+
$this->request = $request;
18+
}
19+
20+
21+
/**
22+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
23+
*/
24+
public function beforeAddCollectionData(Tree $subject, $collection = null): array
25+
{
26+
$postData = $this->request->getPost();
27+
$storeId = $postData['store_id'];
28+
29+
if (!isset($postData['store_id'])) {
30+
return [$collection];
31+
}
32+
33+
$collection->setProductStoreId(
34+
$storeId
35+
)->setStoreId(
36+
$storeId
37+
);
38+
39+
return [$collection];
40+
}
41+
}

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ Here are some scenarios where Snowdog's Menu can be effectively used:
3131
## User Guide and Documentation
3232
To learn more about Magento 2 Menu by Snowdog, go to [wiki](https://github.com/SnowdogApps/magento2-menu/wiki).
3333

34+
## Magento Versions Compatibility
35+
Menu can be installed on most 2.x Magento versions.
36+
If your Magento version does not work with newest Menu version, see [Contributing](#contributing).
37+
3438
## Contributing
3539
Contributions are welcome! If you find a bug or have a feature request, feel free to open an issue or submit a pull request.
3640

0 commit comments

Comments
 (0)