Magento 2 : Override core Interface and Model












3















I am trying to override core interface of Customer Group.



I add my custom get and set methods to core Api interface.




Vendormagentocustomer-moduleApiDataGroupInterface.php




Where its working fine.



But when i am trying to override it its doesn't seems to be work.



Here i am sharing my module code.




ZeroCoolAdvacedReviewsApiDataGroupInterface.php




<?php

namespace ZeroCoolAdvancedReviewsApiDataGroupInterface;


interface GroupInterface extends ExtensibleDataInterface
{
const SHIPPING_METHOD = 'shipping_method';

/**
* Get shipping method
*
* @return string
*/
public function getShippingMethod();

/**
* Set shipping method
*
* @param int $shippingMethod
* @return $this
*/
public function setShippingMethod($shippingMethod);

}



ZeroCoolAdvancedReviewsetcdi.xml




<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCustomerBlockAdminhtmlGroupEditForm">
<plugin name="add_form_field" type="ZeroCoolAdvancedReviewsModelPluginForm" sortOrder="1"/>
</type>
<type name="MagentoCustomerControllerAdminhtmlGroupSave">
<plugin name="save_field" type="ZeroCoolAdvancedReviewsModelPluginForm" sortOrder="1"/>
</type>
<preference for="MagentoCustomerModelDataGroup" type="ZeroCoolAdvancedReviewsModelDataGroup" />
<preference for="MagentoCustomerApiDataGroupInterface" type="ZeroCoolAdvancedReviewsApiDataGroupInterface" />


There's also one question available but it doesn't have any answers till now.



Stack Exchange



Thanks in advance.










share|improve this question

























  • I need to change core api model file ...How to override core api interface .....How to do this ....If u know please help me

    – Mano M
    Jul 14 '18 at 1:38
















3















I am trying to override core interface of Customer Group.



I add my custom get and set methods to core Api interface.




Vendormagentocustomer-moduleApiDataGroupInterface.php




Where its working fine.



But when i am trying to override it its doesn't seems to be work.



Here i am sharing my module code.




ZeroCoolAdvacedReviewsApiDataGroupInterface.php




<?php

namespace ZeroCoolAdvancedReviewsApiDataGroupInterface;


interface GroupInterface extends ExtensibleDataInterface
{
const SHIPPING_METHOD = 'shipping_method';

/**
* Get shipping method
*
* @return string
*/
public function getShippingMethod();

/**
* Set shipping method
*
* @param int $shippingMethod
* @return $this
*/
public function setShippingMethod($shippingMethod);

}



ZeroCoolAdvancedReviewsetcdi.xml




<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCustomerBlockAdminhtmlGroupEditForm">
<plugin name="add_form_field" type="ZeroCoolAdvancedReviewsModelPluginForm" sortOrder="1"/>
</type>
<type name="MagentoCustomerControllerAdminhtmlGroupSave">
<plugin name="save_field" type="ZeroCoolAdvancedReviewsModelPluginForm" sortOrder="1"/>
</type>
<preference for="MagentoCustomerModelDataGroup" type="ZeroCoolAdvancedReviewsModelDataGroup" />
<preference for="MagentoCustomerApiDataGroupInterface" type="ZeroCoolAdvancedReviewsApiDataGroupInterface" />


There's also one question available but it doesn't have any answers till now.



Stack Exchange



Thanks in advance.










share|improve this question

























  • I need to change core api model file ...How to override core api interface .....How to do this ....If u know please help me

    – Mano M
    Jul 14 '18 at 1:38














3












3








3


2






I am trying to override core interface of Customer Group.



I add my custom get and set methods to core Api interface.




Vendormagentocustomer-moduleApiDataGroupInterface.php




Where its working fine.



But when i am trying to override it its doesn't seems to be work.



Here i am sharing my module code.




ZeroCoolAdvacedReviewsApiDataGroupInterface.php




<?php

namespace ZeroCoolAdvancedReviewsApiDataGroupInterface;


interface GroupInterface extends ExtensibleDataInterface
{
const SHIPPING_METHOD = 'shipping_method';

/**
* Get shipping method
*
* @return string
*/
public function getShippingMethod();

/**
* Set shipping method
*
* @param int $shippingMethod
* @return $this
*/
public function setShippingMethod($shippingMethod);

}



ZeroCoolAdvancedReviewsetcdi.xml




<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCustomerBlockAdminhtmlGroupEditForm">
<plugin name="add_form_field" type="ZeroCoolAdvancedReviewsModelPluginForm" sortOrder="1"/>
</type>
<type name="MagentoCustomerControllerAdminhtmlGroupSave">
<plugin name="save_field" type="ZeroCoolAdvancedReviewsModelPluginForm" sortOrder="1"/>
</type>
<preference for="MagentoCustomerModelDataGroup" type="ZeroCoolAdvancedReviewsModelDataGroup" />
<preference for="MagentoCustomerApiDataGroupInterface" type="ZeroCoolAdvancedReviewsApiDataGroupInterface" />


There's also one question available but it doesn't have any answers till now.



Stack Exchange



Thanks in advance.










share|improve this question
















I am trying to override core interface of Customer Group.



I add my custom get and set methods to core Api interface.




Vendormagentocustomer-moduleApiDataGroupInterface.php




Where its working fine.



But when i am trying to override it its doesn't seems to be work.



Here i am sharing my module code.




ZeroCoolAdvacedReviewsApiDataGroupInterface.php




<?php

namespace ZeroCoolAdvancedReviewsApiDataGroupInterface;


interface GroupInterface extends ExtensibleDataInterface
{
const SHIPPING_METHOD = 'shipping_method';

/**
* Get shipping method
*
* @return string
*/
public function getShippingMethod();

/**
* Set shipping method
*
* @param int $shippingMethod
* @return $this
*/
public function setShippingMethod($shippingMethod);

}



ZeroCoolAdvancedReviewsetcdi.xml




<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCustomerBlockAdminhtmlGroupEditForm">
<plugin name="add_form_field" type="ZeroCoolAdvancedReviewsModelPluginForm" sortOrder="1"/>
</type>
<type name="MagentoCustomerControllerAdminhtmlGroupSave">
<plugin name="save_field" type="ZeroCoolAdvancedReviewsModelPluginForm" sortOrder="1"/>
</type>
<preference for="MagentoCustomerModelDataGroup" type="ZeroCoolAdvancedReviewsModelDataGroup" />
<preference for="MagentoCustomerApiDataGroupInterface" type="ZeroCoolAdvancedReviewsApiDataGroupInterface" />


There's also one question available but it doesn't have any answers till now.



Stack Exchange



Thanks in advance.







magento2 overrides interface






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 21 mins ago







Vivek

















asked Feb 16 '18 at 6:47









VivekVivek

1,330324




1,330324













  • I need to change core api model file ...How to override core api interface .....How to do this ....If u know please help me

    – Mano M
    Jul 14 '18 at 1:38



















  • I need to change core api model file ...How to override core api interface .....How to do this ....If u know please help me

    – Mano M
    Jul 14 '18 at 1:38

















I need to change core api model file ...How to override core api interface .....How to do this ....If u know please help me

– Mano M
Jul 14 '18 at 1:38





I need to change core api model file ...How to override core api interface .....How to do this ....If u know please help me

– Mano M
Jul 14 '18 at 1:38










2 Answers
2






active

oldest

votes


















3














Magento 2 Preference does not allow us to override the interfaces. Preferences are used to specify the implementation classes for the interfaces and overriding implementation classes. It does not allow to override interface with an interface



Then, how can we override the interfaces to send our extra informations over the interface? That's where the beautiful concept comes in - Extensions Attributes.



From the official doc:




Extension attributes are new in Magento 2. They are used to extend
functionality and often use more complex data types than custom
attributes. These attributes do not appear on the GUI.




In your case, if you check the MagentoCustomerApiDataGroupInterface interface, you can find these 2 methods at the bottom, which helps you to send your shipping information through this methods.



 /**
* Retrieve existing extension attributes object or create a new one.
*
* @return MagentoCustomerApiDataGroupExtensionInterface|null
*/
public function getExtensionAttributes();

/**
* Set an extension attributes object.
*
* @param MagentoCustomerApiDataGroupExtensionInterface $extensionAttributes
* @return $this
*/
public function setExtensionAttributes(MagentoCustomerApiDataGroupExtensionInterface $extensionAttributes);


For more information on how to add extension attributes,
http://devdocs.magento.com/guides/v2.0/extension-dev-guide/extension_attributes/adding-attributes.html






share|improve this answer
























  • Thanks for respond back, It helps me little bit. Can you please explain me in more detail i am new with M2. That would be great if you can.

    – Vivek
    Feb 16 '18 at 9:37



















2














Below solution worked for me.



As per MIKE suggested we can't directly override magento's core interfaces.



So than there's comes role of Extension Attributes.




etc/extension_attributes.xml




<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="MagentoCheckoutApiDataShippingInformationInterface">
<attribute code="custom_shipping_charge" type="string"/>
</extension_attributes>

<extension_attributes for="MagentoCustomerApiDataGroupInterface">
<attribute code="custom_shipping_amount" type="string"/>
</extension_attributes>

</config>



Execute : php bin/magento setup:di:compile




After that your get and set method will generated under below path.




magento_root/generated/code/Magento/Customer/Api/Data/GroupExtensionInterface.php




Now you can use those methods.



$groups->getCustomShippingAmount();
$groups->setCustomShippingAmount();


Hope this will help you.






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%2f213753%2fmagento-2-override-core-interface-and-model%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Magento 2 Preference does not allow us to override the interfaces. Preferences are used to specify the implementation classes for the interfaces and overriding implementation classes. It does not allow to override interface with an interface



    Then, how can we override the interfaces to send our extra informations over the interface? That's where the beautiful concept comes in - Extensions Attributes.



    From the official doc:




    Extension attributes are new in Magento 2. They are used to extend
    functionality and often use more complex data types than custom
    attributes. These attributes do not appear on the GUI.




    In your case, if you check the MagentoCustomerApiDataGroupInterface interface, you can find these 2 methods at the bottom, which helps you to send your shipping information through this methods.



     /**
    * Retrieve existing extension attributes object or create a new one.
    *
    * @return MagentoCustomerApiDataGroupExtensionInterface|null
    */
    public function getExtensionAttributes();

    /**
    * Set an extension attributes object.
    *
    * @param MagentoCustomerApiDataGroupExtensionInterface $extensionAttributes
    * @return $this
    */
    public function setExtensionAttributes(MagentoCustomerApiDataGroupExtensionInterface $extensionAttributes);


    For more information on how to add extension attributes,
    http://devdocs.magento.com/guides/v2.0/extension-dev-guide/extension_attributes/adding-attributes.html






    share|improve this answer
























    • Thanks for respond back, It helps me little bit. Can you please explain me in more detail i am new with M2. That would be great if you can.

      – Vivek
      Feb 16 '18 at 9:37
















    3














    Magento 2 Preference does not allow us to override the interfaces. Preferences are used to specify the implementation classes for the interfaces and overriding implementation classes. It does not allow to override interface with an interface



    Then, how can we override the interfaces to send our extra informations over the interface? That's where the beautiful concept comes in - Extensions Attributes.



    From the official doc:




    Extension attributes are new in Magento 2. They are used to extend
    functionality and often use more complex data types than custom
    attributes. These attributes do not appear on the GUI.




    In your case, if you check the MagentoCustomerApiDataGroupInterface interface, you can find these 2 methods at the bottom, which helps you to send your shipping information through this methods.



     /**
    * Retrieve existing extension attributes object or create a new one.
    *
    * @return MagentoCustomerApiDataGroupExtensionInterface|null
    */
    public function getExtensionAttributes();

    /**
    * Set an extension attributes object.
    *
    * @param MagentoCustomerApiDataGroupExtensionInterface $extensionAttributes
    * @return $this
    */
    public function setExtensionAttributes(MagentoCustomerApiDataGroupExtensionInterface $extensionAttributes);


    For more information on how to add extension attributes,
    http://devdocs.magento.com/guides/v2.0/extension-dev-guide/extension_attributes/adding-attributes.html






    share|improve this answer
























    • Thanks for respond back, It helps me little bit. Can you please explain me in more detail i am new with M2. That would be great if you can.

      – Vivek
      Feb 16 '18 at 9:37














    3












    3








    3







    Magento 2 Preference does not allow us to override the interfaces. Preferences are used to specify the implementation classes for the interfaces and overriding implementation classes. It does not allow to override interface with an interface



    Then, how can we override the interfaces to send our extra informations over the interface? That's where the beautiful concept comes in - Extensions Attributes.



    From the official doc:




    Extension attributes are new in Magento 2. They are used to extend
    functionality and often use more complex data types than custom
    attributes. These attributes do not appear on the GUI.




    In your case, if you check the MagentoCustomerApiDataGroupInterface interface, you can find these 2 methods at the bottom, which helps you to send your shipping information through this methods.



     /**
    * Retrieve existing extension attributes object or create a new one.
    *
    * @return MagentoCustomerApiDataGroupExtensionInterface|null
    */
    public function getExtensionAttributes();

    /**
    * Set an extension attributes object.
    *
    * @param MagentoCustomerApiDataGroupExtensionInterface $extensionAttributes
    * @return $this
    */
    public function setExtensionAttributes(MagentoCustomerApiDataGroupExtensionInterface $extensionAttributes);


    For more information on how to add extension attributes,
    http://devdocs.magento.com/guides/v2.0/extension-dev-guide/extension_attributes/adding-attributes.html






    share|improve this answer













    Magento 2 Preference does not allow us to override the interfaces. Preferences are used to specify the implementation classes for the interfaces and overriding implementation classes. It does not allow to override interface with an interface



    Then, how can we override the interfaces to send our extra informations over the interface? That's where the beautiful concept comes in - Extensions Attributes.



    From the official doc:




    Extension attributes are new in Magento 2. They are used to extend
    functionality and often use more complex data types than custom
    attributes. These attributes do not appear on the GUI.




    In your case, if you check the MagentoCustomerApiDataGroupInterface interface, you can find these 2 methods at the bottom, which helps you to send your shipping information through this methods.



     /**
    * Retrieve existing extension attributes object or create a new one.
    *
    * @return MagentoCustomerApiDataGroupExtensionInterface|null
    */
    public function getExtensionAttributes();

    /**
    * Set an extension attributes object.
    *
    * @param MagentoCustomerApiDataGroupExtensionInterface $extensionAttributes
    * @return $this
    */
    public function setExtensionAttributes(MagentoCustomerApiDataGroupExtensionInterface $extensionAttributes);


    For more information on how to add extension attributes,
    http://devdocs.magento.com/guides/v2.0/extension-dev-guide/extension_attributes/adding-attributes.html







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Feb 16 '18 at 7:47









    MikeMike

    953412




    953412













    • Thanks for respond back, It helps me little bit. Can you please explain me in more detail i am new with M2. That would be great if you can.

      – Vivek
      Feb 16 '18 at 9:37



















    • Thanks for respond back, It helps me little bit. Can you please explain me in more detail i am new with M2. That would be great if you can.

      – Vivek
      Feb 16 '18 at 9:37

















    Thanks for respond back, It helps me little bit. Can you please explain me in more detail i am new with M2. That would be great if you can.

    – Vivek
    Feb 16 '18 at 9:37





    Thanks for respond back, It helps me little bit. Can you please explain me in more detail i am new with M2. That would be great if you can.

    – Vivek
    Feb 16 '18 at 9:37













    2














    Below solution worked for me.



    As per MIKE suggested we can't directly override magento's core interfaces.



    So than there's comes role of Extension Attributes.




    etc/extension_attributes.xml




    <?xml version="1.0"?>

    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
    <extension_attributes for="MagentoCheckoutApiDataShippingInformationInterface">
    <attribute code="custom_shipping_charge" type="string"/>
    </extension_attributes>

    <extension_attributes for="MagentoCustomerApiDataGroupInterface">
    <attribute code="custom_shipping_amount" type="string"/>
    </extension_attributes>

    </config>



    Execute : php bin/magento setup:di:compile




    After that your get and set method will generated under below path.




    magento_root/generated/code/Magento/Customer/Api/Data/GroupExtensionInterface.php




    Now you can use those methods.



    $groups->getCustomShippingAmount();
    $groups->setCustomShippingAmount();


    Hope this will help you.






    share|improve this answer






























      2














      Below solution worked for me.



      As per MIKE suggested we can't directly override magento's core interfaces.



      So than there's comes role of Extension Attributes.




      etc/extension_attributes.xml




      <?xml version="1.0"?>

      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
      <extension_attributes for="MagentoCheckoutApiDataShippingInformationInterface">
      <attribute code="custom_shipping_charge" type="string"/>
      </extension_attributes>

      <extension_attributes for="MagentoCustomerApiDataGroupInterface">
      <attribute code="custom_shipping_amount" type="string"/>
      </extension_attributes>

      </config>



      Execute : php bin/magento setup:di:compile




      After that your get and set method will generated under below path.




      magento_root/generated/code/Magento/Customer/Api/Data/GroupExtensionInterface.php




      Now you can use those methods.



      $groups->getCustomShippingAmount();
      $groups->setCustomShippingAmount();


      Hope this will help you.






      share|improve this answer




























        2












        2








        2







        Below solution worked for me.



        As per MIKE suggested we can't directly override magento's core interfaces.



        So than there's comes role of Extension Attributes.




        etc/extension_attributes.xml




        <?xml version="1.0"?>

        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
        <extension_attributes for="MagentoCheckoutApiDataShippingInformationInterface">
        <attribute code="custom_shipping_charge" type="string"/>
        </extension_attributes>

        <extension_attributes for="MagentoCustomerApiDataGroupInterface">
        <attribute code="custom_shipping_amount" type="string"/>
        </extension_attributes>

        </config>



        Execute : php bin/magento setup:di:compile




        After that your get and set method will generated under below path.




        magento_root/generated/code/Magento/Customer/Api/Data/GroupExtensionInterface.php




        Now you can use those methods.



        $groups->getCustomShippingAmount();
        $groups->setCustomShippingAmount();


        Hope this will help you.






        share|improve this answer















        Below solution worked for me.



        As per MIKE suggested we can't directly override magento's core interfaces.



        So than there's comes role of Extension Attributes.




        etc/extension_attributes.xml




        <?xml version="1.0"?>

        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
        <extension_attributes for="MagentoCheckoutApiDataShippingInformationInterface">
        <attribute code="custom_shipping_charge" type="string"/>
        </extension_attributes>

        <extension_attributes for="MagentoCustomerApiDataGroupInterface">
        <attribute code="custom_shipping_amount" type="string"/>
        </extension_attributes>

        </config>



        Execute : php bin/magento setup:di:compile




        After that your get and set method will generated under below path.




        magento_root/generated/code/Magento/Customer/Api/Data/GroupExtensionInterface.php




        Now you can use those methods.



        $groups->getCustomShippingAmount();
        $groups->setCustomShippingAmount();


        Hope this will help you.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 19 mins ago

























        answered Feb 16 '18 at 12:54









        VivekVivek

        1,330324




        1,330324






























            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%2f213753%2fmagento-2-override-core-interface-and-model%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

            What other Star Trek series did the main TNG cast show up in?

            Berlina muro

            Berlina aerponto