Smile-SA / magento2-module-offer

Offer Module for Retailer Suite
6 stars 13 forks source link

Invalid signatures for OfferSearchResultsInterface and OfferSearchResults #22

Open xi-ao opened 3 weeks ago

xi-ao commented 3 weeks ago

Preconditions

Magento Version : EE 2.4.7-p2

Module Offer Version : 2.0.1

Environment : Developer/Production

PHP 8.3

Steps to reproduce

  1. Install the module
  2. Send an API request to /V1/retaileroffer/list?searchCriteria[pageSize]=2

Actual result

The following error shows up:

    TypeError: Smile\Offer\Model\OfferRepository::getList(): Return value must be of type Smile\Offer\Api\Data\OfferSearchResultsInterface, Magento\Framework\Api\SearchResults returned in /vendor/smile/module-offer/Model/OfferRepository.php:103

The reason is simple: the di.xml specifies

https://github.com/Smile-SA/magento2-module-offer/blob/ba0e1a73376056dc745f75fd8cdcc613325f2161/etc/di.xml#L4

while the method's signature is

https://github.com/Smile-SA/magento2-module-offer/blob/ba0e1a73376056dc745f75fd8cdcc613325f2161/Api/OfferRepositoryInterface.php#L33-L40

but OfferSearchResultsInterface is not a subclass of SearchResults.

The easiest fix here would be to remove this useless Smile\Offer\Api\Data\OfferSearchResultsInterface and directly use Magento\Framework\Api\SearchResults in both the interface and the class.

xi-ao commented 3 weeks ago

Sorry, the API endpoint does not exist in the module, we added it to be able to get offers but the URL I gave is not native. You need to add this in a webapi.xml to make it work:


    <route url="/V1/retaileroffer/list" method="GET">
        <service class="Smile\Offer\Api\OfferRepositoryInterface" method="getList"/>
        <resources>
            <resource ref="Smile_RetailerOffer::retailer_offers"/>
        </resources>
    </route>

Anyway, the bug still applies.

xi-ao commented 21 hours ago

The easiest fix here would be to remove this useless Smile\Offer\Api\Data\OfferSearchResultsInterface and directly use Magento\Framework\Api\SearchResults in both the interface and the class.

Actually no, that won't be a fix but rather a new bug, because in this case the API call would return empty objects instead of the items' data.

So I guess the proper fix would be to create a new Smile\Offer\Model\OfferSearchResults and update di.xml accordingly.