Whenever you save attribute from the admin panel, Magento will run validation on it and it will change your backend type based on input type. You can see that in getBackendTypeByInput
method inside Mage_Adminhtml_Catalog_Product_AttributeController
class.
/**
* Detect backend storage type using frontend input type
*
* @return string backend_type field value
* @param string $type frontend_input field value
*/
public function getBackendTypeByInput($type)
{
$field = null;
switch ($type) {
case 'text':
case 'gallery':
case 'media_image':
case 'multiselect':
$field = 'varchar';
break;
case 'image':
case 'textarea':
$field = 'text';
break;
case 'date':
$field = 'datetime';
break;
case 'select':
case 'boolean':
$field = 'int';
break;
case 'price':
$field = 'decimal';
break;
}
return $field;
}
You can use this as a guideline when adding new attributes via install script. If you are adding attribute via admin you don't have to worry about that. Of course, if you modify backend or frontend type directly from DB, Magento will validate and 'fix' the attribute on next save.
In other words you should never, ever change attribute properties directly from DB. Especially if the attribute already has some values saved. Doing this will result in attribute values being written in different entity type tables, which is what happened in your case. This will result in various issues, e.g. attribute disappearing from layered navigation, not searchable or filterable, cannot be saved, etc.
Fix for this is simple. First you need to determine what your backend/input types are. Then you need to make sure that the combination is valid using the code above and that it won't be changed in the future by manual editing.
Let's assume you want decimal/price. This means that your values should be saved in catalog_product_entity_decimal
table. You will have to check all the other catalog_product_entity_*
tables and remove all entries associated with your attribute_id
. If you need to preserve the data you can also export rows before you delete them (without value_id
) and import them in catalog_product_entity_decimal
table.
This should fix your attribute. Remember to reindex after this is done.
The data for the bundle grid comes from the following file:
Magento_Bundle/Ui/DataProvider/Product/Form/Modifier/Composite.php
I created a module which adds a plugin.
di.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<type name="Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\Composite">
<plugin name="my-composite-modifier" type="Namespace\Modulename\Plugin\CompositePlugin" sortOrder="1" />
</type>
</config>
Then the php to start playing with the data.
Plugin/CompositePlugin.php:
<?php
namespace Namespace\Modulename\Plugin;
class CompositePlugin
{
public function afterModifyData(\Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\Composite $subject, $data)
{
// Do something with the data here!
// Bundle items are under:
// $data[product_id]["bundle_options"]["bundle_options"]
return $data;
}
}
Hopefully this helps someone else.
Best Answer
I will try to explain brief about Bundle product. the below 3 tables important for bundle product
Example :
Sprite Yoga Companion Kit consider as bundle product.
Sprite Stasis Ball : : consider as bundle associate bundle item title.
1) Sprite Stasis Ball 55 cm - This product as simple product want to display as radio button
2) Sprite Stasis Ball 65 cm - This product as simple product want to display as radio button
3) Sprite Stasis Ball 75 cm - This product as simple product want to display as radio button
How it will store in Table?
catalog_product_bundle_selection : associate bundle items and price are stored in this table.
catalog_product_bundle_option : How we want to display (Radio,Multiple select, dropdown,checkbox) is stored in this table. In this table "Type" is the colum as (Radio,Multiple select, dropdown,checkbox).
catalog_product_bundle_option_value : option type title stored in table. Title is the value of option. (Example : Sprite Stasis Ball)
Hope it will clear i think