Skip to content

Commit

Permalink
Merge pull request #545 from magento-dragons/MAGETWO-59950
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Oleksii Korshenko authored Oct 28, 2016
2 parents f3dc998 + a5cdd10 commit 572505c
Show file tree
Hide file tree
Showing 29 changed files with 1,145 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function beforeSave($object)
if (isset($stockData['qty']) && $stockData['qty'] === '') {
$stockData['qty'] = null;
}
if ($object->getStockData() !== null || $stockData !== null) {
if ($object->getStockData() !== null && $stockData !== null) {
$object->setStockData(array_replace((array)$object->getStockData(), (array)$stockData));
}
$object->unsetData($this->getAttribute()->getAttributeCode());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Model\ResourceModel\Product;

use Magento\Framework\DB\Select;

/**
* Interface BaseSelectProcessorInterface
*/
interface BaseSelectProcessorInterface
{
/**
* Product table alias
*/
const PRODUCT_RELATION_ALIAS = 'link';

/**
* @param Select $select
* @return Select
*/
public function process(Select $select);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Model\ResourceModel\Product;

use Magento\Framework\DB\Select;
use Magento\Framework\Exception\InputException;

/**
* Class CompositeBaseSelectProcessor
*/
class CompositeBaseSelectProcessor implements BaseSelectProcessorInterface
{
/**
* @var BaseSelectProcessorInterface[]
*/
private $baseSelectProcessors;

/**
* @param BaseSelectProcessorInterface[] $baseSelectProcessors
* @throws InputException
*/
public function __construct(
array $baseSelectProcessors
) {
foreach ($baseSelectProcessors as $baseSelectProcessor) {
if (!$baseSelectProcessor instanceof BaseSelectProcessorInterface) {
throw new InputException(
__('Processor %1 doesn\'t implement BaseSelectProcessorInterface', get_class($baseSelectProcessor))
);
}
}
$this->baseSelectProcessors = $baseSelectProcessors;
}

/**
* @param Select $select
* @return Select
*/
public function process(Select $select)
{
foreach ($this->baseSelectProcessors as $baseSelectProcessor) {
$select = $baseSelectProcessor->process($select);
}
return $select;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*/
namespace Magento\Catalog\Model\ResourceModel\Product\Indexer;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DB\Select;
use Magento\Store\Model\Store;
use Magento\Catalog\Model\ResourceModel\Product\LinkedProductSelectBuilderInterface;

class LinkedProductSelectBuilderByIndexPrice implements LinkedProductSelectBuilderInterface
Expand All @@ -27,36 +27,51 @@ class LinkedProductSelectBuilderByIndexPrice implements LinkedProductSelectBuild
*/
private $customerSession;

/**
* @var BaseSelectProcessorInterface
*/
private $baseSelectProcessor;

/**
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
* @param \Magento\Customer\Model\Session $customerSession
* @param BaseSelectProcessorInterface $baseSelectProcessor
*/
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\ResourceConnection $resourceConnection,
\Magento\Customer\Model\Session $customerSession
\Magento\Customer\Model\Session $customerSession,
BaseSelectProcessorInterface $baseSelectProcessor = null
) {
$this->storeManager = $storeManager;
$this->resource = $resourceConnection;
$this->customerSession = $customerSession;
$this->baseSelectProcessor = (null !== $baseSelectProcessor)
? $baseSelectProcessor : ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class);
}

/**
* {@inheritdoc}
*/
public function build($productId)
{
return [$this->resource->getConnection()->select()
$priceSelect = $this->resource->getConnection()->select()
->from(['t' => $this->resource->getTableName('catalog_product_index_price')], 'entity_id')
->joinInner(
['link' => $this->resource->getTableName('catalog_product_relation')],
'link.child_id = t.entity_id',
[
BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS
=> $this->resource->getTableName('catalog_product_relation')
],
BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS . '.child_id = t.entity_id',
[]
)->where('link.parent_id = ? ', $productId)
)->where(BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS . '.parent_id = ? ', $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(1);
$priceSelect = $this->baseSelectProcessor->process($priceSelect);

return [$priceSelect];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Catalog\Model\ResourceModel\Product;

use Magento\Catalog\Model\Product;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DB\Select;
use Magento\Store\Model\Store;

Expand All @@ -31,22 +32,31 @@ class LinkedProductSelectBuilderByBasePrice implements LinkedProductSelectBuilde
*/
private $catalogHelper;

/**
* @var BaseSelectProcessorInterface
*/
private $baseSelectProcessor;

/**
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
* @param \Magento\Eav\Model\Config $eavConfig
* @param \Magento\Catalog\Helper\Data $catalogHelper
* @param BaseSelectProcessorInterface $baseSelectProcessor
*/
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\ResourceConnection $resourceConnection,
\Magento\Eav\Model\Config $eavConfig,
\Magento\Catalog\Helper\Data $catalogHelper
\Magento\Catalog\Helper\Data $catalogHelper,
BaseSelectProcessorInterface $baseSelectProcessor = null
) {
$this->storeManager = $storeManager;
$this->resource = $resourceConnection;
$this->eavConfig = $eavConfig;
$this->catalogHelper = $catalogHelper;
$this->baseSelectProcessor = (null !== $baseSelectProcessor)
? $baseSelectProcessor : ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class);
}

/**
Expand All @@ -58,14 +68,18 @@ public function build($productId)
$priceSelect = $this->resource->getConnection()->select()
->from(['t' => $priceAttribute->getBackendTable()], 'entity_id')
->joinInner(
['link' => $this->resource->getTableName('catalog_product_relation')],
'link.child_id = t.entity_id',
[
BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS
=> $this->resource->getTableName('catalog_product_relation')
],
BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS . '.child_id = t.entity_id',
[]
)->where('link.parent_id = ? ', $productId)
)->where(BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS . '.parent_id = ? ', $productId)
->where('t.attribute_id = ?', $priceAttribute->getAttributeId())
->where('t.value IS NOT NULL')
->order('t.value ' . Select::SQL_ASC)
->limit(1);
$priceSelect = $this->baseSelectProcessor->process($priceSelect);

$priceSelectDefault = clone $priceSelect;
$priceSelectDefault->where('t.store_id = ?', Store::DEFAULT_STORE_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Catalog\Model\ResourceModel\Product;

use Magento\Catalog\Model\Product;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DB\Select;
use Magento\Store\Model\Store;

Expand Down Expand Up @@ -41,28 +42,37 @@ class LinkedProductSelectBuilderBySpecialPrice implements LinkedProductSelectBui
*/
private $localeDate;

/**
* @var BaseSelectProcessorInterface
*/
private $baseSelectProcessor;

/**
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
* @param \Magento\Eav\Model\Config $eavConfig
* @param \Magento\Catalog\Helper\Data $catalogHelper
* @param \Magento\Framework\Stdlib\DateTime $dateTime
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
* @param BaseSelectProcessorInterface $baseSelectProcessor
*/
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\ResourceConnection $resourceConnection,
\Magento\Eav\Model\Config $eavConfig,
\Magento\Catalog\Helper\Data $catalogHelper,
\Magento\Framework\Stdlib\DateTime $dateTime,
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
BaseSelectProcessorInterface $baseSelectProcessor = null
) {
$this->storeManager = $storeManager;
$this->resource = $resourceConnection;
$this->eavConfig = $eavConfig;
$this->catalogHelper = $catalogHelper;
$this->dateTime = $dateTime;
$this->localeDate = $localeDate;
$this->baseSelectProcessor = (null !== $baseSelectProcessor)
? $baseSelectProcessor : ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class);
}

/**
Expand All @@ -80,8 +90,11 @@ public function build($productId)
$specialPrice = $connection->select()
->from(['t' => $specialPriceAttribute->getBackendTable()], 'entity_id')
->joinInner(
['link' => $this->resource->getTableName('catalog_product_relation')],
'link.child_id = t.entity_id',
[
BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS
=> $this->resource->getTableName('catalog_product_relation')
],
BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS . '.child_id = t.entity_id',
[]
)->joinInner(
['special_from' => $specialPriceFromDate->getBackendTable()],
Expand All @@ -97,7 +110,7 @@ public function build($productId)
$specialPriceToDate->getAttributeId()
),
''
)->where('link.parent_id = ? ', $productId)
)->where(BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS . '.parent_id = ? ', $productId)
->where('t.attribute_id = ?', $specialPriceAttribute->getAttributeId())
->where('t.value IS NOT NULL')
->where(
Expand All @@ -108,6 +121,7 @@ public function build($productId)
$currentDate
)->order('t.value ' . Select::SQL_ASC)
->limit(1);
$specialPrice = $this->baseSelectProcessor->process($specialPrice);

$specialPriceDefault = clone $specialPrice;
$specialPriceDefault->where('t.store_id = ?', Store::DEFAULT_STORE_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
namespace Magento\Catalog\Model\ResourceModel\Product;

use Magento\Catalog\Model\Product;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DB\Select;

class LinkedProductSelectBuilderByTierPrice implements LinkedProductSelectBuilderInterface
Expand Down Expand Up @@ -35,22 +35,31 @@ class LinkedProductSelectBuilderByTierPrice implements LinkedProductSelectBuilde
*/
private $catalogHelper;

/**
* @var BaseSelectProcessorInterface
*/
private $baseSelectProcessor;

/**
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
* @param \Magento\Customer\Model\Session $customerSession
* @param \Magento\Catalog\Helper\Data $catalogHelper
* @param BaseSelectProcessorInterface $baseSelectProcessor
*/
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\ResourceConnection $resourceConnection,
\Magento\Customer\Model\Session $customerSession,
\Magento\Catalog\Helper\Data $catalogHelper
\Magento\Catalog\Helper\Data $catalogHelper,
BaseSelectProcessorInterface $baseSelectProcessor = null
) {
$this->storeManager = $storeManager;
$this->resource = $resourceConnection;
$this->customerSession = $customerSession;
$this->catalogHelper = $catalogHelper;
$this->baseSelectProcessor = (null !== $baseSelectProcessor)
? $baseSelectProcessor : ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class);
}

/**
Expand All @@ -59,16 +68,20 @@ public function __construct(
public function build($productId)
{
$priceSelect = $this->resource->getConnection()->select()
->from(['t' => $this->resource->getTableName('catalog_product_entity_tier_price')], 'entity_id')
->joinInner(
['link' => $this->resource->getTableName('catalog_product_relation')],
'link.child_id = t.entity_id',
[]
)->where('link.parent_id = ? ', $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);
->from(['t' => $this->resource->getTableName('catalog_product_entity_tier_price')], 'entity_id')
->joinInner(
[
BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS
=> $this->resource->getTableName('catalog_product_relation')
],
BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS . '.child_id = t.entity_id',
[]
)->where(BaseSelectProcessorInterface::PRODUCT_RELATION_ALIAS . '.parent_id = ? ', $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);
$priceSelect = $this->baseSelectProcessor->process($priceSelect);

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

0 comments on commit 572505c

Please sign in to comment.