Skip to content

Commit 17d0647

Browse files
author
Yaroslav Voronoy
committed
Merge remote-tracking branch 'mainline/merchant_beta' into SUPEE-7245
2 parents bf5de91 + 930f1f8 commit 17d0647

File tree

100 files changed

+7935
-58
lines changed

Some content is hidden

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

100 files changed

+7935
-58
lines changed

app/code/Magento/Catalog/Api/CategoryManagementInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,11 @@ public function getTree($rootCategoryId = null, $depth = null);
3333
* @throws \Magento\Framework\Exception\NoSuchEntityException
3434
*/
3535
public function move($categoryId, $parentId, $afterId = null);
36+
37+
/**
38+
* Provide the number of category count
39+
*
40+
* @return int
41+
*/
42+
public function getCount();
3643
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Api;
7+
8+
/**
9+
* @api
10+
*/
11+
interface ProductManagementInterface
12+
{
13+
/**
14+
* Provide the number of product count
15+
*
16+
* @param null|int $status
17+
* @return int
18+
*/
19+
public function getCount($status = null);
20+
}

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,31 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product
2626
*/
2727
protected $productTypeManager;
2828

29+
/**
30+
* @var \Magento\Catalog\Api\ProductRepositoryInterface
31+
*/
32+
protected $productRepository;
33+
2934
/**
3035
* @param Action\Context $context
3136
* @param Builder $productBuilder
3237
* @param Initialization\Helper $initializationHelper
3338
* @param \Magento\Catalog\Model\Product\Copier $productCopier
3439
* @param \Magento\Catalog\Model\Product\TypeTransitionManager $productTypeManager
40+
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
3541
*/
3642
public function __construct(
3743
\Magento\Backend\App\Action\Context $context,
3844
Product\Builder $productBuilder,
3945
Initialization\Helper $initializationHelper,
4046
\Magento\Catalog\Model\Product\Copier $productCopier,
41-
\Magento\Catalog\Model\Product\TypeTransitionManager $productTypeManager
47+
\Magento\Catalog\Model\Product\TypeTransitionManager $productTypeManager,
48+
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository
4249
) {
4350
$this->initializationHelper = $initializationHelper;
4451
$this->productCopier = $productCopier;
4552
$this->productTypeManager = $productTypeManager;
53+
$this->productRepository = $productRepository;
4654
parent::__construct($context, $productBuilder);
4755
}
4856

@@ -72,6 +80,7 @@ public function execute()
7280

7381
$originalSku = $product->getSku();
7482
$product->save();
83+
$this->handleImageRemoveError($data, $product->getId());
7584
$productId = $product->getId();
7685

7786
/**
@@ -140,4 +149,33 @@ public function execute()
140149
}
141150
return $resultRedirect;
142151
}
152+
153+
/**
154+
* Notify customer when image was not deleted in specific case.
155+
* TODO: temporary workaround must be eliminated in MAGETWO-45306
156+
*
157+
* @param array $postData
158+
* @param int $productId
159+
* @return void
160+
*/
161+
private function handleImageRemoveError($postData, $productId)
162+
{
163+
if (isset($postData['product']['media_gallery']['images'])) {
164+
$removedImagesAmount = 0;
165+
foreach ($postData['product']['media_gallery']['images'] as $image) {
166+
if (!empty($image['removed'])) {
167+
$removedImagesAmount++;
168+
}
169+
}
170+
if ($removedImagesAmount) {
171+
$expectedImagesAmount = count($postData['product']['media_gallery']['images']) - $removedImagesAmount;
172+
$product = $this->productRepository->getById($productId);
173+
if ($expectedImagesAmount != count($product->getMediaGallery('images'))) {
174+
$this->messageManager->addNotice(
175+
__('The image cannot be removed as it has been assigned to the other image role')
176+
);
177+
}
178+
}
179+
}
180+
}
143181
}

app/code/Magento/Catalog/Model/CategoryManagement.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\Catalog\Model;
99

10+
use Magento\Catalog\Model\Resource\Category\CollectionFactory;
11+
1012
class CategoryManagement implements \Magento\Catalog\Api\CategoryManagementInterface
1113
{
1214
/**
@@ -22,13 +24,16 @@ class CategoryManagement implements \Magento\Catalog\Api\CategoryManagementInter
2224
/**
2325
* @param \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository
2426
* @param Category\Tree $categoryTree
27+
* @param CollectionFactory $categoriesFactory
2528
*/
2629
public function __construct(
2730
\Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository,
28-
\Magento\Catalog\Model\Category\Tree $categoryTree
31+
\Magento\Catalog\Model\Category\Tree $categoryTree,
32+
\Magento\Catalog\Model\Resource\Category\CollectionFactory $categoriesFactory
2933
) {
3034
$this->categoryRepository = $categoryRepository;
3135
$this->categoryTree = $categoryTree;
36+
$this->categoriesFactory = $categoriesFactory;
3237
}
3338

3439
/**
@@ -72,4 +77,15 @@ public function move($categoryId, $parentId, $afterId = null)
7277
}
7378
return true;
7479
}
80+
81+
/**
82+
* {@inheritdoc}
83+
*/
84+
public function getCount()
85+
{
86+
$categories = $this->categoriesFactory->create();
87+
/** @var \Magento\Catalog\Model\Resource\Category\Collection $categories */
88+
$categories->addAttributeToFilter('parent_id', ['gt' => 0]);
89+
return $categories->getSize();
90+
}
7591
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,11 +1512,11 @@ public function getMediaGalleryImages()
15121512
if (!$this->hasData('media_gallery_images') && is_array($this->getMediaGallery('images'))) {
15131513
$images = $this->_collectionFactory->create();
15141514
foreach ($this->getMediaGallery('images') as $image) {
1515-
if (isset($image['disabled']) && $image['disabled']) {
1515+
if ((isset($image['disabled']) && $image['disabled']) || empty($image['value_id'])) {
15161516
continue;
15171517
}
15181518
$image['url'] = $this->getMediaConfig()->getMediaUrl($image['file']);
1519-
$image['id'] = isset($image['value_id']) ? $image['value_id'] : null;
1519+
$image['id'] = $image['value_id'];
15201520
$image['path'] = $directory->getAbsolutePath($this->getMediaConfig()->getMediaPath($image['file']));
15211521
$images->addItem(new \Magento\Framework\Object($image));
15221522
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Model;
7+
8+
use Magento\Catalog\Api\ProductManagementInterface;
9+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
10+
use Magento\Catalog\Model\Resource\Product\CollectionFactory;
11+
12+
class ProductManagement implements ProductManagementInterface
13+
{
14+
/**
15+
* @var CollectionFactory
16+
*/
17+
protected $productsFactory;
18+
19+
/**
20+
* @param CollectionFactory $productsFactory
21+
*/
22+
public function __construct(CollectionFactory $productsFactory)
23+
{
24+
$this->productsFactory = $productsFactory;
25+
}
26+
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
public function getCount($status = null)
31+
{
32+
$products = $this->productsFactory->create();
33+
/** @var \Magento\Catalog\Model\Resource\Product\Collection $products */
34+
switch ($status) {
35+
case Status::STATUS_ENABLED:
36+
$products->addAttributeToFilter('status', Status::STATUS_ENABLED);
37+
break;
38+
case Status::STATUS_DISABLED:
39+
$products->addAttributeToFilter('status', Status::STATUS_DISABLED);
40+
break;
41+
}
42+
return $products->getSize();
43+
}
44+
}

app/code/Magento/Catalog/Test/Unit/Model/CategoryManagementTest.php

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,35 @@ class CategoryManagementTest extends \PHPUnit_Framework_TestCase
1313
protected $model;
1414

1515
/**
16-
* @var \PHPUnit_Framework_MockObject_MockObject
16+
* @var \Magento\Catalog\Api\CategoryRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
1717
*/
1818
protected $categoryRepositoryMock;
1919

2020
/**
21-
* @var \PHPUnit_Framework_MockObject_MockObject
21+
* @var \Magento\Catalog\Model\Category\Tree|\PHPUnit_Framework_MockObject_MockObject
2222
*/
2323
protected $categoryTreeMock;
2424

25+
/**
26+
* @var \Magento\Catalog\Model\Resource\Category\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
protected $categoriesFactoryMock;
29+
2530
protected function setUp()
2631
{
27-
$this->categoryRepositoryMock = $this->getMock('\Magento\Catalog\Api\CategoryRepositoryInterface');
28-
$this->categoryTreeMock = $this->getMock('\Magento\Catalog\Model\Category\Tree', [], [], '', false);
32+
$this->categoryRepositoryMock = $this->getMock('Magento\Catalog\Api\CategoryRepositoryInterface');
33+
$this->categoryTreeMock = $this->getMock('Magento\Catalog\Model\Category\Tree', [], [], '', false);
34+
$this->categoriesFactoryMock = $this->getMock(
35+
'Magento\Catalog\Model\Resource\Category\CollectionFactory',
36+
['create'],
37+
[],
38+
'',
39+
false
40+
);
2941
$this->model = new \Magento\Catalog\Model\CategoryManagement(
3042
$this->categoryRepositoryMock,
31-
$this->categoryTreeMock
43+
$this->categoryTreeMock,
44+
$this->categoriesFactoryMock
3245
);
3346
}
3447

@@ -171,4 +184,28 @@ public function testMoveWithCouldNotMoveException()
171184
->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('message')));
172185
$this->model->move($categoryId, $parentId, $afterId);
173186
}
187+
188+
public function testGetCount()
189+
{
190+
$categoriesMock = $this->getMock('\Magento\Catalog\Model\Resource\Category\Collection', [], [], '', false);
191+
192+
$this->categoriesFactoryMock
193+
->expects($this->once())
194+
->method('create')
195+
->willReturn($categoriesMock);
196+
$categoriesMock
197+
->expects($this->once())
198+
->method('addAttributeToFilter')
199+
->with('parent_id', ['gt' => 0])
200+
->willReturnSelf();
201+
$categoriesMock
202+
->expects($this->once())
203+
->method('getSize')
204+
->willReturn('expected');
205+
206+
$this->assertEquals(
207+
'expected',
208+
$this->model->getCount()
209+
);
210+
}
174211
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Test\Unit\Model;
7+
8+
class ProductManagementTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\Catalog\Model\ProductManagement
12+
*/
13+
protected $model;
14+
15+
/**
16+
* @var \Magento\Catalog\Model\Resource\Product\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $productsFactoryMock;
19+
20+
protected function setUp()
21+
{
22+
$this->productsFactoryMock = $this->getMock(
23+
'Magento\Catalog\Model\Resource\Product\CollectionFactory',
24+
['create'],
25+
[],
26+
'',
27+
false
28+
);
29+
$this->model = new \Magento\Catalog\Model\ProductManagement(
30+
$this->productsFactoryMock
31+
);
32+
}
33+
34+
public function testGetEnabledCount()
35+
{
36+
$statusEnabled = 1;
37+
$productsMock = $this->getMock('Magento\Catalog\Model\Resource\Product\Collection', [], [], '', false);
38+
39+
$this->productsFactoryMock
40+
->expects($this->once())
41+
->method('create')
42+
->willReturn($productsMock);
43+
$productsMock
44+
->expects($this->once())
45+
->method('addAttributeToFilter')
46+
->with('status', $statusEnabled)
47+
->willReturnSelf();
48+
$productsMock
49+
->expects($this->once())
50+
->method('getSize')
51+
->willReturn('expected');
52+
53+
$this->assertEquals(
54+
'expected',
55+
$this->model->getCount($statusEnabled)
56+
);
57+
}
58+
59+
public function testGetDisabledCount()
60+
{
61+
$statusDisabled = 2;
62+
$productsMock = $this->getMock('\Magento\Catalog\Model\Resource\Product\Collection', [], [], '', false);
63+
64+
$this->productsFactoryMock
65+
->expects($this->once())
66+
->method('create')
67+
->willReturn($productsMock);
68+
$productsMock
69+
->expects($this->once())
70+
->method('addAttributeToFilter')
71+
->with('status', $statusDisabled)
72+
->willReturnSelf();
73+
$productsMock
74+
->expects($this->once())
75+
->method('getSize')
76+
->willReturn('expected');
77+
78+
$this->assertEquals(
79+
'expected',
80+
$this->model->getCount($statusDisabled)
81+
);
82+
}
83+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<preference for="Magento\Catalog\Api\ProductAttributeManagementInterface" type="Magento\Catalog\Model\Product\Attribute\Management" />
4343
<preference for="Magento\Catalog\Api\AttributeSetManagementInterface" type="Magento\Catalog\Model\Product\Attribute\SetManagement" />
4444
<preference for="Magento\Catalog\Api\AttributeSetRepositoryInterface" type="Magento\Catalog\Model\Product\Attribute\SetRepository" />
45+
<preference for="Magento\Catalog\Api\ProductManagementInterface" type="Magento\Catalog\Model\ProductManagement" />
4546
<type name="Magento\Log\Model\Resource\Log">
4647
<plugin name="catalogLog" type="Magento\Catalog\Model\Plugin\Log" />
4748
</type>

app/code/Magento/ConfigurableProduct/Api/ConfigurableProductManagementInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,12 @@ interface ConfigurableProductManagementInterface
2020
* @return \Magento\Catalog\Api\Data\ProductInterface[]
2121
*/
2222
public function generateVariation(\Magento\Catalog\Api\Data\ProductInterface $product, $options);
23+
24+
/**
25+
* Provide the number of product count
26+
*
27+
* @param null|int $status
28+
* @return int
29+
*/
30+
public function getCount($status = null);
2331
}

0 commit comments

Comments
 (0)