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

Ensure order state handles with partial shipment #38679

Open
wants to merge 4 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/code/Magento/Sales/Model/Order/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function getQtyToShip()
*/
public function getSimpleQtyToShip()
{
$qty = $this->getQtyOrdered() - max($this->getQtyShipped(), $this->getQtyRefunded()) - $this->getQtyCanceled();
$qty = $this->getQtyOrdered() - $this->getQtyShipped() - $this->getQtyRefunded() - $this->getQtyCanceled();
return max(round($qty, 8), 0);
}

Expand Down
64 changes: 64 additions & 0 deletions dev/tests/integration/testsuite/Magento/Sales/Model/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Magento\Sales\Model;

use Magento\Catalog\Test\Fixture\Product as ProductFixture;
use Magento\Catalog\Test\Fixture\Virtual as ProductVirtualFixture;
use Magento\Checkout\Test\Fixture\PlaceOrder as PlaceOrderFixture;
use Magento\Checkout\Test\Fixture\SetBillingAddress as SetBillingAddressFixture;
use Magento\Checkout\Test\Fixture\SetDeliveryMethod as SetDeliveryMethodFixture;
Expand All @@ -18,6 +19,7 @@
use Magento\Quote\Test\Fixture\GuestCart as GuestCartFixture;
use Magento\Sales\Test\Fixture\Creditmemo as CreditmemoFixture;
use Magento\Sales\Test\Fixture\Invoice as InvoiceFixture;
use Magento\Sales\Test\Fixture\Shipment as ShipmentFixture;
use Magento\SalesRule\Model\Rule;
use Magento\SalesRule\Test\Fixture\Rule as RuleFixture;
use Magento\TestFramework\Fixture\Config as Config;
Expand Down Expand Up @@ -90,4 +92,66 @@ public function testMultipleCreditmemosForZeroTotalOrder()
'Should be possible to create second credit memo for zero total order if not all items are refunded yet'
);
}

/**
* Tests that an order with mixed product types in cart and with physical items either shipped or refunded cannot be shipped
*/
#[
Config('carriers/freeshipping/active', '1', 'store', 'default'),
Config('payment/free/active', '1', 'store', 'default'),
DataFixture(ProductFixture::class, as: 'product'),
DataFixture(ProductVirtualFixture::class, as: 'virtual'),
DataFixture(GuestCartFixture::class, as: 'cart'),
DataFixture(
RuleFixture::class,
[
'simple_action' => Rule::BY_PERCENT_ACTION,
'discount_amount' => 100,
'apply_to_shipping' => 0,
'stop_rules_processing' => 0,
'sort_order' => 1,
]
),
DataFixture(
AddProductToCartFixture::class,
['cart_id' => '$cart.id$', 'product_id' => '$product.id$', 'qty' => 2]
),
DataFixture(
AddProductToCartFixture::class,
['cart_id' => '$cart.id$', 'product_id' => '$virtual.id$', 'qty' => 2]
),
DataFixture(SetBillingAddressFixture::class, ['cart_id' => '$cart.id$']),
DataFixture(SetShippingAddressFixture::class, ['cart_id' => '$cart.id$']),
DataFixture(SetGuestEmailFixture::class, ['cart_id' => '$cart.id$']),
DataFixture(
SetDeliveryMethodFixture::class,
['cart_id' => '$cart.id$', 'carrier_code' => 'freeshipping', 'method_code' => 'freeshipping']
),
DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$cart.id$', 'method' => 'free']),
DataFixture(PlaceOrderFixture::class, ['cart_id' => '$cart.id$'], 'order'),
DataFixture(InvoiceFixture::class, ['order_id' => '$order.id$'], 'invoice'),
DataFixture(
CreditmemoFixture::class,
['order_id' => '$order.id$', 'items' => [['qty' => 1, 'product_id' => '$product.id$']]],
'creditmemo'
),
DataFixture(
ShipmentFixture::class,
['order_id' => '$order.id$', 'items' => [['qty' => 1, 'product_id' => '$product.id$']]],
'shipment'
)
]
public function testOrderWithPartialShipmentAndPartialRefundAndMixedCartItems()
{
$order = $this->fixtures->get('order');
$this->assertFalse(
$order->canShip(),
'All items are shipped or refunded or virtual'
);
$this->assertEquals(
Order::STATE_COMPLETE,
$order->getStatus()
);
}
}