-
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 #258 from magento-south/MAGETWO-56012
Story: MAGETWO-56012 SearchCriteria Unified Processing MAGETWO-56079 SearchCriteria Unified Processing for Cms, Customer and Eav modules MAGETWO-56080 SearchCriteria Unified Processing for GiftWrapping, Quote and Tax modules MAGETWO-56081 SearchCriteria Unified Processing for autogenerated repositories of GiftCardAccount, Rma and Sales modules MAGETWO-56082 SearchCriteria Unified Processing for Rma, Sales, SalesRule and Staging modules MAGETWO-56083 SearchCriteria Unified Processing for Ui, Vault, and VersionsCms modules
- Loading branch information
Showing
172 changed files
with
7,861 additions
and
1,927 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
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
32 changes: 32 additions & 0 deletions
32
...og/Model/Api/SearchCriteria/CollectionProcessor/FilterProcessor/ProductCategoryFilter.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,32 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Catalog\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor; | ||
|
||
use Magento\Catalog\Model\ResourceModel\Product\Collection; | ||
use Magento\Framework\Api\Filter; | ||
use Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor\CustomFilterInterface; | ||
use Magento\Framework\Data\Collection\AbstractDb; | ||
|
||
class ProductCategoryFilter implements CustomFilterInterface | ||
{ | ||
/** | ||
* Apply category_id Filter to Product Collection | ||
* | ||
* @param Filter $filter | ||
* @param AbstractDb $collection | ||
* @return bool Whether the filter is applied | ||
*/ | ||
public function apply(Filter $filter, AbstractDb $collection) | ||
{ | ||
$conditionType = $filter->getConditionType() ? $filter->getConditionType() : 'eq'; | ||
$categoryFilter = [$conditionType => [$filter->getValue()]]; | ||
|
||
/** @var Collection $collection */ | ||
$collection->addCategoriesFilter($categoryFilter); | ||
|
||
return true; | ||
} | ||
} |
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
73 changes: 73 additions & 0 deletions
73
...odel/Api/SearchCriteria/CollectionProcessor/FilterProcessor/ProductCategoryFilterTest.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,73 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Catalog\Test\Unit\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor; | ||
|
||
use Magento\Catalog\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor\ProductCategoryFilter; | ||
use Magento\Catalog\Model\ResourceModel\Product\Collection; | ||
use Magento\Framework\Api\Filter; | ||
|
||
class ProductCategoryFilterTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** @var ProductCategoryFilter */ | ||
private $model; | ||
|
||
protected function setUp() | ||
{ | ||
$this->model = new ProductCategoryFilter(); | ||
} | ||
|
||
public function testApply() | ||
{ | ||
/** @var Filter|\PHPUnit_Framework_MockObject_MockObject $filterMock */ | ||
$filterMock = $this->getMockBuilder(Filter::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
/** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */ | ||
$collectionMock = $this->getMockBuilder(Collection::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$filterMock->expects($this->exactly(2)) | ||
->method('getConditionType') | ||
->willReturn('condition'); | ||
$filterMock->expects($this->once()) | ||
->method('getValue') | ||
->willReturn('value'); | ||
|
||
$collectionMock->expects($this->once()) | ||
->method('addCategoriesFilter') | ||
->with(['condition' => ['value']]); | ||
|
||
$this->assertTrue($this->model->apply($filterMock, $collectionMock)); | ||
} | ||
|
||
public function testApplyWithoutCondition() | ||
{ | ||
/** @var Filter|\PHPUnit_Framework_MockObject_MockObject $filterMock */ | ||
$filterMock = $this->getMockBuilder(Filter::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
/** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */ | ||
$collectionMock = $this->getMockBuilder(Collection::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$filterMock->expects($this->once()) | ||
->method('getConditionType') | ||
->willReturn(null); | ||
$filterMock->expects($this->once()) | ||
->method('getValue') | ||
->willReturn('value'); | ||
|
||
$collectionMock->expects($this->once()) | ||
->method('addCategoriesFilter') | ||
->with(['eq' => ['value']]); | ||
|
||
$this->assertTrue($this->model->apply($filterMock, $collectionMock)); | ||
} | ||
} |
Oops, something went wrong.