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

Ticket-agnostic cart #3522

Open
wants to merge 74 commits into
base: feature/ET-2189-cart-coupons
Choose a base branch
from
Open

Conversation

JPry
Copy link
Contributor

@JPry JPry commented Feb 3, 2025

🎫 Ticket

ET-2200

🗒️ Description

This PR updates the cart component to be able to handle non-ticket items (e.g. an agnostic cart).

The main changes are:

  • Create a new class \TEC\Tickets\Commerce\Cart\Agnostic_Cart, which implements the Cart_Interface interface.
  • A new class \TEC\Tickets\Commerce\Cart\Cart_Item was created to handle the cart items. This class implements ArrayAccess with a few additional methods, and an assurance of some common properties.
  • The new Agnostic_Cart class becomes the default cart class (see \TEC\Tickets\Commerce\Cart::get_repository()).
  • The Agnostic_Cart class has its own unit test suite similar to the Unmanaged_Cart suite to ensure it works as expected.
  • Except for tests, wherever we referenced the prior cart class, Unmanaged_Cart, we should now be referencing Cart_Interface instead.
  • A number of methods from the Unmanaged_Cart class were moved over to the Abstract_Cart parent class.
  • Some of the logic for whether an item can be added to the cart was moved to the Tribe__Tickets__Tickets_Handler class.
  • Within the get_cart_total() and get_cart_subtotal() methods, I implemented logic to prevent unnecessary duplicate calculations. During the process of working through this code, I discovered that the get_cart_total() method is called over 30 times within a single request, and the old logic allowed for those calculations to be performed fresh each time, even if the cart contents had not changed. This new logic handles when the cart contents have changed, and will ensure calculations are updated afterwards.
  • The Abstract_Cart::get_items_in_cart() and Commerce\Cart::get_items_in_cart() methods have been updated to allow getting items of a particular type, or all items. The default behavior is to only get ticket items to preserve the current functionality in other places without needing to modify everything within this PR.

Template file updates:

  • src/views/v2/commerce/checkout/cart/ticket.php - I added this file to handle the display of ticket items in the cart.
  • src/views/v2/commerce/checkout/cart/items.php - This template file was updated to handle the display of ticket vs. non-ticket items. For the time being, the old item.php tempalte is identical to the ticket.php template, but now it will be easy to handle the display of non-ticket items in the cart.

There are some new hooks added:

  • tec_tickets_commerce_cart_cookie_expiration filter - allows filtering the cookie expiration time for the cart.
  • tec_tickets_commerce_cart_repo_prepare_data filter - allows filtering the data within the cart repository class (e.g. inside Abstract_Cart::prepare_data()).
  • tec_tickets_commerce_cart_process action - allows access to the cart object and the $data array within the process() method. This is where additional types of items can be hooked into the cart.
  • tec_tickets_commerce_cart_add_full_item_params filter - allows filtering the full item parameters before calculations are performed.
  • tec_tickets_commerce_cart_transient_expiration filter - allows filtering the transient expiration time for the cart.

There are some hooks that were deprecated:

  • tec_tickets_commerce_cart_expiration - use tec_tickets_commerce_cart_cookie_expiration instead.

🎥 Artifacts

✔️ Checklist

  • Ran npm run changelog to add changelog file(s). More info here
  • Code is covered by NEW wpunit or integration tests.
  • Code is covered by EXISTING wpunit or integration tests.
  • Are all the required tests passing?
  • Automated code review comments are addressed.
  • Have you added Artifacts?
  • Check the base branch for your PR.
  • Add your PR to the project board for the release.

@JPry JPry self-assigned this Feb 3, 2025
@JPry JPry force-pushed the feature/agnostic-cart branch from ae58137 to b3bdf21 Compare February 3, 2025 15:17
@JPry JPry force-pushed the feature/agnostic-cart branch from c396808 to c77979d Compare February 3, 2025 22:36
/**
* @var array|null The list of items, null if not retrieved from transient yet.
*/
protected $items = null;

/**
* {@inheritDoc}
*/
public function has_public_page() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Methods and properties removed from this class were added to the Abstract_Cart class.

*/
public function has_items() {
$items = $this->get_items();

// When we don't have items, return false.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added to ensure the method behaves as indicated by the interface.

@JPry JPry marked this pull request as ready for review February 6, 2025 21:44
@JPry JPry requested a review from a team February 6, 2025 22:18
src/Tickets/Commerce/Cart.php Show resolved Hide resolved
src/Tickets/Commerce/Cart.php Show resolved Hide resolved
@JPry JPry requested a review from redscar February 13, 2025 00:44
@JPry JPry force-pushed the feature/agnostic-cart branch from f14fe96 to b06f2ce Compare February 13, 2025 00:46
Copy link
Member

@Camwyn Camwyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment

Copy link
Member

@Camwyn Camwyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request changes

@Camwyn
Copy link
Member

Camwyn commented Feb 13, 2025

Ignore the rando comment/request/approval above. Jeremy and I were testing something.

src/Tickets/Commerce/Cart.php Show resolved Hide resolved
src/Tickets/Commerce/Cart/Abstract_Cart.php Show resolved Hide resolved
src/Tickets/Commerce/Cart/Agnostic_Cart.php Show resolved Hide resolved
src/Tickets/Commerce/Cart/Agnostic_Cart.php Outdated Show resolved Hide resolved
src/Tickets/Commerce/Cart/Agnostic_Cart.php Show resolved Hide resolved
src/Tickets/Commerce/Cart/Agnostic_Cart.php Outdated Show resolved Hide resolved
@JPry JPry force-pushed the feature/agnostic-cart branch from 7a1004e to ae5ddf8 Compare February 14, 2025 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants