public function pjActionGetTotal() { $this->setAjax(true); if ($this->isXHR()) { $price = 0; $subtotal = 0; $delivery = 0; $tax = 0; $total = 0; $pjProductModel = pjProductModel::factory(); $pjProductPriceModel = pjProductPriceModel::factory(); $pjExtraModel = pjExtraModel::factory(); $product_arr = $pjProductModel->whereIn("t1.id", $_POST['product_id'])->findAll()->getData(); $extra_arr = $pjExtraModel->findAll()->getData(); foreach ($_POST['product_id'] as $hash => $product_id) { foreach ($product_arr as $product) { if ($product['id'] == $product_id) { $_price = 0; $extra_price = 0; if ($product['set_different_sizes'] == 'T') { $price_arr = $pjProductPriceModel->reset()->find($_POST['price_id'][$hash])->getData(); if ($price_arr) { $_price = $price_arr['price']; } } else { $_price = $product['price']; } $product_price = $_price * $_POST['cnt'][$hash]; if (isset($_POST['extra_id']) && isset($_POST['extra_id'][$hash])) { foreach ($_POST['extra_id'][$hash] as $oi_id => $extra_id) { if (isset($_POST['extra_cnt'][$hash][$oi_id]) && (int) $_POST['extra_cnt'][$hash][$oi_id] > 0) { foreach ($extra_arr as $extra) { if ($extra['id'] == $extra_id) { $extra_price += $extra['price'] * $_POST['extra_cnt'][$hash][$oi_id]; break; } } } } } $_price = $product_price + $extra_price; $price += $_price; break; } } } if ($_POST['type'] == 'delivery' && isset($_POST['d_location_id']) && (int) $_POST['d_location_id'] > 0) { $arr = pjPriceModel::factory()->where("t1.location_id", $_POST['d_location_id'])->where("(t1.total_from <= {$price})")->where("(t1.total_to >= {$price})")->findAll()->limit(1)->getData(); if (count($arr) === 1) { $delivery = $arr[0]['price']; } } $discount = 0; if ($_POST['voucher_code'] !== false) { if ($_POST['type'] == 'delivery') { $resp = pjAppController::getDiscount($_POST, $this->option_arr); if ($resp['code'] == 200) { $voucher_discount = $resp['voucher_discount']; switch ($resp['voucher_type']) { case 'percent': $discount = ($subtotal + $delivery) * $voucher_discount / 100; break; case 'amount': $discount = $voucher_discount; break; } } } } $subtotal = $price + $delivery - $discount; if (!empty($this->option_arr['o_tax_payment'])) { $tax = $subtotal * $this->option_arr['o_tax_payment'] / 100; } $total = $subtotal + $tax; $price = number_format($price, 2); $discount = number_format($discount, 2); $delivery = number_format($delivery, 2); $subtotal = number_format($subtotal, 2); $tax = number_format($tax, 2); $total = number_format($total, 2); pjAppController::jsonResponse(compact('price', 'discount', 'delivery', 'subtotal', 'tax', 'total')); } exit; }
function pjActionAddPromo() { $this->setAjax(true); if ($this->isXHR()) { $pre = array('type' => $this->_get('type'), 'd_date' => $this->_get('d_date'), 'd_hour' => $this->_get('d_hour'), 'd_minute' => $this->_get('d_minute'), 'p_date' => $this->_get('p_date'), 'p_hour' => $this->_get('p_hour'), 'p_minute' => $this->_get('p_minute')); $resp = pjAppController::getDiscount(array_merge($_POST, $pre), $this->option_arr); $promo_statuses = __('promo_statuses', true, false); $resp['text'] = $promo_statuses[$resp['code']]; if ($resp['code'] == 200) { $this->_set('voucher_code', $resp['voucher_code']); /* Manmohan code here */ $this->_set('voucher_code_for', $resp['voucher_code_for']); $this->_set('voucher_product_id', $resp['voucher_product_id']); $this->_set('voucher_category_id', $resp['voucher_category_id']); /* Manmohan end of code here */ $this->_set('voucher_type', $resp['voucher_type']); $this->_set('voucher_discount', $resp['voucher_discount']); $voucher = array('voucher_code' => $resp['voucher_code'], 'voucher_code_for' => $resp['voucher_code_for'], 'voucher_product_id' => $resp['voucher_product_id'], 'voucher_category_id' => $resp['voucher_category_id'], 'voucher_type' => $resp['voucher_type'], 'voucher_discount' => $resp['voucher_discount']); $_SESSION['voucher'] = $voucher; } pjAppController::jsonResponse($resp); } }