forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from magento/develop
Merged mg2 develop into develop
- Loading branch information
Showing
53 changed files
with
1,422 additions
and
177 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ addons: | |
- postfix | ||
language: php | ||
php: | ||
- 5.6 | ||
- 5.6.29 | ||
- 7.0 | ||
env: | ||
global: | ||
|
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
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
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
67 changes: 67 additions & 0 deletions
67
app/code/Magento/Catalog/Model/ResourceModel/Product/Website/SelectProcessor.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,67 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Catalog\Model\ResourceModel\Product\Website; | ||
|
||
use Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface; | ||
use Magento\Framework\DB\Select; | ||
use Magento\Framework\EntityManager\MetadataPool; | ||
use Magento\Catalog\Api\Data\ProductInterface; | ||
use Magento\Framework\App\ResourceConnection; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
|
||
/** | ||
* Filter products that belongs to current website | ||
*/ | ||
class SelectProcessor implements BaseSelectProcessorInterface | ||
{ | ||
/** | ||
* @var ResourceConnection | ||
*/ | ||
private $resource; | ||
|
||
/** | ||
* @var MetadataPool | ||
*/ | ||
private $metadataPool; | ||
|
||
/** | ||
* @var StoreManagerInterface | ||
*/ | ||
private $storeManager; | ||
|
||
/** | ||
* @param MetadataPool $metadataPool | ||
* @param ResourceConnection $resource | ||
* @param StoreManagerInterface $storeManager | ||
*/ | ||
public function __construct( | ||
MetadataPool $metadataPool, | ||
ResourceConnection $resource, | ||
StoreManagerInterface $storeManager | ||
) { | ||
$this->metadataPool = $metadataPool; | ||
$this->resource = $resource; | ||
$this->storeManager = $storeManager; | ||
} | ||
|
||
/** | ||
* Joins website-product relation table to filter products that are only in current website | ||
* | ||
* {@inheritdoc} | ||
*/ | ||
public function process(Select $select) | ||
{ | ||
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); | ||
$select->joinInner( | ||
['pw' => $this->resource->getTableName('catalog_product_website')], | ||
'pw.product_id = ' . BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS . '.' . $linkField | ||
. ' AND pw.website_id = ' . $this->storeManager->getWebsite()->getId(), | ||
[] | ||
); | ||
|
||
return $select; | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
app/code/Magento/Catalog/Test/Unit/Model/CollectionProviderTest.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,110 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Test\Unit\Model; | ||
|
||
use Magento\Catalog\Model\ProductLink\CollectionProvider; | ||
use Magento\Catalog\Model\ProductLink\CollectionProviderInterface; | ||
use Magento\Catalog\Model\ProductLink\Converter\ConverterInterface; | ||
use Magento\Catalog\Model\ProductLink\Converter\ConverterPool; | ||
use Magento\Catalog\Model\Product; | ||
|
||
class CollectionProviderTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var CollectionProvider | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $converterPoolMock; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $providerMock; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $productMock; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $converterMock; | ||
|
||
protected function setUp() | ||
{ | ||
$this->productMock = $this->getMock(Product::class, [], [], '', false, false); | ||
$this->converterPoolMock = $this->getMock(ConverterPool::class, [], [], '', false, false); | ||
$this->providerMock = $this->getMock(CollectionProviderInterface::class); | ||
$this->converterMock = $this->getMock(ConverterInterface::class); | ||
|
||
$this->model = new CollectionProvider($this->converterPoolMock, ['crosssell' => $this->providerMock]); | ||
} | ||
|
||
/** | ||
* Test sort order of linked products based on configured item position. | ||
*/ | ||
public function testGetCollection() | ||
{ | ||
$linkedProductOneMock = $this->getMock(Product::class, [], [], '', false, false); | ||
$linkedProductTwoMock = $this->getMock(Product::class, [], [], '', false, false); | ||
$linkedProductThreeMock = $this->getMock(Product::class, [], [], '', false, false); | ||
|
||
$linkedProductOneMock->expects($this->once())->method('getId')->willReturn(1); | ||
$linkedProductTwoMock->expects($this->once())->method('getId')->willReturn(2); | ||
$linkedProductThreeMock->expects($this->once())->method('getId')->willReturn(3); | ||
|
||
$this->converterPoolMock->expects($this->once()) | ||
->method('getConverter') | ||
->with('crosssell') | ||
->willReturn($this->converterMock); | ||
|
||
$map = [ | ||
[$linkedProductOneMock, ['name' => 'Product One', 'position' => 10]], | ||
[$linkedProductTwoMock, ['name' => 'Product Two', 'position' => 2]], | ||
[$linkedProductThreeMock, ['name' => 'Product Three', 'position' => 2]], | ||
]; | ||
|
||
$this->converterMock->expects($this->exactly(3))->method('convert')->willReturnMap($map); | ||
|
||
$this->providerMock->expects($this->once()) | ||
->method('getLinkedProducts') | ||
->with($this->productMock) | ||
->willReturn( | ||
[ | ||
$linkedProductOneMock, | ||
$linkedProductTwoMock, | ||
$linkedProductThreeMock | ||
] | ||
); | ||
|
||
$expectedResult = [ | ||
2 => ['name' => 'Product Two', 'position' => 2], | ||
3 => ['name' => 'Product Three', 'position' => 2], | ||
10 => ['name' => 'Product One', 'position' => 10], | ||
]; | ||
|
||
$actualResult = $this->model->getCollection($this->productMock, 'crosssell'); | ||
|
||
$this->assertEquals($expectedResult, $actualResult, 'Sort order of linked products in incorrect'); | ||
} | ||
|
||
/** | ||
* Test exception when collection provider is not configured for product link type. | ||
* | ||
* @expectedException \Magento\Framework\Exception\NoSuchEntityException | ||
* @expectedExceptionMessage Collection provider is not registered | ||
*/ | ||
public function testGetCollectionWithMissingProviders() | ||
{ | ||
$this->model->getCollection($this->productMock, 'upsell'); | ||
} | ||
} |
Oops, something went wrong.