Skip to content

Commit

Permalink
Merge pull request Smile-SA#1392 from rbayet/fix-1369-virtual-categor…
Browse files Browse the repository at this point in the history
…y-root-default-value

Fixes Smile-SA#1369 virtual_category_root new default value 2.3.x
  • Loading branch information
romainruaud authored Apr 25, 2019
2 parents 3ff2d69 + c0109f5 commit 0a9d043
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
$this->virtualCategorySetup->addUseStorePositionsAttribute($this->eavSetupFactory->create(['setup' => $setup]));
}

if (version_compare($context->getVersion(), '1.4.1', '<')) {
$this->virtualCategorySetup->updateVirtualCategoryRootDefaultValue($this->eavSetupFactory->create(['setup' => $setup]));
}

$setup->endSetup();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function createVirtualCategoriesAttributes($eavSetup)
'input' => null,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
'required' => false,
'default' => 0,
'default' => null,
'visible' => true,
'note' => "Root display of the virtual category (usefull to display a facet category on virtual).",
'sort_order' => 200,
Expand Down Expand Up @@ -205,6 +205,40 @@ public function updateVirtualCategoryRootTypeToInt(\Magento\Eav\Setup\EavSetup $
return $this;
}

/**
* Migration from 1.4.0 to 1.4.1 :
* - Updating the attribute virtual_category_root default value from 0 to NULL
* - Deleting the attribute storage table rows with 0 as value
* (new default value of NULL means no rows in storage table for newly created categories)
*
* @param \Magento\Eav\Setup\EavSetup $eavSetup EAV module Setup
*
* @return $this
*/
public function updateVirtualCategoryRootDefaultValue(\Magento\Eav\Setup\EavSetup $eavSetup)
{
$setup = $eavSetup->getSetup();

// Fix the attribute default value.
$eavSetup->updateAttribute(Category::ENTITY, 'virtual_category_root', 'default_value', null);

// Retrieve information about the attribute and storage config.
$virtualRootAttributeId = $eavSetup->getAttribute(Category::ENTITY, 'virtual_category_root', 'attribute_id');

$targetTable = $setup->getTable('catalog_category_entity_int');

// Delete rows with the old default value.
$setup->getConnection()->delete(
$targetTable,
[
"attribute_id = {$virtualRootAttributeId}",
"value = 0",
]
);

return $this;
}

/**
* Create table containing position of products in virtual categories.
*
Expand Down
2 changes: 1 addition & 1 deletion src/module-elasticsuite-virtual-category/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Smile_ElasticsuiteVirtualCategory" setup_version="1.4.0">
<module name="Smile_ElasticsuiteVirtualCategory" setup_version="1.4.1">
<sequence>
<module name="Smile_ElasticsuiteCatalogRule" />
<module name="Magento_Rule" />
Expand Down

0 comments on commit 0a9d043

Please sign in to comment.