55use Drupal \commerce \CommerceContentEntityStorage ;
66use Drupal \commerce_order \Entity \OrderTypeInterface ;
77use Drupal \commerce_store \Entity \StoreInterface ;
8+ use Drupal \Component \Datetime \TimeInterface ;
89use Drupal \Core \Cache \CacheBackendInterface ;
910use Drupal \Core \Database \Connection ;
1011use Drupal \Core \Entity \EntityManagerInterface ;
@@ -25,6 +26,13 @@ class PromotionStorage extends CommerceContentEntityStorage implements Promotion
2526 */
2627 protected $ usage ;
2728
29+ /**
30+ * The time.
31+ *
32+ * @var \Drupal\Component\Datetime\TimeInterface
33+ */
34+ protected $ time ;
35+
2836 /**
2937 * Constructs a new PromotionStorage object.
3038 *
@@ -42,11 +50,14 @@ class PromotionStorage extends CommerceContentEntityStorage implements Promotion
4250 * The event dispatcher.
4351 * @param \Drupal\commerce_promotion\PromotionUsageInterface $usage
4452 * The usage.
53+ * @param \Drupal\Component\Datetime\TimeInterface $time
54+ * The time.
4555 */
46- public function __construct (EntityTypeInterface $ entity_type , Connection $ database , EntityManagerInterface $ entity_manager , CacheBackendInterface $ cache , LanguageManagerInterface $ language_manager , EventDispatcherInterface $ event_dispatcher , PromotionUsageInterface $ usage ) {
56+ public function __construct (EntityTypeInterface $ entity_type , Connection $ database , EntityManagerInterface $ entity_manager , CacheBackendInterface $ cache , LanguageManagerInterface $ language_manager , EventDispatcherInterface $ event_dispatcher , PromotionUsageInterface $ usage, TimeInterface $ time ) {
4757 parent ::__construct ($ entity_type , $ database , $ entity_manager , $ cache , $ language_manager , $ event_dispatcher );
4858
4959 $ this ->usage = $ usage ;
60+ $ this ->time = $ time ;
5061 }
5162
5263 /**
@@ -60,22 +71,24 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
6071 $ container ->get ('cache.entity ' ),
6172 $ container ->get ('language_manager ' ),
6273 $ container ->get ('event_dispatcher ' ),
63- $ container ->get ('commerce_promotion.usage ' )
74+ $ container ->get ('commerce_promotion.usage ' ),
75+ $ container ->get ('datetime.time ' )
6476 );
6577 }
6678
6779 /**
6880 * {@inheritdoc}
6981 */
7082 public function loadAvailable (OrderTypeInterface $ order_type , StoreInterface $ store ) {
83+ $ today = gmdate ('Y-m-d ' , $ this ->time ->getRequestTime ());
7184 $ query = $ this ->getQuery ();
7285 $ or_condition = $ query ->orConditionGroup ()
73- ->condition ('end_date ' , gmdate ( ' Y-m-d ' ) , '>= ' )
74- ->notExists ('end_date ' , gmdate ( ' Y-m-d ' ) );
86+ ->condition ('end_date ' , $ today , '>= ' )
87+ ->notExists ('end_date ' , $ today );
7588 $ query
7689 ->condition ('stores ' , [$ store ->id ()], 'IN ' )
7790 ->condition ('order_types ' , [$ order_type ->id ()], 'IN ' )
78- ->condition ('start_date ' , gmdate ( ' Y-m-d ' ) , '<= ' )
91+ ->condition ('start_date ' , $ today , '<= ' )
7992 ->condition ('status ' , TRUE )
8093 ->condition ($ or_condition );
8194 // Only load promotions without coupons. Promotions with coupons are loaded
0 commit comments