magento / inventory

Magento Inventory Project (a.k.a MSI)
Open Software License 3.0
336 stars 247 forks source link

InventoryAPI implementing StockExtensionInterface breaks adding in any other Extension Attribute #3362

Open sdouma opened 1 year ago

sdouma commented 1 year ago

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.

m2-assistant[bot] commented 1 year ago

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


sdouma commented 1 year ago

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