Skip to content

Commit b95691e

Browse files
committed
MAGETWO-58918: Unable to create custom image attribute in category - for 2.1.x
1 parent acca7cb commit b95691e

File tree

3 files changed

+46
-29
lines changed

3 files changed

+46
-29
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ public function execute()
266266
public function imagePreprocessing(array $data)
267267
{
268268
$emptyImageAttributes = $this->getEmptyImageAttributes($data);
269-
foreach ($emptyImageAttributes as $attributeCode => $attributeModel) {
269+
$attributeCodes = array_keys($emptyImageAttributes);
270+
foreach ($attributeCodes as $attributeCode) {
270271
$data[$attributeCode] = false;
271272
}
272273

app/code/Magento/Catalog/Model/Category/DataProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ public function getData()
224224
private function convertValues(Category $category, array $categoryData)
225225
{
226226
$imageAttributes = $this->getImageAttributes($category, $categoryData);
227-
foreach ($imageAttributes as $attributeCode => $attribute) {
227+
$attributeCodes = array_keys($imageAttributes);
228+
foreach ($attributeCodes as $attributeCode) {
228229
unset($categoryData[$attributeCode]);
229230
$categoryData[$attributeCode][0]['name'] = $category->getData($attributeCode);
230231
$categoryData[$attributeCode][0]['url'] = $category->getImageUrl($attributeCode);

lib/internal/Magento/Framework/App/Utility/Files.php

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,33 +1287,7 @@ public function classFileExists($class, &$path = '')
12871287

12881288
$directories = array_merge($directories, $this->getPaths());
12891289

1290-
foreach ($directories as $dir) {
1291-
$fullPath = $dir . '/' . $path;
1292-
if ($this->classFileExistsCheckContent($fullPath, $namespace, $className)) {
1293-
return true;
1294-
}
1295-
$classParts = explode('/', $path, 3);
1296-
if (count($classParts) >= 3) {
1297-
// Check if it's PSR-4 class with trimmed vendor and package name parts
1298-
$trimmedFullPath = $dir . '/' . $classParts[2];
1299-
if ($this->classFileExistsCheckContent($trimmedFullPath, $namespace, $className)) {
1300-
return true;
1301-
}
1302-
}
1303-
$classParts = explode('/', $path, 4);
1304-
if (count($classParts) >= 4) {
1305-
// Check if it's a library under framework directory
1306-
$trimmedFullPath = $dir . '/' . $classParts[3];
1307-
if ($this->classFileExistsCheckContent($trimmedFullPath, $namespace, $className)) {
1308-
return true;
1309-
}
1310-
$trimmedFullPath = $dir . '/' . $classParts[2] . '/' . $classParts[3];
1311-
if ($this->classFileExistsCheckContent($trimmedFullPath, $namespace, $className)) {
1312-
return true;
1313-
}
1314-
}
1315-
}
1316-
return false;
1290+
return $this->checkDirectories($path, $directories, $namespace, $className);
13171291
}
13181292

13191293
/**
@@ -1555,4 +1529,45 @@ protected function getFilesSubset(array $dirPatterns, $fileNamePattern, $exclude
15551529
}
15561530
return $fileSet;
15571531
}
1532+
1533+
/**
1534+
* Check class exists in searchable directories.
1535+
*
1536+
* @param string $path
1537+
* @param array $directories
1538+
* @param string $namespace
1539+
* @param string $className
1540+
* @return bool
1541+
*/
1542+
private function checkDirectories(&$path, $directories, $namespace, $className)
1543+
{
1544+
foreach ($directories as $dir) {
1545+
$fullPath = $dir . '/' . $path;
1546+
if ($this->classFileExistsCheckContent($fullPath, $namespace, $className)) {
1547+
return true;
1548+
}
1549+
$classParts = explode('/', $path, 3);
1550+
if (count($classParts) >= 3) {
1551+
// Check if it's PSR-4 class with trimmed vendor and package name parts
1552+
$trimmedFullPath = $dir . '/' . $classParts[2];
1553+
if ($this->classFileExistsCheckContent($trimmedFullPath, $namespace, $className)) {
1554+
return true;
1555+
}
1556+
}
1557+
$classParts = explode('/', $path, 4);
1558+
if (count($classParts) >= 4) {
1559+
// Check if it's a library under framework directory
1560+
$trimmedFullPath = $dir . '/' . $classParts[3];
1561+
if ($this->classFileExistsCheckContent($trimmedFullPath, $namespace, $className)) {
1562+
return true;
1563+
}
1564+
$trimmedFullPath = $dir . '/' . $classParts[2] . '/' . $classParts[3];
1565+
if ($this->classFileExistsCheckContent($trimmedFullPath, $namespace, $className)) {
1566+
return true;
1567+
}
1568+
}
1569+
}
1570+
1571+
return false;
1572+
}
15581573
}

0 commit comments

Comments
 (0)