-
Notifications
You must be signed in to change notification settings - Fork 42
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
base: feature/ET-2189-cart-coupons
Are you sure you want to change the base?
Ticket-agnostic cart #3522
Conversation
ae58137
to
b3bdf21
Compare
c396808
to
c77979d
Compare
/** | ||
* @var array|null The list of items, null if not retrieved from transient yet. | ||
*/ | ||
protected $items = null; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function has_public_page() { |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
f14fe96
to
b06f2ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request changes
Ignore the rando comment/request/approval above. Jeremy and I were testing something. |
This comes from the Cart_Interface
The Items array might have a different structure and values
7a1004e
to
ae5ddf8
Compare
🎫 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:
\TEC\Tickets\Commerce\Cart\Agnostic_Cart
, which implements theCart_Interface
interface.\TEC\Tickets\Commerce\Cart\Cart_Item
was created to handle the cart items. This class implementsArrayAccess
with a few additional methods, and an assurance of some common properties.Agnostic_Cart
class becomes the default cart class (see\TEC\Tickets\Commerce\Cart::get_repository()
).Agnostic_Cart
class has its own unit test suite similar to theUnmanaged_Cart
suite to ensure it works as expected.Unmanaged_Cart
, we should now be referencingCart_Interface
instead.Unmanaged_Cart
class were moved over to theAbstract_Cart
parent class.Tribe__Tickets__Tickets_Handler
class.get_cart_total()
andget_cart_subtotal()
methods, I implemented logic to prevent unnecessary duplicate calculations. During the process of working through this code, I discovered that theget_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.Abstract_Cart::get_items_in_cart()
andCommerce\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 getticket
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 olditem.php
tempalte is identical to theticket.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. insideAbstract_Cart::prepare_data()
).tec_tickets_commerce_cart_process
action - allows access to the cart object and the$data
array within theprocess()
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
- usetec_tickets_commerce_cart_cookie_expiration
instead.🎥 Artifacts
✔️ Checklist
npm run changelog
to add changelog file(s). More info herewpunit
orintegration
tests.wpunit
orintegration
tests.