Commit 8467c8d3f77c35043d5a346ca00c390b6e64d7c9
1 parent
2e23f037
Google ecommerce
Showing
3 changed files
with
108 additions
and
83 deletions
Show diff stats
common/models/Orders.php
common/models/OrdersProducts.php
1 | 1 | <?php |
2 | - | |
3 | -namespace common\models; | |
4 | - | |
5 | -use common\modules\product\models\ProductVariant; | |
6 | - | |
7 | -class OrdersProducts extends \yii\db\ActiveRecord | |
8 | -{ | |
9 | - public static function tableName() | |
10 | - { | |
11 | - return 'orders_products'; | |
12 | - } | |
13 | 2 | |
14 | - public function rules() | |
15 | - { | |
16 | - return [ | |
17 | - [['order_id'], 'required'], | |
18 | - //['email', 'email'], | |
19 | - [['product_name','name','price','count','sum_cost','mod_id','sku'], 'safe'], | |
20 | - ]; | |
21 | - } | |
3 | + namespace common\models; | |
22 | 4 | |
5 | + use common\modules\product\models\ProductVariant; | |
23 | 6 | |
24 | - public function attributeLabels() | |
25 | - { | |
26 | - return [ | |
27 | - 'product_name'=>'Продукт', | |
28 | - 'name'=>'Вид', | |
29 | - 'art'=>'Артикул', | |
30 | - 'cost'=>'Цена за один', | |
31 | - 'count'=>'Кол.', | |
32 | - 'sum_cost'=>'Сумма', | |
33 | - ]; | |
34 | - } | |
35 | - | |
36 | - public function getProductVariant() | |
7 | + class OrdersProducts extends \yii\db\ActiveRecord | |
37 | 8 | { |
38 | - return $this->hasOne(ProductVariant::className(), ['product_variant_id' => 'mod_id']); | |
39 | - } | |
40 | -} | |
41 | 9 | \ No newline at end of file |
10 | + public static function tableName() | |
11 | + { | |
12 | + return 'orders_products'; | |
13 | + } | |
14 | + | |
15 | + public function rules() | |
16 | + { | |
17 | + return [ | |
18 | + [ | |
19 | + [ 'order_id' ], | |
20 | + 'required', | |
21 | + ], | |
22 | + //['email', 'email'], | |
23 | + [ | |
24 | + [ | |
25 | + 'product_name', | |
26 | + 'name', | |
27 | + 'price', | |
28 | + 'count', | |
29 | + 'sum_cost', | |
30 | + 'mod_id', | |
31 | + 'sku', | |
32 | + ], | |
33 | + 'safe', | |
34 | + ], | |
35 | + ]; | |
36 | + } | |
37 | + | |
38 | + public function attributeLabels() | |
39 | + { | |
40 | + return [ | |
41 | + 'product_name' => 'Продукт', | |
42 | + 'name' => 'Вид', | |
43 | + 'art' => 'Артикул', | |
44 | + 'cost' => 'Цена за один', | |
45 | + 'count' => 'Кол.', | |
46 | + 'sum_cost' => 'Сумма', | |
47 | + ]; | |
48 | + } | |
49 | + | |
50 | + public function getProductVariant() | |
51 | + { | |
52 | + return $this->hasOne(ProductVariant::className(), [ 'product_variant_id' => 'mod_id' ]); | |
53 | + } | |
54 | + } | |
42 | 55 | \ No newline at end of file | ... | ... |
frontend/views/order/success.php
... | ... | @@ -9,19 +9,19 @@ |
9 | 9 | \Yii::$app->session->remove('order_data'); |
10 | 10 | $order = $order_data[ 'order' ]; |
11 | 11 | $variants = $order_data[ 'variants' ]; |
12 | - | |
13 | - $this->params['remarketing']['type'] = 'conversion'; | |
12 | + | |
13 | + $this->params[ 'remarketing' ][ 'type' ] = 'conversion'; | |
14 | 14 | if (count($variants) > 1) { |
15 | 15 | foreach ($variants as $variant) { |
16 | - $this->params['remarketing']['id'][] = $variant['mod_id']; | |
17 | - $this->params['remarketing']['price'][] = $variant['price']; | |
16 | + $this->params[ 'remarketing' ][ 'id' ][] = $variant[ 'mod_id' ]; | |
17 | + $this->params[ 'remarketing' ][ 'price' ][] = $variant[ 'price' ]; | |
18 | 18 | } |
19 | - } elseif(!empty($variants) && isset($variants[0])) { | |
20 | - $this->params['remarketing']['id'] = $variants[0]['mod_id']; | |
21 | - $this->params['remarketing']['price'] = $variants[0]['price']; | |
19 | + } elseif (!empty( $variants ) && isset( $variants[ 0 ] )) { | |
20 | + $this->params[ 'remarketing' ][ 'id' ] = $variants[ 0 ][ 'mod_id' ]; | |
21 | + $this->params[ 'remarketing' ][ 'price' ] = $variants[ 0 ][ 'price' ]; | |
22 | 22 | } else { |
23 | - $this->params['remarketing']['id'] = ''; | |
24 | - $this->params['remarketing']['price'] = ''; | |
23 | + $this->params[ 'remarketing' ][ 'id' ] = ''; | |
24 | + $this->params[ 'remarketing' ][ 'price' ] = ''; | |
25 | 25 | } |
26 | 26 | |
27 | 27 | ?> |
... | ... | @@ -33,45 +33,52 @@ |
33 | 33 | <div class="orderBox"> |
34 | 34 | <table width="725px" border="0" cellspacing="0" cellpadding="5" style="margin:auto;"> |
35 | 35 | <tbody> |
36 | - <tr valign="middle"> | |
37 | - <td height="10" nowrap=""></td> | |
38 | - </tr> | |
39 | - <tr valign="top"> | |
40 | - <td> | |
41 | - Заказ успешно осуществлён! Во время обработки вашего заказа менеджер свяжется с Вами. | |
42 | - <br><br> | |
43 | - <div align="center"> | |
44 | - <b>Уникальный номер заказа</b>: <?= $order->id; ?> | |
45 | - </div> | |
46 | - <br><br> | |
47 | - <div align="center"> | |
48 | - <font size="+1">Спасибо за заказ!!</font><br><br> | |
49 | - <a href="/" style="display:inline">« На главную</a> | |
50 | - </div> | |
51 | - <!-- Google ECommerce Code --> | |
52 | - <script> | |
53 | - ga('require', 'ecommerce'); | |
54 | - ga( | |
55 | - 'ecommerce:addItem', { | |
56 | - 'id' : '80b44fd0967bebcc4d3f5ba9ceb4d06f', | |
57 | - 'name' : 'подвесной светильник Massive', | |
58 | - 'price' : '366', | |
59 | - 'category' : 'люстры', | |
60 | - 'quantity' : '1' | |
61 | - } | |
62 | - ); | |
63 | - ga( | |
64 | - 'ecommerce:addTransaction', { | |
65 | - 'id' : '80b44fd0967bebcc4d3f5ba9ceb4d06f', | |
66 | - 'affiliation' : 'www.linija-svitla.ua', | |
67 | - 'revenue' : '366', | |
68 | - 'tax' : '73.2' | |
36 | + <tr valign="middle"> | |
37 | + <td height="10" nowrap=""></td> | |
38 | + </tr> | |
39 | + <tr valign="top"> | |
40 | + <td> | |
41 | + Заказ успешно осуществлён! Во время обработки вашего заказа менеджер свяжется с Вами. | |
42 | + <br><br> | |
43 | + <div align="center"> | |
44 | + <b>Уникальный номер заказа</b>: <?= $order->id; ?> | |
45 | + </div> | |
46 | + <br><br> | |
47 | + <div align="center"> | |
48 | + <font size="+1">Спасибо за заказ!!</font><br><br> | |
49 | + <a href="/" style="display:inline">« На главную</a> | |
50 | + </div> | |
51 | + <!-- Google ECommerce Code --> | |
52 | + <script> | |
53 | + ga('require', 'ecommerce'); | |
54 | + <?php | |
55 | + $sum = 0; | |
56 | + foreach ($order->products as $product) { | |
57 | + ?> | |
58 | + ga( | |
59 | + 'ecommerce:addItem', { | |
60 | + 'id': '<?= $order->id; ?>', | |
61 | + 'name': '<?= $product->product_name; ?>', | |
62 | + 'price': '<?= $product->price; ?>', | |
63 | + 'sku': '<?= $product->sku; ?>', // Product sku | |
64 | + 'quantity': '<?= $product->quantity; ?>' // Product count | |
65 | + } | |
66 | + ); | |
67 | + <?php | |
68 | + $sum += $product->sum_cost; | |
69 | 69 | } |
70 | - ); | |
71 | - ga('ecommerce:send'); | |
72 | - </script> | |
73 | - </td> | |
74 | - </tr> | |
70 | + ?> | |
71 | + ga( | |
72 | + 'ecommerce:addTransaction', { | |
73 | + 'id': '<?= $order->id; ?>', | |
74 | + 'affiliation': 'www.linija-svitla.ua', | |
75 | + 'revenue': '<?= $sum; ?>', | |
76 | + } | |
77 | + ); | |
78 | + ga('ecommerce:send'); | |
79 | + </script> | |
80 | + </td> | |
81 | + </tr> | |
75 | 82 | </tbody> |
76 | 83 | </table> |
77 | 84 | <br> | ... | ... |