diff --git a/app/Plugins/Total/Discount/AppConfig.php b/app/Plugins/Total/Discount/AppConfig.php index 2220d5e9..e614ea20 100644 --- a/app/Plugins/Total/Discount/AppConfig.php +++ b/app/Plugins/Total/Discount/AppConfig.php @@ -138,11 +138,9 @@ public function getData() $totalMethod = session('totalMethod', []); $discount = $totalMethod['Discount']??''; - $check = json_decode((new FrontController)->check($discount, $uID), true); + $check = (new FrontController)->check($discount, $uID); if (!empty($discount) && !$check['error']) { - $storeID = $check['content']['store_id']; - //Get cart item with group store id $subtotalWithTax = ShopCurrency::sumCartCheckout()['subTotalWithTax'] ?? null; if (!$subtotalWithTax) { return $arrData; @@ -152,8 +150,13 @@ public function getData() } else { $value = sc_currency_value($check['content']['reward']); } - //Add info for earch store - $dataStore[$storeID]['value'] = $value; + if (sc_config_global('MultiVendorPro') || sc_config_global('MultiStorePro')) { + //Add info for earch store + $storeID = $check['content']['store_id']; + $dataStore[$storeID]['value'] = $value; + } else { + $dataStore = []; + } $arrData = array( 'title' => '' . $this->title . ': ' . $discount . '', @@ -179,11 +182,6 @@ public function getData() * */ public function endApp($data = []) { - $customer = session('customer'); - $orderID = $data['orderID'] ?? ''; - $code = $data['code'] ?? ''; - $uID = $customer->id ?? 0; - $msg = 'Order #'.$orderID; - return (new FrontController)->apply($code, $uID, $msg); + return; } } diff --git a/app/Plugins/Total/Discount/Controllers/FrontController.php b/app/Plugins/Total/Discount/Controllers/FrontController.php index b565d55a..4bdb0df0 100644 --- a/app/Plugins/Total/Discount/Controllers/FrontController.php +++ b/app/Plugins/Total/Discount/Controllers/FrontController.php @@ -96,19 +96,19 @@ public function check($code, $uID = null) $uID = (int) $uID; $promocode = (new Discount)->getPromotionByCode($code); if ($promocode === null) { - return json_encode(['error' => 1, 'msg' => "error_code_not_exist"]); + return ['error' => 1, 'msg' => sc_language_render($this->plugin->pathPlugin.'::lang.process.invalid')]; } //Check user login if ($promocode->login && !$uID) { - return json_encode(['error' => 1, 'msg' => "error_login"]); + return ['error' => 1, 'msg' => sc_language_render($this->plugin->pathPlugin.'::lang.process.must_login')]; } if ($promocode->limit == 0 || $promocode->limit <= $promocode->used) { - return json_encode(['error' => 1, 'msg' => "error_code_cant_use"]); + return ['error' => 1, 'msg' => sc_language_render($this->plugin->pathPlugin.'::lang.process.over')]; } if ($promocode->status == 0 || $promocode->isExpired()) { - return json_encode(['error' => 1, 'msg' => "error_code_expired_disabled"]); + return ['error' => 1, 'msg' => sc_language_render($this->plugin->pathPlugin.'::lang.process.expire')]; } if ($promocode->login) { //check if this user has already used this code already @@ -117,11 +117,10 @@ public function check($code, $uID = null) $arrUsers[] = $value->pivot->customer_id; } if (in_array($uID, $arrUsers)) { - return json_encode(['error' => 1, 'msg' => "error_user_used"]); + return ['error' => 1, 'msg' => sc_language_render($this->plugin->pathPlugin.'::lang.process.used')]; } } - - return json_encode(['error' => 0, 'content' => $promocode]); + return ['error' => 0, 'content' => $promocode]; } /** @@ -135,11 +134,10 @@ public function apply($code, $uID = null, $msg = null) { //check code valid $checkCode = $this->check($code, $uID); - $check = json_decode($checkCode, true); - if ($check['error'] === 0) { + if ($checkCode['error'] === 0) { $promocode = (new Discount)->getPromotionByCode($code); - if($promocode) { + if ($promocode) { try { // increment used $promocode->used += 1; @@ -149,12 +147,12 @@ public function apply($code, $uID = null, $msg = null) 'used_at' => Carbon::now(), 'log' => $msg, ]); - return json_encode(['error' => 0, 'content' => $promocode->load('users')]); + return ['error' => 0, 'content' => $promocode->load('users')]; } catch (\Throwable $e) { - return json_encode(['error' => 1, 'msg' => $e->getMessage()]); + return ['error' => 1, 'msg' => $e->getMessage()]; } } else { - return json_encode(['error' => 1, 'msg' => 'error_code_not_exist']); + return ['error' => 1, 'msg' => sc_language_render($this->plugin->pathPlugin.'::lang.process.undefined')]; } } else { @@ -272,24 +270,10 @@ public function useDiscount() $html = ''; $code = request('code'); $uID = request('uID'); - $check = json_decode($this->check($code, $uID), true); + $check = $this->check($code, $uID); if ($check['error'] == 1) { $error = 1; - if ($check['msg'] == 'error_code_not_exist') { - $msg = sc_language_render($this->plugin->pathPlugin.'::lang.process.invalid'); - } elseif ($check['msg'] == 'error_code_cant_use') { - $msg = sc_language_render($this->plugin->pathPlugin.'::lang.process.over'); - } elseif ($check['msg'] == 'error_code_expired_disabled') { - $msg = sc_language_render($this->plugin->pathPlugin.'::lang.process.expire'); - } elseif ($check['msg'] == 'error_user_used') { - $msg = sc_language_render($this->plugin->pathPlugin.'::lang.process.used'); - } elseif ($check['msg'] == 'error_uID_input') { - $msg = sc_language_render($this->plugin->pathPlugin.'::lang.process.customer_id_invalid'); - } elseif ($check['msg'] == 'error_login') { - $msg = sc_language_render($this->plugin->pathPlugin.'::lang.process.must_login'); - } else { - $msg = sc_language_render($this->plugin->pathPlugin.'::lang.process.undefined'); - } + $msg = $check['msg']; } else { $content = $check['content']; if ($content['type'] === 1) { diff --git a/app/Plugins/Total/Discount/Models/PluginModel.php b/app/Plugins/Total/Discount/Models/PluginModel.php index 5926ae58..9d06c57b 100644 --- a/app/Plugins/Total/Discount/Models/PluginModel.php +++ b/app/Plugins/Total/Discount/Models/PluginModel.php @@ -63,11 +63,10 @@ public function install() }); Schema::create($this->table_related, function (Blueprint $table) { - $table->integer('customer_id'); - $table->integer('discount_id'); + $table->integer('customer_id')->index(); + $table->integer('discount_id')->index(); $table->text('log')->nullable(); $table->timestamp('used_at')->nullable(); - $table->primary(['customer_id', 'discount_id']); }); diff --git a/app/Plugins/Total/Discount/Views/Admin.blade.php b/app/Plugins/Total/Discount/Views/Admin.blade.php index 0b3d49d7..d3a9f18c 100644 --- a/app/Plugins/Total/Discount/Views/Admin.blade.php +++ b/app/Plugins/Total/Discount/Views/Admin.blade.php @@ -167,10 +167,10 @@
+ class="col-sm-2 col-form-label">{{ sc_language_render('admin.select_store') }}