-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshops.php
115 lines (89 loc) · 4.71 KB
/
shops.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
<?php
/******************************************************************************
*
* Subrion Coupons & Deals Software
* Copyright (C) 2018 Intelliants, LLC <https://intelliants.com>
*
* This file is part of Subrion Coupons & Deals Software.
*
* This program is a commercial software and any kind of using it must agree
* to the license, see <https://subrion.pro/license.html>.
*
* This copyright notice may not be removed from the software source without
* the permission of Subrion respective owners.
*
*
* https://subrion.pro/product/coupons-script.html
*
******************************************************************************/
if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
$iaShop = $iaCore->factoryItem('shop');
switch ($iaView->name()) {
case 'shop_view':
$iaCoupon = $iaCore->factoryItem('coupon');
// get shop by id
if (isset($iaCore->requestPath[0]) && !empty($iaCore->requestPath[0])) {
$shop = $iaShop->getByAlias($iaCore->requestPath[0]);
if (empty($shop)) {
return iaView::errorPage(iaView::ERROR_NOT_FOUND);
}
// increment views counter
$iaShop->incrementViewsCounter($shop['id']);
$iaCore->startHook('phpViewListingBeforeStart', [
'listing' => $shop['id'],
'item' => $iaShop->getItemName(),
'title' => $shop['title'],
'desc' => $shop['description']
]);
// breadcrumb formation
iaBreadcrumb::add(iaLanguage::get('shops'), IA_MODULE_URL . 'shops/');
iaBreadcrumb::replaceEnd($shop['title']);
$coupons = $couponsExpired = [];
switch (true) {
case !isset($_GET['sorting']) || 'all' == $_GET['sorting']:
$coupons = $iaCoupon->get("`shop_id` = '{$shop['id']}' && (`expire_date` IS NULL || `expire_date` >= NOW())", '`expire_date` ASC', 100);
$couponsExpired = $iaCore->get('show_expired_coupons') ? $iaCoupon->get("`shop_id` = '{$shop['id']}' && `expire_date` IS NOT NULL && `expire_date` < NOW()", '`expire_date` ASC', 100) : [];
$couponsNum = count($coupons) + count($couponsExpired);
break;
case ('active' == $_GET['sorting']):
$coupons = $iaCoupon->get("`shop_id` = '{$shop['id']}' && (`expire_date` IS NULL || `expire_date` >= NOW())", '`expire_date` ASC', 100);
$couponsNum = count($coupons);
break;
case ('expired' == $_GET['sorting']):
$couponsExpired = $iaCore->get('show_expired_coupons') ? $iaCoupon->get("`shop_id` = {$shop['id']} && (`expire_date` IS NOT NULL && `expire_date` < NOW()) ", '`expire_date` ASC', 100) : [];
$couponsNum = count($couponsExpired);
}
$iaView->assign('coupons', $coupons);
$iaView->assign('coupons_expired', $couponsExpired);
$iaView->assign('couponsNum', $couponsNum);
$sections = $iaCore->factory('field')->getTabs($iaShop->getItemName(), $shop);
$iaView->assign('sections', $sections);
// set shop meta values
$iaView->set('description', $shop['meta_description_' . $iaView->language]);
$iaView->set('keywords', $shop['meta_keywords_' . $iaView->language]);
$iaView->set('title', $shop['title_' . $iaView->language]);
$iaView->assign('item', $shop);
$iaView->display('shop-view');
} else {
return iaView::errorPage(iaView::ERROR_NOT_FOUND);
}
break;
case 'shops':
// gets current page and defines start position
$pagination = [
'limit' => $iaCore->get('coupons_shops_per_page', 20),
'url' => $iaCore->factory('page', iaCore::FRONT)->getUrlByName('shops') . '?page={page}'
];
$page = !empty($_GET['page']) ? (int)$_GET['page'] : 1;
$start = (max($page, 1) - 1) * $pagination['limit'];
$shopsList = $iaShop->get('', null, $pagination['limit'], $start, true);
$pagination['total'] = $iaShop->foundRows();
$iaView->assign('pagination', $pagination);
$iaView->assign('shops', $shopsList);
$iaView->display('shops');
break;
default:
return iaView::errorPage(iaView::ERROR_NOT_FOUND);
}
$iaView->set('filtersItemName', $iaShop->getItemName());
}