public function addCommerceOrderToAnalytics($analytics = null, $orderModel = null)
{
if ($orderModel) {
if ($analytics) {
// First, include the transaction data
$analytics->setTransactionId($orderModel->number)->setRevenue($orderModel->totalPrice)->setTax($orderModel->TotalTax)->setShipping($orderModel->totalShippingCost);
// Coupon code?
if ($orderModel->couponCode) {
$analytics->setCouponCode($orderModel->couponCode);
}
// Add each line item in the transaction
// Two cases - variant and non variant products
$index = 1;
foreach ($orderModel->lineItems as $key => $lineItem) {
$this->addProductDataFromLineItem($analytics, $lineItem, $index, "");
$index++;
}
}
}
}