Skip to content

Commit

Permalink
[EngCom] Public Pull Requests - 2.3-develop
Browse files Browse the repository at this point in the history
 - merged latest code from mainline branch
  • Loading branch information
magento-engcom-team authored May 17, 2018
2 parents 5dc7409 + 7769546 commit 18872d0
Showing 1 changed file with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -659,25 +659,30 @@ protected function makeTempCategoryTreeIndex()
*/
protected function fillTempCategoryTreeIndex($temporaryName)
{
// This finds all children (cc2) that descend from a parent (cc) by path.
// For example, cc.path may be '1/2', and cc2.path may be '1/2/3/4/5'.
$temporarySelect = $this->connection->select()->from(
['cc' => $this->getTable('catalog_category_entity')],
['parent_id' => 'entity_id']
)->joinInner(
['cc2' => $this->getTable('catalog_category_entity')],
'cc2.path LIKE ' . $this->connection->getConcatSql(
[$this->connection->quoteIdentifier('cc.path'), $this->connection->quote('/%')]
),
['child_id' => 'entity_id']
$selects = $this->prepareSelectsByRange(
$this->connection->select()
->from(
['c' => $this->getTable('catalog_category_entity')],
['entity_id', 'path']
),
'entity_id'
);

$this->connection->query(
$temporarySelect->insertFromSelect(
$temporaryName,
['parent_id', 'child_id']
)
);
foreach ($selects as $select) {
$values = [];

foreach ($this->connection->fetchAll($select) as $category) {
foreach (explode('/', $category['path']) as $parentId) {
if ($parentId !== $category['entity_id']) {
$values[] = [$parentId, $category['entity_id']];
}
}
}

if (count($values) > 0) {
$this->connection->insertArray($temporaryName, ['parent_id', 'child_id'], $values);
}
}
}

/**
Expand Down

0 comments on commit 18872d0

Please sign in to comment.