Skip to content

Commit f780505

Browse files
Merge branch '2.4-develop' into MC-35152
2 parents c4446ec + 3b19d14 commit f780505

File tree

70 files changed

+4818
-348
lines changed

Some content is hidden

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

70 files changed

+4818
-348
lines changed

app/code/Magento/AdminAnalytics/Test/Mftf/Test/TrackingScriptTest.xml

Lines changed: 0 additions & 26 deletions
This file was deleted.

app/code/Magento/Catalog/Model/ResourceModel/Category/AggregateCount.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
use Magento\Catalog\Model\Category;
99

1010
/**
11+
* Aggregate count for parent category after deleting child category
12+
*
1113
* Class AggregateCount
1214
*/
1315
class AggregateCount
1416
{
1517
/**
18+
* Reduces children count for parent categories
19+
*
1620
* @param Category $category
1721
* @return void
1822
*/
@@ -25,9 +29,7 @@ public function processDelete(Category $category)
2529
*/
2630
$parentIds = $category->getParentIds();
2731
if ($parentIds) {
28-
$childDecrease = $category->getChildrenCount() + 1;
29-
// +1 is itself
30-
$data = ['children_count' => new \Zend_Db_Expr('children_count - ' . $childDecrease)];
32+
$data = ['children_count' => new \Zend_Db_Expr('children_count - 1')];
3133
$where = ['entity_id IN(?)' => $parentIds];
3234
$resourceModel->getConnection()->update($resourceModel->getEntityTable(), $data, $where);
3335
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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\Catalog\Test\Unit\Model\ResourceModel\Category;
9+
10+
use Magento\Catalog\Model\Category;
11+
use Magento\Catalog\Model\ResourceModel\Category\AggregateCount;
12+
use Magento\Catalog\Model\ResourceModel\Category as ResourceCategory;
13+
use Magento\Framework\DB\Adapter\AdapterInterface;
14+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
15+
use PHPUnit\Framework\MockObject\MockObject;
16+
use PHPUnit\Framework\TestCase;
17+
18+
/**
19+
* Aggregate count model test
20+
*/
21+
class AggregateCountTest extends TestCase
22+
{
23+
24+
/**
25+
* @var AggregateCount
26+
*/
27+
protected $aggregateCount;
28+
29+
/**
30+
* @var ObjectManagerHelper
31+
*/
32+
protected $objectManagerHelper;
33+
34+
/**
35+
* @var Category|MockObject
36+
*/
37+
protected $categoryMock;
38+
39+
/**
40+
* @var ResourceCategory|MockObject
41+
*/
42+
protected $resourceCategoryMock;
43+
44+
/**
45+
* @var AdapterInterface|MockObject
46+
*/
47+
protected $connectionMock;
48+
49+
/**
50+
* {@inheritdoc}
51+
*/
52+
public function setUp(): void
53+
{
54+
$this->categoryMock = $this->createMock(Category::class);
55+
$this->resourceCategoryMock = $this->createMock(ResourceCategory::class);
56+
$this->connectionMock = $this->getMockBuilder(AdapterInterface::class)
57+
->getMockForAbstractClass();
58+
$this->objectManagerHelper = new ObjectManagerHelper($this);
59+
$this->aggregateCount = $this->objectManagerHelper->getObject(AggregateCount::class);
60+
}
61+
62+
/**
63+
* @return void
64+
*/
65+
public function testProcessDelete(): void
66+
{
67+
$parentIds = 3;
68+
$table = 'catalog_category_entity';
69+
70+
$this->categoryMock->expects($this->once())
71+
->method('getResource')
72+
->willReturn($this->resourceCategoryMock);
73+
$this->categoryMock->expects($this->once())
74+
->method('getParentIds')
75+
->willReturn($parentIds);
76+
$this->resourceCategoryMock->expects($this->any())
77+
->method('getEntityTable')
78+
->willReturn($table);
79+
$this->resourceCategoryMock->expects($this->once())
80+
->method('getConnection')
81+
->willReturn($this->connectionMock);
82+
$this->connectionMock->expects($this->once())
83+
->method('update')
84+
->with(
85+
$table,
86+
['children_count' => new \Zend_Db_Expr('children_count - 1')],
87+
['entity_id IN(?)' => $parentIds]
88+
);
89+
$this->aggregateCount->processDelete($this->categoryMock);
90+
}
91+
}

app/code/Magento/Customer/Block/DataProviders/AddressAttributeData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function getFrontendLabel(string $attributeCode): string
5252
{
5353
try {
5454
$attribute = $this->addressMetadata->getAttributeMetadata($attributeCode);
55-
$frontendLabel = $attribute->getFrontendLabel();
55+
$frontendLabel = $attribute->getStoreLabel() ?: $attribute->getFrontendLabel();
5656
} catch (NoSuchEntityException $e) {
5757
$frontendLabel = '';
5858
}

app/code/Magento/Customer/Model/Plugin/CustomerAuthorization.php

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
namespace Magento\Customer\Model\Plugin;
88

99
use Magento\Authorization\Model\UserContextInterface;
10+
use Magento\Customer\Model\CustomerFactory;
11+
use Magento\Customer\Model\ResourceModel\Customer as CustomerResource;
1012
use Magento\Integration\Api\AuthorizationServiceInterface as AuthorizationService;
13+
use Magento\Store\Model\StoreManagerInterface;
1114

1215
/**
1316
* Plugin around \Magento\Framework\Authorization::isAllowed
@@ -19,16 +22,41 @@ class CustomerAuthorization
1922
/**
2023
* @var UserContextInterface
2124
*/
22-
protected $userContext;
25+
private $userContext;
26+
27+
/**
28+
* @var CustomerFactory
29+
*/
30+
private $customerFactory;
31+
32+
/**
33+
* @var CustomerResource
34+
*/
35+
private $customerResource;
36+
37+
/**
38+
* @var StoreManagerInterface
39+
*/
40+
private $storeManager;
2341

2442
/**
2543
* Inject dependencies.
2644
*
2745
* @param UserContextInterface $userContext
46+
* @param CustomerFactory $customerFactory
47+
* @param CustomerResource $customerResource
48+
* @param StoreManagerInterface $storeManager
2849
*/
29-
public function __construct(UserContextInterface $userContext)
30-
{
50+
public function __construct(
51+
UserContextInterface $userContext,
52+
CustomerFactory $customerFactory,
53+
CustomerResource $customerResource,
54+
StoreManagerInterface $storeManager
55+
) {
3156
$this->userContext = $userContext;
57+
$this->customerFactory = $customerFactory;
58+
$this->customerResource = $customerResource;
59+
$this->storeManager = $storeManager;
3260
}
3361

3462
/**
@@ -53,9 +81,15 @@ public function aroundIsAllowed(
5381
&& $this->userContext->getUserId()
5482
&& $this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER
5583
) {
56-
return true;
57-
} else {
58-
return $proceed($resource, $privilege);
84+
$customer = $this->customerFactory->create();
85+
$this->customerResource->load($customer, $this->userContext->getUserId());
86+
$currentStoreId = $this->storeManager->getStore()->getId();
87+
$sharedStoreIds = $customer->getSharedStoreIds();
88+
if (in_array($currentStoreId, $sharedStoreIds)) {
89+
return true;
90+
}
5991
}
92+
93+
return $proceed($resource, $privilege);
6094
}
6195
}

app/code/Magento/GiftMessageGraphQl/Model/Resolver/Cart/GiftMessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function resolve(
6666
array $args = null
6767
) {
6868
if (!isset($value['model'])) {
69-
throw new GraphQlInputException(__('"model" value should be specified'));
69+
throw new GraphQlInputException(__('"model" value must be specified'));
7070
}
7171

7272
$cart = $value['model'];
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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\GiftMessageGraphQl\Model\Resolver\Cart\Item;
9+
10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\GraphQl\Config\Element\Field;
12+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
13+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
14+
use Magento\Framework\GraphQl\Query\Resolver\Value;
15+
use Magento\Framework\GraphQl\Query\ResolverInterface;
16+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
17+
use Magento\GiftMessage\Api\ItemRepositoryInterface;
18+
use Magento\GiftMessage\Helper\Message as GiftMessageHelper;
19+
20+
/**
21+
* Class provides ability to get GiftMessage for cart item
22+
*/
23+
class GiftMessage implements ResolverInterface
24+
{
25+
/**
26+
* @var ItemRepositoryInterface
27+
*/
28+
private $itemRepository;
29+
30+
/**
31+
* @var GiftMessageHelper
32+
*/
33+
private $giftMessageHelper;
34+
35+
/**
36+
* @param ItemRepositoryInterface $itemRepository
37+
* @param GiftMessageHelper $giftMessageHelper
38+
*/
39+
public function __construct(
40+
ItemRepositoryInterface $itemRepository,
41+
GiftMessageHelper $giftMessageHelper
42+
) {
43+
$this->itemRepository = $itemRepository;
44+
$this->giftMessageHelper = $giftMessageHelper;
45+
}
46+
47+
/**
48+
* Return information about Gift message for item cart
49+
*
50+
* @param Field $field
51+
* @param ContextInterface $context
52+
* @param ResolveInfo $info
53+
* @param array|null $value
54+
* @param array|null $args
55+
*
56+
* @return array|Value|mixed
57+
* @throws GraphQlInputException
58+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
59+
*/
60+
public function resolve(
61+
Field $field,
62+
$context,
63+
ResolveInfo $info,
64+
array $value = null,
65+
array $args = null
66+
) {
67+
if (!isset($value['model'])) {
68+
throw new GraphQlInputException(__('"model" value must be specified'));
69+
}
70+
71+
$quoteItem = $value['model'];
72+
73+
if (!$this->giftMessageHelper->isMessagesAllowed('items', $quoteItem)) {
74+
return null;
75+
}
76+
77+
if (!$this->giftMessageHelper->isMessagesAllowed('item', $quoteItem)) {
78+
return null;
79+
}
80+
81+
try {
82+
$giftItemMessage = $this->itemRepository->get($quoteItem->getQuoteId(), $quoteItem->getItemId());
83+
} catch (LocalizedException $e) {
84+
throw new GraphQlInputException(__('Can\'t load cart item'));
85+
}
86+
87+
if (!isset($giftItemMessage)) {
88+
return null;
89+
}
90+
91+
return [
92+
'to' => $giftItemMessage->getRecipient() ?? '',
93+
'from' => $giftItemMessage->getSender() ?? '',
94+
'message'=> $giftItemMessage->getMessage() ?? ''
95+
];
96+
}
97+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# GiftMessageGraphQl
22

3-
**GiftMessageGraphQl** provides information about gift messages for cart, cart items, order and order items.
3+
**GiftMessageGraphQl** provides information about gift messages for carts, cart items, orders and order items.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
10+
<type name="Magento\StoreGraphQl\Model\Resolver\Store\StoreConfigDataProvider">
11+
<arguments>
12+
<argument name="extendedConfigData" xsi:type="array">
13+
<item name="allow_order" xsi:type="string">sales/gift_options/allow_order</item>
14+
<item name="allow_items" xsi:type="string">sales/gift_options/allow_items</item>
15+
</argument>
16+
</arguments>
17+
</type>
18+
</config>

0 commit comments

Comments
 (0)