Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
module-store
Setup
Patch
Data
UpdateStoreGroupCodes.php
Go to the documentation of this file.
1
<?php
7
namespace
Magento\Store\Setup\Patch\Data
;
8
9
use
Magento\Framework\App\ResourceConnection
;
10
use
Magento\Framework\Setup\Patch\DataPatchInterface
;
11
use
Magento\Framework\Setup\Patch\PatchVersionInterface
;
12
17
class
UpdateStoreGroupCodes
implements
DataPatchInterface
,
PatchVersionInterface
18
{
22
private
$moduleDataSetup;
23
28
public
function
__construct
(
29
\
Magento
\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup
30
) {
31
$this->moduleDataSetup = $moduleDataSetup;
32
}
33
37
public
function
apply
()
38
{
39
$this->updateStoreGroupCodes();
40
}
41
45
private
function
updateStoreGroupCodes()
46
{
47
$connection
= $this->moduleDataSetup->getConnection();
48
$storeGroupTable = $this->moduleDataSetup->getTable(
'store_group'
);
49
$select
=
$connection
->select()->from(
50
$storeGroupTable,
51
[
'group_id'
,
'name'
]
52
);
53
54
$groupList =
$connection
->fetchPairs(
$select
);
55
56
$codes = [];
57
foreach
($groupList as
$groupId
=> $groupName) {
58
$code
= preg_replace(
'/\s+/'
,
'_'
, $groupName);
59
$code
= preg_replace(
'/[^a-z0-9-_]/'
,
''
, strtolower(
$code
));
60
$code
= preg_replace(
'/^[^a-z]+/'
,
''
,
$code
);
61
62
if
(empty(
$code
)) {
63
$code
=
'store_group'
;
64
}
65
66
if
(array_key_exists(
$code
, $codes)) {
67
$codes[
$code
]++;
68
$code
=
$code
. $codes[
$code
];
69
}
70
$codes[
$code
] = 1;
71
72
$connection
->update(
73
$storeGroupTable,
74
[
'code'
=>
$code
],
75
[
'group_id = ?'
=>
$groupId
]
76
);
77
}
78
}
79
83
public
static
function
getDependencies
()
84
{
85
return
[];
86
}
87
91
public
static
function
getVersion
()
92
{
93
return
'2.1.0'
;
94
}
95
99
public
function
getAliases
()
100
{
101
return
[];
102
}
103
}
Magento\Store\Setup\Patch\Data\UpdateStoreGroupCodes\__construct
__construct(\Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup)
Definition:
UpdateStoreGroupCodes.php:28
Magento\Framework\Setup\Patch\DataPatchInterface
Definition:
DataPatchInterface.php:12
Magento\Store\Setup\Patch\Data\UpdateStoreGroupCodes
Definition:
UpdateStoreGroupCodes.php:17
Magento\Store\Setup\Patch\Data\UpdateStoreGroupCodes\getAliases
getAliases()
Definition:
UpdateStoreGroupCodes.php:99
$select
$select
Definition:
catalog_rule_10_off_not_logged_rollback.php:14
Magento\Store\Setup\Patch\Data\UpdateStoreGroupCodes\apply
apply()
Definition:
UpdateStoreGroupCodes.php:37
$groupId
$groupId
Definition:
filterable_attributes.php:14
Magento
Magento\Framework\Setup\Patch\PatchVersionInterface
Definition:
PatchVersionInterface.php:13
Magento\Store\Setup\Patch\Data\UpdateStoreGroupCodes\getDependencies
static getDependencies()
Definition:
UpdateStoreGroupCodes.php:83
Magento\Store\Setup\Patch\Data\UpdateStoreGroupCodes\getVersion
static getVersion()
Definition:
UpdateStoreGroupCodes.php:91
Magento\Store\Setup\Patch\Data
Definition:
UpdateStoreGroupCodes.php:7
$connection
$connection
Definition:
bulk.php:13
Magento\Framework\App\ResourceConnection
$code
$code
Definition:
info.phtml:12