Skip to content

Commit

Permalink
NEXT-37386 - Updated changelog; Minor text updates; Review update;
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert Scherman committed Jul 29, 2024
1 parent 04bac71 commit e40670a
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 39 deletions.
1 change: 1 addition & 0 deletions .bc-exclude.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
'**/src/Core/Checkout/Payment/Cart/PaymentHandler/DefaultPayment.php', // duplicate class declarations for compatibility reasons
'**/src/Core/Checkout/Payment/Cart/PaymentHandler/InvoicePayment.php', // duplicate class declarations for compatibility reasons
'**/src/Core/Checkout/Payment/Cart/PaymentHandler/PrePayment.php', // duplicate class declarations for compatibility reasons
'**/src/Core/Checkout/Cart/Event/CartChangedEvent.php', // duplicate class declarations for compatibility reasons
],
'errors' => [
'Shopware\\\\Core\\\\System\\\\SystemConfig\\\\Util\\\\ConfigReader#\\$xsdFile', // Can not be inspected through reflection (__DIR__ constant)
Expand Down
4 changes: 2 additions & 2 deletions changelog/_unreleased/2024-07-22-add-cart-event-interface.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Abstract and reduce rule condition components
issue: NEXT-00000
issue: NEXT-37386
author: Justus Maier
author_email: [email protected]
author_github: @justusNBB
Expand All @@ -26,4 +26,4 @@ author_github: @justusNBB
* `Core/Checkout/Cart/Event/LineItemRemovedEvent`
* Deprecated `Shopware\Core\Checkout\Cart\Event\CartChangedEvent` method `getContext()` should return `Context`, the attribute name `$context` and the (missing) type of attribute `$cart`: Until this is solved CartChangedEvent cannot implement `ShopwareSalesChannelEvent`
* Added `Shopware\Core\Checkout\Cart\Event\CartChangedEvent` method `getSalesChannelContext()` for consistency
* Added `Shopware\Core\Checkout\Cart\Event\CartLoadedEvent` method `getContext()` for consistency
* Added `Shopware\Core\Checkout\Cart\Event\CartLoadedEvent` method `getContext()` for consistency
5 changes: 5 additions & 0 deletions phpstan-v67-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ parameters:
message: "#^Multiple class/interface/trait is not allowed in single file$#"
count: 1
path: src/Storefront/Page/Product/Review/ReviewLoaderResult.php

-
message: "#^Multiple class/interface/trait is not allowed in single file$#"
count: 1
path: src/Core/Checkout/Cart/Event/CartChangedEvent.php
108 changes: 72 additions & 36 deletions src/Core/Checkout/Cart/Event/CartChangedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,86 @@
namespace Shopware\Core\Checkout\Cart\Event;

use Shopware\Core\Checkout\Cart\Cart;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Event\ShopwareSalesChannelEvent;
use Shopware\Core\Framework\Feature;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Contracts\EventDispatcher\Event;

#[Package('checkout')]
class CartChangedEvent extends Event implements CartEvent
{
/**
* @deprecated tag:v6.7.0 - Param $cart will be typed and readonly when implementing ShopwareSalesChannelEvent
*
* @var Cart
*/
protected $cart;

/**
* @deprecated tag:v6.7.0 - Param $context will be renamed to $salesChannelContext when implementing ShopwareSalesChannelEvent
*
* @var SalesChannelContext
*/
protected $context;

public function __construct(Cart $cart, SalesChannelContext $context)
if (Feature::isActive('v6.7.0.0')) {
#[Package('checkout')]
class CartChangedEvent extends Event implements CartEvent, ShopwareSalesChannelEvent
{
$this->cart = $cart;
$this->context = $context;
}
public function __construct(
protected readonly Cart $cart,
protected readonly SalesChannelContext $salesChannelContext,
) {
}

public function getCart(): Cart
{
return $this->cart;
}
public function getCart(): Cart
{
return $this->cart;
}

/**
* @deprecated tag:v6.7.0 - Should actually return Context like the other events: Use getSalesChannelContext() instead
*/
public function getContext(): SalesChannelContext
{
// TODO implements ShopwareSalesChannelEvent
// return $this->salesChannelContext->getContext();
return $this->getSalesChannelContext();
}
public function getContext(): Context
{
return $this->getSalesChannelContext()->getContext();
}

public function getSalesChannelContext(): SalesChannelContext
public function getSalesChannelContext(): SalesChannelContext
{
return $this->salesChannelContext;
}
}
} else {
#[Package('checkout')]
class CartChangedEvent extends Event implements CartEvent
{
return $this->context;
/**
* @deprecated tag:v6.7.0 - $cart property will be typed and readonly
*
* @var Cart
*/
protected $cart;

/**
* @deprecated tag:v6.7.0 - $context property will be removed
*
* @var SalesChannelContext
*/
protected $context;

protected readonly SalesChannelContext $salesChannelContext;

public function __construct(Cart $cart, SalesChannelContext $context)
{
$this->cart = $cart;
$this->context = $context;
$this->salesChannelContext = $context;
}

public function getCart(): Cart
{
return $this->cart;
}

/**
* @deprecated tag:v6.7.0 - Use getSalesChannelContext() instead.
*/
public function getContext(): SalesChannelContext
{
Feature::triggerDeprecationOrThrow(
'v6.7.0.0',
'Use getSalesChannelContext() instead of getContext() to get the SalesChannelContext.'
);

return $this->context;
}

public function getSalesChannelContext(): SalesChannelContext
{
return $this->salesChannelContext;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public function remove(Request $request, Cart $cart, SalesChannelContext $contex
$this->cartPersister->save($cart, $context);

$this->eventDispatcher->dispatch(new AfterLineItemRemovedEvent($lineItems, $cart, $context));

$this->eventDispatcher->dispatch(new CartChangedEvent($cart, $context));

return new CartResponse($cart);
Expand Down
1 change: 1 addition & 0 deletions src/Core/Checkout/Cart/SalesChannel/CartService.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public function order(Cart $cart, SalesChannelContext $context, RequestDataBag $
}

$cart = $this->createNew($context->getToken());

$this->eventDispatcher->dispatch(new CartChangedEvent($cart, $context));

return $orderId;
Expand Down

0 comments on commit e40670a

Please sign in to comment.