-
Notifications
You must be signed in to change notification settings - Fork 255
#2863864 - Disable promotions via cron if end date or usage limit hit#708
#2863864 - Disable promotions via cron if end date or usage limit hit #708swickham78 wants to merge 21 commits intodrupalcommerce:8.x-2.x from
Conversation
@mglaman
mglaman
left a 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.
There are a few changes and no tests. We definitely need to test this.
I don't think we need to use a queue worker. But I'd like to use more of the API for querying the promotions. Even if this means running an entity query to load invalid via end date. Then load valid and check their usages and add to list of promotions to exired/disable.
I'm not too worried on the performance since this should only be invoked during cron.
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.
If the storage provides a method to load expired, we can just keep this within the cron, no need for its own function. If people want to run this manually then they can.
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.
@bojanz I think this is fine versus a queue. There shouldn't be that much activity, generally.
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.
We already have this query in the usage service :: getUsageMultiple. It feels like we should rework this method a bit so it can be used.
https://github.com/drupalcommerce/commerce/blob/8.x-2.x/modules/promotion/src/PromotionUsage.php#L65
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.
Would it work if I add another method to PromotionStorage that will load and check promotion uses by calling getUsageMultiple? That way I can run a quick query to only pass promotions to it which are active and have a usage set.
I think the only way I can mess around with getUsageMultiple to handle return usage on its own would be to be just make it load all promotions if none are passed which could be excessive even if we're not too concerned w/ performance.
Thoughts?
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 is using a regular select, when we can run $this->getQuery().
I'd actually rather do a load of ->condition('end_date', gmdate('Y-m-d'), '<') and ->condition('status', TRUE)
We need < because it's valid if >=. This would cancel promotions on their last day.
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.
We return the invalid and set them as disabled. Then I'd say run the usage checks afterwards for anything not yet expired
... promotions_disable_expired
...making use of existing service.
mglaman
commented
Apr 7, 2017
@swickham78 at quick glance this looks good, better change. Bojan made some changes which are causing conflict.
swickham78
commented
Apr 7, 2017
@mglaman Conflicts have been addressed.
mglaman
commented
Apr 8, 2017
@swickham78 okay, cool. Errors are just PHPCS. I'll get around to a proper review
... promotions_disable_expired
@mglaman
mglaman
left a 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.
The storage methods are tested, but the cron op is still not tested.
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.
Document blocks should only be on the interface, implementers just do {@inheritdoc}
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.
Document blocks should only be on the interface, implementers just do {@inheritdoc}
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.
@bojanz name bikeshedding.
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.
Can do assertCount
6be1d5c to
b8a7444
Compare
...making use of existing service.
...ham78/commerce into promotions_disable_expired
swickham78
commented
Jun 28, 2017
@mglaman Completely forgot this was left unresolved. Just pushed a new commit with adjustments based on your last notes.
5b3779b to
2941d08
Compare
...making use of existing service.
...making use of existing service.
...ham78/commerce into promotions_disable_expired
swickham78
commented
Aug 11, 2017
@mglaman Looks like this got lost in the shuffle. Nothing changed since the last push, just did a rebase and fixed some conflicts that came form it.
53ec70a to
3bc1b88
Compare
807c6e8 to
8898142
Compare
No description provided.