Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:magento/magento2 into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
sivajik34 committed Apr 6, 2017
2 parents 48d683c + 3c8619d commit 5834df6
Show file tree
Hide file tree
Showing 77 changed files with 2,997 additions and 360 deletions.
31 changes: 2 additions & 29 deletions app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,11 @@
class Price extends \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice
{
/**
* Reindex temporary (price result data) for all products
*
* @return $this
* @throws \Exception
* @inheritdoc
*/
public function reindexAll()
{
$this->tableStrategy->setUseIdxTable(true);

$this->beginTransaction();
try {
$this->_prepareBundlePrice();
$this->commit();
} catch (\Exception $e) {
$this->rollBack();
throw $e;
}

return $this;
}

/**
* Reindex temporary (price result data) for defined product(s)
*
* @param int|array $entityIds
* @return $this
*/
public function reindexEntity($entityIds)
protected function reindex($entityIds = null)
{
$this->_prepareBundlePrice($entityIds);

return $this;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions app/code/Magento/Bundle/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,17 @@
</argument>
</arguments>
</type>
<type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BatchSizeCalculator">
<arguments>
<argument name="estimators" xsi:type="array">
<item name="bundle" xsi:type="object">Magento\Catalog\Model\Indexer\Price\CompositeProductBatchSizeManagement</item>
</argument>
</arguments>
</type>
<type name="Magento\Bundle\Model\ResourceModel\Indexer\Price">
<arguments>
<argument name="tableStrategy" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\TemporaryTableStrategy</argument>
<argument name="connectionName" xsi:type="string">indexer</argument>
</arguments>
</type>
</config>
152 changes: 102 additions & 50 deletions app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ abstract class AbstractAction
*/
private $productResource;

/**
* @var \Magento\Indexer\Model\ResourceModel\FrontendResource
*/
private $indexerFrontendResource;

/**
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
Expand All @@ -84,6 +89,7 @@ abstract class AbstractAction
* @param \Magento\Catalog\Model\Product\Type $catalogProductType
* @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\Factory $indexerPriceFactory
* @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice $defaultIndexerResource
* @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $indexerFrontendResource
*/
public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $config,
Expand All @@ -93,7 +99,8 @@ public function __construct(
\Magento\Framework\Stdlib\DateTime $dateTime,
\Magento\Catalog\Model\Product\Type $catalogProductType,
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\Factory $indexerPriceFactory,
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice $defaultIndexerResource
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice $defaultIndexerResource,
\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerFrontendResource = null
) {
$this->_config = $config;
$this->_storeManager = $storeManager;
Expand All @@ -104,6 +111,10 @@ public function __construct(
$this->_indexerPriceFactory = $indexerPriceFactory;
$this->_defaultIndexerResource = $defaultIndexerResource;
$this->_connection = $this->_defaultIndexerResource->getConnection();
$this->indexerFrontendResource = $indexerFrontendResource ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\FrontendResource::class
);
}

/**
Expand All @@ -124,7 +135,7 @@ protected function _syncData(array $processIds = [])
{
// delete invalid rows
$select = $this->_connection->select()->from(
['index_price' => $this->_defaultIndexerResource->getTable('catalog_product_index_price')],
['index_price' => $this->getIndexTargetTable()],
null
)->joinLeft(
['ip_tmp' => $this->_defaultIndexerResource->getIdxTable()],
Expand All @@ -141,7 +152,7 @@ protected function _syncData(array $processIds = [])

$this->_insertFromTable(
$this->_defaultIndexerResource->getIdxTable(),
$this->_defaultIndexerResource->getTable('catalog_product_index_price')
$this->getIndexTargetTable()
);
return $this;
}
Expand Down Expand Up @@ -217,61 +228,90 @@ protected function _prepareTierPriceIndex($entityIds = null)
{
$table = $this->_defaultIndexerResource->getTable('catalog_product_index_tier_price');
$this->_emptyTable($table);

$tierPriceExpression = $this->_connection->getCheckSql(
'tp.value = 0',
'product_price.value * (1 - tp.percentage_value / 100)',
'tp.value'
);
$websiteExpression = $this->_connection->getCheckSql(
'tp.website_id = 0',
'ROUND(' . $tierPriceExpression . ' * cwd.rate, 4)',
$tierPriceExpression
);
if (empty($entityIds)) {
return $this;
}
$linkField = $this->getProductIdFieldName();
$priceAttribute = $this->getProductResource()->getAttribute('price');

$select = $this->_connection->select()->from(
$baseColumns = [
'cpe.entity_id',
'tp.customer_group_id',
'tp.website_id'
];
if ($linkField !== 'entity_id') {
$baseColumns[] = 'cpe.' . $linkField;
};
$subSelect = $this->_connection->select()->from(
['cpe' => $this->_defaultIndexerResource->getTable('catalog_product_entity')],
['cpe.entity_id']
)->join(
array_merge_recursive(
$baseColumns,
[
'min(tp.value) AS value',
'min(tp.percentage_value) AS percentage_value'
]
)
)->joinInner(
['tp' => $this->_defaultIndexerResource->getTable(['catalog_product_entity', 'tier_price'])],
'tp.' . $linkField . ' = cpe.' . $linkField,
[]
)->join(
['cg' => $this->_defaultIndexerResource->getTable('customer_group')],
'tp.all_groups = 1 OR (tp.all_groups = 0 AND tp.customer_group_id = cg.customer_group_id)',
['customer_group_id']
)->join(
['cw' => $this->_defaultIndexerResource->getTable('store_website')],
'tp.website_id = 0 OR tp.website_id = cw.website_id',
['website_id']
)->join(
['cwd' => $this->_defaultIndexerResource->getTable('catalog_product_index_website')],
'cw.website_id = cwd.website_id',
[]
)->join(
['product_price' => $priceAttribute->getBackend()->getTable()],
'tp.' . $linkField . ' = product_price.' . $linkField,
[]
)->where(
'cw.website_id != 0'
)->where(
'product_price.attribute_id = ?',
$priceAttribute->getAttributeId()
)->columns(
new \Zend_Db_Expr("MIN({$websiteExpression})")
)->group(
['cpe.entity_id', 'cg.customer_group_id', 'cw.website_id']
);
)->where("cpe.entity_id IN(?)", $entityIds)
->where("tp.website_id != 0")
->group(['cpe.entity_id', 'tp.customer_group_id', 'tp.website_id']);

$subSelect2 = $this->_connection->select()
->from(
['cpe' => $this->_defaultIndexerResource->getTable('catalog_product_entity')],
array_merge_recursive(
$baseColumns,
[
'MIN(ROUND(tp.value * cwd.rate, 4)) AS value',
'MIN(ROUND(tp.percentage_value * cwd.rate, 4)) AS percentage_value'

]
)
)
->joinInner(
['tp' => $this->_defaultIndexerResource->getTable(['catalog_product_entity', 'tier_price'])],
'tp.' . $linkField . ' = cpe.' . $linkField,
[]
)->join(
['cw' => $this->_defaultIndexerResource->getTable('store_website')],
true,
[]
)
->joinInner(
['cwd' => $this->_defaultIndexerResource->getTable('catalog_product_index_website')],
'cw.website_id = cwd.website_id',
[]
)
->where("cpe.entity_id IN(?)", $entityIds)
->where("tp.website_id = 0")
->group(
['cpe.entity_id', 'tp.customer_group_id', 'tp.website_id']
);

if (!empty($entityIds)) {
$select->where("cpe.entity_id IN(?)", $entityIds);
}
$unionSelect = $this->_connection->select()
->union([$subSelect, $subSelect2], \Magento\Framework\DB\Select::SQL_UNION_ALL);
$select = $this->_connection->select()
->from(
['b' => new \Zend_Db_Expr(sprintf('(%s)', $unionSelect->assemble()))],
[
'b.entity_id',
'b.customer_group_id',
'b.website_id',
'MIN(IF(b.value = 0, product_price.value * (1 - b.percentage_value / 100), b.value))'
]
)
->joinInner(
['product_price' => $priceAttribute->getBackend()->getTable()],
'b.' . $linkField . ' = product_price.' . $linkField,
[]
)
->group(['b.entity_id', 'b.customer_group_id', 'b.website_id']);

$query = $select->insertFromSelect($table, [], false);

$query = $select->insertFromSelect($table);
$this->_connection->query($query);

return $this;
}

Expand Down Expand Up @@ -460,7 +500,7 @@ protected function _copyRelationIndexData($parentIds, $excludeIds = null)

if ($children) {
$select = $this->_connection->select()->from(
$this->_defaultIndexerResource->getTable('catalog_product_index_price')
$this->getIndexTargetTable()
)->where(
'entity_id IN(?)',
$children
Expand All @@ -472,6 +512,18 @@ protected function _copyRelationIndexData($parentIds, $excludeIds = null)
return $this;
}

/**
* Retrieve index table that will be used for write operations.
*
* This method is used during both partial and full reindex to identify the the table.
*
* @return string
*/
protected function getIndexTargetTable()
{
return $this->indexerFrontendResource->getMainTable();
}

/**
* @return string
*/
Expand Down
Loading

0 comments on commit 5834df6

Please sign in to comment.