Skip to content

Commit 7761a2e

Browse files
committed
Merge remote-tracking branch 'origin/2.4-develop' into Hammer-Plateform-Health-04Sept24
2 parents efdf631 + 0611e75 commit 7761a2e

File tree

101 files changed

+922
-381
lines changed

Some content is hidden

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

101 files changed

+922
-381
lines changed

app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/tree.phtml

Lines changed: 61 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
</div>
1919
<div class="tree-actions">
2020
<?php if ($root):?>
21-
<a id="colapseAll" href="#"><?= $block->escapeHtml(__('Collapse All')) ?></a>
21+
<a id="colapseAll" href="#"><?= $escaper->escapeHtml(__('Collapse All')) ?></a>
2222
<span class="separator">|</span>
23-
<a id="expandAll" href="#"><?= $block->escapeHtml(__('Expand All')) ?></a>
23+
<a id="expandAll" href="#"><?= $escaper->escapeHtml(__('Expand All')) ?></a>
2424
<?php endif; ?>
2525
</div>
2626
<?php if ($root):?>
@@ -39,11 +39,11 @@
3939
</div>
4040
</div>
4141

42-
<div data-id="information-dialog-tree" class="messages">
43-
<div class="message message-notice">
44-
<div><?= $block->escapeHtml(__('This operation can take a long time')) ?></div>
42+
<div data-id="information-dialog-tree" class="messages">
43+
<div class="message message-notice">
44+
<div><?= $escaper->escapeHtml(__('This operation can take a long time')) ?></div>
45+
</div>
4546
</div>
46-
</div>
4747

4848
<?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
4949
'display: none;',
@@ -73,7 +73,7 @@
7373
treeInstance,
7474
script;
7575
$scriptString .= 'currentNodeId = ' . (int)$block->getCategoryId() . ',
76-
76+
defaultTree = '. $block->getTreeJson() .',
7777
defaultParams = {
7878
text: ' . /* @noEscape */ json_encode(htmlentities($root->getName())) . ',
7979
allowDrop: ' . ($root->getIsVisible() ? 'true' : 'false') . ',
@@ -93,6 +93,32 @@ script;
9393
*/
9494
treeDiv.jstree({
9595
core: {
96+
'data' : function (obj, callback) {
97+
if(obj.id != '#' && obj.children.length === 0){
98+
let data = {
99+
id: obj.id,
100+
store: defaultParams.store_id,
101+
form_key: FORM_KEY
102+
};
103+
104+
$.ajax({
105+
url: '{$block->escapeJs($block->getLoadTreeUrl())}',
106+
type: "POST",
107+
data: data,
108+
dataType: 'json',
109+
success: function (response) {
110+
TreeConfig.updateChildrenKey(response);
111+
callback.call(this, response);
112+
},
113+
error: function (jqXHR, status, error) {
114+
console.log(status + ': ' + error);
115+
}
116+
});
117+
}else{
118+
TreeConfig.updateChildrenKey(defaultTree);
119+
callback.call(this, defaultTree);
120+
}
121+
},
96122
check_callback: function (operation, node) {
97123
//Draggable false for root categories
98124
return !(operation === 'move_node' &&
@@ -102,57 +128,10 @@ script;
102128
plugins: ['dnd'],
103129
}).bind('move_node.jstree', function (e, data) {
104130
TreeConfig.categoryMove(data);
131+
}).bind('ready.jstree', function(e, data) {
132+
TreeConfig.selectNode(data);
105133
});
106-
107134
treeInstance = treeDiv.jstree(true);
108-
let root = treeInstance.get_node('#');
109-
this.buildCategoryTree(treeDiv, root, '{$block->getTreeJson()}', true);
110-
111-
let catId = treeInstance.get_node(defaultParams.category_id);
112-
if (catId) {
113-
currentNodeId = defaultParams.category_id;
114-
} else if (defaultParams.parent > 0 && defaultParams.category_id === 0) {
115-
currentNodeId = defaultParams.parent;
116-
}
117-
118-
// select and open child node
119-
if (defaultParams.expanded) {
120-
treeInstance.open_all();
121-
} else {
122-
let selectedNode = treeInstance.get_node(currentNodeId);
123-
treeInstance.select_node(selectedNode, true);
124-
125-
setTimeout(function () {
126-
treeInstance.open_node(selectedNode);
127-
}, 15);
128-
}
129-
},
130-
131-
buildCategoryTree: function(treeDiv, parent, config, firstLoad){
132-
if (!config) return;
133-
134-
if(firstLoad){
135-
config = $.parseJSON(config);
136-
}
137-
138-
for (let i = 0; i < config.length; i++) {
139-
let nodeConfig = config[i],
140-
newNode = {
141-
text: nodeConfig.text,
142-
id: nodeConfig.id,
143-
allowDrag: nodeConfig.allowDrag,
144-
allowDrop: nodeConfig.allowDrop,
145-
cls: nodeConfig.cls,
146-
store: nodeConfig.store,
147-
li_attr: { class: nodeConfig.cls}
148-
};
149-
150-
const parentTree = treeInstance.create_node(parent, newNode, 'last');
151-
152-
if (nodeConfig.children) {
153-
this.buildCategoryTree(treeDiv, parentTree, nodeConfig.children, false);
154-
}
155-
}
156135
},
157136
158137
categoryMove : function (obj){
@@ -237,10 +216,33 @@ script;
237216
treeDiv.on('changed.jstree', function (e, data) {
238217
TreeConfig.categoryClick(data);
239218
});
219+
},
240220
241-
treeDiv.on("open_node.jstree", function (e, data) {
242-
TreeConfig.handleOpenNode(data);
243-
});
221+
updateChildrenKey : function(treeJson) {
222+
treeJson.forEach(node => {
223+
if (Array.isArray(node.children) && node.children.length === 0) {
224+
node.children = true;
225+
} else if (Array.isArray(node.children)) {
226+
TreeConfig.updateChildrenKey(node.children);
227+
}
228+
});
229+
},
230+
231+
selectNode : function(data){
232+
if (defaultParams.expanded) {
233+
treeInstance.open_all();
234+
} else {
235+
let catId = treeInstance.get_node(defaultParams.category_id);
236+
if (catId) {
237+
currentNodeId = defaultParams.category_id;
238+
} else if (defaultParams.parent > 0 && defaultParams.category_id === 0) {
239+
currentNodeId = defaultParams.parent;
240+
}
241+
242+
let selectedNode = treeInstance.get_node(currentNodeId);
243+
treeInstance.select_node(selectedNode, true);
244+
treeInstance.open_node(selectedNode);
245+
}
244246
},
245247
246248
categoryClick : function(data){
@@ -257,63 +259,6 @@ script;
257259
}
258260
},
259261
260-
handleOpenNode : function(data){
261-
let parentNode = data.node;
262-
if (parentNode && parentNode.children.length > 0) {
263-
264-
parentNode.children.forEach(function(childId) {
265-
266-
let childNode = data.instance.get_node(childId, false);
267-
268-
// Check if the child node has no children (is not yet loaded)
269-
if (childNode.children && childNode.children.length === 0
270-
&& childNode.original && !childNode.original.lastNode) {
271-
272-
$.ajax({
273-
url: '{$block->escapeJs($block->escapeUrl($block->getLoadTreeUrl()))}',
274-
type: "POST",
275-
data: {
276-
id: childNode.original.id,
277-
store: childNode.original.store,
278-
form_key: FORM_KEY
279-
},
280-
dataType: 'json',
281-
success: function (response) {
282-
TreeConfig.handleSuccessResponse(response, childNode, data);
283-
},
284-
error: function (jqXHR, status, error) {
285-
console.log(status + ': ' + error);
286-
}
287-
});
288-
}
289-
});
290-
}
291-
},
292-
293-
handleSuccessResponse : function(response, childNode, data){
294-
if (response.length > 0) {
295-
response.forEach(newNode => {
296-
TreeConfig.addLastNodeFlag(newNode);
297-
298-
// Create the new node and execute node callback
299-
data.instance.create_node(childNode, newNode, 'last');
300-
});
301-
302-
// open all node if, expand all link clicked
303-
if(expandAll === true){
304-
data.instance.open_all();
305-
}
306-
}
307-
},
308-
309-
addLastNodeFlag : function(treeData) {
310-
if (treeData.children) {
311-
treeData.children.forEach(child => TreeConfig.addLastNodeFlag(child));
312-
} else {
313-
treeData.lastNode = true;
314-
}
315-
},
316-
317262
expandAll : function(){
318263
expandAll = true;
319264
treeInstance.open_all();
@@ -343,13 +288,6 @@ script;
343288
TreeConfig.categoryClick(data);
344289
});
345290
346-
/**
347-
* jstree handle open node
348-
*/
349-
treeDiv.on('open_node.jstree', function (e, data) {
350-
TreeConfig.handleOpenNode(data);
351-
});
352-
353291
/**
354292
* create default tree
355293
*/

app/code/Magento/CatalogGraphQl/Plugin/ProductAttributeSortInput.php

Lines changed: 76 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,30 @@
2323
use GraphQL\Language\Visitor;
2424
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
2525
use Magento\GraphQl\Model\Query\ContextInterface;
26+
use Magento\Framework\App\RequestInterface;
27+
use Magento\Framework\Serialize\SerializerInterface;
2628

2729
class ProductAttributeSortInput
2830
{
31+
/**
32+
* @var RequestInterface
33+
*/
34+
private $request;
35+
36+
/**
37+
* @var SerializerInterface
38+
*/
39+
private $jsonSerializer;
40+
41+
/**
42+
* @param RequestInterface $request
43+
* @param SerializerInterface $jsonSerializer
44+
*/
45+
public function __construct(RequestInterface $request, SerializerInterface $jsonSerializer)
46+
{
47+
$this->request = $request;
48+
$this->jsonSerializer = $jsonSerializer;
49+
}
2950
/**
3051
* Plugin to preserve the original order of sort fields
3152
*
@@ -47,43 +68,83 @@ public function beforeResolve(
4768
array $value = null,
4869
array $args = null
4970
): array {
71+
72+
$data = $this->getDataFromRequest($this->request);
5073
if (isset($args['sort'])) {
51-
$args['sort'] = $this->getSortFieldsOrder($info, $args['sort']);
74+
$args['sort'] = $this->getSortFieldsOrder(
75+
$info,
76+
$args['sort'],
77+
isset($data['variables']['sort']) ? array_keys($data['variables']['sort']) : null
78+
);
5279
}
5380
return [$field, $context, $info, $value, $args];
5481
}
5582

83+
/**
84+
* Get data from request body or query string
85+
*
86+
* @param RequestInterface $request
87+
* @return array
88+
*/
89+
private function getDataFromRequest(RequestInterface $request): array
90+
{
91+
$data = [];
92+
if ($request->isPost()) {
93+
$data = $this->jsonSerializer->unserialize($request->getContent());
94+
} elseif ($request->isGet()) {
95+
$data = $request->getParams();
96+
$data['variables'] = isset($data['variables']) ?
97+
$this->jsonSerializer->unserialize($data['variables']) : null;
98+
$data['variables'] = is_array($data['variables']) ?
99+
$data['variables'] : null;
100+
}
101+
return $data;
102+
}
103+
56104
/**
57105
* Get sort fields in the original order
58106
*
59107
* @param ResolveInfo $info
60108
* @param array $sortFields
109+
* @param array|null $requestSortFields
61110
* @return array
62111
* @throws \Exception
63112
*/
64-
private function getSortFieldsOrder(ResolveInfo $info, array $sortFields)
113+
private function getSortFieldsOrder(ResolveInfo $info, array $sortFields, ?array $requestSortFields): array
65114
{
66115
$sortFieldsOriginal = [];
67116
Visitor::visit(
68117
$info->operation,
69118
[
70119
'enter' => [
71-
NodeKind::ARGUMENT => function (Node $node) use (&$sortFieldsOriginal, $sortFields) {
120+
NodeKind::ARGUMENT => function (Node $node) use (
121+
&$sortFieldsOriginal,
122+
$sortFields,
123+
$requestSortFields
124+
) {
72125
if ($node->name->value === 'sort') {
73-
Visitor::visit(
74-
$node->value,
75-
[
76-
'enter' => [
77-
NodeKind::OBJECT_FIELD =>
78-
function (Node $node) use (&$sortFieldsOriginal, $sortFields) {
79-
if (isset($sortFields[$node->name->value])) {
80-
$sortFieldsOriginal[$node->name->value] =
81-
$sortFields[$node->name->value];
126+
if (isset($requestSortFields)) {
127+
foreach ($requestSortFields as $fieldName) {
128+
if (isset($sortFields[$fieldName])) {
129+
$sortFieldsOriginal[$fieldName] = $sortFields[$fieldName];
130+
}
131+
}
132+
} else {
133+
Visitor::visit(
134+
$node->value,
135+
[
136+
'enter' => [
137+
NodeKind::OBJECT_FIELD =>
138+
function (Node $node) use (&$sortFieldsOriginal, $sortFields) {
139+
if (isset($sortFields[$node->name->value])) {
140+
$sortFieldsOriginal[$node->name->value] =
141+
$sortFields[$node->name->value];
142+
}
82143
}
83-
}
144+
]
84145
]
85-
]
86-
);
146+
);
147+
}
87148
return Visitor::stop();
88149
}
89150
}

app/code/Magento/CatalogSearch/i18n/en_US.csv

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ name,name
3939
"Rebuild Catalog product fulltext search index","Rebuild Catalog product fulltext search index"
4040
"Please enter a valid price range.","Please enter a valid price range."
4141
"This value must be compatible with the corresponding setting in the configured search engine. Be aware: a low query length limit may cause the performance impact.","This value must be compatible with the corresponding setting in the configured search engine. Be aware: a low query length limit may cause the performance impact."
42-
"This value must be compatible with the corresponding setting in the configured search engine.","This value must be compatible with the corresponding setting in the configured search engine."
42+
"This value must be compatible with the corresponding setting in the configured search engine.","This value must be compatible with the corresponding setting in the configured search engine."
43+
"If not specified, Default Search Engine will be used.","If not specified, Default Search Engine will be used."
44+
"This search engine option is no longer supported by Adobe. It is recommended to use OpenSearch as a search engine instead.","This search engine option is no longer supported by Adobe. It is recommended to use OpenSearch as a search engine instead."
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright 2024 Adobe
5+
* All Rights Reserved.
6+
*/
7+
-->
8+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
9+
<body>
10+
<referenceContainer name="js">
11+
<block class="Magento\Backend\Block\Template" name="search_engine_comment_js" template="Magento_CatalogSearch::search_engine_comment.phtml"/>
12+
</referenceContainer>
13+
</body>
14+
</page>

0 commit comments

Comments
 (0)