PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.20
VikAppointments Services Booking Calendar v1.2.20
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / controllers / packages.php
vikappointments / site / controllers Last commit date
calendarweek.php 1 month ago cart.php 1 month ago confirmapp.php 1 month ago empattachser.php 1 month ago empeditcoupon.php 1 month ago empeditcustfield.php 1 month ago empeditlocation.php 1 month ago empeditpay.php 1 month ago empeditprofile.php 1 month ago empeditservice.php 1 month ago empeditwdays.php 1 month ago emplocwdays.php 1 month ago emplogin.php 1 month ago employeesearch.php 1 month ago employeeslist.php 1 month ago empmakerecur.php 1 month ago empmanres.php 1 month ago empsettings.php 1 month ago empsubscr.php 1 month ago empsubscrorder.php 1 month ago index.html 1 month ago modules.php 1 month ago order.php 1 month ago packages.php 1 month ago packagesconfirm.php 1 month ago packagesorder.php 1 month ago servicesearch.php 1 month ago subscriptions.php 1 month ago subscrpayment.php 1 month ago userprofile.php 1 month ago waitinglist.php 1 month ago
packages.php
123 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 VAPLoader::import('libraries.mvc.controllers.admin');
15
16 /**
17 * VikAppointments packages controller.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsControllerPackages extends VAPControllerAdmin
22 {
23 /**
24 * Method used to add an item into the cart via AJAX.
25 *
26 * @return void
27 */
28 public function addcart()
29 {
30 $app = JFactory::getApplication();
31 $input = $app->input;
32
33 $args = array();
34 $args['id'] = $input->getUint('id_package', 0);
35 $args['units'] = $input->getUint('units', 1);
36
37 // get cart model
38 $model = $this->getModel('packagescart');
39
40 // push item into the cart
41 $item = $model->addItem($args);
42
43 if (!$item)
44 {
45 // get error from model
46 $error = $model->getError($index = null, $string = true);
47 UIErrorFactory::raiseError(500, $error);
48 }
49
50 $result = new stdClass;
51 $result->item = $item->toArray();
52 $result->totalCost = $model->getCart()->getTotalCost();
53
54 // send response to caller
55 $this->sendJSON($result);
56 }
57
58 /**
59 * Method used to remove an item from the cart via AJAX.
60 *
61 * @return void
62 */
63 public function removecart()
64 {
65 $app = JFactory::getApplication();
66 $input = $app->input;
67
68 $args = array();
69 $args['id'] = $input->getUint('id_package', 0);
70 $args['units'] = $input->getUint('units', 1);
71
72 // get cart model
73 $model = $this->getModel('packagescart');
74
75 // remove item from the cart
76 $res = $model->removeItem($args);
77
78 if (!$res)
79 {
80 // get error from model
81 $error = $model->getError($index = null, $string = true);
82 UIErrorFactory::raiseError(500, $error);
83 }
84
85 // get cart handler
86 $cart = $model->getCart();
87
88 $result = new stdClass;
89 $result->idPackage = $args['id'];
90 $result->isEmpty = $cart->isEmpty();
91 $result->totalCost = $cart->getTotalCost();
92
93 // check whether the quantity of the package is still higher than 0
94 $index = $cart->indexOf($args['id']);
95
96 if ($index != -1)
97 {
98 $result->item = $cart->getPackageAt($index)->toArray();
99 }
100 else
101 {
102 $result->item = false;
103 }
104
105 // send response to caller
106 $this->sendJSON($result);
107 }
108
109 /**
110 * AJAX task to empty the appointments cart.
111 *
112 * @return void
113 */
114 public function emptycart()
115 {
116 // flush the cart
117 $this->getModel('packagescart')->emptyCart();
118
119 // send response to caller
120 $this->sendJSON(1);
121 }
122 }
123