Event fire before save invoice in `sales_invoice` tableObserver or plugin use before the invoice creationHow to add filtering to custom table field column in Customers admin grid in Magento2?i need set flag in model save before event and get in model save after event in magento 2How to set a custom shipping address on checkout page?Magento2: How to correctly render a json in grid fieldI have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.2.5: Add, Update and Delete existing products Custom OptionsHow save value in custom_attribute of “sale_order_grid”How apply Filter on the basis of Custom Attribute in Order Grid ProgramaticallyOrder Detail page get Order Item Collection When select any order in admin order grid in Magento 2Observer or plugin use before the invoice creation

Should a narrator ever describe things based on a characters view instead of fact?

CLI: Get information Ubuntu releases

What kind of footwear is suitable for walking in micro gravity environment?

How do researchers send unsolicited emails asking for feedback on their works?

Why is indicated airspeed rather than ground speed used during the takeoff roll?

Do people actually use the word "kaputt" in conversation?

Determine voltage drop over 10G resistors with cheap multimeter

How to balance a monster modification (zombie)?

Fair way to split coins

Hot air balloons as primitive bombers

UK Tourist Visa- Enquiry

How old is Nick Fury?

Is there any common country to visit for uk and schengen visa?

Gauss brackets with double vertical lines

Do native speakers use "ultima" and "proxima" frequently in spoken English?

label a part of commutative diagram

Have the tides ever turned twice on any open problem?

Why I don't get the wanted width of tcbox?

Symbolism of 18 Journeyers

Do I need an EFI partition for each 18.04 ubuntu I have on my HD?

How to test the sharpness of a knife?

Justification failure in beamer enumerate list

PTIJ: At the Passover Seder, is one allowed to speak more than once during Maggid?

How to find the largest number(s) in a list of elements, possibly non-unique?



Event fire before save invoice in `sales_invoice` table


Observer or plugin use before the invoice creationHow to add filtering to custom table field column in Customers admin grid in Magento2?i need set flag in model save before event and get in model save after event in magento 2How to set a custom shipping address on checkout page?Magento2: How to correctly render a json in grid fieldI have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.2.5: Add, Update and Delete existing products Custom OptionsHow save value in custom_attribute of “sale_order_grid”How apply Filter on the basis of Custom Attribute in Order Grid ProgramaticallyOrder Detail page get Order Item Collection When select any order in admin order grid in Magento 2Observer or plugin use before the invoice creation













0















I want to save value in sales_invoice table of custom attribute ("current_seller_id").
i want to know any event that fire before save the invoice in sales_invoice table or use plugin of which method.
.
I already done like this functionality in sales_order table via using event sales_model_service_quote_submit_before
code is give below .



public function execute(MagentoFrameworkEventObserver $observer)

$order = $observer->getData('order');
$quote = $observer->getData('quote');
$quoteItems = $quote->getItems();
foreach ($quoteItems as $quoteItem)
if ($quoteItem->getCurrentSellerId() != "")
$items[]=$quoteItem->getCurrentSellerId();


$seller_ids=implode(',',$items);
$order->setCurrentSellerId($seller_ids);
return $this;



Same i want to do with sales_invoice table.
Can anyone guide me ?










share|improve this question


























    0















    I want to save value in sales_invoice table of custom attribute ("current_seller_id").
    i want to know any event that fire before save the invoice in sales_invoice table or use plugin of which method.
    .
    I already done like this functionality in sales_order table via using event sales_model_service_quote_submit_before
    code is give below .



    public function execute(MagentoFrameworkEventObserver $observer)

    $order = $observer->getData('order');
    $quote = $observer->getData('quote');
    $quoteItems = $quote->getItems();
    foreach ($quoteItems as $quoteItem)
    if ($quoteItem->getCurrentSellerId() != "")
    $items[]=$quoteItem->getCurrentSellerId();


    $seller_ids=implode(',',$items);
    $order->setCurrentSellerId($seller_ids);
    return $this;



    Same i want to do with sales_invoice table.
    Can anyone guide me ?










    share|improve this question
























      0












      0








      0








      I want to save value in sales_invoice table of custom attribute ("current_seller_id").
      i want to know any event that fire before save the invoice in sales_invoice table or use plugin of which method.
      .
      I already done like this functionality in sales_order table via using event sales_model_service_quote_submit_before
      code is give below .



      public function execute(MagentoFrameworkEventObserver $observer)

      $order = $observer->getData('order');
      $quote = $observer->getData('quote');
      $quoteItems = $quote->getItems();
      foreach ($quoteItems as $quoteItem)
      if ($quoteItem->getCurrentSellerId() != "")
      $items[]=$quoteItem->getCurrentSellerId();


      $seller_ids=implode(',',$items);
      $order->setCurrentSellerId($seller_ids);
      return $this;



      Same i want to do with sales_invoice table.
      Can anyone guide me ?










      share|improve this question














      I want to save value in sales_invoice table of custom attribute ("current_seller_id").
      i want to know any event that fire before save the invoice in sales_invoice table or use plugin of which method.
      .
      I already done like this functionality in sales_order table via using event sales_model_service_quote_submit_before
      code is give below .



      public function execute(MagentoFrameworkEventObserver $observer)

      $order = $observer->getData('order');
      $quote = $observer->getData('quote');
      $quoteItems = $quote->getItems();
      foreach ($quoteItems as $quoteItem)
      if ($quoteItem->getCurrentSellerId() != "")
      $items[]=$quoteItem->getCurrentSellerId();


      $seller_ids=implode(',',$items);
      $order->setCurrentSellerId($seller_ids);
      return $this;



      Same i want to do with sales_invoice table.
      Can anyone guide me ?







      magento2 sales-invoice savedata






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 14 hours ago









      HaFiz UmerHaFiz Umer

      3289




      3289




















          1 Answer
          1






          active

          oldest

          votes


















          1














          If you want to be in sync with your code you already have implemented in Observer or plugin use before the invoice creation you should use for this also a plugin method after MagentoSalesModelOrderInvoice::register(). This is the method wich calls also the register method for each item.



          So if you create the plugin method after MagentoSalesModelOrderInvoice::register() you will have all the current seller IDs of the invoice items and can access them there.



          The plugin function could be something like this:



          public function afterRegister(MagentoSalesModelOrderInvoice $subject, $result)

          $items = [];
          foreach ($result->getAllItems() as $item)
          $items[]=$item->getCurrentSellerId();

          $seller_ids=implode(',',$items);
          $result->setCurrentSellerId($seller_ids);

          return $result;



          It is almost the same action point as using the sales_order_invoice_register event but the recommended way to change data is to use plugins.






          share|improve this answer























          • HelgeB ! i try this solution. in this plugin use $result->getAllItems(). Dear i use plugin of this method(getAllItems()) . public function afterGetAllItems(MagentoSalesModelOrderInvoice $subject,$items) generate error in the method define line. Error is ` Uncaught ArgumentCountError: Too few arguments to function CodilityVendorOrderPluginItem::beforeRegister(), 1 passed in /var/www/html/codility-magento-market-place/vendor/magento/framework/Interception/Interceptor.php on line 121 and exactly 2 expected `

            – HaFiz Umer
            12 hours ago











          • I don't know hat happens in your code, the error you have posted is about the beforeRegister() method in the item not in a afterRegister method for the invoice as proposed in the answer. Also I wouldn't suggest to use afterGetAllItems() but afterRegister as posted in my answer.

            – HelgeB
            12 hours ago











          • HelgeB ! it work fine . Thank you Dear. Actually i was use beforeRegister() plugin . i just use now afterRegister it work fine. in my last question you own say you can use before or after plugin thats why i replace after with before and get error. I don't why can you explain why we can't use beforeRegister plugin ? Thanks

            – HaFiz Umer
            12 hours ago











          • In the case of the invoice you need to add your code after register, because the register calls for each items are fired within the invoice register method. Therefore before the invoice register method your items do not have the current seller id. Just look at the code of MagentoSalesModelOrderInvoice::register() and you will understand why you need the after plugin in this case.

            – HelgeB
            11 hours ago











          • yes got it ! understand thank you

            – HaFiz Umer
            11 hours ago










          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266366%2fevent-fire-before-save-invoice-in-sales-invoice-table%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          If you want to be in sync with your code you already have implemented in Observer or plugin use before the invoice creation you should use for this also a plugin method after MagentoSalesModelOrderInvoice::register(). This is the method wich calls also the register method for each item.



          So if you create the plugin method after MagentoSalesModelOrderInvoice::register() you will have all the current seller IDs of the invoice items and can access them there.



          The plugin function could be something like this:



          public function afterRegister(MagentoSalesModelOrderInvoice $subject, $result)

          $items = [];
          foreach ($result->getAllItems() as $item)
          $items[]=$item->getCurrentSellerId();

          $seller_ids=implode(',',$items);
          $result->setCurrentSellerId($seller_ids);

          return $result;



          It is almost the same action point as using the sales_order_invoice_register event but the recommended way to change data is to use plugins.






          share|improve this answer























          • HelgeB ! i try this solution. in this plugin use $result->getAllItems(). Dear i use plugin of this method(getAllItems()) . public function afterGetAllItems(MagentoSalesModelOrderInvoice $subject,$items) generate error in the method define line. Error is ` Uncaught ArgumentCountError: Too few arguments to function CodilityVendorOrderPluginItem::beforeRegister(), 1 passed in /var/www/html/codility-magento-market-place/vendor/magento/framework/Interception/Interceptor.php on line 121 and exactly 2 expected `

            – HaFiz Umer
            12 hours ago











          • I don't know hat happens in your code, the error you have posted is about the beforeRegister() method in the item not in a afterRegister method for the invoice as proposed in the answer. Also I wouldn't suggest to use afterGetAllItems() but afterRegister as posted in my answer.

            – HelgeB
            12 hours ago











          • HelgeB ! it work fine . Thank you Dear. Actually i was use beforeRegister() plugin . i just use now afterRegister it work fine. in my last question you own say you can use before or after plugin thats why i replace after with before and get error. I don't why can you explain why we can't use beforeRegister plugin ? Thanks

            – HaFiz Umer
            12 hours ago











          • In the case of the invoice you need to add your code after register, because the register calls for each items are fired within the invoice register method. Therefore before the invoice register method your items do not have the current seller id. Just look at the code of MagentoSalesModelOrderInvoice::register() and you will understand why you need the after plugin in this case.

            – HelgeB
            11 hours ago











          • yes got it ! understand thank you

            – HaFiz Umer
            11 hours ago















          1














          If you want to be in sync with your code you already have implemented in Observer or plugin use before the invoice creation you should use for this also a plugin method after MagentoSalesModelOrderInvoice::register(). This is the method wich calls also the register method for each item.



          So if you create the plugin method after MagentoSalesModelOrderInvoice::register() you will have all the current seller IDs of the invoice items and can access them there.



          The plugin function could be something like this:



          public function afterRegister(MagentoSalesModelOrderInvoice $subject, $result)

          $items = [];
          foreach ($result->getAllItems() as $item)
          $items[]=$item->getCurrentSellerId();

          $seller_ids=implode(',',$items);
          $result->setCurrentSellerId($seller_ids);

          return $result;



          It is almost the same action point as using the sales_order_invoice_register event but the recommended way to change data is to use plugins.






          share|improve this answer























          • HelgeB ! i try this solution. in this plugin use $result->getAllItems(). Dear i use plugin of this method(getAllItems()) . public function afterGetAllItems(MagentoSalesModelOrderInvoice $subject,$items) generate error in the method define line. Error is ` Uncaught ArgumentCountError: Too few arguments to function CodilityVendorOrderPluginItem::beforeRegister(), 1 passed in /var/www/html/codility-magento-market-place/vendor/magento/framework/Interception/Interceptor.php on line 121 and exactly 2 expected `

            – HaFiz Umer
            12 hours ago











          • I don't know hat happens in your code, the error you have posted is about the beforeRegister() method in the item not in a afterRegister method for the invoice as proposed in the answer. Also I wouldn't suggest to use afterGetAllItems() but afterRegister as posted in my answer.

            – HelgeB
            12 hours ago











          • HelgeB ! it work fine . Thank you Dear. Actually i was use beforeRegister() plugin . i just use now afterRegister it work fine. in my last question you own say you can use before or after plugin thats why i replace after with before and get error. I don't why can you explain why we can't use beforeRegister plugin ? Thanks

            – HaFiz Umer
            12 hours ago











          • In the case of the invoice you need to add your code after register, because the register calls for each items are fired within the invoice register method. Therefore before the invoice register method your items do not have the current seller id. Just look at the code of MagentoSalesModelOrderInvoice::register() and you will understand why you need the after plugin in this case.

            – HelgeB
            11 hours ago











          • yes got it ! understand thank you

            – HaFiz Umer
            11 hours ago













          1












          1








          1







          If you want to be in sync with your code you already have implemented in Observer or plugin use before the invoice creation you should use for this also a plugin method after MagentoSalesModelOrderInvoice::register(). This is the method wich calls also the register method for each item.



          So if you create the plugin method after MagentoSalesModelOrderInvoice::register() you will have all the current seller IDs of the invoice items and can access them there.



          The plugin function could be something like this:



          public function afterRegister(MagentoSalesModelOrderInvoice $subject, $result)

          $items = [];
          foreach ($result->getAllItems() as $item)
          $items[]=$item->getCurrentSellerId();

          $seller_ids=implode(',',$items);
          $result->setCurrentSellerId($seller_ids);

          return $result;



          It is almost the same action point as using the sales_order_invoice_register event but the recommended way to change data is to use plugins.






          share|improve this answer













          If you want to be in sync with your code you already have implemented in Observer or plugin use before the invoice creation you should use for this also a plugin method after MagentoSalesModelOrderInvoice::register(). This is the method wich calls also the register method for each item.



          So if you create the plugin method after MagentoSalesModelOrderInvoice::register() you will have all the current seller IDs of the invoice items and can access them there.



          The plugin function could be something like this:



          public function afterRegister(MagentoSalesModelOrderInvoice $subject, $result)

          $items = [];
          foreach ($result->getAllItems() as $item)
          $items[]=$item->getCurrentSellerId();

          $seller_ids=implode(',',$items);
          $result->setCurrentSellerId($seller_ids);

          return $result;



          It is almost the same action point as using the sales_order_invoice_register event but the recommended way to change data is to use plugins.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 13 hours ago









          HelgeBHelgeB

          2,5781320




          2,5781320












          • HelgeB ! i try this solution. in this plugin use $result->getAllItems(). Dear i use plugin of this method(getAllItems()) . public function afterGetAllItems(MagentoSalesModelOrderInvoice $subject,$items) generate error in the method define line. Error is ` Uncaught ArgumentCountError: Too few arguments to function CodilityVendorOrderPluginItem::beforeRegister(), 1 passed in /var/www/html/codility-magento-market-place/vendor/magento/framework/Interception/Interceptor.php on line 121 and exactly 2 expected `

            – HaFiz Umer
            12 hours ago











          • I don't know hat happens in your code, the error you have posted is about the beforeRegister() method in the item not in a afterRegister method for the invoice as proposed in the answer. Also I wouldn't suggest to use afterGetAllItems() but afterRegister as posted in my answer.

            – HelgeB
            12 hours ago











          • HelgeB ! it work fine . Thank you Dear. Actually i was use beforeRegister() plugin . i just use now afterRegister it work fine. in my last question you own say you can use before or after plugin thats why i replace after with before and get error. I don't why can you explain why we can't use beforeRegister plugin ? Thanks

            – HaFiz Umer
            12 hours ago











          • In the case of the invoice you need to add your code after register, because the register calls for each items are fired within the invoice register method. Therefore before the invoice register method your items do not have the current seller id. Just look at the code of MagentoSalesModelOrderInvoice::register() and you will understand why you need the after plugin in this case.

            – HelgeB
            11 hours ago











          • yes got it ! understand thank you

            – HaFiz Umer
            11 hours ago

















          • HelgeB ! i try this solution. in this plugin use $result->getAllItems(). Dear i use plugin of this method(getAllItems()) . public function afterGetAllItems(MagentoSalesModelOrderInvoice $subject,$items) generate error in the method define line. Error is ` Uncaught ArgumentCountError: Too few arguments to function CodilityVendorOrderPluginItem::beforeRegister(), 1 passed in /var/www/html/codility-magento-market-place/vendor/magento/framework/Interception/Interceptor.php on line 121 and exactly 2 expected `

            – HaFiz Umer
            12 hours ago











          • I don't know hat happens in your code, the error you have posted is about the beforeRegister() method in the item not in a afterRegister method for the invoice as proposed in the answer. Also I wouldn't suggest to use afterGetAllItems() but afterRegister as posted in my answer.

            – HelgeB
            12 hours ago











          • HelgeB ! it work fine . Thank you Dear. Actually i was use beforeRegister() plugin . i just use now afterRegister it work fine. in my last question you own say you can use before or after plugin thats why i replace after with before and get error. I don't why can you explain why we can't use beforeRegister plugin ? Thanks

            – HaFiz Umer
            12 hours ago











          • In the case of the invoice you need to add your code after register, because the register calls for each items are fired within the invoice register method. Therefore before the invoice register method your items do not have the current seller id. Just look at the code of MagentoSalesModelOrderInvoice::register() and you will understand why you need the after plugin in this case.

            – HelgeB
            11 hours ago











          • yes got it ! understand thank you

            – HaFiz Umer
            11 hours ago
















          HelgeB ! i try this solution. in this plugin use $result->getAllItems(). Dear i use plugin of this method(getAllItems()) . public function afterGetAllItems(MagentoSalesModelOrderInvoice $subject,$items) generate error in the method define line. Error is ` Uncaught ArgumentCountError: Too few arguments to function CodilityVendorOrderPluginItem::beforeRegister(), 1 passed in /var/www/html/codility-magento-market-place/vendor/magento/framework/Interception/Interceptor.php on line 121 and exactly 2 expected `

          – HaFiz Umer
          12 hours ago





          HelgeB ! i try this solution. in this plugin use $result->getAllItems(). Dear i use plugin of this method(getAllItems()) . public function afterGetAllItems(MagentoSalesModelOrderInvoice $subject,$items) generate error in the method define line. Error is ` Uncaught ArgumentCountError: Too few arguments to function CodilityVendorOrderPluginItem::beforeRegister(), 1 passed in /var/www/html/codility-magento-market-place/vendor/magento/framework/Interception/Interceptor.php on line 121 and exactly 2 expected `

          – HaFiz Umer
          12 hours ago













          I don't know hat happens in your code, the error you have posted is about the beforeRegister() method in the item not in a afterRegister method for the invoice as proposed in the answer. Also I wouldn't suggest to use afterGetAllItems() but afterRegister as posted in my answer.

          – HelgeB
          12 hours ago





          I don't know hat happens in your code, the error you have posted is about the beforeRegister() method in the item not in a afterRegister method for the invoice as proposed in the answer. Also I wouldn't suggest to use afterGetAllItems() but afterRegister as posted in my answer.

          – HelgeB
          12 hours ago













          HelgeB ! it work fine . Thank you Dear. Actually i was use beforeRegister() plugin . i just use now afterRegister it work fine. in my last question you own say you can use before or after plugin thats why i replace after with before and get error. I don't why can you explain why we can't use beforeRegister plugin ? Thanks

          – HaFiz Umer
          12 hours ago





          HelgeB ! it work fine . Thank you Dear. Actually i was use beforeRegister() plugin . i just use now afterRegister it work fine. in my last question you own say you can use before or after plugin thats why i replace after with before and get error. I don't why can you explain why we can't use beforeRegister plugin ? Thanks

          – HaFiz Umer
          12 hours ago













          In the case of the invoice you need to add your code after register, because the register calls for each items are fired within the invoice register method. Therefore before the invoice register method your items do not have the current seller id. Just look at the code of MagentoSalesModelOrderInvoice::register() and you will understand why you need the after plugin in this case.

          – HelgeB
          11 hours ago





          In the case of the invoice you need to add your code after register, because the register calls for each items are fired within the invoice register method. Therefore before the invoice register method your items do not have the current seller id. Just look at the code of MagentoSalesModelOrderInvoice::register() and you will understand why you need the after plugin in this case.

          – HelgeB
          11 hours ago













          yes got it ! understand thank you

          – HaFiz Umer
          11 hours ago





          yes got it ! understand thank you

          – HaFiz Umer
          11 hours ago

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266366%2fevent-fire-before-save-invoice-in-sales-invoice-table%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Sum ergo cogito? 1 nng

          三茅街道4182Guuntc Dn precexpngmageondP