calendarweek.php
3 years ago
cart.php
1 month ago
confirmapp.php
2 years ago
empattachser.php
4 years ago
empeditcoupon.php
4 years ago
empeditcustfield.php
4 years ago
empeditlocation.php
4 years ago
empeditpay.php
4 years ago
empeditprofile.php
4 months ago
empeditservice.php
4 years ago
empeditwdays.php
4 years ago
emplocwdays.php
4 years ago
emplogin.php
2 years ago
employeesearch.php
2 years ago
employeeslist.php
4 years ago
empmakerecur.php
1 month ago
empmanres.php
1 month ago
empsettings.php
2 years ago
empsubscr.php
4 years ago
empsubscrorder.php
1 year ago
index.html
6 years ago
modules.php
1 year ago
order.php
4 months ago
packages.php
4 years ago
packagesconfirm.php
4 years ago
packagesorder.php
1 year ago
servicesearch.php
2 years ago
subscriptions.php
4 years ago
subscrpayment.php
1 year ago
userprofile.php
4 months ago
waitinglist.php
4 years 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 |