Skip to content

Commit bd01667

Browse files
author
vnayda
committed
MAGETWO-57055: [Backport] - [GitHub] Configurable product disabling lowest price associated product still shows its price #4419 - for 2.1
1 parent 378f711 commit bd01667

25 files changed

+781
-131
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Model\ResourceModel\Product;
7+
8+
use Magento\Framework\DB\Select;
9+
10+
/**
11+
* Interface BaseSelectProcessorInterface
12+
* @api
13+
*/
14+
interface BaseSelectProcessorInterface
15+
{
16+
/**
17+
* Product table alias
18+
*/
19+
const PRODUCT_TABLE_ALIAS = 'child';
20+
21+
/**
22+
* @param Select $select
23+
* @return Select
24+
*/
25+
public function process(Select $select);
26+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Model\ResourceModel\Product;
7+
8+
use Magento\Framework\DB\Select;
9+
use Magento\Framework\Exception\InputException;
10+
11+
/**
12+
* Class CompositeBaseSelectProcessor
13+
*/
14+
class CompositeBaseSelectProcessor implements BaseSelectProcessorInterface
15+
{
16+
/**
17+
* @var BaseSelectProcessorInterface[]
18+
*/
19+
private $baseSelectProcessors;
20+
21+
/**
22+
* @param BaseSelectProcessorInterface[] $baseSelectProcessors
23+
* @throws InputException
24+
*/
25+
public function __construct(
26+
array $baseSelectProcessors
27+
) {
28+
foreach ($baseSelectProcessors as $baseSelectProcessor) {
29+
if (!$baseSelectProcessor instanceof BaseSelectProcessorInterface) {
30+
throw new InputException(
31+
__('Processor %1 doesn\'t implement BaseSelectProcessorInterface', get_class($baseSelectProcessor))
32+
);
33+
}
34+
}
35+
$this->baseSelectProcessors = $baseSelectProcessors;
36+
}
37+
38+
/**
39+
* @param Select $select
40+
* @return Select
41+
*/
42+
public function process(Select $select)
43+
{
44+
foreach ($this->baseSelectProcessors as $baseSelectProcessor) {
45+
$select = $baseSelectProcessor->process($select);
46+
}
47+
return $select;
48+
}
49+
}

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
namespace Magento\Catalog\Model\ResourceModel\Product\Indexer;
77

88
use Magento\Catalog\Api\Data\ProductInterface;
9-
use Magento\Catalog\Model\Product;
9+
use Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface;
10+
use Magento\Framework\App\ObjectManager;
1011
use Magento\Framework\DB\Select;
1112
use Magento\Catalog\Model\ResourceModel\Product\LinkedProductSelectBuilderInterface;
1213

@@ -32,22 +33,31 @@ class LinkedProductSelectBuilderByIndexPrice implements LinkedProductSelectBuild
3233
*/
3334
private $metadataPool;
3435

36+
/**
37+
* @var BaseSelectProcessorInterface
38+
*/
39+
private $baseSelectProcessor;
40+
3541
/**
3642
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
3743
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
3844
* @param \Magento\Customer\Model\Session $customerSession
3945
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
46+
* @param BaseSelectProcessorInterface $baseSelectProcessor
4047
*/
4148
public function __construct(
4249
\Magento\Store\Model\StoreManagerInterface $storeManager,
4350
\Magento\Framework\App\ResourceConnection $resourceConnection,
4451
\Magento\Customer\Model\Session $customerSession,
45-
\Magento\Framework\EntityManager\MetadataPool $metadataPool
52+
\Magento\Framework\EntityManager\MetadataPool $metadataPool,
53+
BaseSelectProcessorInterface $baseSelectProcessor = null
4654
) {
4755
$this->storeManager = $storeManager;
4856
$this->resource = $resourceConnection;
4957
$this->customerSession = $customerSession;
5058
$this->metadataPool = $metadataPool;
59+
$this->baseSelectProcessor = (null !== $baseSelectProcessor)
60+
? $baseSelectProcessor : ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class);
5161
}
5262

5363
/**
@@ -58,24 +68,27 @@ public function build($productId)
5868
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
5969
$productTable = $this->resource->getTableName('catalog_product_entity');
6070

61-
return [$this->resource->getConnection()->select()
71+
$priceSelect = $this->resource->getConnection()->select()
6272
->from(['parent' => $productTable], '')
6373
->joinInner(
6474
['link' => $this->resource->getTableName('catalog_product_relation')],
6575
"link.parent_id = parent.$linkField",
6676
[]
6777
)->joinInner(
68-
['child' => $productTable],
69-
"child.entity_id = link.child_id",
78+
[BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS => $productTable],
79+
sprintf('%s.entity_id = link.child_id', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
7080
['entity_id']
7181
)->joinInner(
7282
['t' => $this->resource->getTableName('catalog_product_index_price')],
73-
't.entity_id = child.entity_id',
83+
sprintf('t.entity_id = %s.entity_id', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
7484
[]
75-
)->where('parent.entity_id = ? ', $productId)
85+
)->where('parent.entity_id = ?', $productId)
7686
->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId())
7787
->where('t.customer_group_id = ?', $this->customerSession->getCustomerGroupId())
7888
->order('t.min_price ' . Select::SQL_ASC)
79-
->limit(1)];
89+
->limit(1);
90+
$priceSelect = $this->baseSelectProcessor->process($priceSelect);
91+
92+
return [$priceSelect];
8093
}
8194
}

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Catalog\Api\Data\ProductInterface;
99
use Magento\Catalog\Model\Product;
10+
use Magento\Framework\App\ObjectManager;
1011
use Magento\Framework\DB\Select;
1112
use Magento\Store\Model\Store;
1213

@@ -37,25 +38,34 @@ class LinkedProductSelectBuilderByBasePrice implements LinkedProductSelectBuilde
3738
*/
3839
private $metadataPool;
3940

41+
/**
42+
* @var BaseSelectProcessorInterface
43+
*/
44+
private $baseSelectProcessor;
45+
4046
/**
4147
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
4248
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
4349
* @param \Magento\Eav\Model\Config $eavConfig
4450
* @param \Magento\Catalog\Helper\Data $catalogHelper
4551
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
52+
* @param BaseSelectProcessorInterface $baseSelectProcessor
4653
*/
4754
public function __construct(
4855
\Magento\Store\Model\StoreManagerInterface $storeManager,
4956
\Magento\Framework\App\ResourceConnection $resourceConnection,
5057
\Magento\Eav\Model\Config $eavConfig,
5158
\Magento\Catalog\Helper\Data $catalogHelper,
52-
\Magento\Framework\EntityManager\MetadataPool $metadataPool
59+
\Magento\Framework\EntityManager\MetadataPool $metadataPool,
60+
BaseSelectProcessorInterface $baseSelectProcessor = null
5361
) {
5462
$this->storeManager = $storeManager;
5563
$this->resource = $resourceConnection;
5664
$this->eavConfig = $eavConfig;
5765
$this->catalogHelper = $catalogHelper;
5866
$this->metadataPool = $metadataPool;
67+
$this->baseSelectProcessor = (null !== $baseSelectProcessor)
68+
? $baseSelectProcessor : ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class);
5969
}
6070

6171
/**
@@ -74,18 +84,19 @@ public function build($productId)
7484
"link.parent_id = parent.$linkField",
7585
[]
7686
)->joinInner(
77-
['child' => $productTable],
78-
"child.entity_id = link.child_id",
87+
[BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS => $productTable],
88+
sprintf('%s.entity_id = link.child_id', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS, $linkField),
7989
['entity_id']
8090
)->joinInner(
8191
['t' => $priceAttribute->getBackendTable()],
82-
"t.$linkField = child.$linkField",
92+
sprintf('t.%s = %s.%1$s', $linkField, BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
8393
[]
84-
)->where('parent.entity_id = ? ', $productId)
94+
)->where('parent.entity_id = ?', $productId)
8595
->where('t.attribute_id = ?', $priceAttribute->getAttributeId())
8696
->where('t.value IS NOT NULL')
8797
->order('t.value ' . Select::SQL_ASC)
8898
->limit(1);
99+
$priceSelect = $this->baseSelectProcessor->process($priceSelect);
89100

90101
$priceSelectDefault = clone $priceSelect;
91102
$priceSelectDefault->where('t.store_id = ?', Store::DEFAULT_STORE_ID);

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77

88
use Magento\Catalog\Api\Data\ProductInterface;
99
use Magento\Catalog\Model\Product;
10+
use Magento\Framework\App\ObjectManager;
1011
use Magento\Framework\DB\Select;
1112
use Magento\Store\Model\Store;
1213

14+
/**
15+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
16+
*/
1317
class LinkedProductSelectBuilderBySpecialPrice implements LinkedProductSelectBuilderInterface
1418
{
1519
/**
@@ -47,6 +51,11 @@ class LinkedProductSelectBuilderBySpecialPrice implements LinkedProductSelectBui
4751
*/
4852
private $metadataPool;
4953

54+
/**
55+
* @var BaseSelectProcessorInterface
56+
*/
57+
private $baseSelectProcessor;
58+
5059
/**
5160
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
5261
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
@@ -55,6 +64,7 @@ class LinkedProductSelectBuilderBySpecialPrice implements LinkedProductSelectBui
5564
* @param \Magento\Framework\Stdlib\DateTime $dateTime
5665
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
5766
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
67+
* @param BaseSelectProcessorInterface $baseSelectProcessor
5868
*/
5969
public function __construct(
6070
\Magento\Store\Model\StoreManagerInterface $storeManager,
@@ -63,7 +73,8 @@ public function __construct(
6373
\Magento\Catalog\Helper\Data $catalogHelper,
6474
\Magento\Framework\Stdlib\DateTime $dateTime,
6575
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
66-
\Magento\Framework\EntityManager\MetadataPool $metadataPool
76+
\Magento\Framework\EntityManager\MetadataPool $metadataPool,
77+
BaseSelectProcessorInterface $baseSelectProcessor = null
6778
) {
6879
$this->storeManager = $storeManager;
6980
$this->resource = $resourceConnection;
@@ -72,6 +83,8 @@ public function __construct(
7283
$this->dateTime = $dateTime;
7384
$this->localeDate = $localeDate;
7485
$this->metadataPool = $metadataPool;
86+
$this->baseSelectProcessor = (null !== $baseSelectProcessor)
87+
? $baseSelectProcessor : ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class);
7588
}
7689

7790
/**
@@ -95,12 +108,12 @@ public function build($productId)
95108
"link.parent_id = parent.$linkField",
96109
[]
97110
)->joinInner(
98-
['child' => $productTable],
99-
"child.entity_id = link.child_id",
111+
[BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS => $productTable],
112+
sprintf('%s.entity_id = link.child_id', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
100113
['entity_id']
101114
)->joinInner(
102115
['t' => $specialPriceAttribute->getBackendTable()],
103-
"t.$linkField = child.$linkField",
116+
sprintf('t.%s = %s.%1$s', $linkField, BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
104117
[]
105118
)->joinLeft(
106119
['special_from' => $specialPriceFromDate->getBackendTable()],
@@ -116,7 +129,7 @@ public function build($productId)
116129
$specialPriceToDate->getAttributeId()
117130
),
118131
''
119-
)->where('parent.entity_id = ? ', $productId)
132+
)->where('parent.entity_id = ?', $productId)
120133
->where('t.attribute_id = ?', $specialPriceAttribute->getAttributeId())
121134
->where('t.value IS NOT NULL')
122135
->where(
@@ -127,6 +140,7 @@ public function build($productId)
127140
$currentDate
128141
)->order('t.value ' . Select::SQL_ASC)
129142
->limit(1);
143+
$specialPrice = $this->baseSelectProcessor->process($specialPrice);
130144

131145
$specialPriceDefault = clone $specialPrice;
132146
$specialPriceDefault->where('t.store_id = ?', Store::DEFAULT_STORE_ID);

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Magento\Catalog\Model\ResourceModel\Product;
77

88
use Magento\Catalog\Api\Data\ProductInterface;
9-
use Magento\Catalog\Model\Product;
9+
use Magento\Framework\App\ObjectManager;
1010
use Magento\Framework\DB\Select;
1111

1212
class LinkedProductSelectBuilderByTierPrice implements LinkedProductSelectBuilderInterface
@@ -41,25 +41,34 @@ class LinkedProductSelectBuilderByTierPrice implements LinkedProductSelectBuilde
4141
*/
4242
private $metadataPool;
4343

44+
/**
45+
* @var BaseSelectProcessorInterface
46+
*/
47+
private $baseSelectProcessor;
48+
4449
/**
4550
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
4651
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
4752
* @param \Magento\Customer\Model\Session $customerSession
4853
* @param \Magento\Catalog\Helper\Data $catalogHelper
4954
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
55+
* @param BaseSelectProcessorInterface $baseSelectProcessor
5056
*/
5157
public function __construct(
5258
\Magento\Store\Model\StoreManagerInterface $storeManager,
5359
\Magento\Framework\App\ResourceConnection $resourceConnection,
5460
\Magento\Customer\Model\Session $customerSession,
5561
\Magento\Catalog\Helper\Data $catalogHelper,
56-
\Magento\Framework\EntityManager\MetadataPool $metadataPool
62+
\Magento\Framework\EntityManager\MetadataPool $metadataPool,
63+
BaseSelectProcessorInterface $baseSelectProcessor = null
5764
) {
5865
$this->storeManager = $storeManager;
5966
$this->resource = $resourceConnection;
6067
$this->customerSession = $customerSession;
6168
$this->catalogHelper = $catalogHelper;
6269
$this->metadataPool = $metadataPool;
70+
$this->baseSelectProcessor = (null !== $baseSelectProcessor)
71+
? $baseSelectProcessor : ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class);
6372
}
6473

6574
/**
@@ -77,18 +86,19 @@ public function build($productId)
7786
"link.parent_id = parent.$linkField",
7887
[]
7988
)->joinInner(
80-
['child' => $productTable],
81-
"child.entity_id = link.child_id",
89+
[BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS => $productTable],
90+
sprintf('%s.entity_id = link.child_id', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
8291
['entity_id']
8392
)->joinInner(
8493
['t' => $this->resource->getTableName('catalog_product_entity_tier_price')],
85-
"t.$linkField = child.$linkField",
94+
sprintf('t.%s = %s.%1$s', $linkField, BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
8695
[]
87-
)->where('parent.entity_id = ? ', $productId)
96+
)->where('parent.entity_id = ?', $productId)
8897
->where('t.all_groups = 1 OR customer_group_id = ?', $this->customerSession->getCustomerGroupId())
8998
->where('t.qty = ?', 1)
9099
->order('t.value ' . Select::SQL_ASC)
91100
->limit(1);
101+
$priceSelect = $this->baseSelectProcessor->process($priceSelect);
92102

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

0 commit comments

Comments
 (0)