Skip to content

Commit 4b3f620

Browse files
[Magento Community Engineering] Community Contributions - 2.3-develop
- merged latest code from mainline branch
2 parents 8b0ce06 + 1ebd7cc commit 4b3f620

File tree

21 files changed

+1242
-26
lines changed

21 files changed

+1242
-26
lines changed

app/code/Magento/AdminAnalytics/view/adminhtml/ui_component/admin_usage_notification.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
<item name="text" xsi:type="string" translate="true"><![CDATA[
8686
<p>Help us improve Magento Admin by allowing us to collect usage data.</p>
8787
<p>All usage data that we collect for this purpose cannot be used to individually identify you and is used only to improve the Magento Admin and related products and services.</p>
88-
<p>You can learn more and opt out at any time by following the instructions in <a href="https://docs.magento.com/m2/ce/user_guide/stores/admin.html" target="_blank">merchant documentation</a>.</p>
88+
<p>You can learn more and opt out at any time by following the instructions in <a href="https://docs.magento.com/m2/ce/user_guide/stores/admin.html" target="_blank" tabindex="0">merchant documentation</a>.</p>
8989
]]></item>
9090
</item>
9191
</argument>

app/code/Magento/AdminAnalytics/view/adminhtml/web/js/modal/component.js

+84-13
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,7 @@ define([
2020
enableLogAction: '${ $.provider }:data.enableLogAction',
2121
disableLogAction: '${ $.provider }:data.disableLogAction'
2222
},
23-
options: {
24-
keyEventHandlers: {
25-
/**
26-
* Prevents escape key from exiting out of modal
27-
*/
28-
escapeKey: function () {
29-
return;
30-
}
31-
}
32-
},
23+
options: {},
3324
notificationWindow: null
3425
},
3526

@@ -41,11 +32,32 @@ define([
4132
this._super();
4233
},
4334

35+
/**
36+
* Configure ESC and TAB so user can't leave modal
37+
* without selecting an option
38+
*
39+
* @returns {Object} Chainable.
40+
*/
41+
initModalEvents: function () {
42+
this._super();
43+
//Don't allow ESC key to close modal
44+
this.options.keyEventHandlers.escapeKey = this.handleEscKey.bind(this);
45+
//Restrict tab action to the modal
46+
this.options.keyEventHandlers.tabKey = this.handleTabKey.bind(this);
47+
48+
return this;
49+
},
50+
4451
/**
4552
* Once the modal is opened it hides the X
4653
*/
4754
onOpened: function () {
48-
$('.modal-header button.action-close').hide();
55+
$('.modal-header button.action-close').attr('disabled', true).hide();
56+
57+
this.focusableElements = $(this.rootSelector).find('a[href], button:enabled');
58+
this.firstFocusableElement = this.focusableElements[0];
59+
this.lastFocusableElement = this.focusableElements[this.focusableElements.length - 1];
60+
this.firstFocusableElement.focus();
4961
},
5062

5163
/**
@@ -104,11 +116,70 @@ define([
104116
* Allows admin usage popup to be shown first and then new release notification
105117
*/
106118
openReleasePopup: function () {
107-
var notifiModal = registry.get('release_notification.release_notification.notification_modal_1');
119+
var notificationModalSelector = 'release_notification.release_notification.notification_modal_1';
108120

109121
if (analyticsPopupConfig.releaseVisible) {
110-
notifiModal.initializeContentAfterAnalytics();
122+
registry.get(notificationModalSelector).initializeContentAfterAnalytics();
111123
}
124+
},
125+
126+
/**
127+
* Handle Tab and Shift+Tab key event
128+
*
129+
* Keep the tab actions restricted to the popup modal
130+
* so the user must select an option to dismiss the modal
131+
*/
132+
handleTabKey: function (event) {
133+
var modal = this,
134+
KEY_TAB = 9;
135+
136+
/**
137+
* Handle Shift+Tab to tab backwards
138+
*/
139+
function handleBackwardTab() {
140+
if (document.activeElement === modal.firstFocusableElement ||
141+
document.activeElement === $(modal.rootSelector)[0]
142+
) {
143+
event.preventDefault();
144+
modal.lastFocusableElement.focus();
145+
}
146+
}
147+
148+
/**
149+
* Handle Tab forward
150+
*/
151+
function handleForwardTab() {
152+
if (document.activeElement === modal.lastFocusableElement) {
153+
event.preventDefault();
154+
modal.firstFocusableElement.focus();
155+
}
156+
}
157+
158+
switch (event.keyCode) {
159+
case KEY_TAB:
160+
if (modal.focusableElements.length === 1) {
161+
event.preventDefault();
162+
break;
163+
}
164+
165+
if (event.shiftKey) {
166+
handleBackwardTab();
167+
break;
168+
}
169+
handleForwardTab();
170+
break;
171+
default:
172+
break;
173+
}
174+
},
175+
176+
/**
177+
* Handle Esc key
178+
*
179+
* Esc key should not close modal
180+
*/
181+
handleEscKey: function (event) {
182+
event.preventDefault();
112183
}
113184
}
114185
);

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php

+44-11
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,57 @@ public function __construct(
4848
public function execute(\Iterator $iterator): array
4949
{
5050
$tree = [];
51+
/** @var CategoryInterface $rootCategory */
52+
$rootCategory = $iterator->current();
5153
while ($iterator->valid()) {
52-
/** @var CategoryInterface $category */
53-
$category = $iterator->current();
54+
/** @var CategoryInterface $currentCategory */
55+
$currentCategory = $iterator->current();
5456
$iterator->next();
55-
$pathElements = explode("/", $category->getPath());
56-
if (empty($tree)) {
57-
$this->startCategoryFetchLevel = count($pathElements) - 1;
57+
if ($this->areParentsActive($currentCategory, $rootCategory, (array)$iterator)) {
58+
$pathElements = explode("/", $currentCategory->getPath());
59+
if (empty($tree)) {
60+
$this->startCategoryFetchLevel = count($pathElements) - 1;
61+
}
62+
$this->iteratingCategory = $currentCategory;
63+
$currentLevelTree = $this->explodePathToArray($pathElements, $this->startCategoryFetchLevel);
64+
if (empty($tree)) {
65+
$tree = $currentLevelTree;
66+
}
67+
$tree = $this->mergeCategoriesTrees($currentLevelTree, $tree);
5868
}
59-
$this->iteratingCategory = $category;
60-
$currentLevelTree = $this->explodePathToArray($pathElements, $this->startCategoryFetchLevel);
61-
if (empty($tree)) {
62-
$tree = $currentLevelTree;
63-
}
64-
$tree = $this->mergeCategoriesTrees($currentLevelTree, $tree);
6569
}
6670
return $tree;
6771
}
6872

73+
/**
74+
* Test that all parents of the current category are active.
75+
*
76+
* Assumes that $categoriesArray are key-pair values and key is the ID of the category and
77+
* all categories in this list are queried as active.
78+
*
79+
* @param CategoryInterface $currentCategory
80+
* @param CategoryInterface $rootCategory
81+
* @param array $categoriesArray
82+
* @return bool
83+
*/
84+
private function areParentsActive(
85+
CategoryInterface $currentCategory,
86+
CategoryInterface $rootCategory,
87+
array $categoriesArray
88+
): bool {
89+
if ($currentCategory === $rootCategory) {
90+
return true;
91+
} elseif (array_key_exists($currentCategory->getParentId(), $categoriesArray)) {
92+
return $this->areParentsActive(
93+
$categoriesArray[$currentCategory->getParentId()],
94+
$rootCategory,
95+
$categoriesArray
96+
);
97+
} else {
98+
return false;
99+
}
100+
}
101+
69102
/**
70103
* Merge together complex categories trees
71104
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\QuoteGraphQl\Model\Resolver;
9+
10+
use Magento\Framework\Exception\NoSuchEntityException;
11+
use Magento\Framework\GraphQl\Config\Element\Field;
12+
use Magento\Framework\GraphQl\Query\ResolverInterface;
13+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
14+
use Magento\QuoteGraphQl\Model\Cart\CreateEmptyCartForCustomer;
15+
use Magento\GraphQl\Model\Query\ContextInterface;
16+
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
17+
use Magento\Quote\Api\CartManagementInterface;
18+
use Magento\Quote\Model\QuoteIdMaskFactory;
19+
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
20+
use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResourceModel;
21+
22+
/**
23+
* Get cart for the customer
24+
*/
25+
class CustomerCart implements ResolverInterface
26+
{
27+
/**
28+
* @var CreateEmptyCartForCustomer
29+
*/
30+
private $createEmptyCartForCustomer;
31+
32+
/**
33+
* @var CartManagementInterface
34+
*/
35+
private $cartManagement;
36+
37+
/**
38+
* @var QuoteIdMaskFactory
39+
*/
40+
private $quoteIdMaskFactory;
41+
42+
/**
43+
* @var QuoteIdMaskResourceModel
44+
*/
45+
private $quoteIdMaskResourceModel;
46+
/**
47+
* @var QuoteIdToMaskedQuoteIdInterface
48+
*/
49+
private $quoteIdToMaskedQuoteId;
50+
51+
/**
52+
* @param CreateEmptyCartForCustomer $createEmptyCartForCustomer
53+
* @param CartManagementInterface $cartManagement
54+
* @param QuoteIdMaskFactory $quoteIdMaskFactory
55+
* @param QuoteIdMaskResourceModel $quoteIdMaskResourceModel
56+
* @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
57+
*/
58+
public function __construct(
59+
CreateEmptyCartForCustomer $createEmptyCartForCustomer,
60+
CartManagementInterface $cartManagement,
61+
QuoteIdMaskFactory $quoteIdMaskFactory,
62+
QuoteIdMaskResourceModel $quoteIdMaskResourceModel,
63+
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
64+
) {
65+
$this->createEmptyCartForCustomer = $createEmptyCartForCustomer;
66+
$this->cartManagement = $cartManagement;
67+
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
68+
$this->quoteIdMaskResourceModel = $quoteIdMaskResourceModel;
69+
$this->quoteIdToMaskedQuoteId = $quoteIdToMaskedQuoteId;
70+
}
71+
72+
/**
73+
* @inheritdoc
74+
*/
75+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
76+
{
77+
$currentUserId = $context->getUserId();
78+
79+
/** @var ContextInterface $context */
80+
if (false === $context->getExtensionAttributes()->getIsCustomer()) {
81+
throw new GraphQlAuthorizationException(__('The request is allowed for logged in customer'));
82+
}
83+
try {
84+
$cart = $this->cartManagement->getCartForCustomer($currentUserId);
85+
} catch (NoSuchEntityException $e) {
86+
$this->createEmptyCartForCustomer->execute($currentUserId, null);
87+
$cart = $this->cartManagement->getCartForCustomer($currentUserId);
88+
}
89+
90+
$maskedId = $this->quoteIdToMaskedQuoteId->execute((int) $cart->getId());
91+
if (empty($maskedId)) {
92+
$quoteIdMask = $this->quoteIdMaskFactory->create();
93+
$quoteIdMask->setQuoteId((int) $cart->getId());
94+
$this->quoteIdMaskResourceModel->save($quoteIdMask);
95+
}
96+
97+
return [
98+
'model' => $cart
99+
];
100+
}
101+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\QuoteGraphQl\Model\Resolver;
9+
10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Framework\GraphQl\Config\Element\Field;
13+
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
14+
use Magento\Framework\GraphQl\Query\ResolverInterface;
15+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
16+
use Magento\Quote\Model\Quote;
17+
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
18+
19+
/**
20+
* Get cart id from the cart
21+
*/
22+
class MaskedCartId implements ResolverInterface
23+
{
24+
/**
25+
* @var QuoteIdToMaskedQuoteIdInterface
26+
*/
27+
private $quoteIdToMaskedQuoteId;
28+
29+
/**
30+
* @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
31+
*/
32+
public function __construct(
33+
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
34+
) {
35+
$this->quoteIdToMaskedQuoteId = $quoteIdToMaskedQuoteId;
36+
}
37+
38+
/**
39+
* @inheritdoc
40+
*/
41+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
42+
{
43+
if (!isset($value['model'])) {
44+
throw new LocalizedException(__('"model" value should be specified'));
45+
}
46+
/** @var Quote $cart */
47+
$cart = $value['model'];
48+
$cartId = (int) $cart->getId();
49+
$maskedCartId = $this->getQuoteMaskId($cartId);
50+
return $maskedCartId;
51+
}
52+
53+
/**
54+
* Get masked id for cart
55+
*
56+
* @param int $quoteId
57+
* @return string
58+
* @throws GraphQlNoSuchEntityException
59+
*/
60+
private function getQuoteMaskId(int $quoteId): string
61+
{
62+
try {
63+
$maskedId = $this->quoteIdToMaskedQuoteId->execute($quoteId);
64+
} catch (NoSuchEntityException $exception) {
65+
throw new GraphQlNoSuchEntityException(__('Current user does not have an active cart.'));
66+
}
67+
return $maskedId;
68+
}
69+
}

0 commit comments

Comments
 (0)