success.php 4.54 KB
<?php
    /**
     * @var Orders $order
     * @var array  $variants
     */
    use common\models\Orders;
    
    $order_data = \Yii::$app->session[ 'order_data' ];
    \Yii::$app->session->remove('order_data');
    $order = $order_data[ 'order' ];
    $variants = $order_data[ 'variants' ];
    
    $this->params[ 'remarketing' ][ 'type' ] = 'conversion';
    if (count($variants) > 1) {
        foreach ($variants as $variant) {
            $this->params[ 'remarketing' ][ 'id' ][] = $variant[ 'mod_id' ];
            $this->params[ 'remarketing' ][ 'price' ][] = $variant[ 'price' ];
        }
    } elseif (!empty( $variants ) && isset( $variants[ 0 ] )) {
        $this->params[ 'remarketing' ][ 'id' ] = $variants[ 0 ][ 'mod_id' ];
        $this->params[ 'remarketing' ][ 'price' ] = $variants[ 0 ][ 'price' ];
    } else {
        $this->params[ 'remarketing' ][ 'id' ] = '';
        $this->params[ 'remarketing' ][ 'price' ] = '';
    }

?>
<div class="block-100">
    <div class="container">
        <div class="col-xs-12">
            <div class="ordering_tbl">
                <form action="ordering.htm?step4" method="post" name="orderForm" id="orderForm" enctype="multipart/form-data">
                    <div class="orderBox">
                        <table width="725px" border="0" cellspacing="0" cellpadding="5" style="margin:auto;">
                            <tbody>
                                <tr valign="middle">
                                    <td height="10" nowrap=""></td>
                                </tr>
                                <tr valign="top">
                                    <td>
                                        Заказ успешно осуществлён! Во время обработки вашего заказа менеджер свяжется с Вами.
                                        <br><br>
                                        <div align="center">
                                            <b>Уникальный номер заказа</b>: <?= $order->id; ?>
                                        </div>
                                        <br><br>
                                        <div align="center">
                                            <font size="+1">Спасибо за заказ!!</font><br><br>
                                            <a href="/" style="display:inline">« На главную</a>
                                        </div>
                                        <!-- Google ECommerce Code -->
                                        <script>
                                            ga('require', 'ecommerce');
                                            <?php
                                            $sum = 0;
                                            foreach ($order->products as $product) {
                                            ?>
                                            ga(
                                                'ecommerce:addItem', {
                                                    'id': '<?= $order->id; ?>',
                                                    'name': '<?= $product->product_name; ?>',
                                                    'price': '<?= $product->price; ?>',
                                                    'sku': '<?= $product->sku; ?>',
                                                    'quantity': '<?= $product->quantity; ?>'
                                                }
                                            );
                                            <?php
                                            $sum += $product->sum_cost;
                                            }
                                            ?>
                                            ga(
                                                'ecommerce:addTransaction', {
                                                    'id': '<?= $order->id; ?>',
                                                    'affiliation': 'www.linija-svitla.ua',
                                                    'revenue': '<?= $sum; ?>',
                                                }
                                            );
                                            ga('ecommerce:send');
                                        </script>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        <br>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>