Skip to content

Commit ad41c3b

Browse files
🔃 [Magento Community Engineering] Community Contributions - 2.4-develop daily delivery
Accepted Community Pull Requests: - #28044: fixed negative children_count after deleting categories (by @ProkopovVitaliy) - #27616: Load appropriate slider widget on demand to improve performance (by @krzksz) - #27064: Customer attribute frontend labels not using the store label values on the frontend (by @nntoan) Fixed GitHub Issues: - #27969: children_count can become negative after deleting categories (reported by @wojtekn) has been fixed in #28044 by @ProkopovVitaliy in 2.4-develop branch Related commits: 1. 0dfd146 2. 0fea657 3. fc65f5b 4. ce3d97f 5. e7b6e45 6. b07a831 7. 85ecd6e 8. fd7663f 9. 0242849 10. 1ff938c 11. caf9ae2 12. 80e3107 13. 5300e3e 14. 62ee4a2 - #28807: [Issue] Load appropriate slider widget on demand to improve performance (reported by @m2-assistant[bot]) has been fixed in #27616 by @krzksz in 2.4-develop branch Related commits: 1. 2a90e76 2. f799baa 3. 62b9453 4. 8bacfbe 5. e08a0a3 6. 0e6ab83 - #27063: [2.3.x] Customer attribute frontend labels not using the store label values on the frontend (reported by @nntoan) has been fixed in #27064 by @nntoan in 2.4-develop branch Related commits: 1. fdec82c 2. 9a7d68d 3. 0bf66d9 4. 9b6e058 5. aa148c3 6. 4c110b7 7. 705b5be 8. 5749b24 9. d4ba184 10. cec82da 11. 2f0dae9 12. 88da24a 13. e99e6e1 14. 5bc8bba 15. 9f20b7f 16. b1480fb 17. 05fbd1f 18. ef806a5 19. dec273f 20. 458ce8d 21. 8848c6a 22. 53498e1 23. 893641c 24. 48411f9 25. b4f98d6 26. 040c23d 27. fc9b841 28. 6a912c2 29. e9b4cf0
2 parents 139ddea + f9f2a20 commit ad41c3b

File tree

8 files changed

+309
-150
lines changed

8 files changed

+309
-150
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Category/AggregateCount.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
use Magento\Catalog\Model\Category;
99

1010
/**
11+
* Aggregate count for parent category after deleting child category
12+
*
1113
* Class AggregateCount
1214
*/
1315
class AggregateCount
1416
{
1517
/**
18+
* Reduces children count for parent categories
19+
*
1620
* @param Category $category
1721
* @return void
1822
*/
@@ -25,9 +29,7 @@ public function processDelete(Category $category)
2529
*/
2630
$parentIds = $category->getParentIds();
2731
if ($parentIds) {
28-
$childDecrease = $category->getChildrenCount() + 1;
29-
// +1 is itself
30-
$data = ['children_count' => new \Zend_Db_Expr('children_count - ' . $childDecrease)];
32+
$data = ['children_count' => new \Zend_Db_Expr('children_count - 1')];
3133
$where = ['entity_id IN(?)' => $parentIds];
3234
$resourceModel->getConnection()->update($resourceModel->getEntityTable(), $data, $where);
3335
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Test\Unit\Model\ResourceModel\Category;
9+
10+
use Magento\Catalog\Model\Category;
11+
use Magento\Catalog\Model\ResourceModel\Category\AggregateCount;
12+
use Magento\Catalog\Model\ResourceModel\Category as ResourceCategory;
13+
use Magento\Framework\DB\Adapter\AdapterInterface;
14+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
15+
use PHPUnit\Framework\MockObject\MockObject;
16+
use PHPUnit\Framework\TestCase;
17+
18+
/**
19+
* Aggregate count model test
20+
*/
21+
class AggregateCountTest extends TestCase
22+
{
23+
24+
/**
25+
* @var AggregateCount
26+
*/
27+
protected $aggregateCount;
28+
29+
/**
30+
* @var ObjectManagerHelper
31+
*/
32+
protected $objectManagerHelper;
33+
34+
/**
35+
* @var Category|MockObject
36+
*/
37+
protected $categoryMock;
38+
39+
/**
40+
* @var ResourceCategory|MockObject
41+
*/
42+
protected $resourceCategoryMock;
43+
44+
/**
45+
* @var AdapterInterface|MockObject
46+
*/
47+
protected $connectionMock;
48+
49+
/**
50+
* {@inheritdoc}
51+
*/
52+
public function setUp(): void
53+
{
54+
$this->categoryMock = $this->createMock(Category::class);
55+
$this->resourceCategoryMock = $this->createMock(ResourceCategory::class);
56+
$this->connectionMock = $this->getMockBuilder(AdapterInterface::class)
57+
->getMockForAbstractClass();
58+
$this->objectManagerHelper = new ObjectManagerHelper($this);
59+
$this->aggregateCount = $this->objectManagerHelper->getObject(AggregateCount::class);
60+
}
61+
62+
/**
63+
* @return void
64+
*/
65+
public function testProcessDelete(): void
66+
{
67+
$parentIds = 3;
68+
$table = 'catalog_category_entity';
69+
70+
$this->categoryMock->expects($this->once())
71+
->method('getResource')
72+
->willReturn($this->resourceCategoryMock);
73+
$this->categoryMock->expects($this->once())
74+
->method('getParentIds')
75+
->willReturn($parentIds);
76+
$this->resourceCategoryMock->expects($this->any())
77+
->method('getEntityTable')
78+
->willReturn($table);
79+
$this->resourceCategoryMock->expects($this->once())
80+
->method('getConnection')
81+
->willReturn($this->connectionMock);
82+
$this->connectionMock->expects($this->once())
83+
->method('update')
84+
->with(
85+
$table,
86+
['children_count' => new \Zend_Db_Expr('children_count - 1')],
87+
['entity_id IN(?)' => $parentIds]
88+
);
89+
$this->aggregateCount->processDelete($this->categoryMock);
90+
}
91+
}

app/code/Magento/Customer/Block/DataProviders/AddressAttributeData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function getFrontendLabel(string $attributeCode): string
5252
{
5353
try {
5454
$attribute = $this->addressMetadata->getAttributeMetadata($attributeCode);
55-
$frontendLabel = $attribute->getFrontendLabel();
55+
$frontendLabel = $attribute->getStoreLabel() ?: $attribute->getFrontendLabel();
5656
} catch (NoSuchEntityException $e) {
5757
$frontendLabel = '';
5858
}

app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/range.js

Lines changed: 14 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ define([
77
'ko',
88
'jquery',
99
'underscore',
10-
'../template/renderer',
11-
'jquery-ui-modules/slider'
10+
'../template/renderer'
1211
], function (ko, $, _, renderer) {
1312
'use strict';
1413

1514
var isTouchDevice = !_.isUndefined(document.ontouchstart),
16-
sliderFn = 'slider';
15+
sliderFn = 'slider',
16+
sliderModule = 'jquery-ui-modules/slider';
17+
18+
if (isTouchDevice) {
19+
sliderFn = 'touchSlider';
20+
sliderModule = 'mage/touch-slider';
21+
}
1722

1823
ko.bindingHandlers.range = {
1924

@@ -41,7 +46,9 @@ define([
4146
}
4247
});
4348

44-
$(element)[sliderFn](config);
49+
require([sliderModule], function () {
50+
$(element)[sliderFn](config);
51+
});
4552
},
4653

4754
/**
@@ -55,149 +62,11 @@ define([
5562

5663
config.value = ko.unwrap(config.value);
5764

58-
$(element)[sliderFn]('option', config);
65+
require([sliderModule], function () {
66+
$(element)[sliderFn]('option', config);
67+
});
5968
}
6069
};
6170

6271
renderer.addAttribute('range');
63-
64-
if (!isTouchDevice) {
65-
return;
66-
}
67-
68-
$.widget('mage.touchSlider', $.ui.slider, {
69-
70-
/**
71-
* Creates instance of widget.
72-
*
73-
* @override
74-
*/
75-
_create: function () {
76-
_.bindAll(
77-
this,
78-
'_mouseDown',
79-
'_mouseMove',
80-
'_onTouchEnd'
81-
);
82-
83-
return this._superApply(arguments);
84-
},
85-
86-
/**
87-
* Initializes mouse events on element.
88-
* @override
89-
*/
90-
_mouseInit: function () {
91-
var result = this._superApply(arguments);
92-
93-
this.element
94-
.off('mousedown.' + this.widgetName)
95-
.on('touchstart.' + this.widgetName, this._mouseDown);
96-
97-
return result;
98-
},
99-
100-
/**
101-
* Elements' 'mousedown' event handler polyfill.
102-
* @override
103-
*/
104-
_mouseDown: function (event) {
105-
var prevDelegate = this._mouseMoveDelegate,
106-
result;
107-
108-
event = this._touchToMouse(event);
109-
result = this._super(event);
110-
111-
if (prevDelegate === this._mouseMoveDelegate) {
112-
return result;
113-
}
114-
115-
$(document)
116-
.off('mousemove.' + this.widgetName)
117-
.off('mouseup.' + this.widgetName);
118-
119-
$(document)
120-
.on('touchmove.' + this.widgetName, this._mouseMove)
121-
.on('touchend.' + this.widgetName, this._onTouchEnd)
122-
.on('tochleave.' + this.widgetName, this._onTouchEnd);
123-
124-
return result;
125-
},
126-
127-
/**
128-
* Documents' 'mousemove' event handler polyfill.
129-
*
130-
* @override
131-
* @param {Event} event - Touch event object.
132-
*/
133-
_mouseMove: function (event) {
134-
event = this._touchToMouse(event);
135-
136-
return this._super(event);
137-
},
138-
139-
/**
140-
* Documents' 'touchend' event handler.
141-
*/
142-
_onTouchEnd: function (event) {
143-
$(document).trigger('mouseup');
144-
145-
return this._mouseUp(event);
146-
},
147-
148-
/**
149-
* Removes previously assigned touch handlers.
150-
*
151-
* @override
152-
*/
153-
_mouseUp: function () {
154-
this._removeTouchHandlers();
155-
156-
return this._superApply(arguments);
157-
},
158-
159-
/**
160-
* Removes previously assigned touch handlers.
161-
*
162-
* @override
163-
*/
164-
_mouseDestroy: function () {
165-
this._removeTouchHandlers();
166-
167-
return this._superApply(arguments);
168-
},
169-
170-
/**
171-
* Removes touch events from document object.
172-
*/
173-
_removeTouchHandlers: function () {
174-
$(document)
175-
.off('touchmove.' + this.widgetName)
176-
.off('touchend.' + this.widgetName)
177-
.off('touchleave.' + this.widgetName);
178-
},
179-
180-
/**
181-
* Adds properties to the touch event to mimic mouse event.
182-
*
183-
* @param {Event} event - Touch event object.
184-
* @returns {Event}
185-
*/
186-
_touchToMouse: function (event) {
187-
var orig = event.originalEvent,
188-
touch = orig.touches[0];
189-
190-
return _.extend(event, {
191-
which: 1,
192-
pageX: touch.pageX,
193-
pageY: touch.pageY,
194-
clientX: touch.clientX,
195-
clientY: touch.clientY,
196-
screenX: touch.screenX,
197-
screenY: touch.screenY
198-
});
199-
}
200-
});
201-
202-
sliderFn = 'touchSlider';
20372
});

dev/tests/integration/testsuite/Magento/Catalog/Model/CategoryTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class CategoryTest extends TestCase
4949
*/
5050
protected $objectManager;
5151

52-
/** @var CategoryRepository */
52+
/** @var CategoryResource */
5353
private $categoryResource;
5454

5555
/** @var CategoryRepositoryInterface */
@@ -355,6 +355,17 @@ public function testDeleteChildren(): void
355355
$this->assertEquals($this->_model->getId(), null);
356356
}
357357

358+
/**
359+
* @magentoDbIsolation enabled
360+
* @magentoAppArea adminhtml
361+
* @magentoDataFixture Magento/Catalog/_files/categories_no_products.php
362+
*/
363+
public function testChildrenCountAfterDeleteParentCategory(): void
364+
{
365+
$this->categoryRepository->deleteByIdentifier(3);
366+
$this->assertEquals(8, $this->categoryResource->getChildrenCount(1));
367+
}
368+
358369
/**
359370
* @magentoDataFixture Magento/Catalog/_files/category.php
360371
*/

dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,22 @@ public function testFaxEnabled(): void
138138
$this->assertStringContainsString('title="Fax"', $block->toHtml());
139139
}
140140

141+
/**
142+
* @magentoDataFixture Magento/Customer/_files/attribute_city_store_label_address.php
143+
*/
144+
public function testCityWithStoreLabel(): void
145+
{
146+
/** @var \Magento\Customer\Block\Form\Register $block */
147+
$block = Bootstrap::getObjectManager()->create(
148+
Register::class
149+
)->setTemplate('Magento_Customer::form/register.phtml')
150+
->setShowAddressFields(true);
151+
$this->setAttributeDataProvider($block);
152+
153+
$this->assertStringNotContainsString('title="City"', $block->toHtml());
154+
$this->assertStringContainsString('title="Suburb"', $block->toHtml());
155+
}
156+
141157
/**
142158
* @inheritdoc
143159
*/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
//@codingStandardsIgnoreFile
7+
/** @var \Magento\Customer\Model\Attribute $model */
8+
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Customer\Model\Attribute::class);
9+
/** @var \Magento\Store\Model\StoreManagerInterface $storeManager */
10+
$storeManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Store\Model\StoreManager::class);
11+
$model->loadByCode('customer_address', 'city');
12+
$storeLabels = $model->getStoreLabels();
13+
$stores = $storeManager->getStores();
14+
/** @var \Magento\Store\Api\Data\WebsiteInterface $website */
15+
foreach ($stores as $store) {
16+
$storeLabels[$store->getId()] = 'Suburb';
17+
}
18+
$model->setStoreLabels($storeLabels);
19+
$model->save();

0 commit comments

Comments
 (0)