diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php index 694c74b2860fb..3f81b2bbd0ea1 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php @@ -84,6 +84,11 @@ public function execute() */ $data = $this->_getSession()->getCategoryData(true); if (isset($data['general'])) { + if (isset($data['general']['image']['delete'])) { + $data['general']['image'] = null; + } else { + unset($data['general']['image']); + } $category->addData($data['general']); } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php index 0d0d6ee9980d9..852c465b1482a 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php @@ -198,6 +198,10 @@ public function execute() $this->messageManager->addError($e->getMessage()); $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); $this->_getSession()->setCategoryData($data); + } catch (\Magento\Framework\Exception\LocalizedException $e) { + $this->messageManager->addError($e->getMessage()); + $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); + $this->_getSession()->setCategoryData($data); } catch (\Exception $e) { $this->messageManager->addError(__('Something went wrong while saving the category.')); $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); diff --git a/app/code/Magento/Catalog/Model/Category.php b/app/code/Magento/Catalog/Model/Category.php index 686f53261009e..7e0507545c65a 100644 --- a/app/code/Magento/Catalog/Model/Category.php +++ b/app/code/Magento/Catalog/Model/Category.php @@ -661,9 +661,15 @@ public function getImageUrl() $url = false; $image = $this->getImage(); if ($image) { - $url = $this->_storeManager->getStore()->getBaseUrl( - \Magento\Framework\UrlInterface::URL_TYPE_MEDIA - ) . 'catalog/category/' . $image; + if (is_string($image)) { + $url = $this->_storeManager->getStore()->getBaseUrl( + \Magento\Framework\UrlInterface::URL_TYPE_MEDIA + ) . 'catalog/category/' . $image; + } else { + throw new \Magento\Framework\Exception\LocalizedException( + __('Something went wrong while getting the image url.') + ); + } } return $url; } diff --git a/app/code/Magento/Catalog/Model/Category/DataProvider.php b/app/code/Magento/Catalog/Model/Category/DataProvider.php index 11bbea66d99c7..e1d1ee848f288 100644 --- a/app/code/Magento/Catalog/Model/Category/DataProvider.php +++ b/app/code/Magento/Catalog/Model/Category/DataProvider.php @@ -277,12 +277,14 @@ public function getAttributesMeta(Type $entityType) protected function addUseConfigSettings($categoryData) { foreach ($this->elementsWithUseConfigSetting as $elementsWithUseConfigSetting) { - if (!isset($categoryData[$elementsWithUseConfigSetting]) || - ($categoryData[$elementsWithUseConfigSetting] == '') - ) { - $categoryData['use_config'][$elementsWithUseConfigSetting] = true; - } else { - $categoryData['use_config'][$elementsWithUseConfigSetting] = false; + if (!isset($categoryData['use_config'][$elementsWithUseConfigSetting])) { + if (!isset($categoryData[$elementsWithUseConfigSetting]) || + ($categoryData[$elementsWithUseConfigSetting] == '') + ) { + $categoryData['use_config'][$elementsWithUseConfigSetting] = true; + } else { + $categoryData['use_config'][$elementsWithUseConfigSetting] = false; + } } } return $categoryData; diff --git a/dev/tests/functional/tests/app/Magento/CatalogRule/Test/TestCase/CreateCatalogRuleTest.php b/dev/tests/functional/tests/app/Magento/CatalogRule/Test/TestCase/CreateCatalogRuleTest.php index 60180ab446d76..8bf4930fdbcd5 100644 --- a/dev/tests/functional/tests/app/Magento/CatalogRule/Test/TestCase/CreateCatalogRuleTest.php +++ b/dev/tests/functional/tests/app/Magento/CatalogRule/Test/TestCase/CreateCatalogRuleTest.php @@ -39,11 +39,17 @@ class CreateCatalogRuleTest extends AbstractCatalogRuleEntityTest * @param CatalogRule $catalogPriceRule * @param string $product * @param string $conditionEntity + * @param bool $isWithApply * @param Customer $customer * @return array */ - public function testCreate(CatalogRule $catalogPriceRule, $product, $conditionEntity, Customer $customer = null) - { + public function testCreate( + CatalogRule $catalogPriceRule, + $product, + $conditionEntity, + $isWithApply = true, + Customer $customer = null + ) { /** @var CatalogProductSimple $productSimple */ $productSimple = $this->fixtureFactory->createByCode('catalogProductSimple', ['dataset' => $product]); // Prepare data @@ -60,8 +66,10 @@ public function testCreate(CatalogRule $catalogPriceRule, $product, $conditionEn $this->catalogRuleNew->getEditForm()->fill($catalogPriceRule, null, $replace); $this->catalogRuleNew->getFormPageActions()->save(); - // Apply Catalog Price Rule - $this->catalogRuleIndex->getGridPageActions()->applyRules(); + if ($isWithApply) { + // Apply Catalog Price Rule + $this->catalogRuleIndex->getGridPageActions()->applyRules(); + } // Create simple product $productSimple->persist(); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/CategoryTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/CategoryTest.php index 2e80d13233b2f..534a39ad58c9f 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/CategoryTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/CategoryTest.php @@ -339,7 +339,7 @@ public function testSaveActionCategoryWithDangerRequest() ); $this->dispatch('backend/catalog/category/save'); $this->assertSessionMessages( - $this->equalTo(['Something went wrong while saving the category.']), + $this->equalTo(['The value of attribute "is_active" must be set']), \Magento\Framework\Message\MessageInterface::TYPE_ERROR ); }