Magento 2 How to prevent product save with custom condition using plugin 'aroundSave'?Rewriting Magento 2 classes vs PluginsMagento2: plugin around method not workingMagento 2 adminhtml getUrl not working as expectedMagento 2.1 Create a filter in the product grid by new attributeHow do I get a methods argument for an after plugin in Magento 2?Magento 2.2.5: Add, Update and Delete existing products Custom OptionsCreating Single Sign-on - Logging in admin throws “Your current session has been expired.”Magento 2 plugin change price of products that have a custom attribute withEvent fire before save invoice in `sales_invoice` tableMagento 2 validate the form input using plugin and save the modified data

Where have Brexit voters gone?

Did people Unsnap to where they were?

Where can I find visible/radio telescopic observations of the center of the Milky Way galaxy?

Inclusion of standard error in regression equation

Does Nitrogen inside commercial airliner wheels prevent blowouts on touchdown?

Any advice on creating fictional locations in real places when writing historical fiction?

Count rotary dial pulses in a phone number (including letters)

What was the idiom for something that we take without a doubt?

How long until a random word with letters "A", "B", "C" ends in the pattern "ABC"?

What is the object moving across the ceiling in this stock footage?

Is real public IP Address hidden when using a system wide proxy in Windows 10?

How strong are Wi-Fi signals?

At what point in European history could a government build a printing press given a basic description?

Maxima of Brownian motion

What does this symbol on the box of power supply mean?

Why did David Cameron offer a referendum on the European Union?

Count Even Digits In Number

Employer asking for online access to bank account - Is this a scam?

Looking for a soft substance that doesn't dissolve underwater

A steel cutting sword?

My employer faked my resume to acquire projects

Is it rude to call a professor by their last name with no prefix in a non-academic setting?

Caught 2 students cheating together on the final exam that I proctored

What does the view outside my ship traveling at light speed look like?



Magento 2 How to prevent product save with custom condition using plugin 'aroundSave'?


Rewriting Magento 2 classes vs PluginsMagento2: plugin around method not workingMagento 2 adminhtml getUrl not working as expectedMagento 2.1 Create a filter in the product grid by new attributeHow do I get a methods argument for an after plugin in Magento 2?Magento 2.2.5: Add, Update and Delete existing products Custom OptionsCreating Single Sign-on - Logging in admin throws “Your current session has been expired.”Magento 2 plugin change price of products that have a custom attribute withEvent fire before save invoice in `sales_invoice` tableMagento 2 validate the form input using plugin and save the modified data






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I want to prevent to save the product with my custom condition, for that, I want to use the plugin with method 'aroundSave',



  • When the user clicks on 'Save & Duplicate' button I do not want to save the original product simply duplicate the product.
    Is the plugin method is correct or I need to override the controller or use catalog_product_save_befor event?

Anyone have any example please share.



for example,



namespace VendorModulePlugin;

class Save

public function aroundExecute(MagentoCatalogControllerAdminhtmlProductSave $subject, $result)

if (some condition == true)
then save product
else
not save the product




How can I achieve this functionality?










share|improve this question






























    0















    I want to prevent to save the product with my custom condition, for that, I want to use the plugin with method 'aroundSave',



    • When the user clicks on 'Save & Duplicate' button I do not want to save the original product simply duplicate the product.
      Is the plugin method is correct or I need to override the controller or use catalog_product_save_befor event?

    Anyone have any example please share.



    for example,



    namespace VendorModulePlugin;

    class Save

    public function aroundExecute(MagentoCatalogControllerAdminhtmlProductSave $subject, $result)

    if (some condition == true)
    then save product
    else
    not save the product




    How can I achieve this functionality?










    share|improve this question


























      0












      0








      0








      I want to prevent to save the product with my custom condition, for that, I want to use the plugin with method 'aroundSave',



      • When the user clicks on 'Save & Duplicate' button I do not want to save the original product simply duplicate the product.
        Is the plugin method is correct or I need to override the controller or use catalog_product_save_befor event?

      Anyone have any example please share.



      for example,



      namespace VendorModulePlugin;

      class Save

      public function aroundExecute(MagentoCatalogControllerAdminhtmlProductSave $subject, $result)

      if (some condition == true)
      then save product
      else
      not save the product




      How can I achieve this functionality?










      share|improve this question
















      I want to prevent to save the product with my custom condition, for that, I want to use the plugin with method 'aroundSave',



      • When the user clicks on 'Save & Duplicate' button I do not want to save the original product simply duplicate the product.
        Is the plugin method is correct or I need to override the controller or use catalog_product_save_befor event?

      Anyone have any example please share.



      for example,



      namespace VendorModulePlugin;

      class Save

      public function aroundExecute(MagentoCatalogControllerAdminhtmlProductSave $subject, $result)

      if (some condition == true)
      then save product
      else
      not save the product




      How can I achieve this functionality?







      magento2 product plugin






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 20 at 9:23







      Utsav Gupta

















      asked May 20 at 6:29









      Utsav GuptaUtsav Gupta

      457215




      457215




















          1 Answer
          1






          active

          oldest

          votes


















          0














          That would be because the admin product form doesn't actually use ProductRepository, at least as of 2.2.2.



          vendor/magento/module-catalog/Controller/Adminhtml/Product/Save.php:



          $product->save();


          You haven't explained what you're actually trying to accomplish, but you would probably be better served by an observer on event catalog_product_save_before or catalog_product_save_after. Those are kicked off by the product resource model, so they should fire regardless of whether the product is saved via ProductRepository or directly.






          share|improve this answer























          • please check updated question. thanks for your help.

            – Utsav Gupta
            May 20 at 7:18











          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%2f275212%2fmagento-2-how-to-prevent-product-save-with-custom-condition-using-plugin-around%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









          0














          That would be because the admin product form doesn't actually use ProductRepository, at least as of 2.2.2.



          vendor/magento/module-catalog/Controller/Adminhtml/Product/Save.php:



          $product->save();


          You haven't explained what you're actually trying to accomplish, but you would probably be better served by an observer on event catalog_product_save_before or catalog_product_save_after. Those are kicked off by the product resource model, so they should fire regardless of whether the product is saved via ProductRepository or directly.






          share|improve this answer























          • please check updated question. thanks for your help.

            – Utsav Gupta
            May 20 at 7:18















          0














          That would be because the admin product form doesn't actually use ProductRepository, at least as of 2.2.2.



          vendor/magento/module-catalog/Controller/Adminhtml/Product/Save.php:



          $product->save();


          You haven't explained what you're actually trying to accomplish, but you would probably be better served by an observer on event catalog_product_save_before or catalog_product_save_after. Those are kicked off by the product resource model, so they should fire regardless of whether the product is saved via ProductRepository or directly.






          share|improve this answer























          • please check updated question. thanks for your help.

            – Utsav Gupta
            May 20 at 7:18













          0












          0








          0







          That would be because the admin product form doesn't actually use ProductRepository, at least as of 2.2.2.



          vendor/magento/module-catalog/Controller/Adminhtml/Product/Save.php:



          $product->save();


          You haven't explained what you're actually trying to accomplish, but you would probably be better served by an observer on event catalog_product_save_before or catalog_product_save_after. Those are kicked off by the product resource model, so they should fire regardless of whether the product is saved via ProductRepository or directly.






          share|improve this answer













          That would be because the admin product form doesn't actually use ProductRepository, at least as of 2.2.2.



          vendor/magento/module-catalog/Controller/Adminhtml/Product/Save.php:



          $product->save();


          You haven't explained what you're actually trying to accomplish, but you would probably be better served by an observer on event catalog_product_save_before or catalog_product_save_after. Those are kicked off by the product resource model, so they should fire regardless of whether the product is saved via ProductRepository or directly.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 20 at 6:36









          Rk RathodRk Rathod

          2,041214




          2,041214












          • please check updated question. thanks for your help.

            – Utsav Gupta
            May 20 at 7:18

















          • please check updated question. thanks for your help.

            – Utsav Gupta
            May 20 at 7:18
















          please check updated question. thanks for your help.

          – Utsav Gupta
          May 20 at 7:18





          please check updated question. thanks for your help.

          – Utsav Gupta
          May 20 at 7:18

















          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%2f275212%2fmagento-2-how-to-prevent-product-save-with-custom-condition-using-plugin-around%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

          Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

          Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

          Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form