Skip to content

Commit 1b5069e

Browse files
Merge remote-tracking branch 'origin/MC-33732' into 2.4-develop-pr36
2 parents b8802de + ba77e5c commit 1b5069e

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

app/code/Magento/Catalog/Model/Category/Attribute/Backend/Sortby.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ public function beforeSave($object)
102102
}
103103
$object->setData($attributeCode, implode(',', $data) ?: null);
104104
}
105+
if ($attributeCode == 'default_sort_by') {
106+
$data = $object->getData($attributeCode);
107+
$attributeValue = (is_array($data) ? reset($data) : (!empty($data))) ? $data : null;
108+
$object->setData($attributeCode, $attributeValue);
109+
}
105110
if (!$object->hasData($attributeCode)) {
106111
$object->setData($attributeCode, null);
107112
}

dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryRepositoryTest.php

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
namespace Magento\Catalog\Api;
88

99
use Magento\Authorization\Model\Role;
10+
use Magento\Authorization\Model\RoleFactory;
1011
use Magento\Authorization\Model\Rules;
12+
use Magento\Authorization\Model\RulesFactory;
13+
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;
1114
use Magento\Integration\Api\AdminTokenServiceInterface;
1215
use Magento\TestFramework\Helper\Bootstrap;
1316
use Magento\TestFramework\TestCase\WebapiAbstract;
1417
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
15-
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;
16-
use Magento\Authorization\Model\RoleFactory;
17-
use Magento\Authorization\Model\RulesFactory;
1818

1919
/**
2020
* Test repository web API.
@@ -218,6 +218,35 @@ public function testUpdate()
218218
$this->deleteCategory($categoryId);
219219
}
220220

221+
/**
222+
* @magentoApiDataFixture Magento/Catalog/_files/category.php
223+
*/
224+
public function testUpdateWithDefaultSortByAttribute()
225+
{
226+
$categoryId = 333;
227+
$categoryData = [
228+
'name' => 'Update Category Test With default_sort_by Attribute',
229+
'is_active' => true,
230+
"available_sort_by" => [],
231+
'custom_attributes' => [
232+
[
233+
'attribute_code' => 'default_sort_by',
234+
'value' => ["name"],
235+
],
236+
],
237+
];
238+
$result = $this->updateCategory($categoryId, $categoryData);
239+
$this->assertEquals($categoryId, $result['id']);
240+
/** @var \Magento\Catalog\Model\Category $model */
241+
$model = Bootstrap::getObjectManager()->get(\Magento\Catalog\Model\Category::class);
242+
$category = $model->load($categoryId);
243+
$this->assertTrue((bool)$category->getIsActive(), 'Category "is_active" must equal to true');
244+
$this->assertEquals("Update Category Test With default_sort_by Attribute", $category->getName());
245+
$this->assertEquals("name", $category->getDefaultSortBy());
246+
// delete category to clean up auto-generated url rewrites
247+
$this->deleteCategory($categoryId);
248+
}
249+
221250
protected function getSimpleCategoryData($categoryData = [])
222251
{
223252
return [

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductAttributeTypeTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function testAttributeTypeResolver()
5252
attribute_type
5353
entity_type
5454
input_type
55-
}
55+
}
5656
}
5757
}
5858
QUERY;
@@ -125,7 +125,7 @@ public function testComplexAttributeTypeResolver()
125125
attribute_type
126126
entity_type
127127
input_type
128-
}
128+
}
129129
}
130130
}
131131
QUERY;
@@ -199,8 +199,8 @@ public function testUnDefinedAttributeType()
199199
{
200200
attribute_code
201201
attribute_type
202-
entity_type
203-
}
202+
entity_type
203+
}
204204
}
205205
}
206206
QUERY;

0 commit comments

Comments
 (0)