title: How to add custom attribute to shipping method in magento2
body: <p>I am trying to create a module in magento2 that would allow to add custom message to carrier or specific method. I successfully created admin section with grid and form. Now I am working on displaying this on frontend. I have created js and template file that works well if the data are in the estimate-shipping-methods result. I thought that the easiest way is to add this message to rate model. I've created a plugin </p>
  
  <pre><code>&lt;type name="Magento\Quote\Model\ShippingMethodManagement"&gt;
      &lt;plugin name="hatimeria_shippingrateinfo_add_message_to_rates"
              type="Hatimeria\ShippingRateInfo\Plugin\ShippingMethodManagement"
              sortOrder="10"
              disabled="false"/&gt;
  &lt;/type&gt;
  </code></pre>
  
  <p>Which fetches messages for current rates and adds them to model. Everything works well but this data is not then outputted to json result. As I found out magento does not simply ouput all data in the model but it returns only those that are defined by <code>ShippingMethodInterface</code>.
  Then I noticed that there is something called extension_attributes and according to docs this should allow me to add my message to the result. So looking at <a href="http://devdocs.magento.com/guides/v2.0/extension-dev-guide/attributes.html" rel="nofollow">docs</a> and Magento_ProductVideo module I've done the following:</p>
  
  <p>in <code>etc/extension_attributes.xml</code></p>
  
  <pre><code>&lt;config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd"&gt;
  &lt;extension_attributes for="Magento\Quote\Api\Data\ShippingMethodInterface"&gt;
      &lt;attribute code="rate_info" type="Hatimeria\ShippingRateInfo\Api\Quote\Data\ShippingMethodInterface" /&gt;
  &lt;/extension_attributes&gt;
  </code></pre>
  
  <p></p>
  
  <p>in <code>etc/di.xml</code>I added preference for my interface</p>
  
  <pre><code>&lt;preference for="Hatimeria\ShippingRateInfo\Api\Quote\Data\ShippingMethodInterface" type="Hatimeria\ShippingRateInfo\Model\Rate\RateInfo" /&gt;
  </code></pre>
  
  <p>now classess, first interface in <code>Hatimeria\ShippingRateInfo\Api\Quote\Data\ShippingMethodIntarface.php</code></p>
  
  <pre><code>namespace Hatimeria\ShippingRateInfo\Api\Quote\Data;
  
  use Magento\Framework\Api\ExtensibleDataInterface;
  
  /**
   * Shipping Rate Info data interface
   *
   * @api
   */
  interface ShippingMethodInterface extends ExtensibleDataInterface
  {
  
      const RATEINFO = 'rate_info';
  
      /**
       * Retrieve rate info message
       *
       * @return string
       */
      public function getRateInfo();
  
      /**
       * Set rate info message
       *
       * @param string $rateInfo
       * @return $this
       */
      public function setRateInfo($rateInfo);
  }
  </code></pre>
  
  <p>and class that actually implements this in <code>Hatimeria\ShippingRateInfo\Model\Rate\RateInfo.php</code></p>
  
  <pre><code>namespace Hatimeria\ShippingRateInfo\Model\Rate;
  
  use Hatimeria\ShippingRateInfo\Api\Quote\Data\ShippingMethodInterface;
  use Magento\Framework\Model\AbstractExtensibleModel;
  
  class RateInfo extends AbstractExtensibleModel implements ShippingMethodInterface
  {
      /**
       * Retrieve rate info message
       *
       * @return string
       */
      public function getRateInfo()
      {
          return $this-&gt;getData(self::RATEINFO);
      }
  
      /**
       * Set rate info message
       *
       * @param string $rateInfo
       * @return $this
       */
      public function setRateInfo($rateInfo)
      {
          return $this-&gt;setData(self::RATEINFO, $rateInfo);
      }
  }
  </code></pre>
  
  <p>And this is not working. When rates are generated no additional extensions are returned by rate model. Any help will be appreciated.</p>