Issues (2407)

application/controller/common/cart.php (4 issues)

1
<?php
2
3
/* 	Divine CMS - Open source CMS for widespread use.
4
    Copyright (c) 2019 Mykola Burakov ([email protected])
5
6
    See SOURCE.txt for other and additional information.
7
8
    This file is part of Divine CMS.
9
10
    This program is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
15
    This program is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
    GNU General Public License for more details.
19
20
    You should have received a copy of the GNU General Public License
21
    along with this program. If not, see <http://www.gnu.org/licenses/>. */
22
23
class ControllerCommonCart extends \Divine\Engine\Core\Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
24
{
25
    public function index()
0 ignored issues
show
Expected 2 blank lines before function; 0 found
Loading history...
26
    {
27
        $this->load->language('common/cart');
28
29
        // Totals
30
        $this->load->model('extension/extension');
31
32
        $totals = array();
33
        $total = 0;
34
35
        // Because __call can not keep var references so we put them into an array.
36
        $total_data = array(
37
            'totals' => &$totals,
38
            'total'  => &$total
39
        );
40
41
        // Display prices
42
        if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
43
            $sort_order = array();
44
45
            $results = $this->model_extension_extension->getExtensions('total');
46
47
            foreach ($results as $key => $value) {
48
                $sort_order[$key] = $this->config->get($value['code'] . '_sort_order');
49
            }
50
51
            array_multisort($sort_order, SORT_ASC, $results);
52
53
            foreach ($results as $result) {
54
                if ($this->config->get($result['code'] . '_status')) {
55
                    $this->load->model('extension/total/' . $result['code']);
56
57
                    // We have to put the totals in an array so that they pass by reference.
58
                    $this->{'model_extension_total_' . $result['code']}->getTotal($total_data);
59
                }
60
            }
61
62
            $sort_order = array();
63
64
            foreach ($totals as $key => $value) {
65
                $sort_order[$key] = $value['sort_order'];
66
            }
67
68
            array_multisort($sort_order, SORT_ASC, $totals);
69
        }
70
71
        $data['text_empty'] = $this->language->get('text_empty');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Loading history...
72
        $data['text_empty_info'] = $this->language->get('text_empty_info');
73
        $data['text_cart'] = $this->language->get('text_cart');
74
        $data['text_checkout'] = $this->language->get('text_checkout');
75
76
        $data['text_items'] = $this->language->get('text_items');
77
        $data['products_count'] = $this->cart->countProducts();
78
        $data['products_price'] = $this->currency->format($total, $this->session->data['currency']);
79
80
        $data['text_header_cart'] = $this->language->get('text_header_cart');
81
        $data['text_header_cart_qt_info'] = $this->language->get('text_header_cart_qt_info');
82
83
        $data['button_remove'] = $this->language->get('button_remove');
84
85
        
86
        $this->load->model('tool/upload');
87
88
        $data['products'] = array();
89
90
        foreach ($this->cart->getProducts() as $product) {
91
            if ($product['image']) {
92
                $image = '/public_html/assets/images/' . $product['image'];
93
            } else {
94
                $image = '/public_html/assets/images/no_image.png';
95
            }
96
97
            $option_data = array();
98
99
            foreach ($product['option'] as $option) {
100
                if ($option['type'] != 'file') {
101
                    $value = $option['value'];
102
                } else {
103
                    $upload_info = $this->model_tool_upload->getUploadByCode($option['value']);
104
105
                    if ($upload_info) {
106
                        $value = $upload_info['name'];
107
                    } else {
108
                        $value = '';
109
                    }
110
                }
111
112
                $option_data[] = array(
113
                    'name'  => $option['name'],
114
                    'value' => (\voku\helper\UTF8::strlen($value) > 20 ? \voku\helper\UTF8::substr($value, 0, 20) . '..' : $value),
0 ignored issues
show
Are you sure voku\helper\UTF8::substr($value, 0, 20) of type false|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

114
                    'value' => (\voku\helper\UTF8::strlen($value) > 20 ? /** @scrutinizer ignore-type */ \voku\helper\UTF8::substr($value, 0, 20) . '..' : $value),
Loading history...
115
                    'type'  => $option['type']
116
                );
117
            }
118
119
            // Display prices
120
            if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
121
                $unit_price = $product['price'];
122
123
                $price = $this->currency->format($unit_price, $this->session->data['currency']);
124
                $total = $this->currency->format($unit_price * $product['quantity'], $this->session->data['currency']);
125
            } else {
126
                $price = false;
127
                $total = false;
128
            }
129
130
            $data['products'][] = array(
131
                'cart_id'   => $product['cart_id'],
132
                'thumb'     => $image,
133
                'name'      => $product['name'],
134
                'model'     => $product['model'],
135
                'option'    => $option_data,
136
                'quantity'  => $product['quantity'],
137
                'price'     => $price,
138
                'total'     => $total,
139
                'href'      => $this->url->link('product/product', 'product_id=' . $product['product_id'])
140
            );
141
        }
142
143
        $data['totals'] = array();
144
145
        foreach ($totals as $total) {
146
            $data['totals'][] = array(
147
                'title' => $total['title'],
148
                'text'  => $this->currency->format($total['value'], $this->session->data['currency']),
149
            );
150
        }
151
152
        $data['cart'] = $this->url->link('checkout/cart');
153
        // $data['checkout'] = $this->url->link('checkout/checkout', '', true);
154
        $data['checkout'] = $this->url->link('checkout/onepagecheckout', '', true);
155
156
        return $this->load->view('common/cart', $data);
157
    }
158
159
    public function info()
160
    {
161
        $this->response->setOutput($this->index());
162
    }
163
}
164