Skip to content

Commit f727054

Browse files
committed
MAGETWO-56557: GITHUB PR#2791
2 parents fe0c96e + 1b30452 commit f727054

File tree

147 files changed

+6215
-1843
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+6215
-1843
lines changed

app/code/Magento/CatalogInventory/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@
7272
<plugin name="catalogInventoryAfterLoad" type="\Magento\CatalogInventory\Model\Plugin\AfterProductLoad"/>
7373
</type>
7474
<type name="Magento\Catalog\Api\ProductRepositoryInterface">
75-
<plugin name="catalogInventoryAroundSave" type="\Magento\CatalogInventory\Model\Plugin\AroundProductRepositorySave"/>
75+
<plugin name="catalogInventoryAroundSave" sortOrder="20" type="Magento\CatalogInventory\Model\Plugin\AroundProductRepositorySave"/>
7676
</type>
7777
</config>

app/code/Magento/CatalogSearch/Model/Search/ReaderPlugin.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,17 @@ public function __construct(
2424
/**
2525
* Merge reader's value with generated
2626
*
27-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
2827
* @param \Magento\Framework\Config\ReaderInterface $subject
29-
* @param \Closure $proceed
30-
* @param string $scope
28+
* @param array $result
29+
* @param string|null $scope
3130
* @return array
31+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3232
*/
33-
public function aroundRead(
33+
public function afterRead(
3434
\Magento\Framework\Config\ReaderInterface $subject,
35-
\Closure $proceed,
35+
array $result,
3636
$scope = null
3737
) {
38-
$result = $proceed($scope);
3938
$result = array_merge_recursive($result, $this->requestGenerator->generate());
4039
return $result;
4140
}

app/code/Magento/CatalogSearch/Test/Unit/Model/Search/ReaderPluginTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ protected function setUp()
2929
);
3030
}
3131

32-
public function testAroundRead()
32+
public function testAfterRead()
3333
{
34+
$readerConfig = ['test' => 'b', 'd' => 'e'];
3435
$this->requestGenerator->expects($this->once())
3536
->method('generate')
3637
->will($this->returnValue(['test' => 'a']));
3738

38-
$result = $this->object->aroundRead(
39+
$result = $this->object->afterRead(
3940
$this->getMockBuilder(\Magento\Framework\Config\ReaderInterface::class)
4041
->disableOriginalConstructor()->getMock(),
41-
function () {
42-
return ['test' => 'b', 'd' => 'e'];
43-
}
42+
$readerConfig,
43+
null
4444
);
4545

4646
$this->assertEquals(['test' => ['b', 'a'], 'd' => 'e'], $result);

app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Category/Move.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class Move
1414
/** @var CategoryUrlPathGenerator */
1515
protected $categoryUrlPathGenerator;
1616

17+
/**
18+
* @var ChildrenCategoriesProvider
19+
*/
20+
private $childrenCategoriesProvider;
21+
1722
/**
1823
* @param CategoryUrlPathGenerator $categoryUrlPathGenerator
1924
* @param ChildrenCategoriesProvider $childrenCategoriesProvider
@@ -27,22 +32,23 @@ public function __construct(
2732
}
2833

2934
/**
35+
* Perform url updating for children categories
36+
*
3037
* @param \Magento\Catalog\Model\ResourceModel\Category $subject
31-
* @param callable $proceed
38+
* @param \Magento\Catalog\Model\ResourceModel\Category $result
3239
* @param Category $category
3340
* @param Category $newParent
3441
* @param null|int $afterCategoryId
35-
* @return callable
42+
* @return \Magento\Catalog\Model\ResourceModel\Category
3643
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3744
*/
38-
public function aroundChangeParent(
45+
public function afterChangeParent(
3946
\Magento\Catalog\Model\ResourceModel\Category $subject,
40-
\Closure $proceed,
41-
$category,
42-
$newParent,
47+
\Magento\Catalog\Model\ResourceModel\Category $result,
48+
Category $category,
49+
Category $newParent,
4350
$afterCategoryId
4451
) {
45-
$result = $proceed($category, $newParent, $afterCategoryId);
4652
$category->setUrlPath($this->categoryUrlPathGenerator->getUrlPath($category));
4753
$category->getResource()->saveAttribute($category, 'url_path');
4854
$this->updateUrlPathForChildren($category);

app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Storage.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@ public function __construct(
3333

3434
/**
3535
* @param \Magento\UrlRewrite\Model\StorageInterface $object
36-
* @param callable $proceed
37-
* @param array $urls
36+
* @param null $result
37+
* @param \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[] $urls
3838
* @return void
3939
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4040
*/
41-
public function aroundReplace(StorageInterface $object, \Closure $proceed, array $urls)
41+
public function afterReplace(StorageInterface $object, $result, array $urls)
4242
{
43-
$proceed($urls);
4443
$toSave = [];
4544
foreach ($this->filterUrls($urls) as $record) {
4645
$metadata = $record->getMetadata();

app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Store/Group.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,19 @@ public function __construct(
6363
}
6464

6565
/**
66-
* @param \Magento\Store\Model\ResourceModel\Group $object
67-
* @param callable $proceed
66+
* Perform updating url for categories and products assigned to the group
67+
*
68+
* @param \Magento\Store\Model\ResourceModel\Group $subject
69+
* @param \Magento\Store\Model\ResourceModel\Group $result
6870
* @param AbstractModel $group
6971
* @return \Magento\Store\Model\ResourceModel\Group
7072
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
7173
*/
72-
public function aroundSave(
73-
\Magento\Store\Model\ResourceModel\Group $object,
74-
\Closure $proceed,
74+
public function afterSave(
75+
\Magento\Store\Model\ResourceModel\Group $subject,
76+
\Magento\Store\Model\ResourceModel\Group $result,
7577
AbstractModel $group
7678
) {
77-
$originGroup = $group;
78-
$result = $proceed($originGroup);
7979
if (!$group->isObjectNew()
8080
&& ($group->dataHasChangedFor('website_id')
8181
|| $group->dataHasChangedFor('root_category_id'))

app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Store/View.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
namespace Magento\CatalogUrlRewrite\Model\Category\Plugin\Store;
77

8-
use Magento\Catalog\Model\Category;
98
use Magento\Catalog\Model\CategoryFactory;
109
use Magento\Catalog\Model\ProductFactory;
1110
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;
@@ -53,19 +52,19 @@ public function __construct(
5352
}
5453

5554
/**
56-
* @param \Magento\Store\Model\ResourceModel\Store $object
57-
* @param callable $proceed
55+
* Perform updating url for categories and products assigned to the store view
56+
*
57+
* @param \Magento\Store\Model\ResourceModel\Store $subject
58+
* @param \Magento\Store\Model\ResourceModel\Store $result
5859
* @param AbstractModel $store
5960
* @return \Magento\Store\Model\ResourceModel\Store
6061
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
6162
*/
62-
public function aroundSave(
63-
\Magento\Store\Model\ResourceModel\Store $object,
64-
\Closure $proceed,
63+
public function afterSave(
64+
\Magento\Store\Model\ResourceModel\Store $subject,
65+
\Magento\Store\Model\ResourceModel\Store $result,
6566
AbstractModel $store
6667
) {
67-
$originStore = $store;
68-
$result = $proceed($originStore);
6968
if ($store->isObjectNew() || $store->dataHasChangedFor('group_id')) {
7069
if (!$store->isObjectNew()) {
7170
$this->urlPersist->deleteByData([UrlRewrite::STORE_ID => $store->getId()]);
@@ -102,6 +101,7 @@ protected function generateProductUrls($websiteId, $originWebsiteId, $storeId)
102101
->addCategoryIds()
103102
->addAttributeToSelect(['name', 'url_path', 'url_key', 'visibility'])
104103
->addWebsiteFilter($websiteIds);
104+
105105
foreach ($collection as $product) {
106106
$product->setStoreId($storeId);
107107
/** @var \Magento\Catalog\Model\Product $product */
@@ -110,6 +110,7 @@ protected function generateProductUrls($websiteId, $originWebsiteId, $storeId)
110110
$this->productUrlRewriteGenerator->generate($product)
111111
);
112112
}
113+
113114
return $urls;
114115
}
115116

@@ -130,23 +131,26 @@ protected function generateCategoryUrls($rootCategoryId, $storeId)
130131
$this->categoryUrlRewriteGenerator->generate($category)
131132
);
132133
}
134+
133135
return $urls;
134136
}
135137

136138
/**
137-
* @param \Magento\Store\Model\ResourceModel\Store $object
138-
* @param callable $proceed
139+
* Delete unused url rewrites
140+
*
141+
* @param \Magento\Store\Model\ResourceModel\Store $subject
142+
* @param \Magento\Store\Model\ResourceModel\Store $result
139143
* @param AbstractModel $store
140-
* @return mixed
144+
* @return \Magento\Store\Model\ResourceModel\Store
141145
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
142146
*/
143-
public function aroundDelete(
144-
\Magento\Store\Model\ResourceModel\Store $object,
145-
\Closure $proceed,
147+
public function afterDelete(
148+
\Magento\Store\Model\ResourceModel\Store $subject,
149+
\Magento\Store\Model\ResourceModel\Store $result,
146150
AbstractModel $store
147151
) {
148-
$result = $proceed($store);
149152
$this->urlPersist->deleteByData([UrlRewrite::STORE_ID => $store->getId()]);
153+
150154
return $result;
151155
}
152156
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogUrlRewrite\Test\Unit\Model\Category\Plugin\Category;
7+
8+
use Magento\CatalogUrlRewrite\Model\Category\Plugin\Category\Move as CategoryMovePlugin;
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
use Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator;
11+
use Magento\CatalogUrlRewrite\Model\Category\ChildrenCategoriesProvider;
12+
use Magento\Catalog\Model\ResourceModel\Category as CategoryResourceModel;
13+
use Magento\Catalog\Model\Category;
14+
15+
class MoveTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* @var ObjectManager
19+
*/
20+
private $objectManager;
21+
22+
/**
23+
* @var ChildrenCategoriesProvider|\PHPUnit_Framework_MockObject_MockObject
24+
*/
25+
private $childrenCategoriesProviderMock;
26+
27+
/**
28+
* @var CategoryUrlPathGenerator|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $categoryUrlPathGeneratorMock;
31+
32+
/**
33+
* @var CategoryResourceModel|\PHPUnit_Framework_MockObject_MockObject
34+
*/
35+
private $subjectMock;
36+
37+
/**
38+
* @var Category|\PHPUnit_Framework_MockObject_MockObject
39+
*/
40+
private $categoryMock;
41+
42+
/**
43+
* @var CategoryMovePlugin
44+
*/
45+
private $plugin;
46+
47+
protected function setUp()
48+
{
49+
$this->objectManager = new ObjectManager($this);
50+
$this->categoryUrlPathGeneratorMock = $this->getMockBuilder(CategoryUrlPathGenerator::class)
51+
->disableOriginalConstructor()
52+
->setMethods(['getUrlPath'])
53+
->getMock();
54+
$this->childrenCategoriesProviderMock = $this->getMockBuilder(ChildrenCategoriesProvider::class)
55+
->disableOriginalConstructor()
56+
->setMethods(['getChildren'])
57+
->getMock();
58+
$this->subjectMock = $this->getMockBuilder(CategoryResourceModel::class)
59+
->disableOriginalConstructor()
60+
->getMock();
61+
$this->categoryMock = $this->getMockBuilder(Category::class)
62+
->disableOriginalConstructor()
63+
->setMethods(['getResource', 'setUrlPath'])
64+
->getMock();
65+
$this->plugin = $this->objectManager->getObject(
66+
CategoryMovePlugin::class,
67+
[
68+
'categoryUrlPathGenerator' => $this->categoryUrlPathGeneratorMock,
69+
'childrenCategoriesProvider' => $this->childrenCategoriesProviderMock
70+
]
71+
);
72+
}
73+
74+
public function testAfterChangeParent()
75+
{
76+
$urlPath = 'test/path';
77+
$this->categoryMock->expects($this->once())
78+
->method('getResource')
79+
->willReturn($this->subjectMock);
80+
$this->childrenCategoriesProviderMock->expects($this->once())
81+
->method('getChildren')
82+
->with($this->categoryMock, true)
83+
->willReturn([]);
84+
$this->categoryUrlPathGeneratorMock->expects($this->once())
85+
->method('getUrlPath')
86+
->with($this->categoryMock)
87+
->willReturn($urlPath);
88+
$this->categoryMock->expects($this->once())
89+
->method('getResource')
90+
->willReturn($this->subjectMock);
91+
$this->categoryMock->expects($this->once())
92+
->method('setUrlPath')
93+
->with($urlPath);
94+
$this->assertSame(
95+
$this->subjectMock,
96+
$this->plugin->afterChangeParent(
97+
$this->subjectMock,
98+
$this->subjectMock,
99+
$this->categoryMock,
100+
$this->categoryMock,
101+
null
102+
)
103+
);
104+
}
105+
}

0 commit comments

Comments
 (0)