Closed (fixed)
Project:
Commerce Core
Version:
8.x-2.x-dev
Component:
Promotions
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
24 Mar 2017 at 20:14 UTC
Updated:
3 Sep 2024 at 12:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
mglamanComment #3
mglamanDidn't get to this, unassigned so it's free for sprints.
Comment #4
swickham commentedI'll be getting at this during the week.
Comment #5
swickham commentedPull request - https://github.com/drupalcommerce/commerce/pull/708
Comment #6
mglamanCommented on PR
Comment #7
swickham commentedMatt, I pushed changes addressing your suggestions, ready for another look.
Comment #8
swickham commentedPR updated, rebased since it's been a little while since this was last looked at.
Comment #9
igor.barato commentedI catch the patch placed on GitHub and updated it.
Fixed loadExpired() to get right timezone.
Replaced undefined function to load multiple usage promotions.
Comment #10
igor.barato commentedFixed PHPLint error.
Comment #11
m_z commentedI tested the patch #10 for Drupal 9.5.9 and Commerce 8.x-2.31 and it works perfectly.
A promotion that has reached the maximum usage and gets deactivated after a cron run.
Don't forget to clear cache after patching the commerce_promotion sub-module.
+1 RTBC
Some should test the patch for Drupal 10 and latest Commerce version!
Comment #12
brunomolica commentedOnly by adding the 'accessCheck' attribute, which is required in a Query object in D10.
Comment #13
brunomolica commentedUpdate a new file because previous doesn't work
Comment #14
brunomolica commentedIt is the last update from this version.
Comment #17
zaporylieI took #14 and turned it into MR. I had to fix tests because they were broken. I also moved cron into its own service class.
I do feel like this feature is needed but at the same time, I am not convinced we need to expand the promotion storage. I see a limited need for loading maxed and expired promotions outside this functionality therefore I would rather keep queries as part of the cron service for now and perhaps promote them to the storage if we find a use-case for that.
Comment #18
jsacksick commentedI agree, not sure there is a need for these 2 new methods on the promotion storage, might make more sene to just add helper protected methods directly in the Cron service.
Also, several other comments:
CronInterface, Drupal core already defines oneloadMaxedUsage()logic should be rewritten to perform direct DB queries with joins... We can easily join on the promotion usage table. The current logic is inefficient... We can directly query the promotions that need to be filtered out.Comment #19
zaporylieGood catch. I noticed commerce_cart also defines its interface so I just followed that strategy. But I agree that better to use core's croninterface if possible.
I believe the problem here is that usage was defined in #2763705: Implement a usage API as backend_overridable so we cannot rely on it being in that db table.
Not sure if that's a big of an issue? One can still extend the promotion and activate it. And if the promotion end date passes while the promotion is still active (as it works currently) the promotion is not applicable anyway. Is there any other factor that should be considered here?
Comment #20
jsacksick commentedIndeed good point, we need to use the services / API, that may result in poor performance but I guess we can't really workaround that.
Also, could you please use property promotion (for the Cron constructor).
Comment #21
zaporyliehttps://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...
It turns out that core's CronInterface is meant less for a single cron task handler and more for the runner as it expects the return type. Do you still believe it's a good fit? I noticed it only because of failing phpstan test in https://git.drupalcode.org/issue/commerce-2863864/-/jobs/2460087
Comment #22
jsacksick commentedAs discussed on Slack, let's define a CronInterface from Commerce core, with a void return type.
Also, let's try to tweak the comments a little bit...
perhaps should be
?
Also,
$promotion_uses = $this->promotionUsage->loadMultiple($promotions);maybe just:
$usage = $this->promotionUsage->loadMultiple($promotions);Let's also refactor:
This to use array_filter().
Comment #23
zaporylieAddressed comments in #22
Comment #24
jsacksick commentedI was reviewing this one more time... And realized the following:
Comment #25
jsacksick commentedMaybe we just introduce a
getPromotionsToDisable()method that performs a single query?From there we'd then need an array_filter() or a loop that returns the promotions that have an end date in the past or that is maxed used.
Comment #26
jsacksick commentedThe one drawback of a consolidated query is that makes the code less readable and that forces the PHP code to implement "duplicated" logic to check if the promotion expired...
Comment #27
zaporylieChatted with Jonathan on Slack and decided to keep the logic as is for readability but introduced a query limit for safe measure.
Comment #29
jsacksick commentedMerged, thanks!!
Comment #30
jsacksick commented