Issue #2901504 by sumanthkumarc: Provide limit by no of orders per user condition for promotions in commerce core - #771
Conversation
…er condition for promotions in commerce core
|
@mglaman Thanks for the review :) When you say limited per user? you mean the option "Usage limits" available in the right hand panes on promotions form?? If so , i saw that no where the mail is passed to check availability per user, also i guess its confusing for user to understand if this is total limit irrespective of users or per user limit. See this available method from promotion class. public function available(OrderInterface $order) {
if (!$this->isEnabled()) {
return FALSE;
}
if (!in_array($order->bundle(), $this->getOrderTypeIds())) {
return FALSE;
}
if (!in_array($order->getStoreId(), $this->getStoreIds())) {
return FALSE;
}
$time = \Drupal::time()->getRequestTime();
if ($this->getStartDate()->format('U') > $time) {
return FALSE;
}
$end_date = $this->getEndDate();
if ($end_date && $end_date->format('U') <= $time) {
return FALSE;
}
if ($usage_limit = $this->getUsageLimit()) {
/** @var \Drupal\commerce_promotion\PromotionUsageInterface $usage */
$usage = \Drupal::service('commerce_promotion.usage');
if ($usage_limit <= $usage->getUsage($this)) {
return FALSE;
}
}
return TRUE;
}let me know if i'm missing anything here :) |
mglaman
left a comment
There was a problem hiding this comment.
@sumanthkumarc I see. I thought we had rate limiting per user.
|
|
||
| $orders = $this->orderStorage->getQuery() | ||
| ->condition('cart', FALSE) | ||
| ->condition('uid', $user_id) |
There was a problem hiding this comment.
Anonymous orders would always fail, correct? Should we be looking up the user's email (or current order email) and any orders with that email?
|
@mglaman Rate/usage limiting is not the same thing. That is "a user can only receive this promotion once". This is "the user can only receive this promotion if this is his first order (or one of the first N)". |

No description provided.