Craft\InstantAnalyticsService::addCommerceOrderToAnalytics PHP Method

addCommerceOrderToAnalytics() public method

Add a Craft Commerce OrderModel to an Analytics object
public addCommerceOrderToAnalytics ( IAnalytics $analytics = null, Commerce_OrderModel $orderModel = null )
$analytics IAnalytics the Analytics object
$orderModel Commerce_OrderModel the Product or Variant
    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++;
                }
            }
        }
    }