From 2d017aa91163159999228683ae7414e0c9df77ed Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 3 Sep 2015 19:40:19 +0300 Subject: [PATCH 1/4] MAGETWO-42369: ->getProductLinks() doesnt return the linked product's sku and position with flat tables turned on --- app/code/Magento/Catalog/Model/Resource/Product/Collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/Resource/Product/Collection.php b/app/code/Magento/Catalog/Model/Resource/Product/Collection.php index 96b2597121705..bf58abafecce0 100644 --- a/app/code/Magento/Catalog/Model/Resource/Product/Collection.php +++ b/app/code/Magento/Catalog/Model/Resource/Product/Collection.php @@ -556,7 +556,7 @@ protected function _initSelect() )->columns( ['status' => new \Zend_Db_Expr(ProductStatus::STATUS_ENABLED)] ); - $this->addAttributeToSelect(['entity_id', 'type_id', 'attribute_set_id']); + $this->addAttributeToSelect(['entity_id', 'type_id', 'attribute_set_id', 'sku']); if ($this->_catalogProductFlatState->getFlatIndexerHelper()->isAddChildData()) { $this->getSelect()->where('e.is_child=?', 0); $this->addAttributeToSelect(['child_id', 'is_child']); From 6aec6ee53f14da5c73bf22fc439de3e30d983886 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 3 Sep 2015 20:44:30 +0300 Subject: [PATCH 2/4] MAGETWO-42369: ->getProductLinks() doesnt return the linked product's sku and position with flat tables turned on --- .../Magento/Catalog/Model/Resource/Product.php | 7 ++++++- .../Model/Resource/Product/Collection.php | 4 +++- .../Catalog/Model/Resource/Product/Flat.php | 18 +++++++++++++++++- .../Eav/Model/Entity/AbstractEntity.php | 4 +++- .../ProviderInterface.php | 16 ++++++++++++++++ 5 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 app/code/Magento/Eav/Model/Resource/Attribute/DefaultEntityAttributes/ProviderInterface.php diff --git a/app/code/Magento/Catalog/Model/Resource/Product.php b/app/code/Magento/Catalog/Model/Resource/Product.php index da4aee259b632..8e82109718869 100644 --- a/app/code/Magento/Catalog/Model/Resource/Product.php +++ b/app/code/Magento/Catalog/Model/Resource/Product.php @@ -13,6 +13,11 @@ */ class Product extends AbstractResource { + /** + * Default product attributes + */ + const DEFAULT_ATTRIBUTES = ['entity_id', 'attribute_set_id', 'type_id', 'created_at', 'updated_at', 'sku']; + /** * Product to website linkage table * @@ -142,7 +147,7 @@ public function getProductCategoryTable() */ protected function _getDefaultAttributes() { - return ['entity_id', 'attribute_set_id', 'type_id', 'created_at', 'updated_at']; + return self::DEFAULT_ATTRIBUTES; } /** diff --git a/app/code/Magento/Catalog/Model/Resource/Product/Collection.php b/app/code/Magento/Catalog/Model/Resource/Product/Collection.php index bf58abafecce0..a9dd4851ec1ca 100644 --- a/app/code/Magento/Catalog/Model/Resource/Product/Collection.php +++ b/app/code/Magento/Catalog/Model/Resource/Product/Collection.php @@ -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 { @@ -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', 'sku']); + $this->addAttributeToSelect($this->getResource()->getDefaultAttributes()); if ($this->_catalogProductFlatState->getFlatIndexerHelper()->isAddChildData()) { $this->getSelect()->where('e.is_child=?', 0); $this->addAttributeToSelect(['child_id', 'is_child']); diff --git a/app/code/Magento/Catalog/Model/Resource/Product/Flat.php b/app/code/Magento/Catalog/Model/Resource/Product/Flat.php index 5f80e34ea9ae4..c21772da989b2 100644 --- a/app/code/Magento/Catalog/Model/Resource/Product/Flat.php +++ b/app/code/Magento/Catalog/Model/Resource/Product/Flat.php @@ -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 */ -class Flat extends \Magento\Framework\Model\Resource\Db\AbstractDb +class Flat extends \Magento\Framework\Model\Resource\Db\AbstractDb implements DefaultAttributesProvider { /** * Store scope Id @@ -231,4 +232,19 @@ public function getMainTable() { return $this->getFlatTableName($this->getStoreId()); } + + /** + * Retrieve default entity static attributes + * + * @return string[] + */ + public function getDefaultAttributes() + { + return array_unique( + array_merge( + \Magento\Catalog\Model\Resource\Product::DEFAULT_ATTRIBUTES, + [$this->getEntityIdField()] + ) + ); + } } diff --git a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php index 921f2e0afa0bf..358d5e08777de 100755 --- a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php +++ b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php @@ -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 @@ -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 diff --git a/app/code/Magento/Eav/Model/Resource/Attribute/DefaultEntityAttributes/ProviderInterface.php b/app/code/Magento/Eav/Model/Resource/Attribute/DefaultEntityAttributes/ProviderInterface.php new file mode 100644 index 0000000000000..4da84e26c3673 --- /dev/null +++ b/app/code/Magento/Eav/Model/Resource/Attribute/DefaultEntityAttributes/ProviderInterface.php @@ -0,0 +1,16 @@ + Date: Mon, 7 Sep 2015 14:51:37 +0300 Subject: [PATCH 3/4] MAGETWO-42369: $product->getProductLinks() doesnt return the linked product's sku and position with flat tables turned on - replace Product::DEFAULT_ATTRIBUTES const with separate class --- .../Product/Attribute/DefaultAttributes.php | 26 +++++++++++++++++++ .../Catalog/Model/Resource/Product.php | 15 ++++++----- .../Catalog/Model/Resource/Product/Flat.php | 10 ++++++- 3 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 app/code/Magento/Catalog/Model/Product/Attribute/DefaultAttributes.php diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/DefaultAttributes.php b/app/code/Magento/Catalog/Model/Product/Attribute/DefaultAttributes.php new file mode 100644 index 0000000000000..fbf1a3a616d3f --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/Attribute/DefaultAttributes.php @@ -0,0 +1,26 @@ +_categoryCollectionFactory = $categoryCollectionFactory; @@ -90,6 +92,7 @@ public function __construct( $this->eventManager = $eventManager; $this->setFactory = $setFactory; $this->typeFactory = $typeFactory; + $this->defaultAttributes = $defaultAttributes; parent::__construct( $context, $storeManager, @@ -147,7 +150,7 @@ public function getProductCategoryTable() */ protected function _getDefaultAttributes() { - return self::DEFAULT_ATTRIBUTES; + return $this->defaultAttributes->getDefaultAttributes(); } /** diff --git a/app/code/Magento/Catalog/Model/Resource/Product/Flat.php b/app/code/Magento/Catalog/Model/Resource/Product/Flat.php index c21772da989b2..c0aec573837a3 100644 --- a/app/code/Magento/Catalog/Model/Resource/Product/Flat.php +++ b/app/code/Magento/Catalog/Model/Resource/Product/Flat.php @@ -36,20 +36,28 @@ class Flat extends \Magento\Framework\Model\Resource\Db\AbstractDb implements De */ 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); } @@ -242,7 +250,7 @@ public function getDefaultAttributes() { return array_unique( array_merge( - \Magento\Catalog\Model\Resource\Product::DEFAULT_ATTRIBUTES, + $this->defaultAttributes->getDefaultAttributes(), [$this->getEntityIdField()] ) ); From 9d930fce8adad574ca6a2e62ce8d134b805ea474 Mon Sep 17 00:00:00 2001 From: Volodymyr Kholoshenko Date: Mon, 7 Sep 2015 15:07:55 +0300 Subject: [PATCH 4/4] MAGETWO-42369: $product->getProductLinks() doesnt return the linked product's sku and position with flat tables turned on --- .../Catalog/Test/Unit/Model/Resource/Product/FlatTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Resource/Product/FlatTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Resource/Product/FlatTest.php index ff70780200bb0..761235e242080 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Resource/Product/FlatTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Resource/Product/FlatTest.php @@ -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') ); }