private function EventTrackerService::getCouponCode in Commerce Google Tag Manager 8.2
Same name and namespace in other branches
- 8 src/EventTrackerService.php \Drupal\commerce_google_tag_manager\EventTrackerService::getCouponCode()
Get the coupon code(s) used with the given commerce order.
Parameters
\Drupal\commerce_order\Entity\OrderInterface $order: The order containing potential coupon code(s).
Return value
string The coupon values separated by comma.
1 call to EventTrackerService::getCouponCode()
- EventTrackerService::purchase in src/
EventTrackerService.php - Track a purchase of the given order entity.
File
- src/
EventTrackerService.php, line 472
Class
- EventTrackerService
- Track different events from Google's Enhanced Ecommerce.
Namespace
Drupal\commerce_google_tag_managerCode
private function getCouponCode(OrderInterface $order) {
if (!$order
->hasField('coupons') || $order
->get('coupons')
->isEmpty()) {
return '';
}
$coupon_codes = array_map(function ($coupon) {
/** @var \Drupal\commerce_promotion\Entity\CouponInterface $coupon */
return $coupon
->getCode();
}, $order
->get('coupons')
->referencedEntities());
if (count($coupon_codes) === 1) {
return $coupon_codes[0];
}
return implode(', ', $coupon_codes);
}