-
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.
Browse files
Browse the repository at this point in the history
- Merge Pull Request magento-engcom/import-export-improvements#94 from VincentMarmiesse/magento2:42-imageskeys - Merged commits: 1. 8d3a237 2. 100e123 3. 36a053f 4. 2bbf5e0 5. c52ad59
- Loading branch information
Showing
4 changed files
with
154 additions
and
5 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
50 changes: 50 additions & 0 deletions
50
app/code/Magento/CatalogImportExport/Model/Import/Product/ImageTypeProcessor.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,50 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\CatalogImportExport\Model\Import\Product; | ||
|
||
use Magento\CatalogImportExport\Model\Import\Proxy\Product\ResourceModel; | ||
|
||
class ImageTypeProcessor | ||
{ | ||
/** | ||
* @var \Magento\CatalogImportExport\Model\Import\Proxy\Product\ResourceModelFactory | ||
*/ | ||
private $resourceFactory; | ||
|
||
/** | ||
* @param \Magento\CatalogImportExport\Model\Import\Proxy\Product\ResourceModelFactory $resourceFactory | ||
*/ | ||
public function __construct( | ||
\Magento\CatalogImportExport\Model\Import\Proxy\Product\ResourceModelFactory $resourceFactory | ||
) { | ||
$this->resourceFactory = $resourceFactory; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getImageTypes() | ||
{ | ||
$imageKeys = []; | ||
/** @var ResourceModel $resource */ | ||
$resource = $this->resourceFactory->create(); | ||
$connection = $resource->getConnection(); | ||
$select = $connection->select(); | ||
$select->from( | ||
$resource->getTable('eav_attribute'), | ||
['code' => 'attribute_code'] | ||
); | ||
$select->where( | ||
'frontend_input = :frontend_input' | ||
); | ||
$bind = [':frontend_input' => 'media_image']; | ||
|
||
$imageKeys = $connection->fetchCol($select, $bind); | ||
$imageKeys[] = '_media_image'; | ||
|
||
return $imageKeys; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...ode/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/ImageTypeProcessorTest.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,59 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\CatalogImportExport\Test\Unit\Model\Import\Product; | ||
|
||
use Magento\CatalogImportExport\Model\Import\Product\ImageTypeProcessor; | ||
|
||
class ImageTypeProcessorTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
public function testGetImageTypes() | ||
{ | ||
$resourceFactory = $this->createPartialMock( | ||
\Magento\CatalogImportExport\Model\Import\Proxy\Product\ResourceModelFactory::class, | ||
['create'] | ||
); | ||
|
||
$resource = $this->getMockBuilder(\Magento\CatalogImportExport\Model\Import\Proxy\Product\ResourceModel::class) | ||
->disableOriginalConstructor() | ||
->setMethods(['getTable', 'getConnection']) | ||
->getMock(); | ||
$resource->expects($this->once()) | ||
->method('getTable') | ||
->with('eav_attribute') | ||
->willReturnArgument(0); | ||
$connection = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class); | ||
$resource->expects($this->any()) | ||
->method('getConnection') | ||
->willReturn($connection); | ||
$resourceFactory->expects($this->once()) | ||
->method('create') | ||
->willReturn($resource); | ||
|
||
$selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$selectMock->expects($this->once()) | ||
->method('from') | ||
->with('eav_attribute', ['code' => 'attribute_code'], null) | ||
->willReturnSelf(); | ||
$selectMock->expects($this->once()) | ||
->method('where') | ||
->with('frontend_input = :frontend_input') | ||
->willReturnSelf(); | ||
$connection->expects($this->any()) | ||
->method('fetchCol') | ||
->willReturn(['image', 'small_image', 'thumbnail', 'swatch_image']); | ||
$connection->expects($this->any()) | ||
->method('select') | ||
->willReturn($selectMock); | ||
|
||
$typeProcessor = new ImageTypeProcessor($resourceFactory); | ||
$this->assertEquals( | ||
['image', 'small_image', 'thumbnail', 'swatch_image', '_media_image'], | ||
$typeProcessor->getImageTypes() | ||
); | ||
} | ||
} |
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