Skip to content

Commit 3c51b12

Browse files
committed
MAGETWO-54682: Fast load of product options
- MAGETWO-55756: Porting to 2.1
1 parent cf195e7 commit 3c51b12

File tree

7 files changed

+93
-35
lines changed

7 files changed

+93
-35
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Catalog\Model\ResourceModel\Product\Indexer;
77

8+
use Magento\Catalog\Api\Data\ProductInterface;
89
use Magento\Catalog\Model\Product;
910
use Magento\Framework\DB\Select;
1011
use Magento\Catalog\Model\ResourceModel\Product\LinkedProductSelectBuilderInterface;
@@ -26,33 +27,51 @@ class LinkedProductSelectBuilderByIndexPrice implements LinkedProductSelectBuild
2627
*/
2728
private $customerSession;
2829

30+
/**
31+
* @var \Magento\Framework\EntityManager\MetadataPool
32+
*/
33+
private $metadataPool;
34+
2935
/**
3036
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
3137
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
3238
* @param \Magento\Customer\Model\Session $customerSession
39+
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
3340
*/
3441
public function __construct(
3542
\Magento\Store\Model\StoreManagerInterface $storeManager,
3643
\Magento\Framework\App\ResourceConnection $resourceConnection,
37-
\Magento\Customer\Model\Session $customerSession
44+
\Magento\Customer\Model\Session $customerSession,
45+
\Magento\Framework\EntityManager\MetadataPool $metadataPool
3846
) {
3947
$this->storeManager = $storeManager;
4048
$this->resource = $resourceConnection;
4149
$this->customerSession = $customerSession;
50+
$this->metadataPool = $metadataPool;
4251
}
4352

4453
/**
4554
* {@inheritdoc}
4655
*/
4756
public function build($productId)
4857
{
58+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
59+
4960
return [$this->resource->getConnection()->select()
50-
->from(['t' => $this->resource->getTableName('catalog_product_index_price')], 'entity_id')
61+
->from(['parent' => 'catalog_product_entity'], '')
5162
->joinInner(
5263
['link' => $this->resource->getTableName('catalog_product_relation')],
53-
'link.child_id = t.entity_id',
64+
"link.parent_id = parent.$linkField",
65+
[]
66+
)->joinInner(
67+
['child' => 'catalog_product_entity'],
68+
"child.entity_id = link.child_id",
69+
['entity_id']
70+
)->joinInner(
71+
['t' => $this->resource->getTableName('catalog_product_index_price')],
72+
't.entity_id = child.entity_id',
5473
[]
55-
)->where('link.parent_id = ? ', $productId)
74+
)->where('parent.entity_id = ? ', $productId)
5675
->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId())
5776
->where('t.customer_group_id = ?', $this->customerSession->getCustomerGroupId())
5877
->order('t.min_price ' . Select::SQL_ASC)

app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderByBasePrice.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,20 @@ public function build($productId)
6666
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
6767
$priceAttribute = $this->eavConfig->getAttribute(Product::ENTITY, 'price');
6868
$priceSelect = $this->resource->getConnection()->select()
69-
->from(['t' => $priceAttribute->getBackendTable()], $linkField)
69+
->from(['parent' => 'catalog_product_entity'], '')
7070
->joinInner(
7171
['link' => $this->resource->getTableName('catalog_product_relation')],
72-
"link.child_id = t.$linkField",
72+
"link.parent_id = parent.$linkField",
7373
[]
74-
)->where('link.parent_id = ? ', $productId)
74+
)->joinInner(
75+
['child' => 'catalog_product_entity'],
76+
"child.entity_id = link.child_id",
77+
['entity_id']
78+
)->joinInner(
79+
['t' => $priceAttribute->getBackendTable()],
80+
"t.$linkField = child.$linkField",
81+
[]
82+
)->where('parent.entity_id = ? ', $productId)
7583
->where('t.attribute_id = ?', $priceAttribute->getAttributeId())
7684
->where('t.value IS NOT NULL')
7785
->order('t.value ' . Select::SQL_ASC)

app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderBySpecialPrice.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,35 @@ public function build($productId)
8787
$timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore());
8888
$currentDate = $this->dateTime->formatDate($timestamp, false);
8989

90-
$specialPrice = $connection->select()
91-
->from(['t' => $specialPriceAttribute->getBackendTable()], $linkField)
90+
$specialPrice = $this->resource->getConnection()->select()
91+
->from(['parent' => 'catalog_product_entity'], '')
9292
->joinInner(
9393
['link' => $this->resource->getTableName('catalog_product_relation')],
94-
"link.child_id = t.{$linkField}",
94+
"link.parent_id = parent.$linkField",
9595
[]
9696
)->joinInner(
97+
['child' => 'catalog_product_entity'],
98+
"child.entity_id = link.child_id",
99+
['entity_id']
100+
)->joinInner(
101+
['t' => $specialPriceAttribute->getBackendTable()],
102+
"t.$linkField = child.$linkField",
103+
[]
104+
)->joinLeft(
97105
['special_from' => $specialPriceFromDate->getBackendTable()],
98106
$connection->quoteInto(
99107
"t.{$linkField} = special_from.{$linkField} AND special_from.attribute_id = ?",
100108
$specialPriceFromDate->getAttributeId()
101109
),
102110
''
103-
)->joinInner(
111+
)->joinLeft(
104112
['special_to' => $specialPriceToDate->getBackendTable()],
105113
$connection->quoteInto(
106114
"t.{$linkField} = special_to.{$linkField} AND special_to.attribute_id = ?",
107115
$specialPriceToDate->getAttributeId()
108116
),
109117
''
110-
)->where('link.parent_id = ? ', $productId)
118+
)->where('parent.entity_id = ? ', $productId)
111119
->where('t.attribute_id = ?', $specialPriceAttribute->getAttributeId())
112120
->where('t.value IS NOT NULL')
113121
->where(

app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderByTierPrice.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,24 @@ public function build($productId)
6969
{
7070
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
7171
$priceSelect = $this->resource->getConnection()->select()
72-
->from(['t' => $this->resource->getTableName('catalog_product_entity_tier_price')], $linkField)
73-
->joinInner(
74-
['link' => $this->resource->getTableName('catalog_product_relation')],
75-
"link.child_id = t.{$linkField}",
76-
[]
77-
)->where('link.parent_id = ? ', $productId)
78-
->where('t.all_groups = 1 OR customer_group_id = ?', $this->customerSession->getCustomerGroupId())
79-
->where('t.qty = ?', 1)
80-
->order('t.value ' . Select::SQL_ASC)
81-
->limit(1);
72+
->from(['parent' => 'catalog_product_entity'], '')
73+
->joinInner(
74+
['link' => $this->resource->getTableName('catalog_product_relation')],
75+
"link.parent_id = parent.$linkField",
76+
[]
77+
)->joinInner(
78+
['child' => 'catalog_product_entity'],
79+
"child.entity_id = link.child_id",
80+
['entity_id']
81+
)->joinInner(
82+
['t' => $this->resource->getTableName('catalog_product_entity_tier_price')],
83+
"t.$linkField = child.$linkField",
84+
[]
85+
)->where('parent.entity_id = ? ', $productId)
86+
->where('t.all_groups = 1 OR customer_group_id = ?', $this->customerSession->getCustomerGroupId())
87+
->where('t.qty = ?', 1)
88+
->order('t.value ' . Select::SQL_ASC)
89+
->limit(1);
8290

8391
$priceSelectDefault = clone $priceSelect;
8492
$priceSelectDefault->where('t.website_id = ?', self::DEFAULT_WEBSITE_ID);

app/code/Magento/CatalogInventory/Helper/Stock.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,7 @@ public function addIsInStockFilterToCollection($collection)
154154
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
155155
);
156156
$resource = $this->getStockStatusResource();
157-
$resource->addStockDataToCollection(
158-
$collection,
159-
!$isShowOutOfStock && $collection->getFlag('require_stock_items')
160-
);
157+
$resource->addStockDataToCollection($collection, !$isShowOutOfStock);
161158
$collection->setFlag($stockFlag, true);
162159
}
163160
}

app/code/Magento/CatalogRule/Model/ResourceModel/Product/LinkedProductSelectBuilderByCatalogRulePrice.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\CatalogRule\Model\ResourceModel\Product;
77

8+
use Magento\Catalog\Api\Data\ProductInterface;
89
use Magento\Catalog\Model\Product;
910
use Magento\Framework\DB\Select;
1011
use Magento\Catalog\Model\ResourceModel\Product\LinkedProductSelectBuilderInterface;
@@ -36,25 +37,33 @@ class LinkedProductSelectBuilderByCatalogRulePrice implements LinkedProductSelec
3637
*/
3738
private $localeDate;
3839

40+
/**
41+
* @var \Magento\Framework\EntityManager\MetadataPool
42+
*/
43+
private $metadataPool;
44+
3945
/**
4046
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
4147
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
4248
* @param \Magento\Customer\Model\Session $customerSession
4349
* @param \Magento\Framework\Stdlib\DateTime $dateTime
4450
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
51+
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
4552
*/
4653
public function __construct(
4754
\Magento\Store\Model\StoreManagerInterface $storeManager,
4855
\Magento\Framework\App\ResourceConnection $resourceConnection,
4956
\Magento\Customer\Model\Session $customerSession,
5057
\Magento\Framework\Stdlib\DateTime $dateTime,
51-
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
58+
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
59+
\Magento\Framework\EntityManager\MetadataPool $metadataPool
5260
) {
5361
$this->storeManager = $storeManager;
5462
$this->resource = $resourceConnection;
5563
$this->customerSession = $customerSession;
5664
$this->dateTime = $dateTime;
5765
$this->localeDate = $localeDate;
66+
$this->metadataPool = $metadataPool;
5867
}
5968

6069
/**
@@ -64,14 +73,23 @@ public function build($productId)
6473
{
6574
$timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore());
6675
$currentDate = $this->dateTime->formatDate($timestamp, false);
76+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
6777

6878
return [$this->resource->getConnection()->select()
69-
->from(['t' => $this->resource->getTableName('catalogrule_product_price')], 'product_id')
70-
->joinInner(
71-
['link' => $this->resource->getTableName('catalog_product_relation')],
72-
'link.child_id = t.product_id',
73-
[]
74-
)->where('link.parent_id = ? ', $productId)
79+
->from(['parent' => 'catalog_product_entity'], '')
80+
->joinInner(
81+
['link' => $this->resource->getTableName('catalog_product_relation')],
82+
"link.parent_id = parent.$linkField",
83+
[]
84+
)->joinInner(
85+
['child' => 'catalog_product_entity'],
86+
"child.entity_id = link.child_id",
87+
['entity_id']
88+
)->joinInner(
89+
['t' => $this->resource->getTableName('catalogrule_product_price')],
90+
't.product_id = child.entity_id',
91+
[]
92+
)->where('parent.entity_id = ? ', $productId)
7593
->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId())
7694
->where('t.customer_group_id = ?', $this->customerSession->getCustomerGroupId())
7795
->where('t.rule_date = ?', $currentDate)

app/code/Magento/ConfigurableProduct/Pricing/Price/ConfigurableOptionsProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public function getProducts(ProductInterface $product)
7676
);
7777

7878
$this->products[$product->getId()] = $this->collectionFactory->create()
79-
->addIdFilter($productIds)
80-
->addPriceData();
79+
->addAttributeToSelect(['price', 'special_price'])
80+
->addIdFilter($productIds);
8181
} else {
8282
$this->products[$product->getId()] = $this->configurable->getUsedProducts($product);
8383
}

0 commit comments

Comments
 (0)