Skip to content

Commit d7ce9ca

Browse files
author
Oleksandr Gorkun
committed
Merge branch '2.3-develop' of https://github.com/magento/magento2ce into MC-18685
2 parents f706d81 + cc599e5 commit d7ce9ca

File tree

50 files changed

+1089
-128
lines changed

Some content is hidden

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

50 files changed

+1089
-128
lines changed

app/code/Magento/Catalog/Model/Attribute/ScopeOverriddenValue.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function containsValue($entityType, $entity, $attributeCode, $storeId)
8181
if ((int)$storeId === Store::DEFAULT_STORE_ID) {
8282
return false;
8383
}
84-
if ($this->attributesValues === null) {
84+
if (!isset($this->attributesValues[$storeId])) {
8585
$this->initAttributeValues($entityType, $entity, (int)$storeId);
8686
}
8787

@@ -110,6 +110,8 @@ public function getDefaultValues($entityType, $entity)
110110
}
111111

112112
/**
113+
* Init attribute values.
114+
*
113115
* @param string $entityType
114116
* @param \Magento\Catalog\Model\AbstractModel $entity
115117
* @param int $storeId
@@ -158,6 +160,8 @@ private function initAttributeValues($entityType, $entity, $storeId)
158160
}
159161

160162
/**
163+
* Returns entity attributes.
164+
*
161165
* @param string $entityType
162166
* @return \Magento\Eav\Api\Data\AttributeInterface[]
163167
*/

app/code/Magento/Catalog/Model/Product/Copier.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
namespace Magento\Catalog\Model\Product;
77

88
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\Catalog\Model\Attribute\ScopeOverriddenValue;
910
use Magento\Catalog\Model\Product;
11+
use Magento\Catalog\Model\ProductFactory;
1012

1113
/**
1214
* Catalog product copier.
@@ -28,25 +30,32 @@ class Copier
2830
protected $copyConstructor;
2931

3032
/**
31-
* @var \Magento\Catalog\Model\ProductFactory
33+
* @var ProductFactory
3234
*/
3335
protected $productFactory;
3436

3537
/**
3638
* @var \Magento\Framework\EntityManager\MetadataPool
3739
*/
3840
protected $metadataPool;
41+
/**
42+
* @var ScopeOverriddenValue
43+
*/
44+
private $scopeOverriddenValue;
3945

4046
/**
4147
* @param CopyConstructorInterface $copyConstructor
42-
* @param \Magento\Catalog\Model\ProductFactory $productFactory
48+
* @param ProductFactory $productFactory
49+
* @param ScopeOverriddenValue $scopeOverriddenValue
4350
*/
4451
public function __construct(
4552
CopyConstructorInterface $copyConstructor,
46-
\Magento\Catalog\Model\ProductFactory $productFactory
53+
ProductFactory $productFactory,
54+
ScopeOverriddenValue $scopeOverriddenValue
4755
) {
4856
$this->productFactory = $productFactory;
4957
$this->copyConstructor = $copyConstructor;
58+
$this->scopeOverriddenValue = $scopeOverriddenValue;
5059
}
5160

5261
/**
@@ -121,19 +130,20 @@ private function setStoresUrl(Product $product, Product $duplicate) : void
121130
$storeIds = $duplicate->getStoreIds();
122131
$productId = $product->getId();
123132
$productResource = $product->getResource();
124-
$defaultUrlKey = $productResource->getAttributeRawValue(
125-
$productId,
126-
'url_key',
127-
\Magento\Store\Model\Store::DEFAULT_STORE_ID
128-
);
129133
$duplicate->setData('save_rewrites_history', false);
130134
foreach ($storeIds as $storeId) {
135+
$useDefault = !$this->scopeOverriddenValue->containsValue(
136+
ProductInterface::class,
137+
$product,
138+
'url_key',
139+
$storeId
140+
);
141+
if ($useDefault) {
142+
continue;
143+
}
131144
$isDuplicateSaved = false;
132145
$duplicate->setStoreId($storeId);
133146
$urlKey = $productResource->getAttributeRawValue($productId, 'url_key', $storeId);
134-
if ($urlKey === $defaultUrlKey) {
135-
continue;
136-
}
137147
do {
138148
$urlKey = $this->modifyUrl($urlKey);
139149
$duplicate->setUrlKey($urlKey);

app/code/Magento/Catalog/Test/Unit/Model/Product/CopierTest.php

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Catalog\Test\Unit\Model\Product;
77

88
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\Catalog\Model\Attribute\ScopeOverriddenValue;
910
use Magento\Catalog\Model\Product;
1011
use Magento\Catalog\Model\Product\Copier;
1112

@@ -46,6 +47,11 @@ class CopierTest extends \PHPUnit\Framework\TestCase
4647
*/
4748
protected $metadata;
4849

50+
/**
51+
* @var ScopeOverriddenValue|\PHPUnit_Framework_MockObject_MockObject
52+
*/
53+
private $scopeOverriddenValue;
54+
4955
protected function setUp()
5056
{
5157
$this->copyConstructorMock = $this->createMock(\Magento\Catalog\Model\Product\CopyConstructorInterface::class);
@@ -59,6 +65,7 @@ protected function setUp()
5965
$this->optionRepositoryMock;
6066
$this->productMock = $this->createMock(Product::class);
6167
$this->productMock->expects($this->any())->method('getEntityId')->willReturn(1);
68+
$this->scopeOverriddenValue = $this->createMock(ScopeOverriddenValue::class);
6269

6370
$this->metadata = $this->getMockBuilder(\Magento\Framework\EntityManager\EntityMetadata::class)
6471
->disableOriginalConstructor()
@@ -67,15 +74,20 @@ protected function setUp()
6774
->disableOriginalConstructor()
6875
->getMock();
6976
$metadataPool->expects($this->any())->method('getMetadata')->willReturn($this->metadata);
77+
7078
$this->_model = new Copier(
7179
$this->copyConstructorMock,
72-
$this->productFactoryMock
80+
$this->productFactoryMock,
81+
$this->scopeOverriddenValue
7382
);
7483

75-
$this->setProperties($this->_model, [
76-
'optionRepository' => $this->optionRepositoryMock,
77-
'metadataPool' => $metadataPool,
78-
]);
84+
$this->setProperties(
85+
$this->_model,
86+
[
87+
'optionRepository' => $this->optionRepositoryMock,
88+
'metadataPool' => $metadataPool,
89+
]
90+
);
7991
}
8092

8193
/**
@@ -103,10 +115,12 @@ public function testCopy()
103115
];
104116
$this->productMock->expects($this->atLeastOnce())->method('getWebsiteIds');
105117
$this->productMock->expects($this->atLeastOnce())->method('getCategoryIds');
106-
$this->productMock->expects($this->any())->method('getData')->willReturnMap([
107-
['', null, $productData],
108-
['linkField', null, '1'],
109-
]);
118+
$this->productMock->expects($this->any())->method('getData')->willReturnMap(
119+
[
120+
['', null, $productData],
121+
['linkField', null, '1'],
122+
]
123+
);
110124

111125
$entityMock = $this->getMockForAbstractClass(
112126
\Magento\Eav\Model\Entity\AbstractEntity::class,
@@ -191,9 +205,11 @@ public function testCopy()
191205

192206
$this->metadata->expects($this->any())->method('getLinkField')->willReturn('linkField');
193207

194-
$duplicateMock->expects($this->any())->method('getData')->willReturnMap([
195-
['linkField', null, '2'],
196-
]);
208+
$duplicateMock->expects($this->any())->method('getData')->willReturnMap(
209+
[
210+
['linkField', null, '2'],
211+
]
212+
);
197213
$this->optionRepositoryMock->expects($this->once())
198214
->method('duplicate')
199215
->with($this->productMock, $duplicateMock);
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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\CatalogCmsGraphQl\Model\Resolver\Category;
9+
10+
use Magento\Catalog\Model\Category;
11+
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Framework\Exception\NoSuchEntityException;
13+
use Magento\Framework\GraphQl\Config\Element\Field;
14+
use Magento\Framework\GraphQl\Query\ResolverInterface;
15+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
16+
use Magento\CmsGraphQl\Model\Resolver\DataProvider\Block as BlockProvider;
17+
18+
/**
19+
* Resolver category cms content
20+
*/
21+
class Block implements ResolverInterface
22+
{
23+
/**
24+
* @var BlockProvider
25+
*/
26+
private $blockProvider;
27+
28+
/**
29+
* @param BlockProvider $blockProvider
30+
*/
31+
public function __construct(BlockProvider $blockProvider)
32+
{
33+
$this->blockProvider = $blockProvider;
34+
}
35+
36+
/**
37+
* @inheritdoc
38+
*/
39+
public function resolve(
40+
Field $field,
41+
$context,
42+
ResolveInfo $info,
43+
array $value = null,
44+
array $args = null
45+
) {
46+
if (!isset($value['model'])) {
47+
throw new LocalizedException(__('"model" value should be specified'));
48+
}
49+
/** @var Category $category */
50+
$category = $value['model'];
51+
$blockId = $category->getLandingPage();
52+
53+
if (empty($blockId)) {
54+
return null;
55+
}
56+
57+
try {
58+
$block = $this->blockProvider->getData($blockId);
59+
} catch (NoSuchEntityException $e) {
60+
return null;
61+
}
62+
63+
return $block;
64+
}
65+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# CatalogCmsGraphQl
2+
3+
**CatalogCmsGraphQl** provides type and resolver information for GraphQL attributes that have dependencies on the Catalog and Cms modules.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "magento/module-catalog-cms-graph-ql",
3+
"description": "N/A",
4+
"type": "magento2-module",
5+
"require": {
6+
"php": "~7.1.3||~7.2.0||~7.3.0",
7+
"magento/framework": "*",
8+
"magento/module-catalog": "*",
9+
"magento/module-cms-graph-ql": "*"
10+
},
11+
"suggest": {
12+
"magento/module-graph-ql": "*",
13+
"magento/module-cms": "*",
14+
"magento/module-catalog-graph-ql": "*"
15+
},
16+
"license": [
17+
"OSL-3.0",
18+
"AFL-3.0"
19+
],
20+
"autoload": {
21+
"files": [
22+
"registration.php"
23+
],
24+
"psr-4": {
25+
"Magento\\CatalogCmsGraphQl\\": ""
26+
}
27+
}
28+
}
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" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\CatalogGraphQl\Model\AttributesJoiner">
10+
<arguments>
11+
<argument name="fieldToAttributeMap" xsi:type="array">
12+
<item name="cms_block" xsi:type="array">
13+
<item name="landing_page" xsi:type="string">landing_page</item>
14+
</item>
15+
</argument>
16+
</arguments>
17+
</type>
18+
</config>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9+
<module name="Magento_CatalogCmsGraphQl" >
10+
<sequence>
11+
<module name="Magento_CmsGraphQl"/>
12+
<module name="Magento_CatalogGraphQl"/>
13+
</sequence>
14+
</module>
15+
</config>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright © Magento, Inc. All rights reserved.
2+
# See COPYING.txt for license details.
3+
4+
interface CategoryInterface {
5+
cms_block: CmsBlock @doc(description: "Category CMS Block.") @resolver(class: "Magento\\CatalogCmsGraphQl\\Model\\Resolver\\Category\\Block")
6+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Framework\Component\ComponentRegistrar;
8+
9+
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_CatalogCmsGraphQl', __DIR__);

0 commit comments

Comments
 (0)