inventory icon indicating copy to clipboard operation
inventory copied to clipboard

InventoryAPI implementing StockExtensionInterface breaks adding in any other Extension Attribute

Open sdouma opened this issue 2 years ago • 2 comments

Summary (*)

When \Magento\InventoryApi\Api\Data\StockExtension implements the extension interface it will break adding any other extension attribute because it isn't going to build in generated. Even if you override the class and interface, magento bases on the generated interface, so when Magento\Ui\DataProvider builds the item data through the hydrate interface, it will base the extension attributes on \Magento\InventoryApi\Api\Data\StockExtension not the preference.

note: I do see the TODO but this has been causing issues for 4 years.

Examples (*)

\Magento\InventoryApi\Api\Data\StockExtension

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
declare(strict_types=1);

namespace Magento\InventoryApi\Api\Data;

/**
 * TODO: temporal fix of extension classes generation during installation
 * Extension class for @see \Magento\InventoryApi\Api\Data\StockInterface
 */
class StockExtension extends \Magento\Framework\Api\AbstractSimpleObject implements StockExtensionInterface
{
    /**
     * @inheritdoc
     */
    public function getSalesChannels(): ?array
    {
        return $this->_get('sales_channels');
    }

    /**
     * @inheritdoc
     */
    public function setSalesChannels(?array $salesChannels): void
    {
        $this->setData('sales_channels', $salesChannels);
    }
}

Proposed solution

Don't implement the interface.

sdouma avatar Sep 30 '22 01:09 sdouma

Hi @sdouma. Thank you for your report. To speed up processing of this issue, make sure that you provided sufficient information.

Add a comment to assign the issue: @magento I am working on this


m2-assistant[bot] avatar Sep 30 '22 01:09 m2-assistant[bot]

Found this #3275 after checking through m2 issues. Been over a year and it is P1 and low risk

sdouma avatar Sep 30 '22 03:09 sdouma