Order item title is being set two times when adding the product to cart.
One from OrderItemStorage::createFromPurchasableEntity and one from AddToCartForm::buildEntity.
Now if for example we want to alter OrderItem->title using the create (or maybe more suitable fields_init_values event), the value is being overwriten from the AddToCartForm::buildEntity set.
So I believe that the second set should go away...
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 3008173-18.patch | 4.6 KB | rgeerolf |
Comments
Comment #2
sagesolutions commentedI agree.
I tried creating an order item manually and overriding the title.
However, because I'm using the purchased entity, the title gets overridden, most likely from:
if I create an OrderItem without setting the purchased_entity, the Order Item title stays set, but I lose the price info from the purchased entity.
Comment #3
skdrupal88Had the same problem, attached patch should fix it.
Comment #5
roblogHi. I'm trying to use the CartEntityAddEvent event to overwrite the title after it is added to the cart, but it is not working, even after applying the patch. Any ideas?
Comment #6
roblogUPDATE: My bad, it is working. The Cart view was displaying the purchased Entity title rather than the OrderItem title. I tweaked the view and everything is good again.
Comment #7
TylerMarshall commentedIt looks like the tests are failing because we are changing the site language to French, which updates the title to the French version of it. If we leave the current patch in #3 in, this functionality breaks, and we get the English version on the french site.
I am not sure if we want to change the title here, or in a different area, or handle this different all together. I will try and get a test up with the current patch that respects the translation.
Comment #8
anas_maw commentedPatch in 3 worked for me as expected
Comment #9
no sssweat commentedShould be noted that order item title field should be added to the form cart view & the summary view, and the purchased entity item field should be removed.
Comment #10
shuhiab commentedThe fix still not available, I am facing the same issue
Comment #11
jglynn commentedThis is also causing me issues with trying to programmatically update order item title in the cart. Seems like this would be a fairly common use case?
Comment #12
johnpitcairn commentedIf an implementation is customizing the order item title, then wouldn't it also be up to that implementation to handle translating the customized title if appropriate? And perhaps the test should accommodate this possibility?
Maybe what is required here is a flag similar to
overridden_unit_price. You'd setoverridden_titletoTRUE, and if that's set the cart shouldn't mess with it and tests should not check translated titles. You'd need to write a test for that yourself, if you had translation functionality in place for overridden titles.Some maintainer input would be good.
Comment #13
johnpitcairn commentedComment #14
narendra.rajwar27Re-rolled patch from comment #3
Comment #16
facine commentedI'm attaching a new approach as recommended by @John Pitcairn
Comment #17
facine commentedThe errors in the tests do not appear to be related to our changes.
Comment #18
rgeerolfI updated the latest patch from facine because the database update collided with the address 2.0 database update added after #16 was created.
Comment #19
jsacksick commentedhm... Feels a bit overkill but probably the only way to preserve a custom order item title on refresh...
We need to update the order item kernel test as well to test the new method.
Comment #20
jsacksick commentedUpdated the order item kernel test and committed the patch. Thanks everyone!