3

I'm trying to extend the Magento2 AheadWorks StoreLocator module by adding an additional field - store type. All works fine on the FE side. On the admin side however I've encountered some obstacles when adding/editing locations - the new field is not being saved.

On a high level, the Magento2 StoreLocator Grid save logic is based on the \Aheadworks\StoreLocator\Api\Data\LocationInterface and the ReflectionClass to produce the location entity data model and then intersect it with the submitted form data. This means that if I want to add another field I need to add the corresponding setter and getter for the field I want to add. I tried the following:

below is a sample of the AW Module interface definition; it contains setters and getters for all database fields;

namespace Aheadworks\StoreLocator\Api\Data;

use Magento\Framework\Api\ExtensibleDataInterface;

/**
 * Location interface.
 */

interface LocationInterface extends ExtensibleDataInterface
{
    const LOCATION_ID = 'location_id';

    /**
     * Get location id
     *
     * @api
     * @return int|null
     */
    public function getLocationId();

    /**
     * Set location id
     *
     * @api
     * @param int $id
     * @return $this
     */
    public function setLocationId($id);

below is how I'm trying to add the extra field following the implementation in the parent interface;

namespace MyCustomModule\StoreLocator\Api\Data;

interface LocationInterface extends \Aheadworks\StoreLocator\Api\Data\LocationInterface
{
    const STORE_TYPE = 'store_type';

    /**
     * Get Store Type
     *
     * @api
     * @return mixed|null
     */
    public function getStoreType();

    /**
     * Set Store Type
     *
     * @api
     * @param $storeType
     * @return $this
     */
    public function setStoreType($storeType);
}

The issue is that Magento\Framework\Reflection\MethodsMap::getMethodMapViaReflection method is not picking up the extending MyCustomModule\StoreLocator\Api\Data\LocationInterface.

Any thoughts on how I can overcome this. Is there a M2 way to extend interfaces?

0

The proper way to extend interfaces is extension attributes - http://devdocs.magento.com/guides/v2.2/extension-dev-guide/attributes.html

I see this class is marked by ExtensibleDataInterface. However, getExtensionAttributes and setExtensionAttributes methods are required to make everything work. So, just check if these methods are present in interface, if yes - extension attributes should help you

| improve this answer | |

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