Skip to content

Commit

Permalink
Merge pull request #579 from magento-troll/MAGETWO-42369
Browse files Browse the repository at this point in the history
[Merchant Beta][MX] Fix MAGETWO-42369 (Product->getProductLinks() with flat tables turned on)
  • Loading branch information
Korshenko, Olexii(okorshenko) committed Sep 8, 2015
2 parents bed175b + 83df056 commit efc2830
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Model\Product\Attribute;

use Magento\Eav\Model\Resource\Attribute\DefaultEntityAttributes\ProviderInterface;

/**
* Product default attributes provider
*
* @codeCoverageIgnore
*/
class DefaultAttributes implements ProviderInterface
{
/**
* Retrieve default entity static attributes
*
* @return string[]
*/
public function getDefaultAttributes()
{
return ['entity_id', 'attribute_set_id', 'type_id', 'created_at', 'updated_at', 'sku'];
}
}
10 changes: 9 additions & 1 deletion app/code/Magento/Catalog/Model/Resource/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class Product extends AbstractResource
*/
protected $typeFactory;

/**
* @var \Magento\Catalog\Model\Product\Attribute\DefaultAttributes
*/
protected $defaultAttributes;

/**
* @param \Magento\Eav\Model\Entity\Context $context
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
Expand All @@ -65,6 +70,7 @@ class Product extends AbstractResource
* @param \Magento\Framework\Event\ManagerInterface $eventManager
* @param \Magento\Eav\Model\Entity\Attribute\SetFactory $setFactory
* @param \Magento\Eav\Model\Entity\TypeFactory $typeFactory
* @param \Magento\Catalog\Model\Product\Attribute\DefaultAttributes $defaultAttributes
* @param array $data
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
Expand All @@ -78,13 +84,15 @@ public function __construct(
\Magento\Framework\Event\ManagerInterface $eventManager,
\Magento\Eav\Model\Entity\Attribute\SetFactory $setFactory,
\Magento\Eav\Model\Entity\TypeFactory $typeFactory,
\Magento\Catalog\Model\Product\Attribute\DefaultAttributes $defaultAttributes,
$data = []
) {
$this->_categoryCollectionFactory = $categoryCollectionFactory;
$this->_catalogCategory = $catalogCategory;
$this->eventManager = $eventManager;
$this->setFactory = $setFactory;
$this->typeFactory = $typeFactory;
$this->defaultAttributes = $defaultAttributes;
parent::__construct(
$context,
$storeManager,
Expand Down Expand Up @@ -142,7 +150,7 @@ public function getProductCategoryTable()
*/
protected function _getDefaultAttributes()
{
return ['entity_id', 'attribute_set_id', 'type_id', 'created_at', 'updated_at'];
return $this->defaultAttributes->getDefaultAttributes();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.NumberOfChildren)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
* @method \Magento\Eav\Model\Resource\Attribute\DefaultEntityAttributes\ProviderInterface getResource()
*/
class Collection extends \Magento\Catalog\Model\Resource\Collection\AbstractCollection
{
Expand Down Expand Up @@ -556,7 +558,7 @@ protected function _initSelect()
)->columns(
['status' => new \Zend_Db_Expr(ProductStatus::STATUS_ENABLED)]
);
$this->addAttributeToSelect(['entity_id', 'type_id', 'attribute_set_id']);
$this->addAttributeToSelect($this->getResource()->getDefaultAttributes());
if ($this->_catalogProductFlatState->getFlatIndexerHelper()->isAddChildData()) {
$this->getSelect()->where('e.is_child=?', 0);
$this->addAttributeToSelect(['child_id', 'is_child']);
Expand Down
26 changes: 25 additions & 1 deletion app/code/Magento/Catalog/Model/Resource/Product/Flat.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
namespace Magento\Catalog\Model\Resource\Product;

use Magento\Store\Model\Store;
use Magento\Eav\Model\Resource\Attribute\DefaultEntityAttributes\ProviderInterface as DefaultAttributesProvider;

/**
* Catalog Product Flat resource model
*
* @author Magento Core Team <core@magentocommerce.com>
*/
class Flat extends \Magento\Framework\Model\Resource\Db\AbstractDb
class Flat extends \Magento\Framework\Model\Resource\Db\AbstractDb implements DefaultAttributesProvider
{
/**
* Store scope Id
Expand All @@ -35,20 +36,28 @@ class Flat extends \Magento\Framework\Model\Resource\Db\AbstractDb
*/
protected $_storeManager;

/**
* @var \Magento\Catalog\Model\Product\Attribute\DefaultAttributes
*/
protected $defaultAttributes;

/**
* @param \Magento\Framework\Model\Resource\Db\Context $context
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Catalog\Model\Config $catalogConfig
* @param \Magento\Catalog\Model\Product\Attribute\DefaultAttributes $defaultAttributes
* @param string|null $resourcePrefix
*/
public function __construct(
\Magento\Framework\Model\Resource\Db\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Catalog\Model\Config $catalogConfig,
\Magento\Catalog\Model\Product\Attribute\DefaultAttributes $defaultAttributes,
$resourcePrefix = null
) {
$this->_storeManager = $storeManager;
$this->_catalogConfig = $catalogConfig;
$this->defaultAttributes = $defaultAttributes;
parent::__construct($context, $resourcePrefix);
}

Expand Down Expand Up @@ -231,4 +240,19 @@ public function getMainTable()
{
return $this->getFlatTableName($this->getStoreId());
}

/**
* Retrieve default entity static attributes
*
* @return string[]
*/
public function getDefaultAttributes()
{
return array_unique(
array_merge(
$this->defaultAttributes->getDefaultAttributes(),
[$this->getEntityIdField()]
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public function setUp()
$this->_model = new \Magento\Catalog\Model\Resource\Product\Flat(
$this->getMock('Magento\Framework\Model\Resource\Db\Context', [], [], '', false),
$this->_storeManagerInterface,
$this->getMock('Magento\Catalog\Model\Config', [], [], '', false)
$this->getMock('Magento\Catalog\Model\Config', [], [], '', false),
$this->getMock('Magento\Catalog\Model\Product\Attribute\DefaultAttributes')
);
}

Expand Down
4 changes: 3 additions & 1 deletion app/code/Magento/Eav/Model/Entity/AbstractEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\Model\Resource\Db\ObjectRelationProcessor;
use Magento\Framework\Model\Resource\Db\TransactionManagerInterface;
use Magento\Eav\Model\Resource\Attribute\DefaultEntityAttributes\ProviderInterface as DefaultAttributesProvider;
use Magento\Framework\Model\Resource\AbstractResource;

/**
* Entity/Attribute/Model - entity abstract
Expand All @@ -26,7 +28,7 @@
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
abstract class AbstractEntity extends \Magento\Framework\Model\Resource\AbstractResource implements EntityInterface
abstract class AbstractEntity extends AbstractResource implements EntityInterface, DefaultAttributesProvider
{
/**
* Read connection
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Eav\Model\Resource\Attribute\DefaultEntityAttributes;

interface ProviderInterface
{
/**
* Retrieve default entity static attributes
*
* @return string[]
*/
public function getDefaultAttributes();
}

0 comments on commit efc2830

Please sign in to comment.