-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from magento-south/MAGETWO-44657
[South] Merchant Beta NewRelic
- Loading branch information
Showing
96 changed files
with
7,848 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
app/code/Magento/Catalog/Api/ProductManagementInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
app/code/Magento/Catalog/Test/Unit/Model/ProductManagementTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.