Created
January 9, 2018 10:44
-
-
Save korbax/632fd492a4b374b3ff93358f52d5f2c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// vendor/magento/module-catalog/Model/ResourceModel/Category.php | |
protected function doReplace($urls) | |
{ | |
foreach ($this->createFilterDataBasedOnUrls($urls) as $type => $urlData) { | |
$urlData[UrlRewrite::ENTITY_TYPE] = $type; | |
$this->deleteByData($urlData); | |
} | |
$data = []; | |
$storeId_requestPaths = []; | |
foreach ($urls as $url) { | |
$storeId = $url->getStoreId(); | |
$requestPath = $url->getRequestPath(); | |
// Skip if is exist in the database | |
$sql = "SELECT * FROM url_rewrite where store_id = $storeId and request_path = '$requestPath'"; | |
$exists = $this->connection->fetchOne($sql); | |
if ($exists) continue; | |
$storeId_requestPaths[] = $storeId . '-' . $requestPath; | |
$data[] = $url->toArray(); | |
} | |
// Remove duplication data; | |
$n = count($storeId_requestPaths); | |
for ($i = 0; $i < $n - 1; $i++) { | |
for ($j = $i + 1; $j < $n; $j++) { | |
if ($storeId_requestPaths[$i] == $storeId_requestPaths[$j]) { | |
unset($data[$j]); | |
} | |
} | |
} | |
$this->insertMultiple($data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment