Skip to content

Error while fetching bundle item with repository #12278

@hatimeria-artur-jewula

Description

@hatimeria-artur-jewula

Preconditions

  1. Magento 2.1.7
  2. PHP 7.0.22

Steps to reproduce

  1. Create a bundle product with at least 1 option of simple product
  2. Create a module which defines any extension attributes for Magento\Catalog\Api\Data\ProductInterface
  3. Create an observer for catalog_product_collection_load_after event and in that observer set extension attribute defined in step 2 on each item
  4. Try to retrieve bundle product using Magento\Catalog\Api\ProductRepositoryInterface::getById() method providing only id of the bundle product created in step 1.

Expected result

  1. Receive an instance of Magento\Catalog\Api\Data\ProductInterface with data of bundle product

Actual result

  1. An error is thrown:
    Argument 1 passed to Magento\Bundle\Model\Link::setExtensionAttributes() must be an instance of Magento\Bundle\Api\Data\LinkExtensionInterface, instance of Magento\Catalog\Api\Data\ProductExtension given, called in vendor/magento/framework/Api/DataObjectHelper.php on line 125

After inspection I found that bundle module defines its own extension attribute bundle_product_options for Magento\Catalog\Api\Data\ProductInterface. When it tries to set it for loaded product it fetches collection of products defined as children in the bundle and converts those products to array of Magento\Bundle\Api\Data\OptionInterface classes. The problem is those products have extension_attributes set in $_data and the class there is Magento\Catalog\Api\Data\ProductExtension as it should be for product class.

Metadata

Metadata

Labels

Area: CatalogIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: dev in progressReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releaseReproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchSeverity: S2Major restrictions or short-term circumventions are required until a fix is available.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions