Merge branch '1.12' into 1.13

* 1.12:
  Do not hardcode checking cart state in processors
  Determine Order being processable on itself
  Add conflict for doctrine/orm:2.14.2
  [CS][DX] Refactor
  [Tasks] Improve Robo task
  [Product][Association] Fix attaching association with numeric code
This commit is contained in:
Grzegorz Sadowski 2023-04-14 09:18:08 +02:00
commit b6c348ffa1
No known key found for this signature in database
GPG key ID: EF87FF4E6E3BD364
21 changed files with 96 additions and 46 deletions

View file

@ -42,3 +42,8 @@ references related issues.
This version is missing the service alias `validator.expression`
which causes ValidatorException exception to be thrown when using `Expression` constraint.
- `doctrine/orm:2.14.2`:
This version introduces not configurable XML validation causing errors when using XML mapping files and gedmo extensions.
- Reference: https://github.com/doctrine/DoctrineBundle/issues/1643

View file

@ -75,8 +75,8 @@ class RoboFile extends Tasks
}
$task
->exec('composer validate --ansi --strict')
->exec('composer update --no-scripts --no-interaction')
->exec('composer validate --ansi --strict')
;
if (in_array($package, ['Bundle/AdminBundle', 'Bundle/ApiBundle', 'Bundle/CoreBundle'])) {
@ -103,10 +103,18 @@ class RoboFile extends Tasks
private function createTestAssets(string $testAppDirectory): void
{
mkdir(sprintf('%s/public/build/admin', $testAppDirectory), 0777, true);
mkdir(sprintf('%s/public/build/shop', $testAppDirectory), 0777, true);
file_put_contents(sprintf('%s/public/build/admin/manifest.json', $testAppDirectory), '{}');
file_put_contents(sprintf('%s/public/build/shop/manifest.json', $testAppDirectory), '{}');
$adminBuildDir = sprintf('%s/public/build/admin', $testAppDirectory);
$shopBuildDir = sprintf('%s/public/build/shop', $testAppDirectory);
if (!file_exists($adminBuildDir)) {
mkdir($adminBuildDir, 0777, true);
file_put_contents(sprintf('%s/manifest.json', $adminBuildDir), '{}');
}
if (!file_exists($shopBuildDir)) {
mkdir($shopBuildDir, 0777, true);
file_put_contents(sprintf('%s/manifest.json', $shopBuildDir), '{}');
}
}
private function startGroup(string $groupName): void

View file

@ -180,6 +180,7 @@
"conflict": {
"doctrine/doctrine-bundle": "2.3.0",
"doctrine/migrations": "3.5.3",
"doctrine/orm": "2.14.2",
"jms/serializer-bundle": "4.1.0",
"lexik/jwt-authentication-bundle": "^2.18",
"symfony/framework-bundle": "5.4.5 || 6.2.8",

View file

@ -37,3 +37,16 @@ Feature: Adding a new product with associations
And this product should have an association "Accessories" with product "LG headphones"
And this product should not have an association "Accessories" with product "LG earphones"
And the product "LG G3" should appear in the store
@ui @javascript
Scenario: Adding a new product with association with numeric code
Given the store has 123 product association type
When I want to create a new simple product
And I specify its code as "lg_g3"
And I name it "LG G3" in "English (United States)"
And I set its price to "$400.00" for "United States" channel
And I associate as 123 the "LG headphones" and "LG earphones" products
And I add it
Then I should be notified that it has been successfully created
And this product should have an association 123 with products "LG headphones" and "LG earphones"
And the product "LG G3" should appear in the store

View file

@ -71,6 +71,14 @@ final class ProductAssociationContext implements Context
}
}
/**
* @Given the store has :firstName product association type
*/
public function theStoreHasProductAssociationType($name)
{
$this->createProductAssociationType($name);
}
/**
* @Given /^the (product "[^"]+") has(?:| also) an (association "[^"]+") with (product "[^"]+")$/
*/

View file

@ -75,7 +75,7 @@ final class ProductsToProductAssociationsTransformer implements DataTransformerI
}
/** @var ProductAssociationInterface $productAssociation */
$productAssociation = $this->getProductAssociationByTypeCode($productAssociationTypeCode);
$productAssociation = $this->getProductAssociationByTypeCode((string) $productAssociationTypeCode);
$this->setAssociatedProductsByProductCodes($productAssociation, $productCodes);
$productAssociations->add($productAssociation);
}

View file

@ -43,7 +43,7 @@ final class OrderAdjustmentsClearer implements OrderProcessorInterface
public function process(OrderInterface $order): void
{
if (OrderInterface::STATE_CART !== $order->getState()) {
if (!$order->canBeProcessed()) {
return;
}

View file

@ -37,7 +37,7 @@ final class OrderPricesRecalculator implements OrderProcessorInterface
/** @var OrderInterface $order */
Assert::isInstanceOf($order, OrderInterface::class);
if (OrderInterface::STATE_CART !== $order->getState()) {
if (!$order->canBeProcessed()) {
return;
}

View file

@ -30,7 +30,7 @@ final class OrderPromotionProcessor implements OrderProcessorInterface
/** @var OrderInterface $order */
Assert::isInstanceOf($order, OrderInterface::class);
if (OrderInterface::STATE_CART !== $order->getState()) {
if (!$order->canBeProcessed()) {
return;
}

View file

@ -43,7 +43,7 @@ final class OrderShipmentProcessor implements OrderProcessorInterface
/** @var OrderInterface $order */
Assert::isInstanceOf($order, OrderInterface::class);
if (OrderInterface::STATE_CART !== $order->getState()) {
if (!$order->canBeProcessed()) {
return;
}

View file

@ -46,7 +46,7 @@ final class OrderTaxesProcessor implements OrderProcessorInterface
/** @var OrderInterface $order */
Assert::isInstanceOf($order, OrderInterface::class);
if (OrderInterface::STATE_CART !== $order->getState()) {
if (!$order->canBeProcessed()) {
return;
}

View file

@ -33,7 +33,7 @@ final class ShippingChargesProcessor implements OrderProcessorInterface
/** @var OrderInterface $order */
Assert::isInstanceOf($order, OrderInterface::class);
if (OrderInterface::STATE_CART !== $order->getState()) {
if (!$order->canBeProcessed()) {
return;
}

View file

@ -832,4 +832,15 @@ final class OrderSpec extends ObjectBehavior
$this->getTaxIncludedTotal()->shouldReturn(1500);
$this->getTaxExcludedTotal()->shouldReturn(800);
}
function it_can_be_processed(): void
{
$this->setState(OrderInterface::STATE_CART);
$this->canBeProcessed()->shouldReturn(true);
$this->setState(OrderInterface::STATE_NEW);
$this->canBeProcessed()->shouldReturn(false);
}
}

View file

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace spec\Sylius\Component\Core\OrderProcessing;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Core\Model\AdjustmentInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Order\Processor\OrderProcessorInterface;
@ -27,7 +28,7 @@ final class OrderAdjustmentsClearerSpec extends ObjectBehavior
function it_removes_adjustments_with_default_types_from_order_recursively(OrderInterface $order): void
{
$order->getState()->willReturn(OrderInterface::STATE_CART);
$order->canBeProcessed()->willReturn(true);
$order->removeAdjustmentsRecursively(AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT)->shouldBeCalled();
$order->removeAdjustmentsRecursively(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->shouldBeCalled();
@ -45,7 +46,7 @@ final class OrderAdjustmentsClearerSpec extends ObjectBehavior
AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT,
]);
$order->getState()->willReturn(OrderInterface::STATE_CART);
$order->canBeProcessed()->willReturn(true);
$order->removeAdjustmentsRecursively(AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT)->shouldBeCalled();
$order->removeAdjustmentsRecursively(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->shouldBeCalled();
@ -53,15 +54,11 @@ final class OrderAdjustmentsClearerSpec extends ObjectBehavior
$this->process($order);
}
function it_does_nothing_if_the_order_is_in_a_state_different_than_cart(OrderInterface $order): void
function it_does_nothing_if_the_order_cannot_be_processed(OrderInterface $order): void
{
$order->getState()->willReturn(OrderInterface::STATE_NEW);
$order->canBeProcessed()->willReturn(false);
$order->removeAdjustmentsRecursively(AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT)->shouldNotBeCalled();
$order->removeAdjustmentsRecursively(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->shouldNotBeCalled();
$order->removeAdjustmentsRecursively(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT)->shouldNotBeCalled();
$order->removeAdjustmentsRecursively(AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT)->shouldNotBeCalled();
$order->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->shouldNotBeCalled();
$order->removeAdjustmentsRecursively(Argument::any())->shouldNotBeCalled();
$this->process($order);
}

View file

@ -46,7 +46,7 @@ final class OrderPricesRecalculatorSpec extends ObjectBehavior
ProductVariantInterface $variant,
ProductVariantPricesCalculatorInterface $productVariantPriceCalculator,
): void {
$order->getState()->willReturn(OrderInterface::STATE_CART);
$order->canBeProcessed()->willReturn(true);
$order->getCustomer()->willReturn($customer);
$order->getChannel()->willReturn(null);
@ -83,9 +83,9 @@ final class OrderPricesRecalculatorSpec extends ObjectBehavior
;
}
function it_does_nothing_if_the_order_is_in_a_state_different_than_cart(OrderInterface $order): void
function it_does_nothing_if_the_order_cannot_be_processed(OrderInterface $order): void
{
$order->getState()->willReturn(OrderInterface::STATE_NEW);
$order->canBeProcessed()->willReturn(false);
$order->getChannel()->shouldNotBeCalled();
$order->getItems()->shouldNotBeCalled();

View file

@ -32,18 +32,18 @@ final class OrderPromotionProcessorSpec extends ObjectBehavior
function it_processes_promotions(PromotionProcessorInterface $promotionProcessor, OrderInterface $order): void
{
$order->getState()->willReturn(OrderInterface::STATE_CART);
$order->canBeProcessed()->willReturn(true);
$promotionProcessor->process($order)->shouldBeCalled();
$this->process($order);
}
function it_does_nothing_if_the_order_is_in_a_state_different_than_cart(
function it_does_nothing_if_the_order_cannot_be_processed(
PromotionProcessorInterface $promotionProcessor,
OrderInterface $order,
): void {
$order->getState()->willReturn(OrderInterface::STATE_NEW);
$order->canBeProcessed()->willReturn(false);
$promotionProcessor->process($order)->shouldNotBeCalled();

View file

@ -54,7 +54,7 @@ final class OrderShipmentProcessorSpec extends ObjectBehavior
ShippingMethodInterface $defaultShippingMethod,
OrderItemInterface $orderItem,
): void {
$order->getState()->willReturn(OrderInterface::STATE_CART);
$order->canBeProcessed()->willReturn(true);
$defaultShippingMethodResolver->getDefaultShippingMethod($shipment)->willReturn($defaultShippingMethod);
@ -88,7 +88,7 @@ final class OrderShipmentProcessorSpec extends ObjectBehavior
ShipmentInterface $shipment,
OrderItemInterface $orderItem,
): void {
$order->getState()->willReturn(OrderInterface::STATE_CART);
$order->canBeProcessed()->willReturn(true);
$defaultShippingMethodResolver->getDefaultShippingMethod($shipment)->willThrow(UnresolvedDefaultShippingMethodException::class);
@ -127,7 +127,7 @@ final class OrderShipmentProcessorSpec extends ObjectBehavior
OrderItemInterface $orderItem,
ProductVariantInterface $productVariant,
): void {
$order->getState()->willReturn(OrderInterface::STATE_CART);
$order->canBeProcessed()->willReturn(true);
$defaultShippingMethodResolver->getDefaultShippingMethod($shipment)->willReturn($defaultShippingMethod);
@ -157,7 +157,7 @@ final class OrderShipmentProcessorSpec extends ObjectBehavior
ProductVariantInterface $productVariant,
ShippingMethodInterface $shippingMethod,
): void {
$order->getState()->willReturn(OrderInterface::STATE_CART);
$order->canBeProcessed()->willReturn(true);
$shipments->first()->willReturn($shipment);
@ -197,7 +197,7 @@ final class OrderShipmentProcessorSpec extends ObjectBehavior
): void {
$this->beConstructedWith($defaultShippingMethodResolver, $shipmentFactory);
$order->getState()->willReturn(OrderInterface::STATE_CART);
$order->canBeProcessed()->willReturn(true);
$shipments->first()->willReturn($shipment);
@ -230,7 +230,7 @@ final class OrderShipmentProcessorSpec extends ObjectBehavior
OrderItemUnitInterface $itemUnitWithoutShipment,
ShippingMethodInterface $shippingMethod,
): void {
$order->getState()->willReturn(OrderInterface::STATE_CART);
$order->canBeProcessed()->willReturn(true);
$shipments->first()->willReturn($shipment);
@ -268,7 +268,7 @@ final class OrderShipmentProcessorSpec extends ObjectBehavior
ShippingMethodInterface $firstShippingMethod,
ShippingMethodInterface $secondShippingMethod,
): void {
$order->getState()->willReturn(OrderInterface::STATE_CART);
$order->canBeProcessed()->willReturn(true);
$shipments->first()->willReturn($shipment);
@ -298,9 +298,9 @@ final class OrderShipmentProcessorSpec extends ObjectBehavior
$this->process($order);
}
function it_does_nothing_if_the_order_is_in_a_state_different_than_cart(OrderInterface $order): void
function it_does_nothing_if_the_order_cannot_be_processed(OrderInterface $order): void
{
$order->getState()->willReturn(OrderInterface::STATE_NEW);
$order->canBeProcessed()->willReturn(false);
$order->isEmpty()->shouldNotBeCalled();
$order->getItems()->shouldNotBeCalled();

View file

@ -55,7 +55,7 @@ final class OrderTaxesProcessorSpec extends ObjectBehavior
TaxCalculationStrategyInterface $strategyOne,
TaxCalculationStrategyInterface $strategyTwo,
): void {
$order->getState()->willReturn(OrderInterface::STATE_CART);
$order->canBeProcessed()->willReturn(true);
$order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()]));
$order->getShipments()->willReturn(new ArrayCollection([$shipment->getWrappedObject()]));
$order->isEmpty()->willReturn(false);
@ -86,7 +86,7 @@ final class OrderTaxesProcessorSpec extends ObjectBehavior
ZoneInterface $zone,
TaxCalculationStrategyInterface $strategy,
): void {
$order->getState()->willReturn(OrderInterface::STATE_CART);
$order->canBeProcessed()->willReturn(true);
$order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()]));
$order->getShipments()->willReturn(new ArrayCollection([]));
$order->isEmpty()->willReturn(false);
@ -107,7 +107,7 @@ final class OrderTaxesProcessorSpec extends ObjectBehavior
function it_does_not_process_taxes_if_there_is_no_order_item(OrderInterface $order): void
{
$order->getState()->willReturn(OrderInterface::STATE_CART);
$order->canBeProcessed()->willReturn(true);
$order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled();
$order->getItems()->willReturn(new ArrayCollection([]));
$order->getShipments()->willReturn(new ArrayCollection([]));
@ -126,7 +126,7 @@ final class OrderTaxesProcessorSpec extends ObjectBehavior
OrderItemInterface $orderItem,
AddressInterface $address,
): void {
$order->getState()->willReturn(OrderInterface::STATE_CART);
$order->canBeProcessed()->willReturn(true);
$order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()]));
$order->getShipments()->willReturn(new ArrayCollection([]));
$order->isEmpty()->willReturn(false);
@ -145,12 +145,12 @@ final class OrderTaxesProcessorSpec extends ObjectBehavior
$this->process($order);
}
function it_does_nothing_if_the_order_is_in_a_state_different_than_cart(
function it_does_nothing_if_the_order_cannot_be_processed(
ZoneProviderInterface $defaultTaxZoneProvider,
PrioritizedServiceRegistryInterface $strategyRegistry,
OrderInterface $order,
): void {
$order->getState()->willReturn(OrderInterface::STATE_NEW);
$order->canBeProcessed()->willReturn(false);
$order->getItems()->shouldNotBeCalled();
$order->getShipments()->shouldNotBeCalled();

View file

@ -38,7 +38,7 @@ final class ShippingChargesProcessorSpec extends ObjectBehavior
function it_removes_existing_shipping_adjustments(OrderInterface $order): void
{
$order->getState()->willReturn(OrderInterface::STATE_CART);
$order->canBeProcessed()->willReturn(true);
$order->getShipments()->willReturn(new ArrayCollection([]));
@ -47,7 +47,7 @@ final class ShippingChargesProcessorSpec extends ObjectBehavior
function it_does_not_apply_any_shipping_charge_if_order_has_no_shipments(OrderInterface $order): void
{
$order->getState()->willReturn(OrderInterface::STATE_CART);
$order->canBeProcessed()->willReturn(true);
$order->getShipments()->willReturn(new ArrayCollection([]));
$order->addAdjustment(Argument::any())->shouldNotBeCalled();
@ -63,7 +63,7 @@ final class ShippingChargesProcessorSpec extends ObjectBehavior
ShipmentInterface $shipment,
ShippingMethodInterface $shippingMethod,
): void {
$order->getState()->willReturn(OrderInterface::STATE_CART);
$order->canBeProcessed()->willReturn(true);
$adjustmentFactory->createNew()->willReturn($adjustment);
$order->getShipments()->willReturn(new ArrayCollection([$shipment->getWrappedObject()]));
@ -93,7 +93,7 @@ final class ShippingChargesProcessorSpec extends ObjectBehavior
function it_does_nothing_if_the_order_is_in_a_state_different_than_cart(OrderInterface $order): void
{
$order->getState()->willReturn(OrderInterface::STATE_NEW);
$order->canBeProcessed()->willReturn(false);
$order->getShipments()->shouldNotBeCalled();
$order->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->shouldNotBeCalled();

View file

@ -315,6 +315,11 @@ class Order implements OrderInterface
$this->recalculateTotal();
}
public function canBeProcessed(): bool
{
return $this->state === self::STATE_CART;
}
/**
* Items total + Adjustments total.
*/

View file

@ -84,4 +84,6 @@ interface OrderInterface extends AdjustableInterface, ResourceInterface, Timesta
public function getAdjustmentsTotalRecursively(?string $type = null): int;
public function removeAdjustmentsRecursively(?string $type = null): void;
public function canBeProcessed(): bool;
}