Skip to content

QuoteRepository get methods won't return CartInterface but Quote model #12802

Closed
@msieprawski

Description

@msieprawski

Preconditions

  1. Magento 2.2.0 CE
  2. PHP 7.024

Steps to reproduce

  1. Create custom module with following etc/di.xml` file:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Quote\Api\Data\CartInterface" type="Vendor\Module\Model\Quote" />
</config>
  1. Create \Vendor\Module\Model\Quote object which extends \Magento\Quote\Model\Quote.
  2. Now execute following code:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cartRepository = $objectManager->create(\Magento\Quote\Api\CartRepositoryInterface::class);
$cartRepository->get(70); // use existing quote ID

Expected result

  1. The result will be an object of instance Vendor\Module\Model\Quote

Actual result

  1. Actual result is an object of instance Magento\Quote\Model\Quote

It's caused by invalid vendor/magento/module-quote/Model/QuoteRepository.php::loadQuote method which uses Magento\Quote\Model\QuoteFactory in the very first line instead of Magento\Quote\Api\Data\CartInterfaceFactory.

The solution is to override QuoteRepository's loadQuote method and use CartInterfaceFactory.

Metadata

Metadata

Assignees

Labels

Fixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions