Error When try to remove the last OrderItem of cart by Api #15983
Labels
API
APIs related issues and PRs.
Potential Bug
Potential bugs or bugfixes, that needs to be reproduced.
Sylius version affected: 1.12.13
Description
When We try to delete the last orderItem from a cart by Api
DELETE /shop/orders/{tokenValue}/items/{itemId}
We have an error
"@context": "/api/v2/contexts/Error", "@type": "hydra:Error", "hydra:title": "An error occurred", "hydra:description": "Expected an instance of Sylius\\Component\\Core\\Model\\OrderInterface. Got: NULL",
Steps to reproduce
example request :
curl --location --request DELETE 'https://sylius.localhost/api/v2/shop/orders/S-WB-2Kdkb/items/53'
In Sylius\Component\Core\Model\Order.php
when we remove the last orderItem from a cart , we pass into the method
`public function removePayment(BasePaymentInterface $payment): void
{
/** @var PaymentInterface $payment */
Assert::isInstanceOf($payment, PaymentInterface::class);
where the order of payment object is set to null,
who accesses the method
`public function getOrder(): ?BaseOrderInterface
{
Assert::isInstanceOf($this->order, OrderInterface::class);
from the Sylius\Component\Core\Model\Payment.php
Possible Solution
As we can see, the method signature can return null, but the Assert::isInstanceOf prohibits us from doing so.
a possible solution would be to modify
`public function getOrder(): ?BaseOrderInterface
{
Assert::isInstanceOf($this->order, OrderInterface::class);
by
`public function getOrder(): ?BaseOrderInterface
{
Assert::nullOrIsInstanceOf($this->order, OrderInterface::class);
The text was updated successfully, but these errors were encountered: