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

#14061 Fix Configurable Product Type resource model 'getChildrenIds' method return format #27246

Conversation

vasilii-b
Copy link

Description (*)

This PR fixes the return type of Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable:getChildrenIds method.

Related Pull Requests

#15167 - Closed and inactive

Fixed Issues (if relevant)

  1. Configurable Product Type resource model 'getChildrenIds' method incorrect return format. #14061: Configurable Product Type resource model 'getChildrenIds' method incorrect return format

Manual testing scenarios (*)

  1. 1nject class \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type
  2. Apply the array of multiple configurable ids to method getChildrenIds
  3. Expecting array to have such structure:
[
"parent id" => ["child id"]
]

Questions or comments

N/A

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 are green)

@m2-assistant
Copy link

m2-assistant bot commented Mar 11, 2020

Hi @vasilii-b. 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 give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@magento-engcom-team magento-engcom-team added Component: ConfigurableProduct Release Line: 2.4 Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner labels Mar 11, 2020
@dmytro-ch dmytro-ch self-assigned this Mar 12, 2020
@dmytro-ch
Copy link
Contributor

@magento run all tests

@eduard13
Copy link
Contributor

@magento run Integration Tests

@dmytro-ch
Copy link
Contributor

UPD
The EE and B2B Integration test fails due to the already existing select query which is not compatible with Content Staging.

@vasilii-b
Copy link
Author

Hi @dmytro-ch,
Thanks for jumping in with the suggestions. The PR has been adjusted accordingly and now the Integration Tests has passed ✅
Could you please proceed with the review?
Thanks!

@dmytro-ch
Copy link
Contributor

dmytro-ch commented Mar 25, 2020

@vasilii-b thank you for the updates!

I've tested the current solution with Content Staging Updates and it works like a charm now. 👍
I also confirm this is the appropriate solution since in case of Commerce version the catalog_product_super_link.parent_id field is linked to row_id instead of entity_id.

Example of resulting query:

SELECT `l`.`product_id`, `p`.`entity_id` AS `parent_id` FROM `catalog_product_super_link` AS `l`
 INNER JOIN `catalog_product_entity` AS `p` ON p.row_id = l.parent_id AND (p.created_in <= '1585149600' AND p.updated_in > '1585149600')
 INNER JOIN `catalog_product_entity` AS `e` ON e.entity_id = l.product_id AND e.required_options = 0 AND (e.created_in <= '1585149600' AND e.updated_in > '1585149600') WHERE (p.entity_id IN ('273'));

@vasilii-b, could you please just squash all commits into a single commit in order to cleanup history?

Thank you!

@vasilii-b
Copy link
Author

Hi @dmytro-ch,
Sure thing! I'll take care of that.

@vasilii-b vasilii-b force-pushed the 14061-Configurable-Product-Type-resource-model-getChildrenIds-method-incorrect-return-format branch from d6f1514 to b362648 Compare March 25, 2020 16:27
@vasilii-b
Copy link
Author

@dmytro-ch the changes have been squashed ✅
Thank you!

@magento-engcom-team
Copy link
Contributor

Hi @dmytro-ch, thank you for the review.
ENGCOM-7205 has been created to process this Pull Request

@vasilii-b
Copy link
Author

Hi @engcom-Alfa, @dmytro-ch,
Can you please update on the current state here?
Thank you!

@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

Have configurable product where a parent with id=5 and 3 childs (2,3,4 ids)

Before:
Screenshot from 2020-04-13 16-48-20

After:
Screenshot from 2020-04-13 17-32-23
The first item of the array is kept for backward-compatibility.

… 14061-Configurable-Product-Type-resource-model-getChildrenIds-method-incorrect-return-format
@VladimirZaets VladimirZaets added this to the 2.4.0 milestone Apr 15, 2020
@VladimirZaets VladimirZaets added Priority: P3 May be fixed according to the position in the backlog. Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. labels Apr 15, 2020
Copy link
Contributor

@VladimirZaets VladimirZaets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @vasilii-b, @dmytro-ch. Thanks for collaboration. I not sure that structure like
[ "parent id" => ["child id"]]
is correct in this case. The method name is getChildrenIds and it should return just an array of ids, like ['child id', 'child id', 'child id'], without nested structure and mentions parent id.

@vasilii-b
Copy link
Author

Hi @VladimirZaets,
Thanks for jumping in!

Let me please bring some light here.
Please have a look over the method we're adjusting getChildrenIds:

/**
* Retrieve Required children ids
* Return grouped array, ex array(
* group => array(ids)
* )
*
* @param int|array $parentId
* @param bool $required
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function getChildrenIds($parentId, $required = true)
{
$select = $this->getConnection()->select()->from(
['l' => $this->getMainTable()],
['product_id', 'parent_id']
)->join(
['p' => $this->getTable('catalog_product_entity')],
'p.' . $this->optionProvider->getProductEntityLinkField() . ' = l.parent_id',
[]
)->join(
['e' => $this->getTable('catalog_product_entity')],
'e.entity_id = l.product_id AND e.required_options = 0',
[]
)->where(
'p.entity_id IN (?)',
$parentId
);
$childrenIds = [
0 => array_column(
$this->getConnection()->fetchAll($select),
'product_id',
'product_id'
)
];
return $childrenIds;
}

It accepts as the first parameter $parentId, which can be a) int or b) array.

When you call the method getChildrenIds([4, 10, 99]) with an array of parent ids, you get a result like (e.g.)

[
   0 => [ 40, 5, 20, 23, 98 ]
];
// in other words
[
  0 => ['child id', 'child id', 'child id', 'child id']
]

Tell me please, how do you know which child id belongs to what parent id you have passed to the original method?

With the fix from this PR the result will be

[
   0 => [ 40, 5, 20, 23, 98 ], // for backward compatibility
   4 => [40, 5],
   10 => [20, 23]
   99 => [98]
];
// in other words
[
    0 => ['child id', 'child id', 'child id', 'child id'], // backward compatibility
    'parent id' => ['child id', 'child id', 'child id', 'child id']
]

Please let me know should there be any questions. Thank you!.

@VladimirZaets
Copy link
Contributor

@vasilii-b yes, sorry I missed that we can pass an array of parent ids there, but I still have concerns due to this method. Return type array of arrays, a method that can receive as parameter int or array, required param that is unused, all of this looks weird. Maybe we should deprecate this method and create a new one. I think this PR is a good candidate for group code review

@slavvka slavvka modified the milestones: 2.4.0, 2.4.1 May 21, 2020
@dmytro-ch
Copy link
Contributor

Hello @vasilii-b, unfortunately, I have to close this PR due to inactivity.
Please reopen and update if you wish to continue.
Thank you!

@dmytro-ch dmytro-ch closed this Jul 31, 2020
@m2-assistant
Copy link

m2-assistant bot commented Jul 31, 2020

Hi @vasilii-b, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: bug fix Award: category of expertise Award: test coverage Component: ConfigurableProduct Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner Priority: P3 May be fixed according to the position in the backlog. Progress: needs update Release Line: 2.4 Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants