How to override protected function Magento 2?How to Override or Extend protected or parent function in Magento 2 using PluginMagento 2 How to override Protected FunctionHow to override protected function in Magento 2Override the private function getConfiguredUsedProductCollection()Magento 2 override the product collection(MagentoCatalogModelResourceModelProductCollection.php)Override construct function in child class magento2Magento 2: How to Override core fileMagento2 : Protected function override with di:compile issueMagento2: how can i override protected functionMagento 2 :Sort Attributes Alphabetically in layered Navigation

Do empty drive bays need to be filled?

Canada travel to US using Global Entry

If there's something that implicates the president why is there then a national security issue? (John Dowd)

Why do radiation hardened IC packages often have long leads?

Is Dumbledore a human lie detector?

How can powerful telekinesis avoid violating Newton's 3rd Law?

ASCII Meme Arrow Generator

Grep Match and extract

What should I be wary of when insurer is taking a lot of time to decide whether car is repairable or a total loss?

Proving that a Russian cryptographic standard is too structured

Is it okay to have a sequel start immediately after the end of the first book?

Was planting UN flag on Moon ever discussed?

Should I put programming books I wrote a few years ago on my resume?

Remove border lines of SRTM tiles rendered as hillshade

Multiband vertical antenna not working as expected

Could a person damage a jet airliner - from the outside - with their bare hands?

What do you call the action of "describing events as they happen" like sports anchors do?

Why is the length of the Kelvin unit of temperature equal to that of the Celsius unit?

Diatonic chords of a pentatonic vs blues scale?

The significance of kelvin as a unit of absolute temperature

What is the Leave No Trace way to dispose of coffee grounds?

Should I refuse to be named as co-author of a low quality paper?

Why is Na5 not played in this line of the French Defense, Advance Variation?

Rail-to-rail op-amp only reaches 90% of VCC, works sometimes, not everytime



How to override protected function Magento 2?


How to Override or Extend protected or parent function in Magento 2 using PluginMagento 2 How to override Protected FunctionHow to override protected function in Magento 2Override the private function getConfiguredUsedProductCollection()Magento 2 override the product collection(MagentoCatalogModelResourceModelProductCollection.php)Override construct function in child class magento2Magento 2: How to Override core fileMagento2 : Protected function override with di:compile issueMagento2: how can i override protected functionMagento 2 :Sort Attributes Alphabetically in layered Navigation






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








0















i want to edit this function in MagentoEavModelResourceModelEntityAttribute.php



protected function _updateDefaultValue($object, $optionId, $intOptionId, &$defaultValue)

if (in_array($optionId, $object->getDefault()))
$frontendInput = $object->getFrontendInput();
if ($frontendInput === 'multiselect')
$defaultValue[] = $intOptionId;
elseif ($frontendInput === 'select')
$defaultValue = [$intOptionId];





I want to check if $ frontendInput == 'checkboxes'
I have override this file but can't. who knows any other way?
Please helpe me! tks.



this is my code



class Attribute extends MagentoEavModelResourceModelEntityAttribute

protected function _updateDefaultValue($object, $optionId, $intOptionId, &$defaultValue)

if (in_array($optionId, $object->getDefault()))










share|improve this question



















  • 1





    You can use <preference> to override MagentoEavModelResourceModelEntityAttribute.php and override only _updateDefaultValue() function.

    – Dhara Bhatti
    Jun 4 at 11:07












  • yes.i tried <preference> but It does not fit into my override function.i have updated my question.

    – Thành Trung Tô
    Jun 4 at 11:33












  • What is the reason for overiding this function ?

    – aravind
    Jun 4 at 12:03











  • @aravind because the field checkbox in my backend does not receive the default value. I need to override this function to set the default value for it.

    – Thành Trung Tô
    Jun 5 at 4:26

















0















i want to edit this function in MagentoEavModelResourceModelEntityAttribute.php



protected function _updateDefaultValue($object, $optionId, $intOptionId, &$defaultValue)

if (in_array($optionId, $object->getDefault()))
$frontendInput = $object->getFrontendInput();
if ($frontendInput === 'multiselect')
$defaultValue[] = $intOptionId;
elseif ($frontendInput === 'select')
$defaultValue = [$intOptionId];





I want to check if $ frontendInput == 'checkboxes'
I have override this file but can't. who knows any other way?
Please helpe me! tks.



this is my code



class Attribute extends MagentoEavModelResourceModelEntityAttribute

protected function _updateDefaultValue($object, $optionId, $intOptionId, &$defaultValue)

if (in_array($optionId, $object->getDefault()))










share|improve this question



















  • 1





    You can use <preference> to override MagentoEavModelResourceModelEntityAttribute.php and override only _updateDefaultValue() function.

    – Dhara Bhatti
    Jun 4 at 11:07












  • yes.i tried <preference> but It does not fit into my override function.i have updated my question.

    – Thành Trung Tô
    Jun 4 at 11:33












  • What is the reason for overiding this function ?

    – aravind
    Jun 4 at 12:03











  • @aravind because the field checkbox in my backend does not receive the default value. I need to override this function to set the default value for it.

    – Thành Trung Tô
    Jun 5 at 4:26













0












0








0








i want to edit this function in MagentoEavModelResourceModelEntityAttribute.php



protected function _updateDefaultValue($object, $optionId, $intOptionId, &$defaultValue)

if (in_array($optionId, $object->getDefault()))
$frontendInput = $object->getFrontendInput();
if ($frontendInput === 'multiselect')
$defaultValue[] = $intOptionId;
elseif ($frontendInput === 'select')
$defaultValue = [$intOptionId];





I want to check if $ frontendInput == 'checkboxes'
I have override this file but can't. who knows any other way?
Please helpe me! tks.



this is my code



class Attribute extends MagentoEavModelResourceModelEntityAttribute

protected function _updateDefaultValue($object, $optionId, $intOptionId, &$defaultValue)

if (in_array($optionId, $object->getDefault()))










share|improve this question
















i want to edit this function in MagentoEavModelResourceModelEntityAttribute.php



protected function _updateDefaultValue($object, $optionId, $intOptionId, &$defaultValue)

if (in_array($optionId, $object->getDefault()))
$frontendInput = $object->getFrontendInput();
if ($frontendInput === 'multiselect')
$defaultValue[] = $intOptionId;
elseif ($frontendInput === 'select')
$defaultValue = [$intOptionId];





I want to check if $ frontendInput == 'checkboxes'
I have override this file but can't. who knows any other way?
Please helpe me! tks.



this is my code



class Attribute extends MagentoEavModelResourceModelEntityAttribute

protected function _updateDefaultValue($object, $optionId, $intOptionId, &$defaultValue)

if (in_array($optionId, $object->getDefault()))







magento2 attributes overrides customer-attribute






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 4 at 11:37







Thành Trung Tô

















asked Jun 4 at 11:00









Thành Trung TôThành Trung Tô

587




587







  • 1





    You can use <preference> to override MagentoEavModelResourceModelEntityAttribute.php and override only _updateDefaultValue() function.

    – Dhara Bhatti
    Jun 4 at 11:07












  • yes.i tried <preference> but It does not fit into my override function.i have updated my question.

    – Thành Trung Tô
    Jun 4 at 11:33












  • What is the reason for overiding this function ?

    – aravind
    Jun 4 at 12:03











  • @aravind because the field checkbox in my backend does not receive the default value. I need to override this function to set the default value for it.

    – Thành Trung Tô
    Jun 5 at 4:26












  • 1





    You can use <preference> to override MagentoEavModelResourceModelEntityAttribute.php and override only _updateDefaultValue() function.

    – Dhara Bhatti
    Jun 4 at 11:07












  • yes.i tried <preference> but It does not fit into my override function.i have updated my question.

    – Thành Trung Tô
    Jun 4 at 11:33












  • What is the reason for overiding this function ?

    – aravind
    Jun 4 at 12:03











  • @aravind because the field checkbox in my backend does not receive the default value. I need to override this function to set the default value for it.

    – Thành Trung Tô
    Jun 5 at 4:26







1




1





You can use <preference> to override MagentoEavModelResourceModelEntityAttribute.php and override only _updateDefaultValue() function.

– Dhara Bhatti
Jun 4 at 11:07






You can use <preference> to override MagentoEavModelResourceModelEntityAttribute.php and override only _updateDefaultValue() function.

– Dhara Bhatti
Jun 4 at 11:07














yes.i tried <preference> but It does not fit into my override function.i have updated my question.

– Thành Trung Tô
Jun 4 at 11:33






yes.i tried <preference> but It does not fit into my override function.i have updated my question.

– Thành Trung Tô
Jun 4 at 11:33














What is the reason for overiding this function ?

– aravind
Jun 4 at 12:03





What is the reason for overiding this function ?

– aravind
Jun 4 at 12:03













@aravind because the field checkbox in my backend does not receive the default value. I need to override this function to set the default value for it.

– Thành Trung Tô
Jun 5 at 4:26





@aravind because the field checkbox in my backend does not receive the default value. I need to override this function to set the default value for it.

– Thành Trung Tô
Jun 5 at 4:26










3 Answers
3






active

oldest

votes


















1














Also In preference method,You can not override a protected function. However you can override the public method which is calling that protected method. In your case, It is also a protected method.






share|improve this answer























  • Do you know any way ?

    – Thành Trung Tô
    Jun 5 at 4:27











  • It is difficult to overide that function in your case, as everywhere it get's called is protected. So, You need to find an alternate solution..

    – aravind
    Jun 5 at 4:50











  • I have been thinking about this problem for more than 6 hours but still haven't found an alternative solution. Anyway, thank you.~~!

    – Thành Trung Tô
    Jun 5 at 4:55


















0














You can use plugin and do following in beforeupdateDefaultValue



 if ($frontendInput === 'multiselect' || $frontendInput === 'checkboxs')
//setFrontendInput to 'multiselect';
elseif($frontendInput === 'select' || $frontendInput === 'radio')
//setFrontendInput to 'select';






share|improve this answer























  • According to docs plugins cant be used on non public methods devdocs.magento.com/guides/v2.3/extension-dev-guide/…

    – Dominic Xigen
    Jun 4 at 20:53











  • it is protected function .can not used plugin.

    – Thành Trung Tô
    Jun 5 at 4:27











  • Can I see how the checkbox is implemented. Or any other method calling it.

    – Prashiddha Raj Joshi
    Jun 5 at 6:49


















0














It can be achieved through preferences,



Vendor/Module/etc/frontend/di.xml



<preference for="MagentoWishlistBlockShareWishlist" 
type="VendorModuleBlockShareWishlist"/>


Vendor/Module/Block/Share/Email/Items.php
namespace VendorModuleBlockShareEmail;



class Items extends MagentoWishlistBlockShareEmailItems

protected function _createWishlistItemCollection()
......







share|improve this answer























    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%2f277210%2fhow-to-override-protected-function-magento-2%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Also In preference method,You can not override a protected function. However you can override the public method which is calling that protected method. In your case, It is also a protected method.






    share|improve this answer























    • Do you know any way ?

      – Thành Trung Tô
      Jun 5 at 4:27











    • It is difficult to overide that function in your case, as everywhere it get's called is protected. So, You need to find an alternate solution..

      – aravind
      Jun 5 at 4:50











    • I have been thinking about this problem for more than 6 hours but still haven't found an alternative solution. Anyway, thank you.~~!

      – Thành Trung Tô
      Jun 5 at 4:55















    1














    Also In preference method,You can not override a protected function. However you can override the public method which is calling that protected method. In your case, It is also a protected method.






    share|improve this answer























    • Do you know any way ?

      – Thành Trung Tô
      Jun 5 at 4:27











    • It is difficult to overide that function in your case, as everywhere it get's called is protected. So, You need to find an alternate solution..

      – aravind
      Jun 5 at 4:50











    • I have been thinking about this problem for more than 6 hours but still haven't found an alternative solution. Anyway, thank you.~~!

      – Thành Trung Tô
      Jun 5 at 4:55













    1












    1








    1







    Also In preference method,You can not override a protected function. However you can override the public method which is calling that protected method. In your case, It is also a protected method.






    share|improve this answer













    Also In preference method,You can not override a protected function. However you can override the public method which is calling that protected method. In your case, It is also a protected method.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jun 4 at 12:01









    aravindaravind

    501113




    501113












    • Do you know any way ?

      – Thành Trung Tô
      Jun 5 at 4:27











    • It is difficult to overide that function in your case, as everywhere it get's called is protected. So, You need to find an alternate solution..

      – aravind
      Jun 5 at 4:50











    • I have been thinking about this problem for more than 6 hours but still haven't found an alternative solution. Anyway, thank you.~~!

      – Thành Trung Tô
      Jun 5 at 4:55

















    • Do you know any way ?

      – Thành Trung Tô
      Jun 5 at 4:27











    • It is difficult to overide that function in your case, as everywhere it get's called is protected. So, You need to find an alternate solution..

      – aravind
      Jun 5 at 4:50











    • I have been thinking about this problem for more than 6 hours but still haven't found an alternative solution. Anyway, thank you.~~!

      – Thành Trung Tô
      Jun 5 at 4:55
















    Do you know any way ?

    – Thành Trung Tô
    Jun 5 at 4:27





    Do you know any way ?

    – Thành Trung Tô
    Jun 5 at 4:27













    It is difficult to overide that function in your case, as everywhere it get's called is protected. So, You need to find an alternate solution..

    – aravind
    Jun 5 at 4:50





    It is difficult to overide that function in your case, as everywhere it get's called is protected. So, You need to find an alternate solution..

    – aravind
    Jun 5 at 4:50













    I have been thinking about this problem for more than 6 hours but still haven't found an alternative solution. Anyway, thank you.~~!

    – Thành Trung Tô
    Jun 5 at 4:55





    I have been thinking about this problem for more than 6 hours but still haven't found an alternative solution. Anyway, thank you.~~!

    – Thành Trung Tô
    Jun 5 at 4:55













    0














    You can use plugin and do following in beforeupdateDefaultValue



     if ($frontendInput === 'multiselect' || $frontendInput === 'checkboxs')
    //setFrontendInput to 'multiselect';
    elseif($frontendInput === 'select' || $frontendInput === 'radio')
    //setFrontendInput to 'select';






    share|improve this answer























    • According to docs plugins cant be used on non public methods devdocs.magento.com/guides/v2.3/extension-dev-guide/…

      – Dominic Xigen
      Jun 4 at 20:53











    • it is protected function .can not used plugin.

      – Thành Trung Tô
      Jun 5 at 4:27











    • Can I see how the checkbox is implemented. Or any other method calling it.

      – Prashiddha Raj Joshi
      Jun 5 at 6:49















    0














    You can use plugin and do following in beforeupdateDefaultValue



     if ($frontendInput === 'multiselect' || $frontendInput === 'checkboxs')
    //setFrontendInput to 'multiselect';
    elseif($frontendInput === 'select' || $frontendInput === 'radio')
    //setFrontendInput to 'select';






    share|improve this answer























    • According to docs plugins cant be used on non public methods devdocs.magento.com/guides/v2.3/extension-dev-guide/…

      – Dominic Xigen
      Jun 4 at 20:53











    • it is protected function .can not used plugin.

      – Thành Trung Tô
      Jun 5 at 4:27











    • Can I see how the checkbox is implemented. Or any other method calling it.

      – Prashiddha Raj Joshi
      Jun 5 at 6:49













    0












    0








    0







    You can use plugin and do following in beforeupdateDefaultValue



     if ($frontendInput === 'multiselect' || $frontendInput === 'checkboxs')
    //setFrontendInput to 'multiselect';
    elseif($frontendInput === 'select' || $frontendInput === 'radio')
    //setFrontendInput to 'select';






    share|improve this answer













    You can use plugin and do following in beforeupdateDefaultValue



     if ($frontendInput === 'multiselect' || $frontendInput === 'checkboxs')
    //setFrontendInput to 'multiselect';
    elseif($frontendInput === 'select' || $frontendInput === 'radio')
    //setFrontendInput to 'select';







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jun 4 at 12:00









    Prashiddha Raj JoshiPrashiddha Raj Joshi

    213




    213












    • According to docs plugins cant be used on non public methods devdocs.magento.com/guides/v2.3/extension-dev-guide/…

      – Dominic Xigen
      Jun 4 at 20:53











    • it is protected function .can not used plugin.

      – Thành Trung Tô
      Jun 5 at 4:27











    • Can I see how the checkbox is implemented. Or any other method calling it.

      – Prashiddha Raj Joshi
      Jun 5 at 6:49

















    • According to docs plugins cant be used on non public methods devdocs.magento.com/guides/v2.3/extension-dev-guide/…

      – Dominic Xigen
      Jun 4 at 20:53











    • it is protected function .can not used plugin.

      – Thành Trung Tô
      Jun 5 at 4:27











    • Can I see how the checkbox is implemented. Or any other method calling it.

      – Prashiddha Raj Joshi
      Jun 5 at 6:49
















    According to docs plugins cant be used on non public methods devdocs.magento.com/guides/v2.3/extension-dev-guide/…

    – Dominic Xigen
    Jun 4 at 20:53





    According to docs plugins cant be used on non public methods devdocs.magento.com/guides/v2.3/extension-dev-guide/…

    – Dominic Xigen
    Jun 4 at 20:53













    it is protected function .can not used plugin.

    – Thành Trung Tô
    Jun 5 at 4:27





    it is protected function .can not used plugin.

    – Thành Trung Tô
    Jun 5 at 4:27













    Can I see how the checkbox is implemented. Or any other method calling it.

    – Prashiddha Raj Joshi
    Jun 5 at 6:49





    Can I see how the checkbox is implemented. Or any other method calling it.

    – Prashiddha Raj Joshi
    Jun 5 at 6:49











    0














    It can be achieved through preferences,



    Vendor/Module/etc/frontend/di.xml



    <preference for="MagentoWishlistBlockShareWishlist" 
    type="VendorModuleBlockShareWishlist"/>


    Vendor/Module/Block/Share/Email/Items.php
    namespace VendorModuleBlockShareEmail;



    class Items extends MagentoWishlistBlockShareEmailItems

    protected function _createWishlistItemCollection()
    ......







    share|improve this answer



























      0














      It can be achieved through preferences,



      Vendor/Module/etc/frontend/di.xml



      <preference for="MagentoWishlistBlockShareWishlist" 
      type="VendorModuleBlockShareWishlist"/>


      Vendor/Module/Block/Share/Email/Items.php
      namespace VendorModuleBlockShareEmail;



      class Items extends MagentoWishlistBlockShareEmailItems

      protected function _createWishlistItemCollection()
      ......







      share|improve this answer

























        0












        0








        0







        It can be achieved through preferences,



        Vendor/Module/etc/frontend/di.xml



        <preference for="MagentoWishlistBlockShareWishlist" 
        type="VendorModuleBlockShareWishlist"/>


        Vendor/Module/Block/Share/Email/Items.php
        namespace VendorModuleBlockShareEmail;



        class Items extends MagentoWishlistBlockShareEmailItems

        protected function _createWishlistItemCollection()
        ......







        share|improve this answer













        It can be achieved through preferences,



        Vendor/Module/etc/frontend/di.xml



        <preference for="MagentoWishlistBlockShareWishlist" 
        type="VendorModuleBlockShareWishlist"/>


        Vendor/Module/Block/Share/Email/Items.php
        namespace VendorModuleBlockShareEmail;



        class Items extends MagentoWishlistBlockShareEmailItems

        protected function _createWishlistItemCollection()
        ......








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        oscprofessionalsoscprofessionals

        37417




        37417



























            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%2f277210%2fhow-to-override-protected-function-magento-2%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