forked from glus73/shopee-prestashop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updatePrice.php
executable file
·97 lines (87 loc) · 2.91 KB
/
updatePrice.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
<?php
/**
* CedCommerce
*
* NOTICE OF LICENSE
*
* This source file is subject to the End User License Agreement(EULA)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://cedcommerce.com/license-agreement.txt
*
* @author CedCommerce Core Team <[email protected]>
* @copyright Copyright CEDCOMMERCE(http://cedcommerce.com/)
* @license http://cedcommerce.com/license-agreement.txt
* @category Ced
* @package CedShopee
*/
include(dirname(__FILE__).'/../../config/config.inc.php');
include_once _PS_MODULE_DIR_ . 'cedshopee/classes/CedShopeeLibrary.php';
include_once(_PS_MODULE_DIR_.'cedshopee/classes/CedShopeeProduct.php');
/*include_once(_PS_MODULE_DIR_.'cedwish/classes/CedTraderaFeeds.php');*/
if (!Tools::isSubmit('secure_key')
|| Tools::getValue('secure_key') != Configuration::get('CEDSHOPEE_CRON_SECURE_KEY')) {
die('Secure key not matched');
}
try {
$CedShopeeLibrary = new CedShopeeLibrary;
$CedShopeeProduct = new CedShopeeProduct;
$db = Db::getInstance();
$product_ids = array();
$res = $db->executeS("SELECT `product_id` FROM `"._DB_PREFIX_."cedshopee_profile_products`");
if (isset($res) && !empty($res) && is_array($res)) {
foreach ($res as $id) {
$product_ids[] = $id['product_id'];
}
}
if (!empty($product_ids)) {
$product_ids = array_unique($product_ids);
}
if (is_array($product_ids) && count($product_ids)) {
$updated = 0;
$fail = 0;
foreach ($product_ids as $product_id) {
$result = $CedShopeeProduct->updatePrice($product_id);
if (isset($result['item'])) {
$updated++;
} elseif (isset($result['error'])) {
$fail++;
}
}
if ($updated) {
if ($fail) {
die(json_encode(array(
'status' => true,
'message' => $updated . ' Product(s) Updated and '.$fail . 'are failed to update '
)));
} else {
die(json_encode(array(
'status' => true,
'message' => $updated . ' Product(s) Updated'
)));
}
} else {
die(json_encode(array(
'status' => false,
'message' => 'Unable to update data.'
)));
}
} else {
die(json_encode(array(
'status' => false,
'message' => 'Please Select Product to Update Price'
)));
}
} catch (\Exception $e) {
$CedShopeeLibrary->log(
'Cron updatePrice',
'Exception',
$e->getMessage(),
$e->getMessage(),
true
);
die(json_encode(array(
'status' => false,
'message' => $e->getMessage()
)));
}