0

I have created a 'New Attribute' into the Product Attributes [/admin/catalog/product_attribute/] for products : [specificity_trait_type].

And then, I added this attribute into the my products [/admin/catalog/product/] for exemple [admin/catalog/product/edit/id/36/] by section Attributes. I need this information into the mysql table "sales_order_item". I can find [sku] or [name] of items but I can not find my mew attribute [specificity_trait_type] of items . What I must do ?

Thanks,

This is new comment : Hi, I need your help and until now, nobody know how can find my new attribute into the mysql table : sales_order_item

I find it into the 3 mysql'sw table : eav_attribute and eav_attribute_option catalog_product_entity_int

like this : eav_attribute

`attribute_id`, `entity_type_id`, `attribute_code`, `           attribute_model`, `backend_model`, `backend_type`, `backend_table`, `frontend_model`, `frontend_input`, `frontend_label`,               `frontend_class`, `source_model`,                                               `is_required`, `is_user_defined`, `default_value`, `is_unique`, `note`
        158,                4,          'specificity_trait_type',   NULL,               NULL,           'int',           NULL,              NULL,           'select',           'specificity_trait_type',   NULL,               'Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Table',        1,              1,              '5639',             0,          NULL);

eav_attribute_option

   `option_id`, `attribute_id`, `sort_order
    5639,           158,                1
    5640,           158,                2
    5641,           158,                3

catalog_product_entity_int

    value_id`,  `attribute_id`,     `store_id`,     entity_id`,     `value
(12708,          158,               0,              36,          5642
(12709,          158,               0,              37,          5642
(12710,          158,               0,              38,          5641
(12711,          158,               0,              39,          5640
(12712,          158,               0,              40,          5640
(12713,          158,               0,              41,          5639
(12714,          158,               0,              42,          5640
(12715,          158,               0,              43,          5641
(12716,          158,               0,              44,          5642

When a client buy some article, I can find his order into the this table of mySql, sales_order_item, with some information of product bought, like this information :

sku, name, product_id, product_type, weight, is_virtual

but without specificity_trait_type (it is my new attribut). What I must do to add this information on the table "sales_order_item" ?

Thanks

0
0

How add my new products-attribute into the table sales_order_item in magento 2 I think, I must crete new modul, musn't I ? if yes, I cant put my new module : myMagento2.5/app/code/Magento/NewProductsAttribute

myMagento2.5\app\code\Magento\SpecificityTraittype\etc module.xml

    <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
  <module name="Magento_SpecificityTraittype" setup_version="0.0.1">
  </module>
</config>

And myMagento2.5\app\code\Magento\SpecificityTraittype registration.php

    \Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Magento_SpecificityTraittype',
    __DIR__
);

myMagento2.5\app\code\Magento\SpecificityTraittype\etc db_schema.xml

    <?xml version="1.0"?>

<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="sales_order_item" resource="sales" engine="innodb" comment="Sales Order Item">
        <column xsi:type="varchar" name="specificity_trait_type" nullable="true" length="255" comment="specificity trait type"/>
    </table>
</schema>

And then : myMagento2.5\app\code\Magento\SpecificityTraittype\Setup UpgradeSchema.php

    namespace Vendor\SalesOrder\Setup;

use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;

class UpgradeSchema implements UpgradeSchemaInterface
{
    /**
     * Upgrades DB schema for a module
     *
     * @param SchemaSetupInterface $setup
     * @param ModuleContextInterface $context
     * @return void
     */
    public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->startSetup();

        $orderTable = 'sales_order_item';

        $setup->getConnection()
            ->addColumn(
                $setup->getTable($orderTable),
                'specificity_trait_type',
                [
                    'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                    'length' => 255,
                    'comment' =>'specificity trait type'
                ]
            );

        $setup->endSetup();
    }
}

and Then, into the shell panel, I run following command :

php bin/magento setup:upgrade
php bin/magento cache:flush
php bin/magento cache:clean

So now, I have a new Column [specificity_trait_type] on my table [sales_order_item]. But I don't know always, how can Magento add a information of trait_type into the this column, when the order save into the this table. For the momnent, this column, (specificity_trait_type) is empty when I buy someting on my magento.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.