magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.48k stars 9.29k forks source link

Join extension attributes are not added to Order and Order Items #14623

Open k4emic opened 6 years ago

k4emic commented 6 years ago

Preconditions

  1. Magento 2.1.3
  2. 7.0.25-0ubuntu0.16.04.1

Steps to reproduce

  1. Define a Extension attribute for the relevant interfaces with a join table:
    <extension_attributes for="Magento\Sales\Api\Data\OrderItemInterface">
        <attribute code="some_id" type="string">
            <join reference_table="SOMETABLE" join_on_field="item_id" reference_field="item_id">
                <field>some_id</field>
            </join>
        </attribute>
    </extension_attributes>
    <extension_attributes for="Magento\Sales\Api\Data\OrderInterface">
        <attribute code="some_id" type="string">
            <join reference_table="SOMETABLE" join_on_field="quote_id" reference_field="quote_id">
                <field>some_id</field>
            </join>
        </attribute>
    </extension_attributes>
  2. Make sure there's matching data in the SOMETABLE table and the sales_order_item table
  3. Request order(s) or order items via REST

Expected result

  1. The "some_id" attribute should be included in the response for orders and order items

Actual result

  1. The extension attribute is not included in any of the two responses

This was partially fixed in #8035, but only for order search results

k4emic commented 6 years ago

I've fixed this (for order items) for my project by adding the following patch to our project, until a permanent solution is found. This will only fix the problem for some requests, but might provide a starting point for someone looking for a better fix.

--- Model/Order.php      2018-04-10 17:03:57.092710675 +0200
+++ Model/Order.php 2018-04-10 17:04:39.608326985 +0200
@@ -266,6 +266,10 @@
      * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
      */
     protected $timezone;
+    /**
+     * @var \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface
+     */
+    private $joinProcessor;

     /**
      * @param \Magento\Framework\Model\Context $context
@@ -322,6 +326,7 @@
         \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $salesOrderCollectionFactory,
         PriceCurrencyInterface $priceCurrency,
         \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productListFactory,
+        \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor,
         \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
         \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
         array $data = []
@@ -346,6 +351,7 @@
         $this->_trackCollectionFactory = $trackCollectionFactory;
         $this->salesOrderCollectionFactory = $salesOrderCollectionFactory;
         $this->priceCurrency = $priceCurrency;
+        $this->joinProcessor = $joinProcessor;
         parent::__construct(
             $context,
             $registry,
@@ -1248,6 +1254,7 @@
     public function getItemsCollection($filterByTypes = [], $nonChildrenOnly = false)
     {
         $collection = $this->_orderItemCollectionFactory->create()->setOrderFilter($this);
+        $this->joinProcessor->process($collection);

         if ($filterByTypes) {
             $collection->filterByTypes($filterByTypes);
ghost commented 6 years ago

Hi @k4emic , thank you for your report. We've acknowledged the issue and added to our backlog.

github-jira-sync-bot commented 3 years ago

Unfortunately, not enough information was provided to create a Jira ticket. Please make sure you added the following label(s): Reproduced on 2.4.x, ^Area:.*

Once all required labels are present, please add Issue: Confirmed label again.

github-jira-sync-bot commented 3 years ago

:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-996 is successfully created for this GitHub issue.

m2-assistant[bot] commented 3 years ago

:white_check_mark: Confirmed by @engcom-Lima. Thank you for verifying the issue.
Issue Available: @engcom-Lima, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

Kiraberos commented 1 year ago

@magento I am working on this

Vasudev-22 commented 1 year ago

@magento I am working on this