Skip to content

Commit e0d7b2b

Browse files
Keep url key from Magento if category exist option is on (#51)
1 parent 4a2d615 commit e0d7b2b

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

Plugin/CategoryExist.php

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,54 @@
33
namespace JustBetter\AkeneoBundle\Plugin;
44

55
use Akeneo\Connector\Helper\Import\Entities;
6-
use Magento\Store\Model\ScopeInterface as scope;
76
use Akeneo\Connector\Helper\Store as StoreHelper;
87
use Magento\Framework\App\Config\ScopeConfigInterface;
8+
use Magento\Store\Model\ScopeInterface;
99

1010
class CategoryExist
1111
{
12-
protected $config;
13-
protected $entitiesHelper;
14-
protected $storeHelper;
15-
1612
public function __construct(
17-
ScopeConfigInterface $config,
18-
Entities $entitiesHelper,
19-
StoreHelper $storeHelper
13+
protected ScopeConfigInterface $config,
14+
protected Entities $entitiesHelper,
15+
protected StoreHelper $storeHelper
2016
) {
21-
$this->config = $config;
22-
$this->entitiesHelper = $entitiesHelper;
23-
$this->storeHelper = $storeHelper;
2417
}
2518

2619
public function beforeSetValues()
2720
{
28-
$extensionEnabled = $this->config->getValue('akeneo_connector/justbetter/categoryexist', scope::SCOPE_WEBSITE);
21+
$extensionEnabled = $this->config->getValue('akeneo_connector/justbetter/categoryexist', ScopeInterface::SCOPE_WEBSITE);
2922
if (!$extensionEnabled) {
30-
return ;
23+
return;
3124
}
3225

3326
$connection = $this->entitiesHelper->getConnection();
3427

3528
$stores = $this->storeHelper->getStores('lang');
3629
foreach ($stores as $local => $affected) {
3730
foreach ($affected as $store) {
38-
$updateUrl = [
39-
'url_key-' . $store['lang'] => null
40-
];
41-
42-
$connection->update(
43-
'tmp_akeneo_connector_entities_category',
44-
$updateUrl,
45-
'_is_new = 0'
46-
);
31+
$columnName = 'url_key-' . $store['lang'];
32+
33+
$query = "
34+
UPDATE tmp_akeneo_connector_entities_category temp
35+
LEFT JOIN catalog_category_entity_varchar eav ON (
36+
eav.entity_id = temp._entity_id
37+
AND eav.attribute_id = (
38+
SELECT attribute_id
39+
FROM eav_attribute
40+
WHERE attribute_code = 'url_key'
41+
AND entity_type_id = (
42+
SELECT entity_type_id
43+
FROM eav_entity_type
44+
WHERE entity_type_code = 'catalog_category'
45+
)
46+
)
47+
AND eav.store_id = {$store['store_id']}
48+
)
49+
SET temp.`{$columnName}` = eav.value
50+
WHERE temp._is_new = 0 AND eav.value IS NOT NULL
51+
";
52+
53+
$connection->query($query);
4754
}
4855
}
4956
}

0 commit comments

Comments
 (0)