From 0b8581c5aaece99aa56b540401f6713a37ff88fd Mon Sep 17 00:00:00 2001 From: Nissa Blagojevic Date: Sat, 15 Oct 2016 17:01:23 +1100 Subject: [PATCH 1/3] Added an optional limit arg to build functions of LinkedProductSelectBuilders and a limit of PHP_INT_MAX to ConfigurableOptionsProvider --- .../Indexer/LinkedProductSelectBuilderByIndexPrice.php | 4 ++-- .../Product/LinkedProductSelectBuilderByBasePrice.php | 5 ++--- .../Product/LinkedProductSelectBuilderBySpecialPrice.php | 5 ++--- .../Product/LinkedProductSelectBuilderByTierPrice.php | 5 ++--- .../Product/LinkedProductSelectBuilderComposite.php | 4 ++-- .../Product/LinkedProductSelectBuilderInterface.php | 3 ++- .../Product/LinkedProductSelectBuilderByCatalogRulePrice.php | 4 ++-- 7 files changed, 14 insertions(+), 16 deletions(-) diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php index 3aa6642c82d84..d4d14976bdf82 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php @@ -63,7 +63,7 @@ public function __construct( /** * {@inheritdoc} */ - public function build($productId) + public function build($productId, $limit = 1) { $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); $productTable = $this->resource->getTableName('catalog_product_entity'); @@ -86,7 +86,7 @@ public function build($productId) ->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId()) ->where('t.customer_group_id = ?', $this->customerSession->getCustomerGroupId()) ->order('t.min_price ' . Select::SQL_ASC) - ->limit(1); + ->limit($limit)]; $priceSelect = $this->baseSelectProcessor->process($priceSelect); return [$priceSelect]; diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderByBasePrice.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderByBasePrice.php index 7caa72b367979..0ecf33fef18cf 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderByBasePrice.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderByBasePrice.php @@ -71,7 +71,7 @@ public function __construct( /** * {@inheritdoc} */ - public function build($productId) + public function build($productId, $limit = 1) { $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); $priceAttribute = $this->eavConfig->getAttribute(Product::ENTITY, 'price'); @@ -95,9 +95,8 @@ public function build($productId) ->where('t.attribute_id = ?', $priceAttribute->getAttributeId()) ->where('t.value IS NOT NULL') ->order('t.value ' . Select::SQL_ASC) - ->limit(1); + ->limit($limit); $priceSelect = $this->baseSelectProcessor->process($priceSelect); - $priceSelectDefault = clone $priceSelect; $priceSelectDefault->where('t.store_id = ?', Store::DEFAULT_STORE_ID); $select[] = $priceSelectDefault; diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderBySpecialPrice.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderBySpecialPrice.php index 68eaf206e293f..c1509f306da9f 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderBySpecialPrice.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderBySpecialPrice.php @@ -90,7 +90,7 @@ public function __construct( /** * {@inheritdoc} */ - public function build($productId) + public function build($productId, $limit = 1) { $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); $connection = $this->resource->getConnection(); @@ -139,9 +139,8 @@ public function build($productId) 'special_to.value IS NULL OR ' . $connection->getDatePartSql('special_to.value') .' >= ?', $currentDate )->order('t.value ' . Select::SQL_ASC) - ->limit(1); + ->limit($limit); $specialPrice = $this->baseSelectProcessor->process($specialPrice); - $specialPriceDefault = clone $specialPrice; $specialPriceDefault->where('t.store_id = ?', Store::DEFAULT_STORE_ID); $select[] = $specialPriceDefault; diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderByTierPrice.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderByTierPrice.php index 25bf83f837de7..b1c6bd76169a3 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderByTierPrice.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderByTierPrice.php @@ -74,7 +74,7 @@ public function __construct( /** * {@inheritdoc} */ - public function build($productId) + public function build($productId, $limit = 1) { $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); $productTable = $this->resource->getTableName('catalog_product_entity'); @@ -97,9 +97,8 @@ public function build($productId) ->where('t.all_groups = 1 OR customer_group_id = ?', $this->customerSession->getCustomerGroupId()) ->where('t.qty = ?', 1) ->order('t.value ' . Select::SQL_ASC) - ->limit(1); + ->limit($limit); $priceSelect = $this->baseSelectProcessor->process($priceSelect); - $priceSelectDefault = clone $priceSelect; $priceSelectDefault->where('t.website_id = ?', self::DEFAULT_WEBSITE_ID); $select[] = $priceSelectDefault; diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderComposite.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderComposite.php index f3dc225685985..1e911a2c8a50a 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderComposite.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderComposite.php @@ -24,11 +24,11 @@ public function __construct($linkedProductSelectBuilder) /** * {@inheritdoc} */ - public function build($productId) + public function build($productId, $limit = 1) { $select = []; foreach ($this->linkedProductSelectBuilder as $productSelectBuilder) { - $select = array_merge($select, $productSelectBuilder->build($productId)); + $select = array_merge($select, $productSelectBuilder->build($productId, $limit)); } return $select; diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderInterface.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderInterface.php index e437791fd3d99..fbc79b1a6570c 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderInterface.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderInterface.php @@ -12,7 +12,8 @@ interface LinkedProductSelectBuilderInterface { /** * @param int $productId + * @param int $limit * @return \Magento\Framework\DB\Select[] */ - public function build($productId); + public function build($productId, $limit = 1); } diff --git a/app/code/Magento/CatalogRule/Model/ResourceModel/Product/LinkedProductSelectBuilderByCatalogRulePrice.php b/app/code/Magento/CatalogRule/Model/ResourceModel/Product/LinkedProductSelectBuilderByCatalogRulePrice.php index 55b76eb225028..ad9eee8460b31 100644 --- a/app/code/Magento/CatalogRule/Model/ResourceModel/Product/LinkedProductSelectBuilderByCatalogRulePrice.php +++ b/app/code/Magento/CatalogRule/Model/ResourceModel/Product/LinkedProductSelectBuilderByCatalogRulePrice.php @@ -79,7 +79,7 @@ public function __construct( /** * {@inheritdoc} */ - public function build($productId) + public function build($productId, $limit = 1) { $timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore()); $currentDate = $this->dateTime->formatDate($timestamp, false); @@ -105,7 +105,7 @@ public function build($productId) ->where('t.customer_group_id = ?', $this->customerSession->getCustomerGroupId()) ->where('t.rule_date = ?', $currentDate) ->order('t.rule_price ' . Select::SQL_ASC) - ->limit(1); + ->limit($limit)]; $priceSelect = $this->baseSelectProcessor->process($priceSelect); return [$priceSelect]; From 5835ee8200388ee1b2fbad933a6df948e90dea01 Mon Sep 17 00:00:00 2001 From: nissablagojevic Date: Wed, 21 Dec 2016 22:16:32 +1100 Subject: [PATCH 2/3] fixed a typo --- .../Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php index d4d14976bdf82..296de7fc5e5bc 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php @@ -86,7 +86,7 @@ public function build($productId, $limit = 1) ->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId()) ->where('t.customer_group_id = ?', $this->customerSession->getCustomerGroupId()) ->order('t.min_price ' . Select::SQL_ASC) - ->limit($limit)]; + ->limit($limit); $priceSelect = $this->baseSelectProcessor->process($priceSelect); return [$priceSelect]; From 90568de09953787bb60f5258056200f55472c140 Mon Sep 17 00:00:00 2001 From: nissablagojevic Date: Wed, 21 Dec 2016 22:30:51 +1100 Subject: [PATCH 3/3] fixed a typo... another one. --- .../Product/LinkedProductSelectBuilderByCatalogRulePrice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/CatalogRule/Model/ResourceModel/Product/LinkedProductSelectBuilderByCatalogRulePrice.php b/app/code/Magento/CatalogRule/Model/ResourceModel/Product/LinkedProductSelectBuilderByCatalogRulePrice.php index ad9eee8460b31..55e0fa50de808 100644 --- a/app/code/Magento/CatalogRule/Model/ResourceModel/Product/LinkedProductSelectBuilderByCatalogRulePrice.php +++ b/app/code/Magento/CatalogRule/Model/ResourceModel/Product/LinkedProductSelectBuilderByCatalogRulePrice.php @@ -105,7 +105,7 @@ public function build($productId, $limit = 1) ->where('t.customer_group_id = ?', $this->customerSession->getCustomerGroupId()) ->where('t.rule_date = ?', $currentDate) ->order('t.rule_price ' . Select::SQL_ASC) - ->limit($limit)]; + ->limit($limit); $priceSelect = $this->baseSelectProcessor->process($priceSelect); return [$priceSelect];