|
3 | 3 | namespace JustBetter\AkeneoBundle\Plugin; |
4 | 4 |
|
5 | 5 | use Akeneo\Connector\Helper\Import\Entities; |
6 | | -use Magento\Store\Model\ScopeInterface as scope; |
7 | 6 | use Akeneo\Connector\Helper\Store as StoreHelper; |
8 | 7 | use Magento\Framework\App\Config\ScopeConfigInterface; |
| 8 | +use Magento\Store\Model\ScopeInterface; |
9 | 9 |
|
10 | 10 | class CategoryExist |
11 | 11 | { |
12 | | - protected $config; |
13 | | - protected $entitiesHelper; |
14 | | - protected $storeHelper; |
15 | | - |
16 | 12 | public function __construct( |
17 | | - ScopeConfigInterface $config, |
18 | | - Entities $entitiesHelper, |
19 | | - StoreHelper $storeHelper |
| 13 | + protected ScopeConfigInterface $config, |
| 14 | + protected Entities $entitiesHelper, |
| 15 | + protected StoreHelper $storeHelper |
20 | 16 | ) { |
21 | | - $this->config = $config; |
22 | | - $this->entitiesHelper = $entitiesHelper; |
23 | | - $this->storeHelper = $storeHelper; |
24 | 17 | } |
25 | 18 |
|
26 | 19 | public function beforeSetValues() |
27 | 20 | { |
28 | | - $extensionEnabled = $this->config->getValue('akeneo_connector/justbetter/categoryexist', scope::SCOPE_WEBSITE); |
| 21 | + $extensionEnabled = $this->config->getValue('akeneo_connector/justbetter/categoryexist', ScopeInterface::SCOPE_WEBSITE); |
29 | 22 | if (!$extensionEnabled) { |
30 | | - return ; |
| 23 | + return; |
31 | 24 | } |
32 | 25 |
|
33 | 26 | $connection = $this->entitiesHelper->getConnection(); |
34 | 27 |
|
35 | 28 | $stores = $this->storeHelper->getStores('lang'); |
36 | 29 | foreach ($stores as $local => $affected) { |
37 | 30 | 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); |
47 | 54 | } |
48 | 55 | } |
49 | 56 | } |
|
0 commit comments