I was trying to insert values into mlx_cot_custom_option_type_value because module files are encrypted. I want to add something after product save

I am using catalog_product_save_after event

Here is what I have tried.

    protected $_resource;

    public function __construct(
        \Magento\Framework\App\ResourceConnection $resource
    ) {
        $this->_resource = $resource;
    $this->connection = $this->_resource->getConnection('core_write');
    $option_id = 186;
    $valueTable = 'mlx_cot_custom_option_type_value';
    $table = $this->_resource->getTableName($valueTable); 
    echo $sql = "Insert Into " . $table . " (option_type_id, option_id, sku, sort_order,weight) Values ('','".$option_id."','".$value['sku']."','1','')";
    $result = $this->connection->query($sql);
    echo "<pre>";

Output is

Insert Into mlx_cot_custom_option_type_value (option_type_id, option_id, sku, sort_order,weight) Values ('','186','Custom-Create-Any-Song-in-a-Music-Box-New','1','')


$this->connection->lastInsertId() give new increment id every time but I can not see any new entry into database

When I run above query using phpmyadmin it will create new entry

  • 1
    Same issue with me when try to insert order id in custom table on after place order event but not working Commented Feb 11, 2018 at 4:41
  • I was trying to do this using event but when i try to do this with plugin it is working Commented Feb 11, 2018 at 11:54
  • Please share your code that is working Commented Feb 11, 2018 at 12:32
  • Try to run the above output - Insert query directly into database so that we can check if sql is working fine. And can you show me your table structure. Commented Oct 22, 2021 at 11:16

1 Answer 1


If you guys are trying to save an attribute to product through observer "catalog_product_save_after", then this can be help:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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