Skip to content

Commit 7478e95

Browse files
committed
Fix for prestashop 1.6
1 parent 2bf7ca5 commit 7478e95

File tree

10 files changed

+290
-42
lines changed

10 files changed

+290
-42
lines changed

model/common/address.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
class ModelCommonAddress extends Model
4+
{
5+
public function getAddress($address_id)
6+
{
7+
$sql = new DbQuery();
8+
$sql->select('*');
9+
$sql->from('address', 'a');
10+
$sql->where('a.`id_address` = '.$address_id);
11+
12+
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
13+
14+
return !empty($result) ? $result[0] : false;
15+
}
16+
}

model/common/customer.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
class ModelCommonCustomer extends Model
4+
{
5+
public function updateCustomer($customer)
6+
{
7+
$this->context->cookie->id_compare = isset($this->context->cookie->id_compare) ? $this->context->cookie->id_compare: CompareProduct::getIdCompareByIdCustomer($customer->id);
8+
$this->context->cookie->id_customer = (int)($customer->id);
9+
$this->context->cookie->customer_lastname = $customer->lastname;
10+
$this->context->cookie->customer_firstname = $customer->firstname;
11+
$this->context->cookie->logged = 1;
12+
$customer->logged = 1;
13+
$this->context->cookie->is_guest = $customer->isGuest();
14+
$this->context->cookie->passwd = $customer->passwd;
15+
$this->context->cookie->email = $customer->email;
16+
17+
// Add customer to the context
18+
$this->context->customer = $customer;
19+
20+
if (Configuration::get('PS_CART_FOLLOWING') && (empty($this->context->cookie->id_cart) || Cart::getNbProducts($this->context->cookie->id_cart) == 0) && $id_cart = (int)Cart::lastNoneOrderedCart($this->context->customer->id)) {
21+
$this->context->cart = new Cart($id_cart);
22+
} else {
23+
$id_carrier = (int)$this->context->cart->id_carrier;
24+
$this->context->cart->id_carrier = 0;
25+
$this->context->cart->setDeliveryOption(null);
26+
}
27+
$this->context->cart->id_customer = (int)$customer->id;
28+
$this->context->cart->secure_key = $customer->secure_key;
29+
30+
if ($this->ajax && isset($id_carrier) && $id_carrier && Configuration::get('PS_ORDER_PROCESS_TYPE')) {
31+
$delivery_option = array($this->context->cart->id_address_delivery => $id_carrier.',');
32+
$this->context->cart->setDeliveryOption($delivery_option);
33+
}
34+
35+
$this->context->cart->save();
36+
$this->context->cookie->id_cart = (int)$this->context->cart->id;
37+
$this->context->cookie->write();
38+
$this->context->cart->autosetProductAddress();
39+
}
40+
}

model/common/language.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ public function getLanguageByLocale($locale)
1919
$sql->select('*');
2020
$sql->from('lang', 'l');
2121
$sql->leftJoin('lang_shop', 'ls', 'ls.`id_lang` = l.`id_lang`');
22-
$sql->where("LOWER(l.locale) LIKE '%".$locale."%'");
22+
if (_PS_VERSION_ > '1.7.0.0') {
23+
$sql->where("LOWER(l.locale) LIKE '%".$locale."%'");
24+
} else {
25+
$sql->where("LOWER(l.language_code) LIKE '%".$locale."%'");
26+
}
27+
2328

2429
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
2530
return !empty($result) ? $result[0] : false;

model/common/store.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
class ModelCommonStore extends Model
4+
{
5+
public function getStores()
6+
{
7+
$sql = new DbQuery();
8+
$sql->select('*');
9+
$sql->from('store', 's');
10+
if (_PS_VERSION_ > '1.7.0.0') {
11+
$sql->leftJoin('store_lang', 'sl', 'sl.`id_store` = s.`id_store`');
12+
$sql->where('cl.`id_lang` = ' . (int) $this->context->language->id);
13+
}
14+
$sql->where('s.`active` = 1');
15+
16+
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
17+
18+
return $result;
19+
}
20+
}

model/store/category.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,28 @@ class ModelStoreCategory extends Model
66
public function getCategory($category_id)
77
{
88
$category = new Category((int) $category_id, (int) $this->context->language->id, 1);
9-
10-
$retriever = new ImageRetriever(
11-
$this->context->link
12-
);
13-
14-
$category->image = $retriever->getImage(
15-
$category,
16-
$category->id_image
17-
);
9+
if (_PS_VERSION_ >= '1.7.0.0') {
10+
$retriever = new ImageRetriever(
11+
$this->context->link
12+
);
13+
$image = $retriever->getImage(
14+
$category,
15+
$category->id_image
16+
);
17+
$thumb = $image['large']['url'];
18+
$thumbLazy = $image['small']['url'];
19+
} else {
20+
$thumb = $this->context->link->getCatImageLink($category->link_rewrite, $category->id_image);
21+
$thumbLazy = $this->context->link->getCatImageLink($category->link_rewrite, $category->id_image);
22+
}
1823

1924
return array(
2025
'id' => $category->id,
2126
'name' => $category->name,
2227
'description' => html_entity_decode($category->description, ENT_QUOTES, 'UTF-8'),
2328
'parent_id' => $category->id_parent,
24-
'image' => $category->image['large']['url'],
25-
'imageLazy' => $category->image['small']['url'],
29+
'image' => $thumb,
30+
'imageLazy' => $thumbLazy,
2631
'keyword' => $category->link_rewrite
2732
);
2833
}

resolver/common/account.php

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ class ResolverCommonAccount extends Resolver
66
{
77
public function login($args)
88
{
9+
$this->load->model('common/customer');
910
$customer = new Customer();
11+
1012
$authentication = $customer->getByEmail(
1113
$args["email"],
1214
$args["password"]
@@ -17,14 +19,19 @@ public function login($args)
1719
} elseif (!$authentication || !$customer->id || $customer->is_guest) {
1820
throw new Exception('Authentication failed.');
1921
} else {
20-
$this->context->updateCustomer($customer);
22+
if (_PS_VERSION_ > '1.7.0.0') {
23+
$this->context->updateCustomer($customer);
24+
} else {
25+
$this->model_common_customer->updateCustomer($customer);
26+
}
2127

2228
Hook::exec('actionAuthentication', ['customer' => $this->context->customer]);
2329

2430
CartRule::autoRemoveFromCart($this->context);
2531
CartRule::autoAddToCart($this->context);
2632
}
2733

34+
2835
return $this->get($customer->id);
2936
}
3037

@@ -35,7 +42,7 @@ public function logout($args)
3542
$cookie->logout();
3643

3744
return array(
38-
'status' => true
45+
'status' => false
3946
);
4047
}
4148

@@ -52,9 +59,14 @@ public function register($args)
5259
$customer->firstname = $customerData['firstName'];
5360
$customer->lastname = $customerData['lastName'];
5461
$customer->email = $customerData['email'];
55-
$crypto = ServiceLocator::get('\\PrestaShop\\PrestaShop\\Core\\Crypto\\Hashing');
56-
57-
$customer->passwd = $crypto->hash($customerData['password']);
62+
63+
if (_PS_VERSION_ > '1.7.0.0') {
64+
$crypto = ServiceLocator::get('\\PrestaShop\\PrestaShop\\Core\\Crypto\\Hashing');
65+
$customer->passwd = $crypto->hash($customerData['password']);
66+
} else {
67+
$customer->passwd = Tools::encrypt($customerData['password']);
68+
}
69+
5870
$customer->save();
5971

6072
return $this->get($customer->id);
@@ -81,9 +93,13 @@ public function editPassword($args)
8193
{
8294
global $cookie;
8395

84-
$crypto = ServiceLocator::get('\\PrestaShop\\PrestaShop\\Core\\Crypto\\Hashing');
96+
if (_PS_VERSION_ > '1.7.0.0') {
97+
$crypto = ServiceLocator::get('\\PrestaShop\\PrestaShop\\Core\\Crypto\\Hashing');
98+
$this->context->customer->passwd = $crypto->hash($args['password']);
99+
} else {
100+
$this->context->customer->passwd = Tools::encrypt($args['password']);
101+
}
85102

86-
$this->context->customer->passwd = $crypto->hash($args['password']);
87103

88104
if (!$this->context->customer->save()) {
89105
throw new Exception("Update failed");
@@ -122,8 +138,9 @@ public function isLogged($args)
122138

123139
public function address($args)
124140
{
125-
global $cookie;
126-
$result = $this->context->customer->getSimpleAddress($args['id'], $cookie->id_lang);
141+
$this->load->model('common/address');
142+
143+
$result = $this->model_common_address->getAddress($args['id']);
127144

128145
return array(
129146
'id' => $args['id'],
@@ -185,6 +202,7 @@ public function addAddress($args)
185202
{
186203
global $cookie;
187204
$addressData = $args['address'];
205+
188206
$address = new Address();
189207
$address->alias = 'My Address';
190208
$address->id_customer = $cookie->id_customer;
@@ -198,6 +216,7 @@ public function addAddress($args)
198216
$address->address1 = $addressData['address1'];
199217
$address->address2 = $addressData['address2'];
200218

219+
201220
if (!$address->save()) {
202221
throw new Exception("Update failed");
203222
}

resolver/common/contact.php

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class ResolverCommonContact extends Resolver
66

77
public function get()
88
{
9+
$this->load->model('common/store');
10+
911
global $cookie;
1012

1113
$address = $this->context->shop->getAddress();
@@ -38,10 +40,19 @@ public function get()
3840

3941
$locations = array();
4042

41-
$imageRetriever = new \PrestaShop\PrestaShop\Adapter\Image\ImageRetriever($this->context->link);
43+
$result = $this->model_common_store->getStores();
4244

43-
foreach (Store::getStores($cookie->id_lang) as $store) {
44-
$image = $imageRetriever->getImage(new Store($store['id_store']), $store['id_store']);
45+
foreach ($result as $store) {
46+
$store_info = new Store($store['id_store']);
47+
if (_PS_VERSION_ > '1.7.0.0') {
48+
$imageRetriever = new \PrestaShop\PrestaShop\Adapter\Image\ImageRetriever($this->context->link);
49+
$image = $imageRetriever->getImage($store_info, $store['id_store']);
50+
$thumb = $image['large']['url'];
51+
$thumbLazy = $image['small']['url'];
52+
} else {
53+
$thumb = $this->context->link->getImageLink($store['name'], $store['id_store']);
54+
$thumbLazy = $this->context->link->getImageLink($store['name'], $store['id_store']);
55+
}
4556

4657
$locations[] = array(
4758
'name' => $store['name'],
@@ -50,12 +61,11 @@ public function get()
5061
'geocode' => $store['latitude'].', '.$store['longitude'],
5162
'telephone' => $store['phone'],
5263
'fax' => $store['fax'],
53-
'image' => $image['large']['url'],
54-
'imageLazy' => $image['small']['url']
64+
'image' => $thumb,
65+
'imageLazy' => $thumbLazy
5566
);
5667
}
5768

58-
5969
return array(
6070
'store' => Configuration::get('PS_SHOP_NAME'),
6171
'email' => Configuration::get('PS_SHOP_EMAIL'),
@@ -111,7 +121,13 @@ public function send($args)
111121
'{message}' => $args['message']
112122
),
113123
Configuration::get('PS_SHOP_EMAIL'),
114-
NULL, NULL, NULL,NULL,NULL,_PS_MODULE_DIR_.'d_vuefront/mails/');
124+
null,
125+
null,
126+
null,
127+
null,
128+
null,
129+
_PS_MODULE_DIR_.'d_vuefront/mails/'
130+
);
115131
} catch (\Exception $e) {
116132
throw new \Exception($e->getMessage());
117133
}

resolver/common/language.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ public function get()
1313

1414
$languages = array();
1515
foreach ($results as $value) {
16-
$code = strtolower($value['locale']);
16+
if(_PS_VERSION_ > '1.7.0.0') {
17+
$locale = $value['locale'];
18+
} else {
19+
$locale = $value['language_code'];
20+
}
21+
$code = strtolower($locale);
1722
if($code == 'en-us') {
1823
$code = 'en-gb';
1924
}

0 commit comments

Comments
 (0)