You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if ($this->hasPayment($payment)) {
$this->payments->removeElement($payment);
$payment->setOrder(null);
}
}`
where the order of payment object is set to null,
After that, following the processing of the request, an onflush event is launched and read by vendor/api-platform/core/src/Doctrine/EventListener/PurgeHttpCacheListener.php
who accesses the method
`public function getOrder(): ?BaseOrderInterface
{
Assert::isInstanceOf($this->order, OrderInterface::class);
return $this->order;
}`
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);
return $this->order;
}`
by
`public function getOrder(): ?BaseOrderInterface
{
Assert::nullOrIsInstanceOf($this->order, OrderInterface::class);
return $this->order;
}`
The text was updated successfully, but these errors were encountered:
Tried to reproduce it on 1.12 and 1.13 version and it seems to work fine
Could you provide more information about order? Maybe the state of the order that you want to remove the item from
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: