Форум программистов, компьютерный форум, киберфорум
OpenCart
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.83/18: Рейтинг темы: голосов - 18, средняя оценка - 4.83
2 / 2 / 0
Регистрация: 09.02.2011
Сообщений: 59
1

Мультимагазин. Проверка по store_id

07.11.2014, 08:34. Показов 3354. Ответов 5
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Здравствуйте!
Есть 2 магазина на OpenCart. Основной (розничный) и Оптовый.
Оба магазина работают на одной БД. Оптовый магазин находится на поддомене.
У каждого магазина в Opencart есть свой id (у основного store_id = 0, у розницы store_id = 1)
Есть покупатели: розничные и оптовые. У каждого покупателя есть столбец в БД store_id для принадлежности к конкретному магазину.

Как сделать проверку при авторизации покупателей, на принадлежность к тому магазину, к которому они относятся. Необходимо сделать так чтобы розничный покупатель не смог авторизироваться в Оптовом магазине , а оптовый - в Розничном.

/catalog/controller/account/login.php
PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php 
class ControllerAccountLogin extends Controller {
    private $error = array();
 
    public function index() {
        $this->load->model('account/customer');
 
        // Login override for admin users
        if (!empty($this->request->get['token'])) {
            $this->customer->logout();
            $this->cart->clear();
 
            unset($this->session->data['wishlist']);
            unset($this->session->data['shipping_address_id']);
            unset($this->session->data['shipping_country_id']);
            unset($this->session->data['shipping_zone_id']);
            unset($this->session->data['shipping_postcode']);
            unset($this->session->data['shipping_method']);
            unset($this->session->data['shipping_methods']);
            unset($this->session->data['payment_address_id']);
            unset($this->session->data['payment_country_id']);
            unset($this->session->data['payment_zone_id']);
            unset($this->session->data['payment_method']);
            unset($this->session->data['payment_methods']);
            unset($this->session->data['comment']);
            unset($this->session->data['order_id']);
            unset($this->session->data['coupon']);
            unset($this->session->data['reward']);
            unset($this->session->data['voucher']);
            unset($this->session->data['vouchers']);
 
            $customer_info = $this->model_account_customer->getCustomerByToken($this->request->get['token']);
 
            if ($customer_info && $this->customer->login($customer_info['email'], '', true)) {
                // Default Addresses
                $this->load->model('account/address');
 
                $address_info = $this->model_account_address->getAddress($this->customer->getAddressId());
 
                if ($address_info) {
                    if ($this->config->get('config_tax_customer') == 'shipping') {
                        $this->session->data['shipping_country_id'] = $address_info['country_id'];
                        $this->session->data['shipping_zone_id'] = $address_info['zone_id'];
                        $this->session->data['shipping_postcode'] = $address_info['postcode'];  
                    }
 
                    if ($this->config->get('config_tax_customer') == 'payment') {
                        $this->session->data['payment_country_id'] = $address_info['country_id'];
                        $this->session->data['payment_zone_id'] = $address_info['zone_id'];
                    }
                } else {
                    unset($this->session->data['shipping_country_id']); 
                    unset($this->session->data['shipping_zone_id']);    
                    unset($this->session->data['shipping_postcode']);
                    unset($this->session->data['payment_country_id']);  
                    unset($this->session->data['payment_zone_id']); 
                }
 
                $this->redirect($this->url->link('account/account', '', 'SSL')); 
            }
        }       
 
        if ($this->customer->isLogged()) {  
            $this->redirect($this->url->link('account/account', '', 'SSL'));
        }
 
        $this->language->load('account/login');
 
        $this->document->setTitle($this->language->get('heading_title'));
 
        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
            unset($this->session->data['guest']);
 
            // Default Shipping Address
            $this->load->model('account/address');
 
            $address_info = $this->model_account_address->getAddress($this->customer->getAddressId());
 
            if ($address_info) {
                if ($this->config->get('config_tax_customer') == 'shipping') {
                    $this->session->data['shipping_country_id'] = $address_info['country_id'];
                    $this->session->data['shipping_zone_id'] = $address_info['zone_id'];
                    $this->session->data['shipping_postcode'] = $address_info['postcode'];  
                }
 
                if ($this->config->get('config_tax_customer') == 'payment') {
                    $this->session->data['payment_country_id'] = $address_info['country_id'];
                    $this->session->data['payment_zone_id'] = $address_info['zone_id'];
                }
            } else {
                unset($this->session->data['shipping_country_id']); 
                unset($this->session->data['shipping_zone_id']);    
                unset($this->session->data['shipping_postcode']);
                unset($this->session->data['payment_country_id']);  
                unset($this->session->data['payment_zone_id']); 
            }
 
            // Added strpos check to pass McAfee PCI compliance test (http://forum.opencart.com/viewtopic.php?f=10&t=12043&p=151494#p151295)
            if (isset($this->request->post['redirect']) && (strpos($this->request->post['redirect'], $this->config->get('config_url')) !== false || strpos($this->request->post['redirect'], $this->config->get('config_ssl')) !== false)) {
                $this->redirect(str_replace('&amp;', '&', $this->request->post['redirect']));
            } else {
                $this->redirect($this->url->link('account/account', '', 'SSL')); 
            }
        }
 
        $this->data['breadcrumbs'] = array();
 
        $this->data['breadcrumbs'][] = array(
            'text'      => $this->language->get('text_home'),
            'href'      => $this->url->link('common/home'),         
            'separator' => false
        );
 
        $this->data['breadcrumbs'][] = array(
            'text'      => $this->language->get('text_account'),
            'href'      => $this->url->link('account/account', '', 'SSL'),
            'separator' => $this->language->get('text_separator')
        );
 
        $this->data['breadcrumbs'][] = array(
            'text'      => $this->language->get('text_login'),
            'href'      => $this->url->link('account/login', '', 'SSL'),        
            'separator' => $this->language->get('text_separator')
        );
 
        $this->data['heading_title'] = $this->language->get('heading_title');
 
        $this->data['text_new_customer'] = $this->language->get('text_new_customer');
        $this->data['text_register'] = $this->language->get('text_register');
        $this->data['text_register_account'] = $this->language->get('text_register_account');
        $this->data['text_returning_customer'] = $this->language->get('text_returning_customer');
        $this->data['text_i_am_returning_customer'] = $this->language->get('text_i_am_returning_customer');
        $this->data['text_forgotten'] = $this->language->get('text_forgotten');
 
        $this->data['entry_email'] = $this->language->get('entry_email');
        $this->data['entry_password'] = $this->language->get('entry_password');
 
        $this->data['button_continue'] = $this->language->get('button_continue');
        $this->data['button_login'] = $this->language->get('button_login');
 
        if (isset($this->error['warning'])) {
            $this->data['error_warning'] = $this->error['warning'];
        } else {
            $this->data['error_warning'] = '';
        }
 
        $this->data['action'] = $this->url->link('account/login', '', 'SSL');
        $this->data['register'] = $this->url->link('account/register', '', 'SSL');
        $this->data['forgotten'] = $this->url->link('account/forgotten', '', 'SSL');
 
        // Added strpos check to pass McAfee PCI compliance test (http://forum.opencart.com/viewtopic.php?f=10&t=12043&p=151494#p151295)
        if (isset($this->request->post['redirect']) && (strpos($this->request->post['redirect'], $this->config->get('config_url')) !== false || strpos($this->request->post['redirect'], $this->config->get('config_ssl')) !== false)) {
            $this->data['redirect'] = $this->request->post['redirect'];
        } elseif (isset($this->session->data['redirect'])) {
            $this->data['redirect'] = $this->session->data['redirect'];
 
            unset($this->session->data['redirect']);            
        } else {
            $this->data['redirect'] = '';
        }
 
        if (isset($this->session->data['success'])) {
            $this->data['success'] = $this->session->data['success'];
 
            unset($this->session->data['success']);
        } else {
            $this->data['success'] = '';
        }
 
        if (isset($this->request->post['email'])) {
            $this->data['email'] = $this->request->post['email'];
        } else {
            $this->data['email'] = '';
        }
 
        if (isset($this->request->post['password'])) {
            $this->data['password'] = $this->request->post['password'];
        } else {
            $this->data['password'] = '';
        }
 
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/login.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/account/login.tpl';
        } else {
            $this->template = 'default/template/account/login.tpl';
        }
 
        $this->children = array(
            'common/column_left',
            'common/column_right',
            'common/content_top',
            'common/content_bottom',
            'common/footer',
            'common/header' 
        );
 
        $this->response->setOutput($this->render());
    }
 
    protected function validate() {
        if (!$this->customer->login($this->request->post['email'], $this->request->post['password'])) {
            $this->error['warning'] = $this->language->get('error_login');
        }
 
        $customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);
 
        if ($customer_info && !$customer_info['approved']) {
            $this->error['warning'] = $this->language->get('error_approved');
        }
 
        if (!$this->error) {
            return true;
        } else {
            return false;
        }
    }
}
?>
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
07.11.2014, 08:34
Ответы с готовыми решениями:

Что быстрее, проверка на null, или проверка на тип перечисления в запросе?
вопрос такой. если несколько таблиц. сходных по структуре в запросе. в первой таблице ...

Проверка кода и советы по его улучшению. Генерация случайных чисел и проверка на уникальность
Привет народ! Занимаюсь изучением Java, захотелось реализовать выборку случайных чисел для лотереи....

Проверка на совпадение + проверка строки на содержание спец. символов
В общем ситуация такая: есть типизированный файл, форма для добавления пользователей (которые...

Проверка метабокса - не сохранять пост, если проверка не пройдена
Всем здравствуйте. Изучаю метабоксы в WP. Столкнулся с проблемой проверки метабокса. Возьмем мой...

5
2 / 2 / 0
Регистрация: 09.02.2011
Сообщений: 59
07.11.2014, 08:37  [ТС] 2
часть кода где встречаается store_id /catalog/model/account/customer.php
PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
class ModelAccountCustomer extends Model {
    public function addCustomer($data) {
        if (isset($data['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($data['customer_group_id'], $this->config->get('config_customer_group_display'))) {
            $customer_group_id = $data['customer_group_id'];
        } else {
            $customer_group_id = $this->config->get('config_customer_group_id');
        }
 
        $this->load->model('account/customer_group');
 
        $customer_group_info = $this->model_account_customer_group->getCustomerGroup($customer_group_id);
 
        $this->db->query("INSERT INTO " . DB_PREFIX . "customer SET store_id = '" . (int)$this->config->get('config_store_id') . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', salt = '" . $this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)) . "', password = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($data['password'])))) . "', newsletter = '" . (isset($data['newsletter']) ? (int)$data['newsletter'] : 0) . "', customer_group_id = '" . (int)$customer_group_id . "', ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "', status = '1', approved = '" . (int)!$customer_group_info['approval'] . "', date_added = NOW()");
 
        $customer_id = $this->db->getLastId();
 
        $this->db->query("INSERT INTO " . DB_PREFIX . "address SET customer_id = '" . (int)$customer_id . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', company = '" . $this->db->escape($data['company']) . "', company_id = '" . $this->db->escape($data['company_id']) . "', tax_id = '" . $this->db->escape($data['tax_id']) . "', address_1 = '" . $this->db->escape($data['address_1']) . "', address_2 = '" . $this->db->escape($data['address_2']) . "', city = '" . $this->db->escape($data['city']) . "', postcode = '" . $this->db->escape($data['postcode']) . "', country_id = '" . (int)$data['country_id'] . "', zone_id = '" . (int)$data['zone_id'] . "'");
 
        $address_id = $this->db->getLastId();
 
        $this->db->query("UPDATE " . DB_PREFIX . "customer SET address_id = '" . (int)$address_id . "' WHERE customer_id = '" . (int)$customer_id . "'");
 
        $this->language->load('mail/customer');
 
        $subject = sprintf($this->language->get('text_subject'), $this->config->get('config_name'));
 
        $message = sprintf($this->language->get('text_welcome'), $this->config->get('config_name')) . "\n\n";
 
        if (!$customer_group_info['approval']) {
            $message .= $this->language->get('text_login') . "\n";
        } else {
            $message .= $this->language->get('text_approval') . "\n";
        }
0
3 / 3 / 0
Регистрация: 10.10.2012
Сообщений: 70
12.12.2015, 20:12 3
Привет. У Вас получилось реализовать?
0
0 / 0 / 1
Регистрация: 19.12.2015
Сообщений: 3
19.12.2015, 14:59 4
Focto, Меня тоже интересует данная тема. Если у вас получилось реализовать разделение подскажите как вы это сделали.
0
2 / 2 / 0
Регистрация: 09.02.2011
Сообщений: 59
21.12.2015, 15:56  [ТС] 5
kogen369,

в system/library/customer.php

меняем

PHP/HTML
1
2
3
4
5
6
7
    public function login($email, $password, $override = false) {
        if ($override) {
            ...
        } else {
            $customer_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE LOWER(email) = '" . $this->db->escape(utf8_strtolower($email)) . "' AND (password = SHA1(CONCAT(salt, SHA1(CONCAT(salt, SHA1('" . $this->db->escape($password) . "'))))) OR password = '" . $this->db->escape(md5($password)) . "') AND status = '1' AND approved = '1'");
        }
...
на

PHP/HTML
1
2
3
4
5
6
7
8
9
    public function login($email, $password, $override = false) {
        if ($override) {
            ...
        } else {
            //$noCrossStoreCustomerSql = "";
            $noCrossStoreCustomerSql = " AND store_id = '".(int)$this->config->get('config_store_id')."'";
            $customer_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE LOWER(email) = '" . $this->db->escape(utf8_strtolower($email)) . "' AND (password = SHA1(CONCAT(salt, SHA1(CONCAT(salt, SHA1('" . $this->db->escape($password) . "'))))) OR password = '" . $this->db->escape(md5($password)) . "') AND status = '1' AND approved = '1'".$noCrossStoreCustomerSql."");
        }
...
0
3 / 3 / 0
Регистрация: 10.10.2012
Сообщений: 70
21.12.2015, 18:01 6
Спасибо, будем пробовать..
0
21.12.2015, 18:01
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
21.12.2015, 18:01
Помогаю со студенческими работами здесь

Проверка нескольких textbox на пустоту, а также проверка их значения
Имеется textbox1, textbox2, textbox3, button1. Нужно сделать так, чтобы проверялось условие: Если...

Проверка наличия шрифта в системе и установить если отсуствует + проверка запущен ли проект с правами админа
Здравствуйте. Как можно проверить наличия шрифта в системе и установить его если отсуствует. Ну...

Проверка internet connection. Проверка доступности сети
Добрый день. Для проверки Internet Connection советуют делать что-то вроде: private boolean...

Проверка данных в Access (проверка Статуса Кандидата)
Всем доброго времени суток! Проблема такая. В бд есть таблица кандидатов, в ней есть номер...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
6
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru