daily pastebin goal
24%
SHARE
TWEET

Untitled

a guest Jan 12th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?xml version="1.0"?>
  2. <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
  3.     <event name="catalog_product_save_after">
  4.         <observer name="test_name" instance="YOUR_NAMESPACEYOUR_MODULENAMEObserverProductsaveafter" />
  5.     </event>
  6. </config>
  7.    
  8. <?php
  9.  
  10. namespace YOURNAMESPACEYOURMODULENAMEObserver;
  11.  
  12. use MagentoFrameworkEventObserverInterface;
  13.  
  14. class Productsaveafter implements ObserverInterface
  15. {    
  16.     public function execute(MagentoFrameworkEventObserver $observer)
  17.     {
  18.         $product = $observer->getEvent()->getProduct();
  19.         $id = $product->getId(); //Get Product Id
  20.  
  21.         //Get Quantity
  22.         $stockItem = $product->getExtensionAttributes()->getStockItem();
  23.         $stockData = $stockItem->getQty();
  24.         // Get new Qty
  25.         $_vendor_qty = $product->getVendorQty();
  26.         $_on_hand_qty = $product->getOnHandQty();
  27.         $totalQty = $_vendor_qty+$_on_hand_qty; //Add New Qty
  28.  
  29.  
  30.         $stockItem->setQty($totalQty); //Set New Qty to Main Qty
  31.         $stockItem->save();
  32.  
  33.     }  
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top