mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
minor #14651 Remove unit from shipment (kayue, everwhatever)
This PR was merged into the 1.11 branch. Discussion ---------- | Q | A | |-----------------|--------------------------------------------------------------| | Branch? | 1.11 | | Bug fix? | yes | | New feature? | no | | BC breaks? | no | | Deprecations? | no | | Related tickets | [ticket](https://github.com/Sylius/Sylius/pull/14133) | | License | MIT | Commits -------981951509aDisassociate OrderItemUnit from all shipments before removal3889e688a9add spec
This commit is contained in:
commit
11e59732d8
2 changed files with 30 additions and 1 deletions
|
|
@ -291,6 +291,13 @@ class Order extends BaseOrder implements OrderInterface
|
|||
|
||||
public function removeShipments(): void
|
||||
{
|
||||
// Disassociate OrderItemUnit from all shipments before removal
|
||||
foreach ($this->shipments as $shipment) {
|
||||
foreach ($shipment->getUnits() as $unit) {
|
||||
$shipment->removeUnit($unit);
|
||||
}
|
||||
}
|
||||
|
||||
$this->shipments->clear();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ namespace spec\Sylius\Component\Core\Model;
|
|||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Sylius\Component\Core\Model\AddressInterface;
|
||||
use Sylius\Component\Core\Model\AdjustmentInterface;
|
||||
use Sylius\Component\Core\Model\CatalogPromotionInterface;
|
||||
|
|
@ -31,6 +32,7 @@ use Sylius\Component\Core\OrderShippingStates;
|
|||
use Sylius\Component\Order\Model\Order as BaseOrder;
|
||||
use Sylius\Component\Order\Model\OrderInterface;
|
||||
use Sylius\Component\Promotion\Model\PromotionCouponInterface;
|
||||
use Sylius\Component\Shipping\Model\ShipmentUnitInterface;
|
||||
|
||||
final class OrderSpec extends ObjectBehavior
|
||||
{
|
||||
|
|
@ -134,13 +136,33 @@ final class OrderSpec extends ObjectBehavior
|
|||
$this->shouldNotHaveShipment($shipment);
|
||||
}
|
||||
|
||||
function it_removes_shipments(ShipmentInterface $shipment): void
|
||||
function it_removes_shipments_with_units(
|
||||
ShipmentInterface $shipment,
|
||||
ShipmentUnitInterface $shipmentUnit
|
||||
): void
|
||||
{
|
||||
$this->addShipment($shipment);
|
||||
$this->hasShipment($shipment)->shouldReturn(true);
|
||||
$shipment->getUnits()->willReturn(new ArrayCollection([$shipmentUnit->getWrappedObject()]));
|
||||
|
||||
$this->removeShipments();
|
||||
|
||||
$shipment->removeUnit(Argument::any())->shouldBeCalled();
|
||||
$this->hasShipment($shipment)->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_removes_shipments_without_units(
|
||||
ShipmentInterface $shipment,
|
||||
ShipmentUnitInterface $shipmentUnit
|
||||
): void
|
||||
{
|
||||
$this->addShipment($shipment);
|
||||
$this->hasShipment($shipment)->shouldReturn(true);
|
||||
$shipment->getUnits()->willReturn(new ArrayCollection([]));
|
||||
|
||||
$this->removeShipments();
|
||||
|
||||
$shipment->removeUnit()->shouldNotBeCalled();
|
||||
$this->hasShipment($shipment)->shouldReturn(false);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue