Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url-key-mapping: Secure correct url keys when the Magento attribute i… #25

Merged
merged 1 commit into from
Sep 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions Job/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,14 +471,45 @@ public function addRequiredData()

/**
* @var string $local
* @var string $affected
* @var array $affected
*/
foreach ($stores as $local => $affected) {
$this->entitiesHelper->copyColumn(
$tmpTable,
$pimAttribute . '-' . $local,
$magentoAttribute . '-' . $local
);

// Format url-key if it is mapped
/** @var bool $isUrlKeyMapped */
$isUrlKeyMapped = $this->configHelper->isUrlKeyMapped();

if ($magentoAttribute === 'url_key' && $isUrlKeyMapped && $connection->tableColumnExists($tmpTable, $pimAttribute . '-' . $local)) {
/** @var \Magento\Framework\DB\Select $select */
$select = $connection->select()->from(
$tmpTable,
[
'identifier' => 'identifier',
'url_key' => 'url_key-' . $local,
]
);
/** @var \Magento\Framework\DB\Statement\Pdo\Mysql $query */
$query = $connection->query($select);

/** @var array $row */
while (($row = $query->fetch())) {
if (isset($row['url_key'])) {
$row['url_key'] = $this->product->formatUrlKey($row['url_key']);
$connection->update(
$tmpTable,
[
'url_key-' . $local => $row['url_key'],
],
['identifier = ?' => $row['identifier']]
);
}
}
}
}
}
}
Expand Down Expand Up @@ -1553,7 +1584,7 @@ public function setUrlRewrite()
* @var array $affected
*/
foreach ($stores as $local => $affected) {
if (!$isUrlKeyMapped && !$connection->tableColumnExists($tmpTable, 'url_key-' . $local)) {
if (!$connection->tableColumnExists($tmpTable, 'url_key-' . $local)) {
$connection->addColumn(
$tmpTable,
'url_key-' . $local,
Expand Down