-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/magento/magento2ce into …
…MAGETWO-56240
- Loading branch information
Showing
210 changed files
with
8,306 additions
and
2,132 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
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.