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

Compatible with Magento 2.4.7, as backward compatibility has been lost in the Magento\Catalog\Model\ProductRepository class #318

Merged
merged 2 commits into from
May 13, 2024

Conversation

TuVanDev
Copy link
Contributor

As of Magento 2.4.7, backward compatibility has been lost in the Magento\Catalog\Model\ProductRepository class. This pull request aims to fix this issue.

Check the issue page in the Magento repo for reference: magento/magento2#38669.


The changes made in this pull request are as follows:

  • Updated version
  • Replaced the __construct() method with multiple methods that utilize ObjectManager to instantiate the necessary instances. This change was made to prevent errors during code complication:

Incompatible argument type: Required type: \Magento\Catalog\Api\Data\ProductSearchResultsInterfaceFactory. Actual type: \Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper; File:
/app/app/code/Doofinder/Feed/Model/ProductRepository.php

  • Additional improvements were made as follows:
    • Fixed typos
    • Removed the unused property, $stockRegistry.
    • Replaced the $excludedCustomAttributes property with a constant. Using a class constant for a fixed value that will be used within a method helps to clearly define and identify the value as a constant for that class. It also ensures that the value remains consistent and cannot be changed or modified within the class methods.
    • Removed nullable parameter type from the $attributes param, as it must be of type array since it is used as the second param in an array_merge() function, which requires an array type.

…t in the Magento\Catalog\Model\ProductRepository class

Check the issue page in the Magento repo for reference: magento/magento2#38669
Model/ProductRepository.php Outdated Show resolved Hide resolved
Copy link
Contributor

@davidmolinacano davidmolinacano left a comment

Choose a reason for hiding this comment

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

LGTM! 🏆 (Although we have to take into account @sofia-doofinder's correction)

Changed inventoryHelper to inventoryHelperFactory

Co-authored-by: sofia-doofinder <92720455+sofia-doofinder@users.noreply.github.com>
Copy link
Contributor

@Aitor-Corrales Aitor-Corrales left a comment

Choose a reason for hiding this comment

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

Using the objectManager directly is not a good practice as it defeats the purpose of dependency injection. That being said, I'm guessing there is no other way to bypass the backwards compatibility issue of the 2.4.7 version. For the future, when this issue gets addressed, I would study going back to the usage of the constructor again, even tho this particular minor version would not work anymore, as Magento will probably decommend it.

@davidmolinacano davidmolinacano merged commit a80bdda into doofinder:master May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants