Magento 2 - How to use plugin to change product visiblity after saving product from backend?

Multi tool use
Multi tool use

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





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







up vote
2
down vote

favorite
1












I am new in Magento 2 and I want to change product visibility after saving product from backend using plugin.



For this I have created custom module and plugin, but I am not sure that we can achieve this using of plugin or not? Or Should I go with Observer?



I am trying something like : -




app/code/Custom/HelloWorld/etc/di.xml




<type name="MagentoCatalogModelProduct">
<plugin name="Custom-HelloWorld-product-model" type="CustomHelloWorldPluginProductPlugin" sortOrder="1" />
</type>



app/code/Custom/HelloWorld/Plugin/ProductPlugin.php




namespace CustomHelloWorldPlugin;

class ProductPlugin

public function beforeSetVisiblity(MagentoCatalogModelProduct $subject, $visiblity)

....




Please suggest. Thanks!










share|improve this question























  • yes, you can go with plugin.
    – kunj
    Aug 30 at 6:54






  • 1




    Thanks for your suggestion. I also have to update DB value as well. Can you please give me any doc links so I can get more information and implement this in our module.
    – Mr. Nanhe
    Aug 30 at 7:10










  • Sure, you can learn more from here : mageplaza.com/magento-2-module-development/…
    – kunj
    Aug 30 at 7:10
















up vote
2
down vote

favorite
1












I am new in Magento 2 and I want to change product visibility after saving product from backend using plugin.



For this I have created custom module and plugin, but I am not sure that we can achieve this using of plugin or not? Or Should I go with Observer?



I am trying something like : -




app/code/Custom/HelloWorld/etc/di.xml




<type name="MagentoCatalogModelProduct">
<plugin name="Custom-HelloWorld-product-model" type="CustomHelloWorldPluginProductPlugin" sortOrder="1" />
</type>



app/code/Custom/HelloWorld/Plugin/ProductPlugin.php




namespace CustomHelloWorldPlugin;

class ProductPlugin

public function beforeSetVisiblity(MagentoCatalogModelProduct $subject, $visiblity)

....




Please suggest. Thanks!










share|improve this question























  • yes, you can go with plugin.
    – kunj
    Aug 30 at 6:54






  • 1




    Thanks for your suggestion. I also have to update DB value as well. Can you please give me any doc links so I can get more information and implement this in our module.
    – Mr. Nanhe
    Aug 30 at 7:10










  • Sure, you can learn more from here : mageplaza.com/magento-2-module-development/…
    – kunj
    Aug 30 at 7:10












up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






1





I am new in Magento 2 and I want to change product visibility after saving product from backend using plugin.



For this I have created custom module and plugin, but I am not sure that we can achieve this using of plugin or not? Or Should I go with Observer?



I am trying something like : -




app/code/Custom/HelloWorld/etc/di.xml




<type name="MagentoCatalogModelProduct">
<plugin name="Custom-HelloWorld-product-model" type="CustomHelloWorldPluginProductPlugin" sortOrder="1" />
</type>



app/code/Custom/HelloWorld/Plugin/ProductPlugin.php




namespace CustomHelloWorldPlugin;

class ProductPlugin

public function beforeSetVisiblity(MagentoCatalogModelProduct $subject, $visiblity)

....




Please suggest. Thanks!










share|improve this question















I am new in Magento 2 and I want to change product visibility after saving product from backend using plugin.



For this I have created custom module and plugin, but I am not sure that we can achieve this using of plugin or not? Or Should I go with Observer?



I am trying something like : -




app/code/Custom/HelloWorld/etc/di.xml




<type name="MagentoCatalogModelProduct">
<plugin name="Custom-HelloWorld-product-model" type="CustomHelloWorldPluginProductPlugin" sortOrder="1" />
</type>



app/code/Custom/HelloWorld/Plugin/ProductPlugin.php




namespace CustomHelloWorldPlugin;

class ProductPlugin

public function beforeSetVisiblity(MagentoCatalogModelProduct $subject, $visiblity)

....




Please suggest. Thanks!







magento2 admin upgrade visibility






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 30 at 6:53









kunj

2,3772421




2,3772421










asked Aug 30 at 6:51









Mr. Nanhe

175




175











  • yes, you can go with plugin.
    – kunj
    Aug 30 at 6:54






  • 1




    Thanks for your suggestion. I also have to update DB value as well. Can you please give me any doc links so I can get more information and implement this in our module.
    – Mr. Nanhe
    Aug 30 at 7:10










  • Sure, you can learn more from here : mageplaza.com/magento-2-module-development/…
    – kunj
    Aug 30 at 7:10
















  • yes, you can go with plugin.
    – kunj
    Aug 30 at 6:54






  • 1




    Thanks for your suggestion. I also have to update DB value as well. Can you please give me any doc links so I can get more information and implement this in our module.
    – Mr. Nanhe
    Aug 30 at 7:10










  • Sure, you can learn more from here : mageplaza.com/magento-2-module-development/…
    – kunj
    Aug 30 at 7:10















yes, you can go with plugin.
– kunj
Aug 30 at 6:54




yes, you can go with plugin.
– kunj
Aug 30 at 6:54




1




1




Thanks for your suggestion. I also have to update DB value as well. Can you please give me any doc links so I can get more information and implement this in our module.
– Mr. Nanhe
Aug 30 at 7:10




Thanks for your suggestion. I also have to update DB value as well. Can you please give me any doc links so I can get more information and implement this in our module.
– Mr. Nanhe
Aug 30 at 7:10












Sure, you can learn more from here : mageplaza.com/magento-2-module-development/…
– kunj
Aug 30 at 7:10




Sure, you can learn more from here : mageplaza.com/magento-2-module-development/…
– kunj
Aug 30 at 7:10










1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










You should use plugin not observer, there is something need to understand that where to use plugin and where to use observers :



Use Plugins :
If you are going to change input, output ( i.e set / save data ) of some function or changing flow of request then should use plugin.



User Observer :
If you are not going to change the flow of request and intended to perform some other action on event then use Observer.






share|improve this answer


















  • 1




    Thanks for your kind suggestion. I have to update DB value as well. Can you please give me any doc links so I can get more information and implement this in our module.
    – Mr. Nanhe
    Aug 30 at 7:04











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',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
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%2f240191%2fmagento-2-how-to-use-plugin-to-change-product-visiblity-after-saving-product-f%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










You should use plugin not observer, there is something need to understand that where to use plugin and where to use observers :



Use Plugins :
If you are going to change input, output ( i.e set / save data ) of some function or changing flow of request then should use plugin.



User Observer :
If you are not going to change the flow of request and intended to perform some other action on event then use Observer.






share|improve this answer


















  • 1




    Thanks for your kind suggestion. I have to update DB value as well. Can you please give me any doc links so I can get more information and implement this in our module.
    – Mr. Nanhe
    Aug 30 at 7:04















up vote
3
down vote



accepted










You should use plugin not observer, there is something need to understand that where to use plugin and where to use observers :



Use Plugins :
If you are going to change input, output ( i.e set / save data ) of some function or changing flow of request then should use plugin.



User Observer :
If you are not going to change the flow of request and intended to perform some other action on event then use Observer.






share|improve this answer


















  • 1




    Thanks for your kind suggestion. I have to update DB value as well. Can you please give me any doc links so I can get more information and implement this in our module.
    – Mr. Nanhe
    Aug 30 at 7:04













up vote
3
down vote



accepted







up vote
3
down vote



accepted






You should use plugin not observer, there is something need to understand that where to use plugin and where to use observers :



Use Plugins :
If you are going to change input, output ( i.e set / save data ) of some function or changing flow of request then should use plugin.



User Observer :
If you are not going to change the flow of request and intended to perform some other action on event then use Observer.






share|improve this answer














You should use plugin not observer, there is something need to understand that where to use plugin and where to use observers :



Use Plugins :
If you are going to change input, output ( i.e set / save data ) of some function or changing flow of request then should use plugin.



User Observer :
If you are not going to change the flow of request and intended to perform some other action on event then use Observer.







share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 30 at 7:08









Amit Bera♦

53.8k1366157




53.8k1366157










answered Aug 30 at 6:58









Naveed

1,6851212




1,6851212







  • 1




    Thanks for your kind suggestion. I have to update DB value as well. Can you please give me any doc links so I can get more information and implement this in our module.
    – Mr. Nanhe
    Aug 30 at 7:04













  • 1




    Thanks for your kind suggestion. I have to update DB value as well. Can you please give me any doc links so I can get more information and implement this in our module.
    – Mr. Nanhe
    Aug 30 at 7:04








1




1




Thanks for your kind suggestion. I have to update DB value as well. Can you please give me any doc links so I can get more information and implement this in our module.
– Mr. Nanhe
Aug 30 at 7:04





Thanks for your kind suggestion. I have to update DB value as well. Can you please give me any doc links so I can get more information and implement this in our module.
– Mr. Nanhe
Aug 30 at 7:04


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f240191%2fmagento-2-how-to-use-plugin-to-change-product-visiblity-after-saving-product-f%23new-answer', 'question_page');

);

Post as a guest













































































4RuiCmHuqaM np6c0hIg fYypg,VzN0zk2,WixRyAunYiQxaitn2Ty3nn4bvyijAuJZ5EKsvaLhZGNp3scC
FCP6,z,5NRgp7YggAtCvnaPqW0pm3xDO2eR718lx4nwFPldvWlS

這個網誌中的熱門文章

How to combine Bézier curves to a surface?

Propositional logic and tautologies

Distribution of Stopped Wiener Process with Stochastic Volatility