We will achieve this functionality through EventObserver.
Here, I have used the event which is called
“controller_action_catalog_product_save_entity_after”
Step 1: Create event.xml in /etc/adminhtml folder in your module.
1 2 3 4 5 6 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="controller_action_catalog_product_save_entity_after"> <observer name="magemonkeys_saveproductlogic" instance="Magemonkeys\Saveproductlogic\Observer\SaveProduct" /> </event> </config> |
Step 2: Create a SaveProduct.php Observer in Observer Folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
<?php namespace Magemonkeys\Saveproductlogic\Observer; use Magento\Framework\Event\ObserverInterface; class SaveProduct implements ObserverInterface { protected $catalogData; protected $_resource; public function __construct( \Magento\Framework\App\ResourceConnection $resource ) { $this->_resource = $resource; } public function execute(\Magento\Framework\Event\Observer $observer) { $connection = $this->_resource->getConnection(); $table_name = $this->_resource->getTableName('product_oem'); $productController = $observer->getController(); $data = $productController->getRequest()->getPostValue(); $mainProduct = $observer->getProduct(); $productId = $mainProduct->getId(); /* You can use you logic here */ if(isset($data['product']['product_oem']) && $productId){ $connection->query('DELETE FROM ' . $table_name . ' WHERE product_id = ' . (int)$productId . ' '); $productOems = $data['product']['product_oem']; if(!is_array($productOems)){ $productOems = array(); $productOems[] = (int)$data['product']['product_oem']; } foreach ($productOems as $k => $v) { $connection->query('INSERT INTO ' . $table_name . ' VALUES ( ' . $v . ', ' . (int)$productId . ',0)'); } } } } ?> |
After creating the above module, please run the upgrade, compile and static:content:deploy command to implement this module.
[crayon-63d3e43659258014137340/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.