Skip to content

Commit

Permalink
MAGETWO-57056: [Backport] [GitHub] Configurable product disabling low…
Browse files Browse the repository at this point in the history
…est price associated product still shows its price #4419 - for 2.0
  • Loading branch information
vnayda committed Oct 27, 2016
1 parent 29ac37e commit 482da28
Show file tree
Hide file tree
Showing 24 changed files with 851 additions and 121 deletions.
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 All @@ -120,4 +134,4 @@ public function build($productId)

return $select;
}
}
}
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

0 comments on commit 482da28

Please sign in to comment.