1

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>";
    print_r($this->connection->lastInsertId());
    die;

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','')

2047

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

Whene 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 – Purushotam Sharma Feb 11 '18 at 4:41
  • I was trying to do this using event but when i try to do this with plugin it is working – Vaibhav Ahalpara Feb 11 '18 at 11:54
  • Please share your code that is working – Purushotam Sharma Feb 11 '18 at 12:32
0

If you guys are trying to save an attribute to product through observer "catalog_product_save_after", then this can be help:
https://webkul.com/blog/mass-update-products-attribute-magento-2/

| improve this answer | |

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.