Commit e57b5eaf024b93dce1d7335774fce311ee6f3cf5
1 parent
28ccb9ba
29.06.16
Showing
2 changed files
with
28 additions
and
24 deletions
Show diff stats
frontend/controllers/BasketController.php
... | ... | @@ -123,9 +123,31 @@ class BasketController extends Controller |
123 | 123 | $text = "# zakaz: ". $order->id .". V blijayshee vremya menedjer svyajetsya s Vami. (044) 303 90 15"; |
124 | 124 | Yii::$app->sms->send($order->phone, $text); |
125 | 125 | |
126 | - return $this->render('success',[ | |
127 | - 'order' => $order, | |
128 | - 'variants' => $productV, | |
126 | + $js = ''; | |
127 | + if(isset($productV) && isset($order)){ | |
128 | + $orderData = " | |
129 | + ga('require', 'ecommerce'); | |
130 | + ga('ecommerce:addTransaction', { | |
131 | + 'id': $order->id, // где ID - транзакции, обязательно | |
132 | + });"; | |
133 | + | |
134 | + foreach($productV as $row){ | |
135 | + $orderData .= " | |
136 | + ga('ecommerce:addItem', { | |
137 | + 'id': {$order->id}, // ID - транзакции, обязательно | |
138 | + 'name': \"{$row['product_name']} {$row['name']}\", // Имя товара | |
139 | + 'price': {$row['price']}, // Цена товара | |
140 | + 'quantity': {$row['count']} // Количество | |
141 | + });"; | |
142 | + | |
143 | + } | |
144 | + $orderData .= "ga('ecommerce:send');"; | |
145 | + $js = $orderData; | |
146 | + | |
147 | + } | |
148 | + | |
149 | + return $this->redirect('success',[ | |
150 | + 'js' => $js | |
129 | 151 | ]); |
130 | 152 | } |
131 | 153 | } | ... | ... |
frontend/views/basket/success.php
... | ... | @@ -9,27 +9,9 @@ $this->title = 'Корзина'; |
9 | 9 | $this->registerMetaTag(['name' => 'description', 'content' => 'Корзина']); |
10 | 10 | $this->registerMetaTag(['name' => 'keywords', 'content' => 'Корзина']); |
11 | 11 | |
12 | -if(isset($variants) && isset($order)){ | |
13 | - $orderData = " | |
14 | - ga('require', 'ecommerce'); | |
15 | - ga('ecommerce:addTransaction', { | |
16 | - 'id': $order->id, // где ID - транзакции, обязательно | |
17 | - });"; | |
18 | - | |
19 | - foreach($variants as $row){ | |
20 | - $orderData .= " | |
21 | - ga('ecommerce:addItem', { | |
22 | - 'id': {$order->id}, // ID - транзакции, обязательно | |
23 | - 'name': \"{$row['product_name']} {$row['name']}\", // Имя товара | |
24 | - 'price': {$row['price']}, // Цена товара | |
25 | - 'quantity': {$row['count']} // Количество | |
26 | - });"; | |
27 | - | |
28 | - } | |
29 | - $orderData .= "ga('ecommerce:send');"; | |
30 | - $this->registerJs ($orderData, View::POS_END); | |
31 | - | |
32 | -} | |
12 | + $this->registerJs ($js, View::POS_END); | |
13 | + | |
14 | + | |
33 | 15 | |
34 | 16 | |
35 | 17 | ?> | ... | ... |