Skip to content

Commit 383f7b5

Browse files
author
Oleksandr Iegorov
committed
MAGETWO-93047: rest/all/V1/categories/:categoryID deletes category name
1 parent 2a76139 commit 383f7b5

File tree

1 file changed

+1
-63
lines changed

1 file changed

+1
-63
lines changed

app/code/Magento/Catalog/Plugin/Model/Attribute/Backend/AttributeValidation.php

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1 @@
1-
<?php
2-
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
5-
*/
6-
namespace Magento\Catalog\Plugin\Model\Attribute\Backend;
7-
8-
use Magento\Store\Model\Store;
9-
10-
class AttributeValidation
11-
{
12-
/**
13-
* @var \Magento\Store\Model\StoreManagerInterface
14-
*/
15-
private $storeManager;
16-
17-
/**
18-
* @var array
19-
*/
20-
private $allowedEntityTypes;
21-
22-
/**
23-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
24-
* @param array $allowedEntityTypes
25-
*/
26-
public function __construct(
27-
\Magento\Store\Model\StoreManagerInterface $storeManager,
28-
$allowedEntityTypes = []
29-
) {
30-
$this->storeManager = $storeManager;
31-
$this->allowedEntityTypes = $allowedEntityTypes;
32-
}
33-
34-
/**
35-
* @param \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject
36-
* @param \Closure $proceed
37-
* @param \Magento\Framework\DataObject $entity
38-
* @throws \Magento\Framework\Exception\NoSuchEntityException
39-
* @return bool
40-
*/
41-
public function aroundValidate(
42-
\Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject,
43-
\Closure $proceed,
44-
\Magento\Framework\DataObject $entity
45-
) {
46-
$isAllowedType = !empty(array_filter(
47-
array_map(function ($allowedEntity) use ($entity) {
48-
return $entity instanceof $allowedEntity;
49-
}, $this->allowedEntityTypes)
50-
)
51-
);
52-
53-
if ($isAllowedType && (int) $this->storeManager->getStore()->getId() !== Store::DEFAULT_STORE_ID) {
54-
$attrCode = $subject->getAttribute()->getAttributeCode();
55-
// Null is meaning "no value" which should be overridden by value from default scope
56-
if (array_key_exists($attrCode, $entity->getData()) && $entity->getData($attrCode) === null) {
57-
return true;
58-
}
59-
}
60-
61-
return $proceed($entity);
62-
}
63-
}
1+
<?php/** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */namespace Magento\Catalog\Plugin\Model\Attribute\Backend;use Magento\Store\Model\Store;class AttributeValidation{ /** * @var \Magento\Store\Model\StoreManagerInterface */ private $storeManager; /** * @var array */ private $allowedEntityTypes; /** * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param array $allowedEntityTypes */ public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManager, $allowedEntityTypes = [] ) { $this->storeManager = $storeManager; $this->allowedEntityTypes = $allowedEntityTypes; } /** * @param \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject * @param \Closure $proceed * @param \Magento\Framework\DataObject $entity * @throws \Magento\Framework\Exception\NoSuchEntityException * @return bool */ public function aroundValidate( \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject, \Closure $proceed, \Magento\Framework\DataObject $entity ) { $isAllowedType = !empty(array_filter(array_map(function ($allowedEntity) use ($entity) { return $entity instanceof $allowedEntity; }, $this->allowedEntityTypes))); if ($isAllowedType && (int) $this->storeManager->getStore()->getId() !== Store::DEFAULT_STORE_ID) { $attrCode = $subject->getAttribute()->getAttributeCode(); // Null is meaning "no value" which should be overridden by value from default scope if (array_key_exists($attrCode, $entity->getData()) && $entity->getData($attrCode) === null) { return true; } } return $proceed($entity); }}

0 commit comments

Comments
 (0)