Skip to content

Commit

Permalink
Merge pull request #141 from magento-south/MAGETWO-44657
Browse files Browse the repository at this point in the history
[South] Merchant Beta NewRelic
  • Loading branch information
slavvka committed Nov 9, 2015
2 parents 9bb51a6 + 5b90cce commit c0620c1
Show file tree
Hide file tree
Showing 96 changed files with 7,848 additions and 14 deletions.
7 changes: 7 additions & 0 deletions app/code/Magento/Catalog/Api/CategoryManagementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ public function getTree($rootCategoryId = null, $depth = null);
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function move($categoryId, $parentId, $afterId = null);

/**
* Provide the number of category count
*
* @return int
*/
public function getCount();
}
20 changes: 20 additions & 0 deletions app/code/Magento/Catalog/Api/ProductManagementInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Api;

/**
* @api
*/
interface ProductManagementInterface
{
/**
* Provide the number of product count
*
* @param null|int $status
* @return int
*/
public function getCount($status = null);
}
18 changes: 17 additions & 1 deletion app/code/Magento/Catalog/Model/CategoryManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Magento\Catalog\Model;

use Magento\Catalog\Model\Resource\Category\CollectionFactory;

class CategoryManagement implements \Magento\Catalog\Api\CategoryManagementInterface
{
/**
Expand All @@ -22,13 +24,16 @@ class CategoryManagement implements \Magento\Catalog\Api\CategoryManagementInter
/**
* @param \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository
* @param Category\Tree $categoryTree
* @param CollectionFactory $categoriesFactory
*/
public function __construct(
\Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository,
\Magento\Catalog\Model\Category\Tree $categoryTree
\Magento\Catalog\Model\Category\Tree $categoryTree,
\Magento\Catalog\Model\Resource\Category\CollectionFactory $categoriesFactory
) {
$this->categoryRepository = $categoryRepository;
$this->categoryTree = $categoryTree;
$this->categoriesFactory = $categoriesFactory;
}

/**
Expand Down Expand Up @@ -72,4 +77,15 @@ public function move($categoryId, $parentId, $afterId = null)
}
return true;
}

/**
* {@inheritdoc}
*/
public function getCount()
{
$categories = $this->categoriesFactory->create();
/** @var \Magento\Catalog\Model\Resource\Category\Collection $categories */
$categories->addAttributeToFilter('parent_id', ['gt' => 0]);
return $categories->getSize();
}
}
44 changes: 44 additions & 0 deletions app/code/Magento/Catalog/Model/ProductManagement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Model;

use Magento\Catalog\Api\ProductManagementInterface;
use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\Catalog\Model\Resource\Product\CollectionFactory;

class ProductManagement implements ProductManagementInterface
{
/**
* @var CollectionFactory
*/
protected $productsFactory;

/**
* @param CollectionFactory $productsFactory
*/
public function __construct(CollectionFactory $productsFactory)
{
$this->productsFactory = $productsFactory;
}

/**
* {@inheritdoc}
*/
public function getCount($status = null)
{
$products = $this->productsFactory->create();
/** @var \Magento\Catalog\Model\Resource\Product\Collection $products */
switch ($status) {
case Status::STATUS_ENABLED:
$products->addAttributeToFilter('status', Status::STATUS_ENABLED);
break;
case Status::STATUS_DISABLED:
$products->addAttributeToFilter('status', Status::STATUS_DISABLED);
break;
}
return $products->getSize();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,35 @@ class CategoryManagementTest extends \PHPUnit_Framework_TestCase
protected $model;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var \Magento\Catalog\Api\CategoryRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $categoryRepositoryMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var \Magento\Catalog\Model\Category\Tree|\PHPUnit_Framework_MockObject_MockObject
*/
protected $categoryTreeMock;

/**
* @var \Magento\Catalog\Model\Resource\Category\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
*/
protected $categoriesFactoryMock;

protected function setUp()
{
$this->categoryRepositoryMock = $this->getMock('\Magento\Catalog\Api\CategoryRepositoryInterface');
$this->categoryTreeMock = $this->getMock('\Magento\Catalog\Model\Category\Tree', [], [], '', false);
$this->categoryRepositoryMock = $this->getMock('Magento\Catalog\Api\CategoryRepositoryInterface');
$this->categoryTreeMock = $this->getMock('Magento\Catalog\Model\Category\Tree', [], [], '', false);
$this->categoriesFactoryMock = $this->getMock(
'Magento\Catalog\Model\Resource\Category\CollectionFactory',
['create'],
[],
'',
false
);
$this->model = new \Magento\Catalog\Model\CategoryManagement(
$this->categoryRepositoryMock,
$this->categoryTreeMock
$this->categoryTreeMock,
$this->categoriesFactoryMock
);
}

Expand Down Expand Up @@ -171,4 +184,28 @@ public function testMoveWithCouldNotMoveException()
->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('message')));
$this->model->move($categoryId, $parentId, $afterId);
}

public function testGetCount()
{
$categoriesMock = $this->getMock('\Magento\Catalog\Model\Resource\Category\Collection', [], [], '', false);

$this->categoriesFactoryMock
->expects($this->once())
->method('create')
->willReturn($categoriesMock);
$categoriesMock
->expects($this->once())
->method('addAttributeToFilter')
->with('parent_id', ['gt' => 0])
->willReturnSelf();
$categoriesMock
->expects($this->once())
->method('getSize')
->willReturn('expected');

$this->assertEquals(
'expected',
$this->model->getCount()
);
}
}
83 changes: 83 additions & 0 deletions app/code/Magento/Catalog/Test/Unit/Model/ProductManagementTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Test\Unit\Model;

class ProductManagementTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Catalog\Model\ProductManagement
*/
protected $model;

/**
* @var \Magento\Catalog\Model\Resource\Product\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
*/
protected $productsFactoryMock;

protected function setUp()
{
$this->productsFactoryMock = $this->getMock(
'Magento\Catalog\Model\Resource\Product\CollectionFactory',
['create'],
[],
'',
false
);
$this->model = new \Magento\Catalog\Model\ProductManagement(
$this->productsFactoryMock
);
}

public function testGetEnabledCount()
{
$statusEnabled = 1;
$productsMock = $this->getMock('Magento\Catalog\Model\Resource\Product\Collection', [], [], '', false);

$this->productsFactoryMock
->expects($this->once())
->method('create')
->willReturn($productsMock);
$productsMock
->expects($this->once())
->method('addAttributeToFilter')
->with('status', $statusEnabled)
->willReturnSelf();
$productsMock
->expects($this->once())
->method('getSize')
->willReturn('expected');

$this->assertEquals(
'expected',
$this->model->getCount($statusEnabled)
);
}

public function testGetDisabledCount()
{
$statusDisabled = 2;
$productsMock = $this->getMock('\Magento\Catalog\Model\Resource\Product\Collection', [], [], '', false);

$this->productsFactoryMock
->expects($this->once())
->method('create')
->willReturn($productsMock);
$productsMock
->expects($this->once())
->method('addAttributeToFilter')
->with('status', $statusDisabled)
->willReturnSelf();
$productsMock
->expects($this->once())
->method('getSize')
->willReturn('expected');

$this->assertEquals(
'expected',
$this->model->getCount($statusDisabled)
);
}
}
1 change: 1 addition & 0 deletions app/code/Magento/Catalog/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<preference for="Magento\Catalog\Api\ProductAttributeManagementInterface" type="Magento\Catalog\Model\Product\Attribute\Management" />
<preference for="Magento\Catalog\Api\AttributeSetManagementInterface" type="Magento\Catalog\Model\Product\Attribute\SetManagement" />
<preference for="Magento\Catalog\Api\AttributeSetRepositoryInterface" type="Magento\Catalog\Model\Product\Attribute\SetRepository" />
<preference for="Magento\Catalog\Api\ProductManagementInterface" type="Magento\Catalog\Model\ProductManagement" />
<type name="Magento\Log\Model\Resource\Log">
<plugin name="catalogLog" type="Magento\Catalog\Model\Plugin\Log" />
</type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@ interface ConfigurableProductManagementInterface
* @return \Magento\Catalog\Api\Data\ProductInterface[]
*/
public function generateVariation(\Magento\Catalog\Api\Data\ProductInterface $product, $options);

/**
* Provide the number of product count
*
* @param null|int $status
* @return int
*/
public function getCount($status = null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\ConfigurableProduct\Model;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\ConfigurableProduct\Model\Resource\Product\Type\Configurable\Product\CollectionFactory;

class ConfigurableProductManagement implements \Magento\ConfigurableProduct\Api\ConfigurableProductManagementInterface
{
/**
Expand All @@ -19,28 +23,54 @@ class ConfigurableProductManagement implements \Magento\ConfigurableProduct\Api\
*/
private $productVariationBuilder;

/**
* @var CollectionFactory
*/
protected $productsFactory;

/**
* @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository
* @param ProductVariationsBuilder $productVariationBuilder
* @param CollectionFactory $productsFactory
*/
public function __construct(
\Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository,
ProductVariationsBuilder $productVariationBuilder
ProductVariationsBuilder $productVariationBuilder,
CollectionFactory $productsFactory
) {
$this->attributeRepository = $attributeRepository;
$this->productVariationBuilder = $productVariationBuilder;
$this->productsFactory = $productsFactory;
}

/**
* {@inheritdoc}
*/
public function generateVariation(\Magento\Catalog\Api\Data\ProductInterface $product, $options)
public function generateVariation(ProductInterface $product, $options)
{
$attributes = $this->getAttributesForMatrix($options);
$products = $this->productVariationBuilder->create($product, $attributes);
return $products;
}

/**
* {@inheritdoc}
*/
public function getCount($status = null)
{
$products = $this->productsFactory->create();
/** @var \Magento\ConfigurableProduct\Model\Resource\Product\Type\Configurable\Product\Collection $products */
switch ($status) {
case Status::STATUS_ENABLED:
$products->addAttributeToFilter('status', Status::STATUS_ENABLED);
break;
case Status::STATUS_DISABLED:
$products->addAttributeToFilter('status', Status::STATUS_DISABLED);
break;
}
return $products->getSize();
}

/**
* Prepare attribute info for variation matrix generation
*
Expand Down
Loading

0 comments on commit c0620c1

Please sign in to comment.