Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

magento/magento2#8035: Join extension attributes are not added to Order results (REST api) #21797

Merged
merged 3 commits into from
Apr 23, 2019

Conversation

swnsma
Copy link
Contributor

@swnsma swnsma commented Mar 16, 2019

Description (*)

FP fix of #8035 for 2.3.

Fixed Issues

  1. Join extension attributes are not added to Order results (REST api) #8035: Join extension attributes are not added to Order results (REST api)

Manual testing scenarios (*)

  1. Create new module.
  2. Create new DB table, related to sales_order table (db_schema.xml):
<table name="custom_table" resource="default" engine="innodb">
    <column xsi:type="int" name="order_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Order ID" />
    <column xsi:type="varchar" name="custom_field" nullable="false"/>
    <constraint xsi:type="foreign" referenceId="CUSTOM_TABLE_ORDER_ID_SALES_ORDER_ENTITY_ID" table="custom_table" column="order_id" referenceTable="sales_order"  referenceColumn="entity_id" onDelete="CASCADE"/>
    <constraint xsi:type="primary" referenceId="PRIMARY">
        <column name="order_id"/>
    </constraint>
</table>
  1. Create new extension attribute for Order Entity (extension_attributes.xml):
<extension_attributes for="Magento\Sales\Api\Data\OrderInterface">
        <attribute code="custom_field" type="string">
            <join reference_table="custom_table" join_on_field="entity_id" reference_field="order_id">
                <field column="custom_field">custom_field</field>
            </join>
        </attribute>
    </extension_attributes>
  1. Try to get list of orders from Order Repository, filtered by this attribute with using of search criteria.
        /** @var \Magento\Sales\Api\OrderRepositoryInterface $repository */
        $repository = ObjectManager::getInstance()->get('\Magento\Sales\Api\OrderRepositoryInterface');
        /** @var \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria */
        $searchCriteria = ObjectManager::getInstance()->get('\Magento\Framework\Api\SearchCriteriaInterface');
        /** @var \Magento\Framework\Api\Search\FilterGroup $filterGroup */
        $filterGroup = ObjectManager::getInstance()->get('\Magento\Framework\Api\Search\FilterGroup');
        /** @var \Magento\Framework\Api\Filter $filter */
        $filter = ObjectManager::getInstance()->get('\Magento\Framework\Api\Filter');
        $filter->setField('custom_field');
        $filter->setValue('custom_value');
        $filter->setConditionType('eq');

        $filterGroup->setFilters([$filter]);
        $searchCriteria->setFilterGroups([$filterGroup]);

        $orderList = $repository->getList($searchCriteria);

E.R.:
List of orders, filtered by criteria.
A.R.:
SQLSTATE[42S22]: Column not found exception

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-engcom-team
Copy link
Contributor

Hi @swnsma. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@magento-engcom-team magento-engcom-team added Component: Sales Release Line: 2.3 Partner: ISM eCompany Pull Request is created by partner ISM eCompany partners-contribution Pull Request is created by Magento Partner labels Mar 16, 2019
@larsroettig larsroettig self-assigned this Mar 16, 2019
@magento-engcom-team
Copy link
Contributor

Hi @ishakhsuvarov, thank you for the review.
ENGCOM-4524 has been created to process this Pull Request

@ishakhsuvarov
Copy link
Contributor

Also, relates to: magento/inventory#2082

@m2-assistant
Copy link

m2-assistant bot commented Apr 23, 2019

Hi @swnsma, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

magento-engcom-team pushed a commit that referenced this pull request Apr 23, 2019
@magento-engcom-team magento-engcom-team added this to the Release: 2.3.2 milestone Apr 23, 2019
@swnsma swnsma deleted the 2.3-develop#8035 branch July 16, 2019 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants