You are here

public function PromotionUsage::register in Commerce Core 8.2

Registers usage for the given order.

Parameters

\Drupal\commerce_order\Entity\OrderInterface $order: The order.

\Drupal\commerce_promotion\Entity\PromotionInterface $promotion: The promotion.

\Drupal\commerce_promotion\Entity\CouponInterface $coupon: (Optional) The used coupon.

Overrides PromotionUsageInterface::register

File

modules/promotion/src/PromotionUsage.php, line 33

Class

PromotionUsage

Namespace

Drupal\commerce_promotion

Code

public function register(OrderInterface $order, PromotionInterface $promotion, CouponInterface $coupon = NULL) {
  $this->connection
    ->insert('commerce_promotion_usage')
    ->fields([
    'promotion_id' => $promotion
      ->id(),
    'coupon_id' => $coupon ? $coupon
      ->id() : 0,
    'order_id' => $order
      ->id(),
    'mail' => $order
      ->getEmail(),
  ])
    ->execute();
}