Skip to content

Commit

Permalink
Merge pull request #367 from magento-api/MAGETWO-36000-Join-Processors
Browse files Browse the repository at this point in the history
[API] Sprint50 Join Processors
  • Loading branch information
Paliarush, Alexander(apaliarush) committed Jun 19, 2015
2 parents 6b5e713 + ad2bf72 commit 8599357
Show file tree
Hide file tree
Showing 86 changed files with 2,410 additions and 772 deletions.
4 changes: 2 additions & 2 deletions app/code/Magento/Backend/Helper/Dashboard/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
/**
* @var \MagentoFrameworkDataCollectionAbstractDb
* @var \Magento\Framework\Data\Collection\AbstractDb
*/
protected $_stores;

Expand Down Expand Up @@ -48,7 +48,7 @@ public function __construct(
/**
* Retrieve stores configured in system.
*
* @return \MagentoFrameworkDataCollectionAbstractDb
* @return \Magento\Framework\Data\Collection\AbstractDb
*/
public function getStores()
{
Expand Down
11 changes: 10 additions & 1 deletion app/code/Magento/Bundle/Model/Product/OptionList.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,30 @@ class OptionList
*/
protected $dataObjectHelper;

/**
* @var \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface
*/
protected $extensionAttributesJoinProcessor;

/**
* @param Type $type
* @param \Magento\Bundle\Api\Data\OptionInterfaceFactory $optionFactory
* @param LinksList $linkList
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
* @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor
*/
public function __construct(
\Magento\Bundle\Model\Product\Type $type,
\Magento\Bundle\Api\Data\OptionInterfaceFactory $optionFactory,
\Magento\Bundle\Model\Product\LinksList $linkList,
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor
) {
$this->type = $type;
$this->optionFactory = $optionFactory;
$this->linkList = $linkList;
$this->dataObjectHelper = $dataObjectHelper;
$this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
}

/**
Expand All @@ -53,6 +61,7 @@ public function __construct(
public function getItems(\Magento\Catalog\Api\Data\ProductInterface $product)
{
$optionCollection = $this->type->getOptionsCollection($product);
$this->extensionAttributesJoinProcessor->process($optionCollection);
$optionList = [];
/** @var \Magento\Bundle\Model\Option $option */
foreach ($optionCollection as $option) {
Expand Down
40 changes: 30 additions & 10 deletions app/code/Magento/Bundle/Test/Unit/Model/Product/OptionListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ class OptionListTest extends \PHPUnit_Framework_TestCase
*/
protected $dataObjectHelperMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $extensionAttributesFactoryMock;

/**
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
*/
protected $objectManager;

protected function setUp()
{
$this->typeMock = $this->getMock('\Magento\Bundle\Model\Product\Type', [], [], '', false);
Expand All @@ -43,15 +53,26 @@ protected function setUp()
'',
false
);
$this->dataObjectHelperMock = $this->getMockBuilder('\Magento\Framework\Api\DataObjectHelper')
->disableOriginalConstructor()
->getMock();
$this->dataObjectHelperMock = $this->getMock('\Magento\Framework\Api\DataObjectHelper', [], [], '', false);
$this->linkListMock = $this->getMock('\Magento\Bundle\Model\Product\LinksList', [], [], '', false);
$this->model = new \Magento\Bundle\Model\Product\OptionList(
$this->typeMock,
$this->optionFactoryMock,
$this->linkListMock,
$this->dataObjectHelperMock
$this->extensionAttributesFactoryMock = $this->getMock(
'\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface',
[],
[],
'',
false
);

$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->model = $this->objectManager->getObject(
'Magento\Bundle\Model\Product\OptionList',
[
'type' => $this->typeMock,
'optionFactory' => $this->optionFactoryMock,
'linkList' => $this->linkListMock,
'dataObjectHelper' => $this->dataObjectHelperMock,
'extensionAttributesJoinProcessor' => $this->extensionAttributesFactoryMock
]
);
}

Expand All @@ -71,8 +92,7 @@ public function testGetItems()
'',
false
);
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$optionsCollMock = $objectManager->getCollectionMock(
$optionsCollMock = $this->objectManager->getCollectionMock(
'Magento\Bundle\Model\Resource\Option\Collection',
[$optionMock]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* @api
*/
interface ProductCustomOptionInterface
interface ProductCustomOptionInterface extends \Magento\Framework\Api\ExtensibleDataInterface
{
/**
* Get product SKU
Expand Down Expand Up @@ -201,4 +201,21 @@ public function getValues();
* @return $this
*/
public function setValues(array $values = null);

/**
* Retrieve existing extension attributes object or create a new one.
*
* @return \Magento\Catalog\Api\Data\ProductCustomOptionExtensionInterface|null
*/
public function getExtensionAttributes();

/**
* Set an extension attributes object.
*
* @param \Magento\Catalog\Api\Data\ProductCustomOptionExtensionInterface $extensionAttributes
* @return $this
*/
public function setExtensionAttributes(
\Magento\Catalog\Api\Data\ProductCustomOptionExtensionInterface $extensionAttributes
);
}
12 changes: 11 additions & 1 deletion app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
'group_price',
];

/**
* @var \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface
*/
protected $joinProcessor;

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
Expand Down Expand Up @@ -351,6 +356,7 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
* @param \Magento\Catalog\Api\Data\ProductLinkExtensionFactory $productLinkExtensionFactory
* @param \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory $mediaGalleryEntryFactory
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
* @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor
* @param array $data
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
Expand Down Expand Up @@ -389,6 +395,7 @@ public function __construct(
\Magento\Catalog\Api\Data\ProductLinkExtensionFactory $productLinkExtensionFactory,
\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory $mediaGalleryEntryFactory,
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor,
array $data = []
) {
$this->metadataService = $metadataService;
Expand Down Expand Up @@ -417,6 +424,7 @@ public function __construct(
$this->productLinkExtensionFactory = $productLinkExtensionFactory;
$this->mediaGalleryEntryFactory = $mediaGalleryEntryFactory;
$this->dataObjectHelper = $dataObjectHelper;
$this->joinProcessor = $joinProcessor;
parent::__construct(
$context,
$registry,
Expand Down Expand Up @@ -1961,7 +1969,9 @@ public function getOptionById($optionId)
public function getOptions()
{
if (empty($this->_options) && $this->getHasOptions() && !$this->optionsInitialized) {
foreach ($this->getProductOptionsCollection() as $option) {
$collection = $this->getProductOptionsCollection();
$this->joinProcessor->process($collection);
foreach ($collection as $option) {
$option->setProduct($this);
$this->addOption($option);
}
Expand Down
34 changes: 31 additions & 3 deletions app/code/Magento/Catalog/Model/Product/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Resource\Product\Option\Value\Collection;
use Magento\Catalog\Pricing\Price\BasePrice;
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\Exception\LocalizedException;

/**
Expand All @@ -26,7 +25,8 @@
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
*/
class Option extends AbstractModel implements \Magento\Catalog\Api\Data\ProductCustomOptionInterface
class Option extends \Magento\Framework\Model\AbstractExtensibleModel
implements \Magento\Catalog\Api\Data\ProductCustomOptionInterface
{
const OPTION_GROUP_TEXT = 'text';

Expand Down Expand Up @@ -116,6 +116,8 @@ class Option extends AbstractModel implements \Magento\Catalog\Api\Data\ProductC
/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
* @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory
* @param Option\Value $productOptionValue
* @param Option\Type\Factory $optionFactory
* @param \Magento\Framework\Stdlib\String $string
Expand All @@ -128,6 +130,8 @@ class Option extends AbstractModel implements \Magento\Catalog\Api\Data\ProductC
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
\Magento\Framework\Api\AttributeValueFactory $customAttributeFactory,
Option\Value $productOptionValue,
\Magento\Catalog\Model\Product\Option\Type\Factory $optionFactory,
\Magento\Framework\Stdlib\String $string,
Expand All @@ -143,6 +147,8 @@ public function __construct(
parent::__construct(
$context,
$registry,
$extensionFactory,
$customAttributeFactory,
$resource,
$resourceCollection,
$data
Expand Down Expand Up @@ -406,7 +412,7 @@ public function saveOptions()
}

/**
* @return AbstractModel
* @return \Magento\Framework\Model\AbstractModel
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function afterSave()
Expand Down Expand Up @@ -845,5 +851,27 @@ public function setValues(array $values = null)
$this->_values = $values;
return $this;
}

/**
* {@inheritdoc}
*
* @return \Magento\Catalog\Api\Data\ProductCustomOptionExtensionInterface|null
*/
public function getExtensionAttributes()
{
return $this->_getExtensionAttributes();
}

/**
* {@inheritdoc}
*
* @param \Magento\Catalog\Api\Data\ProductCustomOptionExtensionInterface $extensionAttributes
* @return $this
*/
public function setExtensionAttributes(
\Magento\Catalog\Api\Data\ProductCustomOptionExtensionInterface $extensionAttributes
) {
return $this->_setExtensionAttributes($extensionAttributes);
}
//@codeCoverageIgnoreEnd
}
24 changes: 11 additions & 13 deletions app/code/Magento/Catalog/Model/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Magento\Catalog\Model\Resource\Product\Collection;
use Magento\Framework\Api\Data\ImageContentInterface;
use Magento\Framework\Api\Data\ImageContentInterfaceFactory;
use Magento\Framework\Api\ExtensionAttributesFactory;
use Magento\Framework\Api\ImageContentValidatorInterface;
use Magento\Framework\Api\ImageProcessorInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
Expand Down Expand Up @@ -137,9 +136,9 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
protected $imageProcessor;

/**
* @var ExtensionAttributesFactory
* @var \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface
*/
protected $extensionAttributesFactory;
protected $extensionAttributesJoinProcessor;

/**
* @param ProductFactory $productFactory
Expand All @@ -149,20 +148,20 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
* @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository
* @param Resource\Product $resourceModel
* @param \Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks $linkInitializer
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
* @param \Magento\Store\Model\StoreManagerInterface $storeManager ,
* @param Product\Initialization\Helper\ProductLinks $linkInitializer
* @param Product\LinkTypeProvider $linkTypeProvider
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\Api\FilterBuilder $filterBuilder
* @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $metadataServiceInterface
* @param \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter
* @param \Magento\Eav\Model\Config $eavConfig
* @param \Magento\Catalog\Model\Product\Option\Converter $optionConverter
* @param Product\Option\Converter $optionConverter
* @param \Magento\Framework\Filesystem $fileSystem
* @param ImageContentValidatorInterface $contentValidator
* @param ImageContentInterfaceFactory $contentFactory
* @param MimeTypeExtensionMap $mimeTypeExtensionMap
* @param \Magento\Eav\Model\Config $eavConfig
* @param ImageProcessorInterface $imageProcessor
* @param ExtensionAttributesFactory $extensionAttributesFactory
* @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -186,7 +185,7 @@ public function __construct(
MimeTypeExtensionMap $mimeTypeExtensionMap,
\Magento\Eav\Model\Config $eavConfig,
ImageProcessorInterface $imageProcessor,
ExtensionAttributesFactory $extensionAttributesFactory
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor
) {
$this->productFactory = $productFactory;
$this->collectionFactory = $collectionFactory;
Expand All @@ -208,7 +207,7 @@ public function __construct(
$this->mimeTypeExtensionMap = $mimeTypeExtensionMap;
$this->eavConfig = $eavConfig;
$this->imageProcessor = $imageProcessor;
$this->extensionAttributesFactory = $extensionAttributesFactory;
$this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
}

/**
Expand Down Expand Up @@ -649,6 +648,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
{
/** @var \Magento\Catalog\Model\Resource\Product\Collection $collection */
$collection = $this->collectionFactory->create();
$this->extensionAttributesJoinProcessor->process($collection);
$defaultAttributeSetId = $this->eavConfig
->getEntityType(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE)
->getDefaultAttributeSetId();
Expand Down Expand Up @@ -681,8 +681,6 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
}
$collection->setCurPage($searchCriteria->getCurrentPage());
$collection->setPageSize($searchCriteria->getPageSize());
$productDataClass = 'Magento\Catalog\Model\Product';
$this->extensionAttributesFactory->process($collection, $productDataClass);
$collection->load();

$searchResult = $this->searchResultsFactory->create();
Expand Down
Loading

0 comments on commit 8599357

Please sign in to comment.