Skip to content

Commit 492a48a

Browse files
merge magento/2.4.1-develop into magento-borg/2.4.1-bugfixes-08132020
2 parents 1df9743 + 2ecd3c1 commit 492a48a

File tree

9 files changed

+332
-101
lines changed

9 files changed

+332
-101
lines changed

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

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
*/
66
namespace Magento\Catalog\Model\ResourceModel;
77

8-
use Magento\Catalog\Api\Data\ProductInterface;
98
use Magento\Catalog\Model\Attribute\LockValidatorInterface;
9+
use Magento\Catalog\Model\ResourceModel\Attribute\RemoveProductAttributeData;
10+
use Magento\Framework\App\ObjectManager;
1011

1112
/**
1213
* Catalog attribute resource model
13-
*
14-
* @author Magento Core Team <core@magentocommerce.com>
1514
*/
1615
class Attribute extends \Magento\Eav\Model\ResourceModel\Entity\Attribute
1716
{
@@ -28,28 +27,33 @@ class Attribute extends \Magento\Eav\Model\ResourceModel\Entity\Attribute
2827
protected $attrLockValidator;
2928

3029
/**
31-
* @var \Magento\Framework\EntityManager\MetadataPool
30+
* @var RemoveProductAttributeData|null
3231
*/
33-
protected $metadataPool;
32+
private $removeProductAttributeData;
3433

3534
/**
3635
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
3736
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
3837
* @param \Magento\Eav\Model\ResourceModel\Entity\Type $eavEntityType
3938
* @param \Magento\Eav\Model\Config $eavConfig
4039
* @param LockValidatorInterface $lockValidator
41-
* @param string $connectionName
40+
* @param string|null $connectionName
41+
* @param RemoveProductAttributeData|null $removeProductAttributeData
4242
*/
4343
public function __construct(
4444
\Magento\Framework\Model\ResourceModel\Db\Context $context,
4545
\Magento\Store\Model\StoreManagerInterface $storeManager,
4646
\Magento\Eav\Model\ResourceModel\Entity\Type $eavEntityType,
4747
\Magento\Eav\Model\Config $eavConfig,
4848
LockValidatorInterface $lockValidator,
49-
$connectionName = null
49+
$connectionName = null,
50+
RemoveProductAttributeData $removeProductAttributeData = null
5051
) {
5152
$this->attrLockValidator = $lockValidator;
5253
$this->_eavConfig = $eavConfig;
54+
$this->removeProductAttributeData = $removeProductAttributeData ?? ObjectManager::getInstance()
55+
->get(RemoveProductAttributeData::class);
56+
5357
parent::__construct($context, $storeManager, $eavEntityType, $connectionName);
5458
}
5559

@@ -135,41 +139,12 @@ public function deleteEntity(\Magento\Framework\Model\AbstractModel $object)
135139
);
136140
}
137141

138-
$backendTable = $attribute->getBackend()->getTable();
139-
if ($backendTable) {
140-
$linkField = $this->getMetadataPool()
141-
->getMetadata(ProductInterface::class)
142-
->getLinkField();
143-
144-
$backendLinkField = $attribute->getBackend()->getEntityIdField();
145-
146-
$select = $this->getConnection()->select()
147-
->from(['b' => $backendTable])
148-
->join(
149-
['e' => $attribute->getEntity()->getEntityTable()],
150-
"b.$backendLinkField = e.$linkField"
151-
)->where('b.attribute_id = ?', $attribute->getId())
152-
->where('e.attribute_set_id = ?', $result['attribute_set_id']);
153-
154-
$this->getConnection()->query($select->deleteFromSelect('b'));
155-
}
142+
$this->removeProductAttributeData->removeData($object, (int)$result['attribute_set_id']);
156143
}
157144

158145
$condition = ['entity_attribute_id = ?' => $object->getEntityAttributeId()];
159146
$this->getConnection()->delete($this->getTable('eav_entity_attribute'), $condition);
160147

161148
return $this;
162149
}
163-
164-
/**
165-
* @return \Magento\Framework\EntityManager\MetadataPool
166-
*/
167-
private function getMetadataPool()
168-
{
169-
if (null === $this->metadataPool) {
170-
$this->metadataPool = \Magento\Framework\App\ObjectManager::getInstance()
171-
->get(\Magento\Framework\EntityManager\MetadataPool::class);
172-
}
173-
return $this->metadataPool;
174-
}
175150
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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\Model\ResourceModel\Attribute;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Framework\App\ResourceConnection;
12+
use Magento\Framework\EntityManager\MetadataPool;
13+
use Magento\Framework\Model\AbstractModel;
14+
15+
/**
16+
* Class for deleting data from attribute additional table by attribute set id.
17+
*/
18+
class RemoveProductAttributeData
19+
{
20+
/**
21+
* @var ResourceConnection
22+
*/
23+
private $resourceConnection;
24+
25+
/**
26+
* @var MetadataPool
27+
*/
28+
private $metadataPool;
29+
30+
/**
31+
* @param ResourceConnection $resourceConnection
32+
* @param MetadataPool $metadataPool
33+
*/
34+
public function __construct(
35+
ResourceConnection $resourceConnection,
36+
MetadataPool $metadataPool
37+
) {
38+
$this->resourceConnection = $resourceConnection;
39+
$this->metadataPool = $metadataPool;
40+
}
41+
42+
/**
43+
* Deletes data from attribute table by attribute set id.
44+
*
45+
* @param AbstractModel $object
46+
* @param int $attributeSetId
47+
* @return void
48+
*/
49+
public function removeData(AbstractModel $object, int $attributeSetId): void
50+
{
51+
$backendTable = $object->getBackend()->getTable();
52+
if ($backendTable) {
53+
$linkField = $this->metadataPool
54+
->getMetadata(ProductInterface::class)
55+
->getLinkField();
56+
57+
$backendLinkField = $object->getBackend()->getEntityIdField();
58+
59+
$select = $this->resourceConnection->getConnection()->select()
60+
->from(['b' => $backendTable])
61+
->join(
62+
['e' => $object->getEntity()->getEntityTable()],
63+
"b.$backendLinkField = e.$linkField"
64+
)->where('b.attribute_id = ?', $object->getId())
65+
->where('e.attribute_set_id = ?', $attributeSetId);
66+
67+
$this->resourceConnection->getConnection()->query($select->deleteFromSelect('b'));
68+
}
69+
}
70+
}

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/AttributeTest.php

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@
88

99
namespace Magento\Catalog\Test\Unit\Model\ResourceModel;
1010

11-
use Magento\Catalog\Api\Data\ProductInterface;
1211
use Magento\Catalog\Model\Attribute\LockValidatorInterface;
1312
use Magento\Catalog\Model\ResourceModel\Attribute;
13+
use Magento\Catalog\Model\ResourceModel\Attribute\RemoveProductAttributeData;
1414
use Magento\Eav\Model\Config;
1515
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
1616
use Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend;
1717
use Magento\Eav\Model\ResourceModel\Entity\Type;
1818
use Magento\Framework\App\ResourceConnection;
1919
use Magento\Framework\DB\Adapter\AdapterInterface as Adapter;
20-
use Magento\Framework\EntityManager\EntityMetadataInterface;
21-
use Magento\Framework\EntityManager\MetadataPool;
2220
use Magento\Framework\Model\AbstractModel;
2321
use Magento\Framework\Model\ResourceModel\Db\Context;
2422
use Magento\ResourceConnections\DB\Select;
@@ -72,9 +70,9 @@ class AttributeTest extends TestCase
7270
private $lockValidatorMock;
7371

7472
/**
75-
* @var EntityMetadataInterface|MockObject
73+
* @var RemoveProductAttributeData|MockObject
7674
*/
77-
private $entityMetaDataInterfaceMock;
75+
private $removeProductAttributeDataMock;
7876

7977
/**
8078
* @inheritDoc
@@ -88,13 +86,7 @@ protected function setUp(): void
8886

8987
$this->connectionMock = $this->getMockBuilder(Adapter::class)
9088
->getMockForAbstractClass();
91-
$this->connectionMock->expects($this->once())->method('select')->willReturn($this->selectMock);
92-
$this->connectionMock->expects($this->once())->method('query')->willReturn($this->selectMock);
9389
$this->connectionMock->expects($this->once())->method('delete')->willReturn($this->selectMock);
94-
$this->selectMock->expects($this->once())->method('from')->willReturnSelf();
95-
$this->selectMock->expects($this->once())->method('join')->willReturnSelf();
96-
$this->selectMock->expects($this->any())->method('where')->willReturnSelf();
97-
$this->selectMock->expects($this->any())->method('deleteFromSelect')->willReturnSelf();
9890

9991
$this->resourceMock = $this->getMockBuilder(ResourceConnection::class)
10092
->disableOriginalConstructor()
@@ -117,26 +109,10 @@ protected function setUp(): void
117109
->disableOriginalConstructor()
118110
->setMethods(['validate'])
119111
->getMockForAbstractClass();
120-
$this->entityMetaDataInterfaceMock = $this->getMockBuilder(EntityMetadataInterface::class)
112+
$this->removeProductAttributeDataMock = $this->getMockBuilder(RemoveProductAttributeData::class)
113+
->setMethods(['removeData'])
121114
->disableOriginalConstructor()
122-
->getMockForAbstractClass();
123-
}
124-
125-
/**
126-
* Sets object non-public property.
127-
*
128-
* @param mixed $object
129-
* @param string $propertyName
130-
* @param mixed $value
131-
*
132-
* @return void
133-
*/
134-
private function setObjectProperty($object, string $propertyName, $value) : void
135-
{
136-
$reflectionClass = new \ReflectionClass($object);
137-
$reflectionProperty = $reflectionClass->getProperty($propertyName);
138-
$reflectionProperty->setAccessible(true);
139-
$reflectionProperty->setValue($object, $value);
115+
->getMock();
140116
}
141117

142118
/**
@@ -156,28 +132,22 @@ public function testDeleteEntity() : void
156132
];
157133

158134
$backendTableName = 'weee_tax';
159-
$backendFieldName = 'value_id';
160135

161136
$attributeModel = $this->getMockBuilder(Attribute::class)
162-
->setMethods(['getEntityAttribute', 'getMetadataPool', 'getConnection', 'getTable'])
137+
->setMethods(['getEntityAttribute', 'getConnection', 'getTable'])
163138
->setConstructorArgs([
164139
$this->contextMock,
165140
$this->storeManagerMock,
166141
$this->eavEntityTypeMock,
167142
$this->eavConfigMock,
168143
$this->lockValidatorMock,
169144
null,
145+
$this->removeProductAttributeDataMock
170146
])->getMock();
171147
$attributeModel->expects($this->any())
172148
->method('getEntityAttribute')
173149
->with($entityAttributeId)
174150
->willReturn($result);
175-
$metadataPoolMock = $this->getMockBuilder(MetadataPool::class)
176-
->disableOriginalConstructor()
177-
->setMethods(['getMetadata'])
178-
->getMock();
179-
180-
$this->setObjectProperty($attributeModel, 'metadataPool', $metadataPoolMock);
181151

182152
$eavAttributeMock = $this->getMockBuilder(AbstractAttribute::class)
183153
->disableOriginalConstructor()
@@ -204,7 +174,7 @@ public function testDeleteEntity() : void
204174

205175
$backendModelMock = $this->getMockBuilder(AbstractBackend::class)
206176
->disableOriginalConstructor()
207-
->setMethods(['getBackend', 'getTable', 'getEntityIdField'])
177+
->setMethods(['getBackend', 'getTable'])
208178
->getMock();
209179

210180
$abstractAttributeMock = $this->getMockBuilder(AbstractAttribute::class)
@@ -216,16 +186,10 @@ public function testDeleteEntity() : void
216186
$eavAttributeMock->expects($this->any())->method('getEntity')->willReturn($abstractAttributeMock);
217187

218188
$backendModelMock->expects($this->any())->method('getTable')->willReturn($backendTableName);
219-
$backendModelMock->expects($this->once())->method('getEntityIdField')->willReturn($backendFieldName);
220-
221-
$metadataPoolMock->expects($this->any())
222-
->method('getMetadata')
223-
->with(ProductInterface::class)
224-
->willReturn($this->entityMetaDataInterfaceMock);
225189

226-
$this->entityMetaDataInterfaceMock->expects($this->any())
227-
->method('getLinkField')
228-
->willReturn('row_id');
190+
$this->removeProductAttributeDataMock->expects($this->once())
191+
->method('removeData')
192+
->with($abstractModelMock, $result['attribute_set_id']);
229193

230194
$attributeModel->expects($this->any())->method('getConnection')->willReturn($this->connectionMock);
231195
$attributeModel->expects($this->any())

app/code/Magento/TaxImportExport/view/adminhtml/templates/importExport.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ script;
7474
<div class="fieldset admin__field">
7575
<span class="admin__field-label"><span><?= $block->escapeHtml(__('Export Tax Rates')) ?></span></span>
7676
<div class="admin__field-control">
77-
<?= $block->getButtonHtml(__('Export Tax Rates'), "this.form.submit()") ?>
77+
<?= $block->getButtonHtml(__('Export Tax Rates'), "export_form.submit()") ?>
7878
</div>
7979
</div>
8080
<?php if ($block->getUseContainer()):?>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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\Weee\Plugin\Catalog\ResourceModel\Attribute;
9+
10+
use Magento\Catalog\Model\ResourceModel\Attribute\RemoveProductAttributeData;
11+
use Magento\Framework\App\ResourceConnection;
12+
use Magento\Framework\Model\AbstractModel;
13+
14+
/**
15+
* Plugin for deleting wee tax attributes data on unassigning weee attribute from attribute set.
16+
*/
17+
class RemoveProductWeeData
18+
{
19+
/**
20+
* @var ResourceConnection
21+
*/
22+
private $resourceConnection;
23+
24+
/**
25+
* @param ResourceConnection $resourceConnection
26+
*/
27+
public function __construct(
28+
ResourceConnection $resourceConnection
29+
) {
30+
$this->resourceConnection = $resourceConnection;
31+
}
32+
33+
/**
34+
* Deletes wee tax attributes data on unassigning weee attribute from attribute set.
35+
*
36+
* @param RemoveProductAttributeData $subject
37+
* @param \Closure $proceed
38+
* @param AbstractModel $object
39+
* @param int $attributeSetId
40+
* @return void
41+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
42+
*/
43+
public function aroundRemoveData(
44+
RemoveProductAttributeData $subject,
45+
\Closure $proceed,
46+
AbstractModel $object,
47+
int $attributeSetId
48+
) {
49+
if ($object->getFrontendInput() == 'weee') {
50+
$select =$this->resourceConnection->getConnection()->select()
51+
->from(['b' => $this->resourceConnection->getTableName('weee_tax')])
52+
->join(
53+
['e' => $object->getEntity()->getEntityTable()],
54+
'b.entity_id = e.entity_id'
55+
)->where('b.attribute_id = ?', $object->getAttributeId())
56+
->where('e.attribute_set_id = ?', $attributeSetId);
57+
58+
$this->resourceConnection->getConnection()->query($select->deleteFromSelect('b'));
59+
} else {
60+
$proceed($object, $attributeSetId);
61+
}
62+
}
63+
}

app/code/Magento/Weee/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,7 @@
8181
<type name="Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper">
8282
<plugin name="weeeAttributeOptionsProcess" type="Magento\Weee\Plugin\Catalog\Controller\Adminhtml\Product\Initialization\Helper\ProcessTaxAttribute"/>
8383
</type>
84+
<type name="Magento\Catalog\Model\ResourceModel\Attribute\RemoveProductAttributeData">
85+
<plugin name="removeWeeAttributesData" type="Magento\Weee\Plugin\Catalog\ResourceModel\Attribute\RemoveProductWeeData" />
86+
</type>
8487
</config>

0 commit comments

Comments
 (0)