Closed (fixed)
Project:
Commerce Core
Version:
8.x-2.x-dev
Component:
Payment
Priority:
Normal
Category:
Bug report
Assigned:
Issue tags:
Reporter:
Created:
21 Mar 2017 at 01:55 UTC
Updated:
13 Mar 2020 at 16:39 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
bojanz commentedLooks like PaymentStorage extends the correct class (CommerceContentEntityStorage), the only thing that we're missing is an "event" in the Payment entity annotation (plus the actual event class and list of events in PaymentEvents, of course).
Comment #3
harings_rob commentedComment #4
nikathone@harings_rob any update on this? thanks
Comment #5
nikathone@bojanz found this https://github.com/drupalcommerce/commerce/pull/684 pull request from @harings_rob and was wondering if there is anything I can do to move this forward as I have some custom code which I would like them to subscribe to payment creation event. Thanks
Comment #6
kiwad commentedI've tried the commits mentionned in #5.
Works quite well. I would make few changes :
in PaymentStorage, all the events should be declared
In PaymentEvent, I would change the name of the function getOrder() to getEntity() which is more inline with other events and also because the function does not get the order entity but the payment entity
Comment #7
kiwad commentedFinally, the events where not triggered when I wanted them and instead of hacking commerce for my project, I ended up using core hooks. Since payments are entities, using function
Comment #8
jackbravo commentedOk, I just re-rolled this patch, and also added the 'event' annotation to the Payment entity, so now all the events should work. There are tests right now for the create and load event. I also changed the getOrder method to getEntity, and added a test for that (as mentioned in comment 6). This issue is related to https://www.drupal.org/node/2856586 so I'm planning on adding that event too but maybe in another patch that depends on this one.
The PR is here: https://github.com/drupalcommerce/commerce/pull/791
Comment #9
harings_rob commentedComment #11
sophie.skWhew, two years later and this finally needed a re-roll. Updated patch attached for the latest version of Commerce.
I don't know if any other work needs to be done to this - I have just straight up rerolled the latest patch. I haven't attached a diff, since the last patch was a seven-part patch.
Comment #13
tonifisler commentedYou could listen for state transitions in an EventListener to achieve something very similar. You won't get any event when there is no change in the state of the payment though. This is what I implemented:
Comment #14
lisastreeter commentedWhile working on a payment logging issue: https://www.drupal.org/project/commerce/issues/2845321, @mglaman pointed me towards this issue. I've separated the payment CRUD events from the payment logging and have combined that code with the latest patch here. Changes to the patch include:
* An update hook for the entity event handler. Without the hook, events weren't firing when the patch was applied to an existing site.
* A few minor updates to the test code.
Comment #15
lisastreeter commentedComment #16
mglamanphpcs says we should move this into a `use` statement. nit on commit
Shouldn't the parent still invoke hooks here which CommerceContentEntityStorage fires events on?
Comment #17
mglamanAddresses #16. Punting to bojanz for review.
Comment #18
bojanz commentedSome of the event constants have var string, some don't. So the file itself is inconsistent. Looking at other files, we usually don't declare it, so I'm going to remove it.
These imports are now unused and trigger phpcs warnings.
While I like the tests, they are actually out of place here, because commerce_payment doesn't fire any events, the Commerce base class does. So if we want test coverage for entity events, it needs to live in the base module (let's say tests/src/Kernel/EntityEventsTest).
I'm going to remove the test/subscriber and commit, and you can make the coverage generic in a followup issue (post-2.17). I hope that's okay.
Comment #20
bojanz commentedThanks, everyone!