22 private $storeManager;
37 private $catalogHelper;
52 private $metadataPool;
57 private $baseSelectProcessor;
74 \
Magento\Framework\Stdlib\DateTime $dateTime,
75 \
Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
82 $this->catalogHelper = $catalogHelper;
84 $this->localeDate = $localeDate;
85 $this->metadataPool = $metadataPool;
86 $this->baseSelectProcessor = (
null !== $baseSelectProcessor)
95 $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
97 $specialPriceAttribute = $this->eavConfig->getAttribute(
Product::ENTITY,
'special_price');
98 $specialPriceFromDate = $this->eavConfig->getAttribute(
Product::ENTITY,
'special_from_date');
99 $specialPriceToDate = $this->eavConfig->getAttribute(
Product::ENTITY,
'special_to_date');
100 $timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore());
101 $currentDate = $this->dateTime->formatDate($timestamp,
false);
102 $productTable = $this->resource->getTableName(
'catalog_product_entity');
104 $specialPrice = $this->resource->getConnection()->select()
105 ->from([
'parent' => $productTable],
'')
107 [
'link' => $this->resource->getTableName(
'catalog_product_relation')],
108 "link.parent_id = parent.$linkField",
115 [
't' => $specialPriceAttribute->getBackendTable()],
119 [
'special_from' => $specialPriceFromDate->getBackendTable()],
121 "t.{$linkField} = special_from.{$linkField} AND special_from.attribute_id = ?",
122 $specialPriceFromDate->getAttributeId()
126 [
'special_to' => $specialPriceToDate->getBackendTable()],
128 "t.{$linkField} = special_to.{$linkField} AND special_to.attribute_id = ?",
129 $specialPriceToDate->getAttributeId()
133 ->where(
't.attribute_id = ?', $specialPriceAttribute->getAttributeId())
134 ->where(
't.value IS NOT NULL')
136 'special_from.value IS NULL OR ' .
$connection->getDatePartSql(
'special_from.value') .
' <= ?',
139 'special_to.value IS NULL OR ' .
$connection->getDatePartSql(
'special_to.value') .
' >= ?',
144 $specialPrice = $this->baseSelectProcessor->process($specialPrice);
146 if (!$this->catalogHelper->isPriceGlobal()) {
147 $priceSelectStore = clone $specialPrice;
148 $priceSelectStore->where(
't.store_id = ?', $this->storeManager->getStore()->getId());
149 $selects[] = $priceSelectStore;
152 $specialPrice->where(
't.store_id = ?', Store::DEFAULT_STORE_ID);
153 $selects[] = $specialPrice;
const PRODUCT_TABLE_ALIAS
__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\EntityManager\MetadataPool $metadataPool, BaseSelectProcessorInterface $baseSelectProcessor=null)