2

I am trying to develop a Module to support saving card_id for a Gateway handling such functionality. So basically you send the card information in frontend, the gateway returns a token then you call the gateway API in the server and it returns a card_id. A customer can have 'n' cards so I am planning to create a schema table 'cards' which relates to customers the same way as addresses do.

My question is how can I add another array to the customer object. The array should be similar to that of customer_addresses.

I have set my extension_attributes.xml like this:

<?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="Magento\Customer\Api\Data\CustomerInterface">
        <attribute code="gateway_card_id" type="text">
            <join reference_table="card_entity"
                reference_field="user_id"
                join_on_field="parent_id"
            >
            <field>group_id</field>
            </join>
        </attribute>
    </extension_attributes>
</config>

The table card_entity already exists too.

The problem is I am not seeing any extension attribute when I call the API /customers/me

1 Answer 1

0

You need declare extension attribute and use plugin on order repository to populate/save card entities. You can review Bundle Module extension attribute declaration as good example of such case implementation.

3
  • Perfect, that is exactly what I was looking for. I am starting to like Magento2 :)
    – awavi
    Nov 30, 2015 at 19:09
  • [KAndy] I have added more information above, I am not seeing any changes in the customer object returned in the API. Can you help?
    – awavi
    Nov 30, 2015 at 21:07
  • @awavi, see official documentation for details
    – KAndy
    Jan 15, 2016 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.