Skip to content

Commit ea52f98

Browse files
author
Momotenko,Natalia(nmomotenko)
committed
Merge pull request #538 from magento-troll/MAGETWO-51814
[Troll] Bugfixes
2 parents f93b8da + 975ba0e commit ea52f98

File tree

32 files changed

+448
-96
lines changed

32 files changed

+448
-96
lines changed

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

+42
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ abstract class Category extends \Magento\Backend\App\Action
1717
*/
1818
const ADMIN_RESOURCE = 'Magento_Catalog::categories';
1919

20+
/**
21+
* @var \Magento\Framework\Stdlib\DateTime\Filter\DateTime
22+
*/
23+
private $dateTimeFilter;
24+
2025
/**
2126
* Initialize requested category and put it into registry.
2227
* Root category can be returned, if inappropriate store/category is specified
@@ -107,4 +112,41 @@ protected function ajaxRequestResponse($category, $resultPage)
107112
$resultJson->setData($eventResponse->getData());
108113
return $resultJson;
109114
}
115+
116+
/**
117+
* @return \Magento\Framework\Stdlib\DateTime\Filter\DateTime
118+
*
119+
* @deprecated
120+
*/
121+
private function getDateTimeFilter()
122+
{
123+
if ($this->dateTimeFilter === null) {
124+
$this->dateTimeFilter = \Magento\Framework\App\ObjectManager::getInstance()
125+
->get(\Magento\Framework\Stdlib\DateTime\Filter\DateTime::class);
126+
}
127+
return $this->dateTimeFilter;
128+
}
129+
130+
/**
131+
* Datetime data preprocessing
132+
*
133+
* @param \Magento\Catalog\Model\Category $category
134+
* @param array $postData
135+
*
136+
* @return array
137+
*/
138+
protected function dateTimePreprocessing($category, $postData)
139+
{
140+
$dateFieldFilters = [];
141+
$attributes = $category->getAttributes();
142+
foreach ($attributes as $attrKey => $attribute) {
143+
if ($attribute->getBackend()->getType() == 'datetime') {
144+
if (array_key_exists($attrKey, $postData) && $postData[$attrKey] != '') {
145+
$dateFieldFilters[$attrKey] = $this->getDateTimeFilter();
146+
}
147+
}
148+
}
149+
$inputFilter = new \Zend_Filter_Input($dateFieldFilters, [], $postData);
150+
return $inputFilter->getUnescaped();
151+
}
110152
}

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

+9
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ public function execute()
5050
return $resultRedirect->setPath('catalog/*/', ['_current' => true, 'id' => null]);
5151
}
5252

53+
/**
54+
* Check if there are data in session (if there was an exception on saving category)
55+
*/
56+
$categoryData = $this->_getSession()->getCategoryData(true);
57+
if (is_array($categoryData)) {
58+
unset($categoryData['image']);
59+
$category->addData($categoryData);
60+
}
61+
5362
$resultPageFactory = $this->_objectManager->get('Magento\Framework\View\Result\PageFactory');
5463
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
5564
$resultPage = $resultPageFactory->create();

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ public function execute()
8080
}
8181

8282
/**
83-
* Check if we have data in session (if during category save was exception)
83+
* Check if there are data in session (if there was an exception on saving category)
8484
*/
85-
$data = $this->_getSession()->getCategoryData(true);
86-
if (isset($data['general'])) {
87-
if (isset($data['general']['image']['delete'])) {
88-
$data['general']['image'] = null;
85+
$categoryData = $this->_getSession()->getCategoryData(true);
86+
if (is_array($categoryData)) {
87+
if (isset($categoryData['image']['delete'])) {
88+
$categoryData['image'] = null;
8989
} else {
90-
unset($data['general']['image']);
90+
unset($categoryData['image']);
9191
}
92-
$category->addData($data['general']);
92+
$category->addData($categoryData);
9393
}
9494

9595
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */

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

+32-31
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
/**
1111
* Class Save
12-
*
12+
*
1313
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1414
*/
1515
class Save extends \Magento\Catalog\Controller\Adminhtml\Category
@@ -34,15 +34,13 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Category
3434
* @var array
3535
*/
3636
protected $stringToBoolInputs = [
37-
'general' => [
38-
'custom_use_parent_settings',
39-
'custom_apply_to_products',
40-
'is_active',
41-
'include_in_menu',
42-
'is_anchor',
43-
'use_default' => ['url_key'],
44-
'use_config' => ['available_sort_by', 'filter_price_range', 'default_sort_by']
45-
]
37+
'custom_use_parent_settings',
38+
'custom_apply_to_products',
39+
'is_active',
40+
'include_in_menu',
41+
'is_anchor',
42+
'use_default' => ['url_key'],
43+
'use_config' => ['available_sort_by', 'filter_price_range', 'default_sort_by']
4644
];
4745

4846
/**
@@ -110,15 +108,18 @@ public function execute()
110108
}
111109

112110
$data['general'] = $this->getRequest()->getPostValue();
113-
$isNewCategory = !isset($data['general']['entity_id']);
114-
$data = $this->stringToBoolConverting($data);
115-
$data = $this->imagePreprocessing($data);
116-
$storeId = isset($data['general']['store_id']) ? $data['general']['store_id'] : null;
111+
$categoryPostData = $data['general'];
112+
113+
$isNewCategory = !isset($categoryPostData['entity_id']);
114+
$categoryPostData = $this->stringToBoolConverting($categoryPostData);
115+
$categoryPostData = $this->imagePreprocessing($categoryPostData);
116+
$categoryPostData = $this->dateTimePreprocessing($category, $categoryPostData);
117+
$storeId = isset($categoryPostData['store_id']) ? $categoryPostData['store_id'] : null;
117118
$store = $this->storeManager->getStore($storeId);
118119
$this->storeManager->setCurrentStore($store->getCode());
119-
$parentId = isset($data['general']['parent']) ? $data['general']['parent'] : null;
120-
if ($data['general']) {
121-
$category->addData($this->_filterCategoryPostData($data['general']));
120+
$parentId = isset($categoryPostData['parent']) ? $categoryPostData['parent'] : null;
121+
if ($categoryPostData) {
122+
$category->addData($this->_filterCategoryPostData($categoryPostData));
122123
if ($isNewCategory) {
123124
$parentCategory = $this->getParentCategory($parentId, $storeId);
124125
$category->setPath($parentCategory->getPath());
@@ -128,10 +129,10 @@ public function execute()
128129
/**
129130
* Process "Use Config Settings" checkboxes
130131
*/
131-
$generalPost = $data['general'];
132+
132133
$useConfig = [];
133-
if (isset($generalPost['use_config']) && !empty($generalPost['use_config'])) {
134-
foreach ($generalPost['use_config'] as $attributeCode => $attributeValue) {
134+
if (isset($categoryPostData['use_config']) && !empty($categoryPostData['use_config'])) {
135+
foreach ($categoryPostData['use_config'] as $attributeCode => $attributeValue) {
135136
if ($attributeValue) {
136137
$useConfig[] = $attributeCode;
137138
$category->setData($attributeCode, null);
@@ -141,11 +142,11 @@ public function execute()
141142

142143
$category->setAttributeSetId($category->getDefaultAttributeSetId());
143144

144-
if (isset($data['general']['category_products'])
145-
&& is_string($data['general']['category_products'])
145+
if (isset($categoryPostData['category_products'])
146+
&& is_string($categoryPostData['category_products'])
146147
&& !$category->getProductsReadonly()
147148
) {
148-
$products = json_decode($data['general']['category_products'], true);
149+
$products = json_decode($categoryPostData['category_products'], true);
149150
$category->setPostedProducts($products);
150151
}
151152
$this->_eventManager->dispatch(
@@ -156,8 +157,8 @@ public function execute()
156157
/**
157158
* Check "Use Default Value" checkboxes values
158159
*/
159-
if (isset($generalPost['use_default']) && !empty($generalPost['use_default'])) {
160-
foreach ($generalPost['use_default'] as $attributeCode => $attributeValue) {
160+
if (isset($categoryPostData['use_default']) && !empty($categoryPostData['use_default'])) {
161+
foreach ($categoryPostData['use_default'] as $attributeCode => $attributeValue) {
161162
if ($attributeValue) {
162163
$category->setData($attributeCode, null);
163164
}
@@ -197,15 +198,15 @@ public function execute()
197198
} catch (\Magento\Framework\Exception\AlreadyExistsException $e) {
198199
$this->messageManager->addError($e->getMessage());
199200
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
200-
$this->_getSession()->setCategoryData($data);
201+
$this->_getSession()->setCategoryData($categoryPostData);
201202
} catch (\Magento\Framework\Exception\LocalizedException $e) {
202203
$this->messageManager->addError($e->getMessage());
203204
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
204-
$this->_getSession()->setCategoryData($data);
205+
$this->_getSession()->setCategoryData($categoryPostData);
205206
} catch (\Exception $e) {
206207
$this->messageManager->addError(__('Something went wrong while saving the category.'));
207208
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
208-
$this->_getSession()->setCategoryData($data);
209+
$this->_getSession()->setCategoryData($categoryPostData);
209210
}
210211
}
211212

@@ -248,9 +249,9 @@ public function execute()
248249
*/
249250
public function imagePreprocessing($data)
250251
{
251-
if (empty($data['general']['image'])) {
252-
unset($data['general']['image']);
253-
$data['general']['image']['delete'] = true;
252+
if (empty($data['image'])) {
253+
unset($data['image']);
254+
$data['image']['delete'] = true;
254255
}
255256
return $data;
256257
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ public function afterSave($object)
111111
} catch (\Exception $e) {
112112
$this->_logger->critical($e);
113113
}
114+
} elseif (isset($value[0]['name'])) {
115+
$object->setData($this->getAttribute()->getName(), $value[0]['name']);
116+
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
114117
}
115118
return $this;
116119
}

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,7 @@ public function getData()
201201
return $this->loadedData;
202202
}
203203
$category = $this->getCurrentCategory();
204-
if (!$category->getId()) {
205-
return [];
206-
} else {
204+
if ($category) {
207205
$categoryData = $category->getData();
208206
$categoryData = $this->addUseDefaultSettings($category, $categoryData);
209207
$categoryData = $this->addUseConfigSettings($categoryData);

app/code/Magento/Catalog/Model/Product/Option.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ class Option extends AbstractExtensibleModel implements ProductCustomOptionInter
6363
*/
6464
protected $optionRepository;
6565

66+
/**
67+
* Option type percent
68+
*/
69+
protected static $typePercent = 'percent';
70+
6671
/**#@+
6772
* Constants
6873
*/
@@ -424,7 +429,7 @@ public function afterSave()
424429
*/
425430
public function getPrice($flag = false)
426431
{
427-
if ($flag && $this->getPriceType() == 'percent') {
432+
if ($flag && $this->getPriceType() == self::$typePercent) {
428433
$basePrice = $this->getProduct()->getPriceInfo()->getPrice(BasePrice::PRICE_CODE)->getValue();
429434
$price = $basePrice * ($this->_getData(self::KEY_PRICE) / 100);
430435
return $price;
@@ -827,6 +832,21 @@ public function getExtensionAttributes()
827832
return $this->_getExtensionAttributes();
828833
}
829834

835+
/**
836+
* Return regular price.
837+
*
838+
* @return float|int
839+
*/
840+
public function getRegularPrice()
841+
{
842+
if ($this->getPriceType() == self::$typePercent) {
843+
$basePrice = $this->getProduct()->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue();
844+
$price = $basePrice * ($this->_getData(self::KEY_PRICE) / 100);
845+
return $price;
846+
}
847+
return $this->_getData(self::KEY_PRICE);
848+
}
849+
830850
/**
831851
* @param Product $product
832852
* @return \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection

app/code/Magento/Catalog/Setup/UpgradeData.php

+13
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,20 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
338338
]
339339
);
340340
}
341+
342+
if (version_compare($context->getVersion(), '2.0.7') < 0) {
343+
/** @var EavSetup $eavSetupF */
344+
$eavSetup= $this->eavSetupFactory->create(['setup' => $setup]);
341345

346+
$eavSetup->updateAttribute(
347+
ProductAttributeInterface::ENTITY_TYPE_CODE,
348+
'meta_description',
349+
[
350+
'note' => 'Maximum 255 chars. Meta Description should optimally be between 150-160 characters'
351+
]
352+
);
353+
}
354+
342355
$setup->endSetup();
343356
}
344357
}

app/code/Magento/Catalog/Test/Unit/Model/Product/OptionTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Catalog\Test\Unit\Model\Product;
77

8+
use \Magento\Catalog\Model\Product\Option;
89
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
910

1011
class OptionTest extends \PHPUnit_Framework_TestCase
@@ -33,4 +34,29 @@ public function testGetProductSku()
3334
$this->productMock->expects($this->once())->method('getSku')->willReturn($productSku);
3435
$this->assertEquals($productSku, $this->model->getProductSku());
3536
}
37+
38+
public function testGetRegularPrice()
39+
{
40+
$priceInfoMock = $this->getMockForAbstractClass(
41+
'Magento\Framework\Pricing\PriceInfoInterface',
42+
[],
43+
'',
44+
false,
45+
false,
46+
true,
47+
['getAmount', 'getPrice']
48+
);
49+
$priceInfoMock->expects($this->once())->method('getPrice')->willReturnSelf();
50+
$amountMock = $this->getMockForAbstractClass('Magento\Framework\Pricing\Amount\AmountInterface');
51+
$priceInfoMock->expects($this->once())->method('getAmount')->willReturn($amountMock);
52+
53+
$this->productMock->expects($this->once())->method('getPriceInfo')->willReturn($priceInfoMock);
54+
55+
$amountMock->expects($this->once())->method('getValue')->willReturn(50);
56+
$this->model->setPrice(50);
57+
$this->model->setPriceType(\Magento\Catalog\Model\Product\Option\Value::TYPE_PERCENT);
58+
$this->assertEquals(25, $this->model->getRegularPrice());
59+
$this->model->setPriceType(null);
60+
$this->assertEquals(50, $this->model->getRegularPrice());
61+
}
3662
}

app/code/Magento/Catalog/etc/module.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_Catalog" setup_version="2.0.6">
9+
<module name="Magento_Catalog" setup_version="2.0.7">
1010
<sequence>
1111
<module name="Magento_Eav"/>
1212
<module name="Magento_Cms"/>

app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ protected function critical($e)
724724
private function roundTime($timeStamp)
725725
{
726726
if (is_numeric($timeStamp) && $timeStamp != 0) {
727-
$timeStamp = $this->dateTime->timestamp($this->dateTime->date('Y-m-d 00:00:00'));
727+
$timeStamp = $this->dateTime->timestamp($this->dateTime->date('Y-m-d 00:00:00', $timeStamp));
728728
}
729729

730730
return $timeStamp;

app/code/Magento/Eav/Setup/EavSetup.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ public function addAttributeOption($option)
909909
*
910910
* @param int|string $entityTypeId
911911
* @param int|string $id
912-
* @param string $field
912+
* @param string|array $field
913913
* @param mixed $value
914914
* @param int $sortOrder
915915
* @return $this

0 commit comments

Comments
 (0)