public function pjActionDeleteClientBulk() { $this->setAjax(true); if ($this->isXHR()) { if (isset($_POST['record']) && count($_POST['record']) > 0) { pjClientModel::factory()->whereIn('id', $_POST['record'])->eraseAll(); $pjOrderModel = pjOrderModel::factory(); $order_id_arr = $pjOrderModel->whereIn('t1.client_id', $_POST['record'])->findAll()->getDataPair("id", "id"); if (!empty($order_id_arr)) { $pjOrderModel->reset()->whereIn('id', $order_id_arr)->eraseAll(); pjOrderItemModel::factory()->whereIn('order_id', $order_id_arr)->eraseAll(); pjOrderPaymentModel::factory()->whereIn('order_id', $order_id_arr)->eraseAll(); } } } exit; }
public function pjActionUpdate() { $this->checkLogin(); if ($this->isAdmin() || $this->isEditor()) { if (isset($_POST['order_update'])) { $pjOrderModel = pjOrderModel::factory(); $pjOrderItemModel = pjOrderItemModel::factory(); $pjProductPriceModel = pjProductPriceModel::factory(); $pjExtraModel = pjExtraModel::factory(); $pjProductModel = pjProductModel::factory(); $arr = $pjOrderModel->find($_POST['id'])->getData(); if (empty($arr)) { pjUtil::redirect($_SERVER['PHP_SELF'] . "?controller=pjAdminOrders&action=pjActionIndex&err=AR08"); } if (isset($_POST['product_id']) && count($_POST['product_id']) > 0) { $keys = array_keys($_POST['product_id']); $pjOrderItemModel->reset()->where('order_id', $_POST['id'])->whereNotIn('hash', $keys)->eraseAll(); $pjOrderItemModel->reset()->where('order_id', $_POST['id'])->where('type', 'extra')->eraseAll(); foreach ($_POST['product_id'] as $k => $pid) { $product = $pjProductModel->reset()->find($pid)->getData(); $price = 0; $price_id = ":NULL"; if ($product['set_different_sizes'] == 'T') { $price_id = $_POST['price_id'][$k]; $price_arr = $pjProductPriceModel->reset()->find($price_id)->getData(); if ($price_arr) { $price = $price_arr['price']; } } else { $price = $product['price']; } if (strpos($k, 'new_') === 0) { $hash = md5(uniqid(rand(), true)); $oid = $pjOrderItemModel->reset()->setAttributes(array('order_id' => $_POST['id'], 'foreign_id' => $pid, 'type' => 'product', 'hash' => $hash, 'price_id' => $price_id, 'price' => $price, 'cnt' => $_POST['cnt'][$k]))->insert()->getInsertId(); if ($oid !== false && (int) $oid > 0) { if (isset($_POST['extra_id']) && isset($_POST['extra_id'][$k])) { foreach ($_POST['extra_id'][$k] as $i => $eid) { $extra_price = 0; $extra_arr = $pjExtraModel->reset()->find($eid)->getData(); if (!empty($extra_arr) && !empty($extra_arr['price'])) { $extra_price = $extra_arr['price']; } $pjOrderItemModel->reset()->setAttributes(array('order_id' => $_POST['id'], 'foreign_id' => $eid, 'type' => 'extra', 'hash' => $hash, 'price_id' => ':NULL', 'price' => $extra_price, 'cnt' => $_POST['extra_cnt'][$k][$i]))->insert(); } } } } else { $pjOrderItemModel->reset()->where('hash', $k)->where('type', 'product')->limit(1)->modifyAll(array('foreign_id' => $pid, 'cnt' => $_POST['cnt'][$k], 'price_id' => $price_id, 'price' => $price)); if (isset($_POST['extra_id']) && isset($_POST['extra_id'][$k])) { foreach ($_POST['extra_id'][$k] as $i => $eid) { $extra_price = 0; $extra_arr = $pjExtraModel->reset()->find($eid)->getData(); if (!empty($extra_arr) && !empty($extra_arr['price'])) { $extra_price = $extra_arr['price']; } $pjOrderItemModel->reset()->setAttributes(array('order_id' => $_POST['id'], 'foreign_id' => $eid, 'type' => 'extra', 'hash' => $k, 'price_id' => ':NULL', 'price' => $extra_price, 'cnt' => $_POST['extra_cnt'][$k][$i]))->insert(); } } } } } $data = array(); $data['ip'] = pjUtil::getClientIp(); switch ($_POST['type']) { case 'pickup': if (!empty($_POST['p_dt'])) { $date_time = $_POST['p_dt']; if (count(explode(" ", $date_time)) == 3) { list($_date, $_time, $_period) = explode(" ", $date_time); $time = pjUtil::formatTime($_time . ' ' . $_period, $this->option_arr['o_time_format']); } else { list($_date, $_time) = explode(" ", $date_time); $time = pjUtil::formatTime($_time, $this->option_arr['o_time_format']); } unset($_POST['p_dt']); unset($_POST['d_dt']); $data['p_dt'] = pjUtil::formatDate($_date, $this->option_arr['o_date_format']) . ' ' . $time; } if (isset($_POST['p_location_id']) && (int) $_POST['p_location_id'] > 0) { $data['location_id'] = $_POST['p_location_id']; } break; case 'delivery': if (!empty($_POST['d_dt'])) { $date_time = $_POST['d_dt']; if (count(explode(" ", $date_time)) == 3) { list($_date, $_time, $_period) = explode(" ", $date_time); $time = pjUtil::formatTime($_time . ' ' . $_period, $this->option_arr['o_time_format']); } else { list($_date, $_time) = explode(" ", $date_time); $time = pjUtil::formatTime($_time, $this->option_arr['o_time_format']); } unset($_POST['p_dt']); unset($_POST['d_dt']); $data['d_dt'] = pjUtil::formatDate($_date, $this->option_arr['o_date_format']) . ' ' . $time; } if (isset($_POST['d_location_id']) && (int) $_POST['d_location_id'] > 0) { $data['location_id'] = $_POST['d_location_id']; } break; } if ($_POST['payment_method'] == 'creditcard') { $data['cc_exp'] = $_POST['cc_exp_month'] . "/" . $_POST['cc_exp_year']; } $pjOrderModel->reset()->where('id', $_POST['id'])->limit(1)->modifyAll(array_merge($_POST, $data)); $err = 'AR01'; pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminOrders&action=pjActionIndex&err={$err}"); } else { $arr = pjOrderModel::factory()->join('pjClient', "t2.id=t1.client_id", 'left outer')->select('t1.*,t2.c_name as client_name')->find($_GET['id'])->getData(); if (count($arr) <= 0) { pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminOrders&action=pjActionIndex&err=AR08"); } $this->set('arr', $arr); $country_arr = pjCountryModel::factory()->select('t1.id, t2.content AS country_title')->join('pjMultiLang', "t2.model='pjCountry' AND t2.foreign_id=t1.id AND t2.field='name' AND t2.locale='" . $this->getLocaleId() . "'", 'left outer')->orderBy('`country_title` ASC')->findAll()->getData(); $this->set('country_arr', $country_arr); $product_arr = pjProductModel::factory()->join('pjMultiLang', "t2.foreign_id = t1.id AND t2.model = 'pjProduct' AND t2.locale = '" . $this->getLocaleId() . "' AND t2.field = 'name'", 'left')->select("t1.*, t2.content AS name, (SELECT GROUP_CONCAT(extra_id SEPARATOR '~:~') FROM `" . pjProductExtraModel::factory()->getTable() . "` WHERE product_id = t1.id GROUP BY product_id LIMIT 1) AS allowed_extras ")->orderBy("name ASC")->findAll()->toArray('allowed_extras', '~:~')->getData(); $this->set('product_arr', $product_arr); $location_arr = pjLocationModel::factory()->join('pjMultiLang', "t2.foreign_id = t1.id AND t2.model = 'pjLocation' AND t2.locale = '" . $this->getLocaleId() . "' AND t2.field = 'name'", 'left')->select("t1.*, t2.content AS name")->orderBy("name ASC")->findAll()->getData(); $this->set('location_arr', $location_arr); $extra_arr = pjExtraModel::factory()->join('pjMultiLang', "t2.foreign_id = t1.id AND t2.model = 'pjExtra' AND t2.locale = '" . $this->getLocaleId() . "' AND t2.field = 'name'", 'left')->select("t1.*, t2.content AS name")->orderBy("name ASC")->findAll()->getData(); $this->set('extra_arr', $extra_arr); $pjProductPriceModel = pjProductPriceModel::factory(); $oi_arr = array(); $_oi_arr = pjOrderItemModel::factory()->where('t1.order_id', $arr['id'])->findAll()->getData(); foreach ($_oi_arr as $item) { if ($item['type'] == 'product') { $item['price_arr'] = $pjProductPriceModel->reset()->join('pjMultiLang', "t2.foreign_id = t1.id AND t2.model = 'pjProductPrice' AND t2.locale = '" . $this->getLocaleId() . "' AND t2.field = 'price_name'", 'left')->select("t1.*, t2.content AS price_name")->where('product_id', $item['foreign_id'])->findAll()->getData(); } $oi_arr[] = $item; } $this->set('oi_arr', $oi_arr); $this->appendJs('chosen.jquery.js', PJ_THIRD_PARTY_PATH . 'harvest/chosen/'); $this->appendCss('chosen.css', PJ_THIRD_PARTY_PATH . 'harvest/chosen/'); $this->appendJs('jquery-ui-sliderAccess.js', PJ_THIRD_PARTY_PATH . 'timepicker/'); $this->appendJs('jquery-ui-timepicker-addon.js', PJ_THIRD_PARTY_PATH . 'timepicker/'); $this->appendCss('jquery-ui-timepicker-addon.css', PJ_THIRD_PARTY_PATH . 'timepicker/'); $this->appendJs('jquery.validate.min.js', PJ_THIRD_PARTY_PATH . 'validate/'); $this->appendJs('jquery.noty.packaged.min.js', PJ_THIRD_PARTY_PATH . 'noty/packaged/'); $this->appendJs('pjAdminOrders.js'); } } else { $this->set('status', 2); } }
public function pjActionGetPaymentForm() { $this->setAjax(true); if ($this->isXHR()) { $arr = pjOrderModel::factory()->select('t1.*')->find($_GET['order_id'])->getData(); $item_arr = pjOrderItemModel::factory()->join('pjMultiLang', "t2.foreign_id = t1.foreign_id AND t2.model = 'pjProduct' AND t2.locale = '" . $this->getLocaleId() . "' AND t2.field = 'name'", 'left')->select('t1.*, t2.content as name')->where('t1.order_id', $_GET['order_id'])->where('t1.type', 'product')->findAll()->getData(); $_arr = array(); foreach ($item_arr as $v) { $_arr[] = stripslashes($v['name']); } $arr['product_name'] = !empty($_arr) ? join("; ", $_arr) : null; $arr['cart_info'] = $item_arr; switch ($arr['payment_method']) { case 'paypal': $this->set('params', array('name' => 'fdPaypal', 'id' => 'fdPaypal', 'business' => $this->option_arr['o_paypal_address'], 'item_name' => $arr['product_name'], 'custom' => $arr['id'], 'amount' => number_format($arr['total'], 2, '.', ''), 'currency_code' => $this->option_arr['o_currency'], 'return' => $this->option_arr['o_thankyou_page'], 'notify_url' => PJ_INSTALL_URL . 'index.php?controller=pjFront&action=pjActionConfirmPaypal', 'target' => '_self')); break; case 'authorize': $this->set('params', array('name' => 'fdAuthorize', 'id' => 'fdAuthorize', 'target' => '_self', 'timezone' => $this->option_arr['o_timezone'], 'transkey' => $this->option_arr['o_authorize_transkey'], 'x_login' => $this->option_arr['o_authorize_merchant_id'], 'x_description' => $arr['product_name'], 'x_amount' => number_format($arr['total'], 2, '.', ''), 'x_invoice_num' => $arr['id'], 'x_receipt_link_url' => $this->option_arr['o_thankyou_page'], 'x_relay_url' => PJ_INSTALL_URL . 'index.php?controller=pjFront&action=pjActionConfirmAuthorize')); break; } $this->set('arr', $arr); $this->set('get', $_GET); } }
public function addOrderDetails(&$arr, $locale_id) { $l_arr = pjLocationModel::factory()->join('pjMultiLang', "t2.foreign_id = t1.id AND t2.model = 'pjLocation' AND t2.locale = '" . $locale_id . "' AND t2.field = 'name'", 'left')->select('t1.*, t2.content as name')->find($arr['location_id'])->getData(); if (count($l_arr) > 0) { $arr['location'] = $l_arr['name']; } $pjOrderItemModel = pjOrderItemModel::factory(); $arr['product_arr'] = $pjOrderItemModel->reset()->join('pjMultiLang', "t2.foreign_id = t1.foreign_id AND t2.model = 'pjProduct' AND t2.locale = '" . $locale_id . "' AND t2.field = 'name'", 'left')->select('t1.*, t2.content as name')->where('t1.order_id', $arr['id'])->where('type', 'product')->findAll()->getData(); foreach ($arr['product_arr'] as $k => $product) { $arr['product_arr'][$k]['extra_arr'] = $pjOrderItemModel->reset()->join('pjMultiLang', "t2.foreign_id = t1.foreign_id AND t2.model = 'pjExtra' AND t2.locale = '" . $locale_id . "' AND t2.field = 'name'", 'left')->select('t1.*, t2.content as name')->where('t1.order_id', $arr['id'])->where('type', 'extra')->where('hash', $product['hash'])->findAll()->getData(); } }