Skip to content

Commit 572505c

Browse files
author
Oleksii Korshenko
authored
Merge pull request #545 from magento-dragons/MAGETWO-59950
Fixed issues: - MAGETWO-59950: Configurable product option price is displayed incorrectly per website - for 2.0.x - MAGETWO-59415: [Backport] - As low as price for configurable product is shown for disabled simple options - for 2.0.11 - MAGETWO-60187: [Backport] Non consistent save Product Stock Item via Web API and repository directly - 2.0 - MAGETWO-57056: [Backport] [GitHub] Configurable product disabling lowest price associated product still shows its price #4419 - for 2.0
2 parents f3dc998 + a5cdd10 commit 572505c

File tree

29 files changed

+1145
-116
lines changed

29 files changed

+1145
-116
lines changed

app/code/Magento/Catalog/Model/Product/Attribute/Backend/Stock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function beforeSave($object)
5959
if (isset($stockData['qty']) && $stockData['qty'] === '') {
6060
$stockData['qty'] = null;
6161
}
62-
if ($object->getStockData() !== null || $stockData !== null) {
62+
if ($object->getStockData() !== null && $stockData !== null) {
6363
$object->setStockData(array_replace((array)$object->getStockData(), (array)$stockData));
6464
}
6565
$object->unsetData($this->getAttribute()->getAttributeCode());
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
*/
13+
interface BaseSelectProcessorInterface
14+
{
15+
/**
16+
* Product table alias
17+
*/
18+
const PRODUCT_RELATION_ALIAS = 'link';
19+
20+
/**
21+
* @param Select $select
22+
* @return Select
23+
*/
24+
public function process(Select $select);
25+
}
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: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
*/
66
namespace Magento\Catalog\Model\ResourceModel\Product\Indexer;
77

8-
use Magento\Catalog\Model\Product;
8+
use Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface;
9+
use Magento\Framework\App\ObjectManager;
910
use Magento\Framework\DB\Select;
10-
use Magento\Store\Model\Store;
1111
use Magento\Catalog\Model\ResourceModel\Product\LinkedProductSelectBuilderInterface;
1212

1313
class LinkedProductSelectBuilderByIndexPrice implements LinkedProductSelectBuilderInterface
@@ -27,36 +27,51 @@ class LinkedProductSelectBuilderByIndexPrice implements LinkedProductSelectBuild
2727
*/
2828
private $customerSession;
2929

30+
/**
31+
* @var BaseSelectProcessorInterface
32+
*/
33+
private $baseSelectProcessor;
34+
3035
/**
3136
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
3237
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
3338
* @param \Magento\Customer\Model\Session $customerSession
39+
* @param BaseSelectProcessorInterface $baseSelectProcessor
3440
*/
3541
public function __construct(
3642
\Magento\Store\Model\StoreManagerInterface $storeManager,
3743
\Magento\Framework\App\ResourceConnection $resourceConnection,
38-
\Magento\Customer\Model\Session $customerSession
44+
\Magento\Customer\Model\Session $customerSession,
45+
BaseSelectProcessorInterface $baseSelectProcessor = null
3946
) {
4047
$this->storeManager = $storeManager;
4148
$this->resource = $resourceConnection;
4249
$this->customerSession = $customerSession;
50+
$this->baseSelectProcessor = (null !== $baseSelectProcessor)
51+
? $baseSelectProcessor : ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class);
4352
}
4453

4554
/**
4655
* {@inheritdoc}
4756
*/
4857
public function build($productId)
4958
{
50-
return [$this->resource->getConnection()->select()
59+
$priceSelect = $this->resource->getConnection()->select()
5160
->from(['t' => $this->resource->getTableName('catalog_product_index_price')], 'entity_id')
5261
->joinInner(
53-
['link' => $this->resource->getTableName('catalog_product_relation')],
54-
'link.child_id = t.entity_id',
62+
[
63+
BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS
64+
=> $this->resource->getTableName('catalog_product_relation')
65+
],
66+
BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS . '.child_id = t.entity_id',
5567
[]
56-
)->where('link.parent_id = ? ', $productId)
68+
)->where(BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS . '.parent_id = ? ', $productId)
5769
->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId())
5870
->where('t.customer_group_id = ?', $this->customerSession->getCustomerGroupId())
5971
->order('t.min_price ' . Select::SQL_ASC)
60-
->limit(1)];
72+
->limit(1);
73+
$priceSelect = $this->baseSelectProcessor->process($priceSelect);
74+
75+
return [$priceSelect];
6176
}
6277
}

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

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

88
use Magento\Catalog\Model\Product;
9+
use Magento\Framework\App\ObjectManager;
910
use Magento\Framework\DB\Select;
1011
use Magento\Store\Model\Store;
1112

@@ -31,22 +32,31 @@ class LinkedProductSelectBuilderByBasePrice implements LinkedProductSelectBuilde
3132
*/
3233
private $catalogHelper;
3334

35+
/**
36+
* @var BaseSelectProcessorInterface
37+
*/
38+
private $baseSelectProcessor;
39+
3440
/**
3541
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
3642
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
3743
* @param \Magento\Eav\Model\Config $eavConfig
3844
* @param \Magento\Catalog\Helper\Data $catalogHelper
45+
* @param BaseSelectProcessorInterface $baseSelectProcessor
3946
*/
4047
public function __construct(
4148
\Magento\Store\Model\StoreManagerInterface $storeManager,
4249
\Magento\Framework\App\ResourceConnection $resourceConnection,
4350
\Magento\Eav\Model\Config $eavConfig,
44-
\Magento\Catalog\Helper\Data $catalogHelper
51+
\Magento\Catalog\Helper\Data $catalogHelper,
52+
BaseSelectProcessorInterface $baseSelectProcessor = null
4553
) {
4654
$this->storeManager = $storeManager;
4755
$this->resource = $resourceConnection;
4856
$this->eavConfig = $eavConfig;
4957
$this->catalogHelper = $catalogHelper;
58+
$this->baseSelectProcessor = (null !== $baseSelectProcessor)
59+
? $baseSelectProcessor : ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class);
5060
}
5161

5262
/**
@@ -58,14 +68,18 @@ public function build($productId)
5868
$priceSelect = $this->resource->getConnection()->select()
5969
->from(['t' => $priceAttribute->getBackendTable()], 'entity_id')
6070
->joinInner(
61-
['link' => $this->resource->getTableName('catalog_product_relation')],
62-
'link.child_id = t.entity_id',
71+
[
72+
BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS
73+
=> $this->resource->getTableName('catalog_product_relation')
74+
],
75+
BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS . '.child_id = t.entity_id',
6376
[]
64-
)->where('link.parent_id = ? ', $productId)
77+
)->where(BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS . '.parent_id = ? ', $productId)
6578
->where('t.attribute_id = ?', $priceAttribute->getAttributeId())
6679
->where('t.value IS NOT NULL')
6780
->order('t.value ' . Select::SQL_ASC)
6881
->limit(1);
82+
$priceSelect = $this->baseSelectProcessor->process($priceSelect);
6983

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

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

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

88
use Magento\Catalog\Model\Product;
9+
use Magento\Framework\App\ObjectManager;
910
use Magento\Framework\DB\Select;
1011
use Magento\Store\Model\Store;
1112

@@ -41,28 +42,37 @@ class LinkedProductSelectBuilderBySpecialPrice implements LinkedProductSelectBui
4142
*/
4243
private $localeDate;
4344

45+
/**
46+
* @var BaseSelectProcessorInterface
47+
*/
48+
private $baseSelectProcessor;
49+
4450
/**
4551
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
4652
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
4753
* @param \Magento\Eav\Model\Config $eavConfig
4854
* @param \Magento\Catalog\Helper\Data $catalogHelper
4955
* @param \Magento\Framework\Stdlib\DateTime $dateTime
5056
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
57+
* @param BaseSelectProcessorInterface $baseSelectProcessor
5158
*/
5259
public function __construct(
5360
\Magento\Store\Model\StoreManagerInterface $storeManager,
5461
\Magento\Framework\App\ResourceConnection $resourceConnection,
5562
\Magento\Eav\Model\Config $eavConfig,
5663
\Magento\Catalog\Helper\Data $catalogHelper,
5764
\Magento\Framework\Stdlib\DateTime $dateTime,
58-
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
65+
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
66+
BaseSelectProcessorInterface $baseSelectProcessor = null
5967
) {
6068
$this->storeManager = $storeManager;
6169
$this->resource = $resourceConnection;
6270
$this->eavConfig = $eavConfig;
6371
$this->catalogHelper = $catalogHelper;
6472
$this->dateTime = $dateTime;
6573
$this->localeDate = $localeDate;
74+
$this->baseSelectProcessor = (null !== $baseSelectProcessor)
75+
? $baseSelectProcessor : ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class);
6676
}
6777

6878
/**
@@ -80,8 +90,11 @@ public function build($productId)
8090
$specialPrice = $connection->select()
8191
->from(['t' => $specialPriceAttribute->getBackendTable()], 'entity_id')
8292
->joinInner(
83-
['link' => $this->resource->getTableName('catalog_product_relation')],
84-
'link.child_id = t.entity_id',
93+
[
94+
BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS
95+
=> $this->resource->getTableName('catalog_product_relation')
96+
],
97+
BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS . '.child_id = t.entity_id',
8598
[]
8699
)->joinInner(
87100
['special_from' => $specialPriceFromDate->getBackendTable()],
@@ -97,7 +110,7 @@ public function build($productId)
97110
$specialPriceToDate->getAttributeId()
98111
),
99112
''
100-
)->where('link.parent_id = ? ', $productId)
113+
)->where(BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS . '.parent_id = ? ', $productId)
101114
->where('t.attribute_id = ?', $specialPriceAttribute->getAttributeId())
102115
->where('t.value IS NOT NULL')
103116
->where(
@@ -108,6 +121,7 @@ public function build($productId)
108121
$currentDate
109122
)->order('t.value ' . Select::SQL_ASC)
110123
->limit(1);
124+
$specialPrice = $this->baseSelectProcessor->process($specialPrice);
111125

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

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

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

8-
use Magento\Catalog\Model\Product;
8+
use Magento\Framework\App\ObjectManager;
99
use Magento\Framework\DB\Select;
1010

1111
class LinkedProductSelectBuilderByTierPrice implements LinkedProductSelectBuilderInterface
@@ -35,22 +35,31 @@ class LinkedProductSelectBuilderByTierPrice implements LinkedProductSelectBuilde
3535
*/
3636
private $catalogHelper;
3737

38+
/**
39+
* @var BaseSelectProcessorInterface
40+
*/
41+
private $baseSelectProcessor;
42+
3843
/**
3944
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
4045
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
4146
* @param \Magento\Customer\Model\Session $customerSession
4247
* @param \Magento\Catalog\Helper\Data $catalogHelper
48+
* @param BaseSelectProcessorInterface $baseSelectProcessor
4349
*/
4450
public function __construct(
4551
\Magento\Store\Model\StoreManagerInterface $storeManager,
4652
\Magento\Framework\App\ResourceConnection $resourceConnection,
4753
\Magento\Customer\Model\Session $customerSession,
48-
\Magento\Catalog\Helper\Data $catalogHelper
54+
\Magento\Catalog\Helper\Data $catalogHelper,
55+
BaseSelectProcessorInterface $baseSelectProcessor = null
4956
) {
5057
$this->storeManager = $storeManager;
5158
$this->resource = $resourceConnection;
5259
$this->customerSession = $customerSession;
5360
$this->catalogHelper = $catalogHelper;
61+
$this->baseSelectProcessor = (null !== $baseSelectProcessor)
62+
? $baseSelectProcessor : ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class);
5463
}
5564

5665
/**
@@ -59,16 +68,20 @@ public function __construct(
5968
public function build($productId)
6069
{
6170
$priceSelect = $this->resource->getConnection()->select()
62-
->from(['t' => $this->resource->getTableName('catalog_product_entity_tier_price')], 'entity_id')
63-
->joinInner(
64-
['link' => $this->resource->getTableName('catalog_product_relation')],
65-
'link.child_id = t.entity_id',
66-
[]
67-
)->where('link.parent_id = ? ', $productId)
68-
->where('t.all_groups = 1 OR customer_group_id = ?', $this->customerSession->getCustomerGroupId())
69-
->where('t.qty = ?', 1)
70-
->order('t.value ' . Select::SQL_ASC)
71-
->limit(1);
71+
->from(['t' => $this->resource->getTableName('catalog_product_entity_tier_price')], 'entity_id')
72+
->joinInner(
73+
[
74+
BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS
75+
=> $this->resource->getTableName('catalog_product_relation')
76+
],
77+
BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS . '.child_id = t.entity_id',
78+
[]
79+
)->where(BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS . '.parent_id = ? ', $productId)
80+
->where('t.all_groups = 1 OR customer_group_id = ?', $this->customerSession->getCustomerGroupId())
81+
->where('t.qty = ?', 1)
82+
->order('t.value ' . Select::SQL_ASC)
83+
->limit(1);
84+
$priceSelect = $this->baseSelectProcessor->process($priceSelect);
7285

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

0 commit comments

Comments
 (0)