Closed (fixed)
Project:
Commerce Core
Version:
8.x-2.x-dev
Component:
Cart
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
10 Oct 2016 at 19:52 UTC
Updated:
5 Nov 2016 at 20:14 UTC
Jump to comment: Most recent
Comments
Comment #2
steveoliver commentedhttps://github.com/drupalcommerce/commerce/pull/527/files shows failing test that should pass when this issue is resolved.
Comment #3
bojanz commentedBig thanks for the failing test!
Comment #4
steveoliver commentedUpdating issue summary to include the child issue that was closed as a duplicate of this.
Comment #5
luksakOk, going to review this on my installation in the coming days...
I guess this needs review?
Comment #6
luksakWorks for me so far! Thank you! Can't RTBC this tough. I am not familiar with 2.x yet...
Comment #7
mglamanThe tests and everything look good. I had one comment I proposed in the PR.
I think the conversion of a cart ID from the
commerce_cart_orderssession item tocommerce_cart_completed_ordersshould be kept in finalizeCart, keeping deleteCartId as an actual deletion of the cart from the session. We can letcommerce_cart_completed_orderspersist and be something populated in finalizeCartComment #8
steveoliver commentedMakes sense. I refactored CartSession methods and usages to be explicit about the handling of active vs. completed carts: https://github.com/drupalcommerce/commerce/pull/527/commits/84714163.
Comment #9
bojanz commentedRetitling.
Comment #11
bojanz commentedThought quite a bit about which API we wanted to have here.
Commerce 1.x had a $completed = FALSE argument for the regular set of functions, which controlled whether active or completed cart ids are manipulated. Boolean arguments are generally bad for DX, you need to know what the TRUE in hasCartId($cart_id, TRUE) stands for. So it made sense for steveoliver to introduce parallel methods, giving us an active and completed version of each method.
However, reviewing this with Matt it struck us that we now have code duplication, since methods only differ in the session key that they use.
In the end I managed to find a better alternative, a $type argument that uses a class constant. Hence we get this usage:
Which is clear, but still allows the implementation to stay lean.
$type defaults to self::ACTIVE by default, which also minimizes the BC break, making it almost non-existent.