10 use Magento\Catalog\Helper\DefaultCategoryFactory;
11 use Magento\Catalog\Setup\CategorySetupFactory;
28 private $moduleDataSetup;
33 private $categorySetupFactory;
38 private $defaultCategoryFactory;
48 CategorySetupFactory $categorySetupFactory,
49 \
Magento\Catalog\Helper\DefaultCategoryFactory $defaultCategoryFactory
51 $this->moduleDataSetup = $moduleDataSetup;
52 $this->categorySetupFactory = $categorySetupFactory;
53 $this->defaultCategoryFactory = $defaultCategoryFactory;
62 public function apply()
65 $categorySetup = $this->categorySetupFactory->create([
'setup' => $this->moduleDataSetup]);
67 $defaultCategory = $this->defaultCategoryFactory->create();
68 $defaultCategoryId = $defaultCategory->getId();
70 $categorySetup->installEntities();
72 $categorySetup->createCategory()
80 ->setName(
'Root Catalog')
81 ->setInitialSetupFlag(
true)
85 $category = $categorySetup->createCategory();
87 ->setId($defaultCategoryId)
90 ->setName(
'Default Category')
91 ->setDisplayMode(
'PRODUCTS')
94 ->setInitialSetupFlag(
true)
95 ->setAttributeSetId(
$category->getDefaultAttributeSetId())
104 $this->moduleDataSetup->getConnection()->insertOnDuplicate(
105 $this->moduleDataSetup->getTable(
'core_config_data'),
120 'display' => [
'name' =>
'Display Settings',
'code' =>
'display-settings',
'sort' => 20,
'id' =>
null],
121 'design' => [
'name' =>
'Custom Design',
'code' =>
'custom-design',
'sort' => 30,
'id' =>
null],
124 foreach ($groups as $k => $groupProp) {
131 'custom_design' => [
'group' =>
'design',
'sort' => 10],
133 'custom_design_from' => [
'group' =>
'design',
'sort' => 30],
134 'custom_design_to' => [
'group' =>
'design',
'sort' => 40],
135 'page_layout' => [
'group' =>
'design',
'sort' => 50],
136 'custom_layout_update' => [
'group' =>
'design',
'sort' => 60],
137 'display_mode' => [
'group' =>
'display',
'sort' => 10],
138 'landing_page' => [
'group' =>
'display',
'sort' => 20],
139 'is_anchor' => [
'group' =>
'display',
'sort' => 30],
140 'available_sort_by' => [
'group' =>
'display',
'sort' => 40],
141 'default_sort_by' => [
'group' =>
'display',
'sort' => 50],
145 $categorySetup->addAttributeToGroup(
148 $groups[$attributeProp[
'group']][
'id'],
150 $attributeProp[
'sort']
158 [
'link_type_id' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_RELATED,
'code' =>
'relation'],
159 [
'link_type_id' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_UPSELL,
'code' =>
'up_sell'],
160 [
'link_type_id' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_CROSSSELL,
'code' =>
'cross_sell'],
163 foreach (
$data as $bind) {
164 $this->moduleDataSetup->getConnection()->insertForce(
165 $this->moduleDataSetup->getTable(
166 'catalog_product_link_type' 177 'link_type_id' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_RELATED,
178 'product_link_attribute_code' =>
'position',
179 'data_type' =>
'int',
182 'link_type_id' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_UPSELL,
183 'product_link_attribute_code' =>
'position',
187 'link_type_id' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_CROSSSELL,
188 'product_link_attribute_code' =>
'position',
193 $this->moduleDataSetup->getConnection()->insertMultiple(
194 $this->moduleDataSetup->getTable(
'catalog_product_link_attribute'),
202 $describe = $this->moduleDataSetup->getConnection()
203 ->describeTable($this->moduleDataSetup->getTable(
'catalog_eav_attribute'));
204 foreach ($describe as $columnData) {
205 if ($columnData[
'COLUMN_NAME'] ==
'attribute_id') {
208 $this->moduleDataSetup->getConnection()->dropColumn(
209 $this->moduleDataSetup->getTable(
'eav_attribute'),
210 $columnData[
'COLUMN_NAME']
214 $newGeneralTabName =
'Product Details';
215 $newPriceTabName =
'Advanced Pricing';
216 $newImagesTabName =
'Image Management';
217 $newMetaTabName =
'Search Engine Optimization';
218 $autosettingsTabName =
'Autosettings';
221 'attribute_group_name' => $newGeneralTabName,
222 'attribute_group_code' => $categorySetup->convertToAttributeGroupCode($newGeneralTabName),
223 'tab_group_code' =>
'basic',
227 'attribute_group_name' => $newImagesTabName,
228 'attribute_group_code' => $categorySetup->convertToAttributeGroupCode($newImagesTabName),
229 'tab_group_code' =>
'basic',
232 'Meta Information' => [
233 'attribute_group_name' => $newMetaTabName,
234 'attribute_group_code' => $categorySetup->convertToAttributeGroupCode($newMetaTabName),
235 'tab_group_code' =>
'basic',
239 'attribute_group_name' => $newPriceTabName,
240 'attribute_group_code' => $categorySetup->convertToAttributeGroupCode($newPriceTabName),
241 'tab_group_code' =>
'advanced',
244 'Design' => [
'attribute_group_code' =>
'design',
'tab_group_code' =>
'advanced',
'sort_order' => 50],
251 foreach ($tabNames as $tabName => $tab) {
254 foreach ($tab as $propertyName => $propertyValue) {
255 $categorySetup->updateAttributeGroup(
268 $categorySetup->updateAttributeGroup(
272 'attribute_group_code',
275 $categorySetup->updateAttributeGroup(
284 $properties = [
'is_required',
'default_value',
'frontend_input_renderer'];
287 'name' => [$newGeneralTabName => 10],
288 'sku' => [$newGeneralTabName => 20],
289 'price' => [$newGeneralTabName => 30],
290 'image' => [$newGeneralTabName => 50],
291 'weight' => [$newGeneralTabName => 70,
'is_required' => 0],
292 'category_ids' => [$newGeneralTabName => 80],
293 'description' => [$newGeneralTabName => 90,
'is_required' => 0],
295 $newGeneralTabName => 100,
297 'default_value' => 1,
298 'frontend_input_renderer' => \Magento\Framework\Data\Form\Element\Hidden::class,
301 'short_description' => [$autosettingsTabName => 0,
'is_required' => 0],
302 'visibility' => [$autosettingsTabName => 20,
'is_required' => 0],
303 'news_from_date' => [$autosettingsTabName => 30],
304 'news_to_date' => [$autosettingsTabName => 40],
305 'country_of_manufacture' => [$autosettingsTabName => 50],
308 foreach ($attributesOrder as $key =>
$value) {
311 foreach (
$value as $propertyName => $propertyValue) {
313 $categorySetup->updateAttribute(
320 $categorySetup->addAttributeToGroup(
333 $categorySetup->updateAttribute(
336 'is_required_in_admin_store',
340 $categorySetup->updateAttribute(
342 'custom_design_from',
346 $categorySetup->updateAttribute(
348 'custom_design_from',
350 \
Magento\Eav\Model\Entity\Attribute\Frontend\Datetime::class
__construct(ModuleDataSetupInterface $moduleDataSetup, CategorySetupFactory $categorySetupFactory, \Magento\Catalog\Helper\DefaultCategoryFactory $defaultCategoryFactory)
const XML_PATH_CATEGORY_ROOT_ID