From 17e2de75eada6348e2a61d28b0b1f905bc71bb75 Mon Sep 17 00:00:00 2001 From: Shohrat Date: Sun, 22 Oct 2023 13:08:31 +0000 Subject: [PATCH] from server 21.10 --- .../api/BlogPostsApiController.php | 14 +- .../api/CategoriesAPIController.php | 9 +- .../controllers/api/ProductsApiController.php | 253 +++++-- .../controllers/api/SmsApiController.php | 55 ++ plugins/ahmadfatoni/apigenerator/routes.php | 23 +- plugins/default.htm | 93 --- plugins/rainlab/user/models/User.php | 8 +- plugins/rainlab/user/models/user/fields.yaml | 7 +- plugins/sms/sms/Plugin.php | 14 + plugins/sms/sms/controllers/SmsSender.php | 18 + .../controllers/smssender/_list_toolbar.htm | 18 + .../controllers/smssender/config_form.yaml | 10 + .../controllers/smssender/config_list.yaml | 12 + .../sms/sms/controllers/smssender/create.htm | 46 ++ .../sms/sms/controllers/smssender/index.htm | 1 + .../sms/sms/controllers/smssender/preview.htm | 22 + .../sms/sms/controllers/smssender/update.htm | 54 ++ plugins/sms/sms/lang/ru/lang.php | 6 + plugins/sms/sms/models/SmsSender.php | 27 + plugins/sms/sms/models/smssender/columns.yaml | 13 + plugins/sms/sms/models/smssender/fields.yaml | 13 + plugins/sms/sms/plugin.yaml | 11 + .../builder_table_create_sms_sms_otp.php | 26 + .../builder_table_update_sms_sms_otp.php | 23 + plugins/sms/sms/updates/version.yaml | 8 + .../tps/birzha/components/CategoryProfile.php | 47 +- plugins/tps/birzha/components/Checkout.php | 31 +- .../birzha/components/FilteredProducts.php | 22 + plugins/tps/birzha/components/Messages.php | 28 +- .../tps/birzha/components/MyFavourites.php | 1 + plugins/tps/birzha/components/OfferForm.php | 29 +- plugins/tps/birzha/components/Offers.php | 25 + plugins/tps/birzha/components/OrderDetail.php | 20 + .../tps/birzha/components/SearchOffers.php | 21 + plugins/tps/birzha/components/Singleoffer.php | 20 + plugins/tps/birzha/components/UserOffers.php | 70 +- .../components/categoryprofile/default.htm | 420 ++++++++---- .../components/filteredproducts/default.htm | 141 ++-- .../birzha/components/messages/chatroom.htm | 17 +- .../birzha/components/messages/default.htm | 150 +++-- .../messages/latest_message_profile.htm | 5 + .../birzha/components/mycomments/default.htm | 18 + .../components/myfavourites/default.htm | 19 + .../birzha/components/myoffers/default.htm | 21 + .../birzha/components/myorders/default.htm | 18 + .../birzha/components/offerform/default.htm | 107 ++- .../tps/birzha/components/offers/default.htm | 72 +- .../birzha/components/orderdetail/default.htm | 32 + .../components/searchoffers/default.htm | 53 +- .../birzha/components/singleoffer/default.htm | 11 +- .../birzha/components/useroffers/default.htm | 143 +++- plugins/tps/birzha/controllers/Products.php | 21 + .../birzha/controllers/products/update.htm | 11 + plugins/tps/birzha/models/Category.php | 4 + .../tps/birzha/models/orderitems/fields.yaml | 4 + plugins/tps/birzha/plugin.yaml | 4 +- ...ilder_table_update_tps_birzha_orders_3.php | 23 + ...er_table_update_tps_birzha_products_39.php | 23 + plugins/tps/birzha/updates/version.yaml | 6 + .../assets/css/default/icofont.min.css | 2 +- themes/gurlushyk/assets/css/newcss.css | 3 + .../gurlushyk/assets/css/owl.carousel.min.css | 2 +- themes/gurlushyk/assets/css/style.css | 631 +++++++++++++++++- themes/gurlushyk/assets/empty_state.png | Bin 0 -> 111161 bytes .../assets/img/core-img/hemmesi2.png | Bin 0 -> 3846 bytes .../assets/img/core-img/no-products.png | Bin 0 -> 11369 bytes themes/gurlushyk/assets/js/inputmask.js | 4 + themes/gurlushyk/assets/js/script.js | 18 +- themes/gurlushyk/layouts/default.htm | 10 + themes/gurlushyk/meta/menus/top-menu.yaml | 301 +-------- themes/gurlushyk/pages/addProduct.htm | 6 +- themes/gurlushyk/pages/chat.htm | 14 + themes/gurlushyk/pages/haryt2.htm | 81 +++ themes/gurlushyk/pages/index.htm | 34 +- themes/gurlushyk/pages/my-messages.htm | 10 + themes/gurlushyk/pages/user-profile.htm | 7 + themes/gurlushyk/partials/customStyle.htm | 211 +++++- themes/gurlushyk/partials/footer.htm | 10 +- themes/gurlushyk/partials/header.htm | 20 +- .../gurlushyk/partials/product/card-item.htm | 7 +- themes/gurlushyk/partials/profile/modal.htm | 8 +- themes/gurlushyk/partials/profile/style1.htm | 11 +- themes/gurlushyk/partials/profile/style2.htm | 37 +- 83 files changed, 2933 insertions(+), 915 deletions(-) create mode 100644 plugins/ahmadfatoni/apigenerator/controllers/api/SmsApiController.php delete mode 100644 plugins/default.htm create mode 100644 plugins/sms/sms/Plugin.php create mode 100644 plugins/sms/sms/controllers/SmsSender.php create mode 100644 plugins/sms/sms/controllers/smssender/_list_toolbar.htm create mode 100644 plugins/sms/sms/controllers/smssender/config_form.yaml create mode 100644 plugins/sms/sms/controllers/smssender/config_list.yaml create mode 100644 plugins/sms/sms/controllers/smssender/create.htm create mode 100644 plugins/sms/sms/controllers/smssender/index.htm create mode 100644 plugins/sms/sms/controllers/smssender/preview.htm create mode 100644 plugins/sms/sms/controllers/smssender/update.htm create mode 100644 plugins/sms/sms/lang/ru/lang.php create mode 100644 plugins/sms/sms/models/SmsSender.php create mode 100644 plugins/sms/sms/models/smssender/columns.yaml create mode 100644 plugins/sms/sms/models/smssender/fields.yaml create mode 100644 plugins/sms/sms/plugin.yaml create mode 100644 plugins/sms/sms/updates/builder_table_create_sms_sms_otp.php create mode 100644 plugins/sms/sms/updates/builder_table_update_sms_sms_otp.php create mode 100644 plugins/sms/sms/updates/version.yaml create mode 100644 plugins/tps/birzha/components/messages/latest_message_profile.htm create mode 100644 plugins/tps/birzha/updates/builder_table_update_tps_birzha_orders_3.php create mode 100644 plugins/tps/birzha/updates/builder_table_update_tps_birzha_products_39.php create mode 100644 themes/gurlushyk/assets/empty_state.png create mode 100644 themes/gurlushyk/assets/img/core-img/hemmesi2.png create mode 100644 themes/gurlushyk/assets/img/core-img/no-products.png create mode 100644 themes/gurlushyk/assets/js/inputmask.js create mode 100644 themes/gurlushyk/pages/chat.htm create mode 100644 themes/gurlushyk/pages/haryt2.htm create mode 100644 themes/gurlushyk/pages/my-messages.htm diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/BlogPostsApiController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/BlogPostsApiController.php index 60de2c9..db10f04 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/BlogPostsApiController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/BlogPostsApiController.php @@ -305,13 +305,21 @@ class BlogPostsApiController extends Controller public function getPlaces(Request $request) { $data = $request->all(); + + //$id = $data["primary"] ?? 0; $data = City::with([ 'translations:locale,model_id,attribute_data', ]) ->where('primary_key', $data["primary"] ?? 0) - ->paginate(100); + ->paginate(100)->toArray(); + // array_unshift($data["data"], array( + // "id" => 0, + // "name" => "Ählisi", + // "order" => 0, + // )); + return response()->json($data, 200); } @@ -342,7 +350,9 @@ class BlogPostsApiController extends Controller ->first(); $data->pathUrl = 'https://gurlushyk.com.tm' . \Config::get('cms.storage.media.path'); - $data->categories[0] = array( + + + $data->categories[] = array( "id" => 0, "name"=> "Hemmesi", ); diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/CategoriesAPIController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/CategoriesAPIController.php index 88e4284..8f7a05b 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/CategoriesAPIController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/CategoriesAPIController.php @@ -38,7 +38,7 @@ class CategoriesAPIController extends Controller ->where('primary_key', $data["primary"] ?? 0) ->orderBy('sort_order', 'asc') ->active() - ->paginate(9); + ->paginate(99); }else{ $dataCat = $this->Category ->select('id', 'name', 'icon', 'status', 'slug', 'sort_order', 'is_featured', 'is_file_category', 'primary_key') @@ -47,13 +47,16 @@ class CategoriesAPIController extends Controller ->where('primary_key', $data["primary"] ?? 0) ->orderBy('sort_order', 'asc') ->active() - ->paginate(9); + ->paginate(99); } if($dataCat) { $dataCat->each(function ($item, $key) { + $dataHaveSub = $this->Category->where("primary_key", $item->id)->count(); + $item->icon = 'https://gurlushyk.com.tm' . \Config::get('cms.storage.media.path') . $item->icon; + $item->sub_category = $dataHaveSub > 0 ? true : false; }); } @@ -88,7 +91,7 @@ class CategoriesAPIController extends Controller } public function subs($id){ - $subs = Category::where('primary_key', $id)->get(); + $subs = Category::where('primary_key', $id)->with("subs")->get(); return $subs; } diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php index c8209b7..87aff7e 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php @@ -5,6 +5,7 @@ use Illuminate\Http\Request; use AhmadFatoni\ApiGenerator\Helpers\Helpers; use Illuminate\Support\Facades\Validator; use TPS\Birzha\Models\Product; +use TPS\Birzha\Models\Favourites; use TPS\Birzha\Models\Category; use TPS\Birzha\Models\City; use TPS\Birzha\Models\Term; @@ -15,6 +16,7 @@ use TPS\Birzha\Classes\ErrorResponseApi; use TPS\Birzha\Classes\MeasureResource; use TPS\Birzha\Classes\ProductResource; use DB; +use Carbon\Carbon; class ProductsAPIController extends Controller { @@ -142,7 +144,7 @@ class ProductsAPIController extends Controller $query->select(DB::raw('avg(rating)')); }]) ->where('vendor_id', $seller) - ->approved(); + ->approved()->orderBy('ends_at', $sortOrder); } @@ -159,6 +161,8 @@ class ProductsAPIController extends Controller ->with([ 'translations:locale,model_id,attribute_data', 'images:attachment_id,attachment_type,disk_name,file_name', + 'vendor:id,name,email,type,logo,banner,shop_title,slogan,is_instagram', + 'place', ])->approved()->orderBy('id', $sortOrder); }else{ @@ -168,6 +172,8 @@ class ProductsAPIController extends Controller ->with([ 'translations:locale,model_id,attribute_data', 'images:attachment_id,attachment_type,disk_name,file_name', + 'vendor:id,name,email,type,logo,banner,shop_title,slogan,is_instagram', + 'place', ]) ->withCount(['comments as rating_avg' => function($query) { $query->select(DB::raw('avg(rating)')); @@ -283,7 +289,7 @@ class ProductsAPIController extends Controller } - $data = $query ? $query->paginate($perPage) : null; + $data = $query ? $query->orderBy('id', "DESC")->orderBy('ends_at', $sortOrder)->paginate($perPage) : null; return response()->json($data, 200); @@ -298,9 +304,9 @@ class ProductsAPIController extends Controller $data = $this->Product::with([ 'translations:locale,model_id,attribute_data', - 'images:attachment_id,attachment_type,disk_name,file_name', + 'images:id,attachment_id,attachment_type,disk_name,file_name', 'vendor:id,name,surname,email,username,logo,banner,type', - 'files', 'place', + 'files', 'place', 'categories:id,name,slug,primary_key,icon' ]) //->withCount('comments')->withAvg('comments', 'rating') ->withCount(['comments as rating_avg' => function($query) { @@ -382,23 +388,16 @@ class ProductsAPIController extends Controller $product = new $this->Product; - - $product->translateContext('tm'); $product->name = $data['name_tm']; - //$product->setAttributeTranslated('name', $data['name_ru'], 'ru'); $product->translateContext('tm'); $product->description = $data['description_tm']; $product->short_description = $data['short_description']; - // Sets a single translated attribute for a language - // $product->setAttributeTranslated('description', $data['description_ru'], 'ru'); - - //$product->setAttributeTranslated('slug', \Str::slug($data['name_ru'],'-'), 'ru'); $product->slug = \Str::slug($data['name_tm'],'-'); $product->status = 'new'; @@ -484,57 +483,77 @@ class ProductsAPIController extends Controller } $data = $request->all(); - + $rules = [ - 'quantity' => 'required|numeric|integer', + //'name_ru' => 'required', + 'name_tm' => 'required', 'price' => 'required|numeric', - 'place' => 'required', + 'place_id' => 'required', 'description_tm' => 'required', - // 'description_en' => 'required', - 'description_ru' => 'required', - 'payment_term_id' => [ - 'required', - 'exists:tps_birzha_terms,id', - // in terms table it must have type = payment - function ($attribute, $value, $fail) { - $t = Term::find($value); - if($t) { - if($t->type != 'payment') $fail(":attribute is invalid"); - } - } - ], - 'packaging' => 'required|in:yes,no', - 'delivery_term_id' => [ - 'required', - 'exists:tps_birzha_terms,id', - // in terms table it must have type = delivery - function ($attribute, $value, $fail) { - $t = Term::find($value); - if($t) { - if($t->type != 'delivery') $fail(":attribute is invalid"); - } - } - ], - 'currency_id' => 'required|exists:tps_birzha_currencies,id', - 'measure_id' => [ - 'required', - // validation for measure deleted_at field - it should - // be null, means it should not be deleted (exists rule not working) - function ($attribute, $value, $fail) { - $m = Measure::find($value); - if(!$m) $fail(":attribute is invalid"); - } - ], - 'old_img' => 'array', + //'description_ru' => 'required', 'new_img' => 'array', + 'is_file' => 'required', + + 'old_img' => 'array', // allowed only jpg & png files with size <= 1024 'new_img.*' => 'mimes:jpg,png|max:1024', + + //'new_file.*' => 'max:9024', + + 'category_id' => [ + 'required', + 'exists:tps_birzha_categories,id', + // validation for category status - it should be active + function ($attribute, $value, $fail) { + $c = Category::find($value); + if($c) { + if($c->status != 1) $fail(":attribute is non-active!"); + } + } + ], + + + //'place_id' => 'required', + ]; $validator = $this->validateForm($data, $rules); if($validator->fails()) { return $this->helpers->apiArrayResponseBuilder(400, 'fail', $validator->errors() ); } + + if($data['is_file'] == 1){ + // validate if no old images and no new images + if(!$request->has('new_file')) { + return response()->json(ErrorResponseApi::translateErrorMessage('atleast_1_file'), 400); + } + + // if new_img field is passed but empty + if($request->has('new_file')) { + $rules = [ + 'new_file' => 'required' + ]; + $validator = $this->validateForm($data, $rules); + if($validator->fails()) { + return $this->helpers->apiArrayResponseBuilder(400, 'fail', $validator->errors() ); + } + } + + + try { + + foreach($data['new_file'] ?? [] as $key => $fileq) { + $product->files = $fileq; + $product->save(); + } + + } catch(\Throwable $e) { + + return $this->helpers->apiArrayResponseBuilder(500, 'server error', ['message' => 'something went wrong file']); + } + + } + // validate if no old images and no new images if((!$request->has('new_img') && !$request->has('old_img'))) { @@ -577,6 +596,106 @@ class ProductsAPIController extends Controller return $this->helpers->apiArrayResponseBuilder(200, 'ok', ['message' => 'updated successfully']); } + + + public function checkUserHasProduct($id) + { + $currentUser = \JWTAuth::parseToken()->authenticate(); + + return $currentUser->products->find($id); + } + + + public function updateStatus($id){ + + if(!$product = $this->checkUserHasProduct($id)) { + return $this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => "Resource id = {$id} could not be found"]); + } + + + try { + + if($product){ + + + if($product->status == "disabled"){ + $product->status = "new"; + $product->save(); + }else{ + + $product->status = "disabled"; + $product->save(); + + } + + } + + } catch(\Throwable $e) { + return $this->helpers->apiArrayResponseBuilder(500, 'server error', ['message' => 'something went wrong']); + } + + return $this->helpers->apiArrayResponseBuilder(200, 'ok', ['message' => 'updated successfully']); + } + + + public function updateEndsAt($id){ + + $currentDate = Carbon::now()->timezone('UTC +05:00'); + $currentDateFormat = $currentDate->format('Y-m-d'); + + if(!$product = $this->checkUserHasProduct($id)) { + return $this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => "Resource id = {$id} could not be found"]); + } + + + try { + + if($product){ + + $product->ends_at = $currentDateFormat; + $product->save(); + + + } + + } catch(\Throwable $e) { + return $this->helpers->apiArrayResponseBuilder(500, 'server error', ['message' => 'something went wrong']); + } + + return $this->helpers->apiArrayResponseBuilder(200, 'ok', ['message' => 'updated successfully']); + } + + + + protected function fillProduct($data, $attachedProduct) { + + + $attachedProduct->translateContext('tm'); + + $attachedProduct->name = $data['name_tm']; + + $attachedProduct->translateContext('tm'); + + $attachedProduct->description = $data['description_tm']; + + $attachedProduct->short_description = $data['short_description']; + + $attachedProduct->slug = \Str::slug($data['name_tm'],'-'); + + $attachedProduct->status = 'new'; + + $attachedProduct->place_id = $data['place_id']; + + $attachedProduct->price = $data['price']; + + $attachedProduct->phone = $data['phone']; + + $attachedProduct->is_file_product = $data['is_file']; + + $attachedProduct->save(); + + return $attachedProduct; + } /** * Delete my product @@ -674,21 +793,7 @@ class ProductsAPIController extends Controller return Validator::make($data, $rules); } - protected function fillProduct($data, $attachedProduct) { - $attachedProduct->translateContext('tm'); - - $attachedProduct->description = $data['description_tm']; - // Sets a single translated attribute for a language - $attachedProduct->setAttributeTranslated('description', $data['description_ru'], 'ru'); - - - - $attachedProduct->price = $data['price']; - $attachedProduct->place = $data['place']; - $attachedProduct->save(); - - return $attachedProduct; - } + public function myProducts() { @@ -719,14 +824,18 @@ class ProductsAPIController extends Controller if(!$product = $this->checkUserHasProduct($id)) { return $this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => "Resource id = {$id} could not be found"]); } else { - return new ProductResource($product); + return $product; } } - - public function checkUserHasProduct($id) - { - $currentUser = \JWTAuth::parseToken()->authenticate(); - - return $currentUser->products->find($id); + + + public function createFav($id){ + $favourite = Favourites::firstOrCreate([ + "product_id" => $id, + "user_id" => \Auth::user()->id, + ]); + return $this->helpers->apiArrayResponseBuilder(200, 'ok', ['message' => 'Added to wishlist']); } + + } diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/SmsApiController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/SmsApiController.php new file mode 100644 index 0000000..70a44df --- /dev/null +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/SmsApiController.php @@ -0,0 +1,55 @@ +SmsSender = $SmsSender; + $this->helpers = $helpers; + } + + public function index(){ + + $otps = SmsSender::where('status', false)->get(); + $answer = []; + + foreach ($otps as $item) { + $answer[] = ["phone_number" => (string)$item->phone, "body" => (string) $item->message]; + $item->status = true; + $item->save(); + } + + $data = [ + "error"=> null, + "message"=> "OK", + "status" => 200, + "category"=> null, + "data" => $answer + ]; + + return response()->json($data, 200); + + } + + + public static function getAfterFilters() {return [];} + public static function getBeforeFilters() {return [];} + public static function getMiddleware() {return [];} + public function callAction($method, $parameters=false) { + return call_user_func_array(array($this, $method), $parameters); + } + +} \ No newline at end of file diff --git a/plugins/ahmadfatoni/apigenerator/routes.php b/plugins/ahmadfatoni/apigenerator/routes.php index 3bce04f..b83a9ff 100644 --- a/plugins/ahmadfatoni/apigenerator/routes.php +++ b/plugins/ahmadfatoni/apigenerator/routes.php @@ -5,12 +5,19 @@ Route::post('fatoni/update/api/{id}', array('as' => 'fatoni.update.api', 'uses' Route::get('fatoni/delete/api/{id}', array('as' => 'fatoni.delete.api', 'uses' => 'AhmadFatoni\ApiGenerator\Controllers\ApiGeneratorController@deleteApi')); Route::group(['prefix' =>'api/v1','namespace' =>'AhmadFatoni\ApiGenerator\Controllers\API'],function ($route){ - + Route::get('sms', 'SmsApiController@index'); Route::resource('categories', 'CategoriesAPIController', ['except' => ['destroy', 'create', 'edit']]); Route::get('category/{id}/subs', ['as' => 'category.subs', 'uses' => 'CategoriesAPIController@subs']); + + + + Route::get('product/{id}/add-wishlist', ['as' => 'create.fav', 'uses' => 'ProductsApiController@createFav']); + + Route::get('products', ['as' => 'products.index', 'uses' => 'ProductsApiController@index']); + Route::get('category/filters', 'CategoriesAPIController@getFilters'); @@ -52,6 +59,14 @@ Route::group(['prefix' =>'api/v1','namespace' =>'AhmadFatoni\ApiGenerator\Contro Route::middleware(['\Tymon\JWTAuth\Middleware\GetUserFromToken'])->group(function () { Route::delete('delete/account', 'VendorApiController@deleteVendor'); + + Route::post('update/products/{id}', 'ProductsApiController@update'); + Route::post('update/status/{id}', 'ProductsApiController@updateStatus'); + Route::delete('delete/product/{id}', 'ProductsApiController@delete'); + Route::delete('products/{id}/image-delete/{image_id}', 'ProductsApiController@imageDelete') + ->where(['id' => '[0-9]+', 'image_id' => '[0-9]+']); + Route::post('update/product/ends_at/{id}', 'ProductsApiController@updateEndsAt'); + Route::post('make/order', 'OrderApiController@createOrder'); Route::get('my/orders', 'OrderApiController@myOrders'); Route::get('vendor/sale/orders', 'OrderApiController@mySaleOrders'); @@ -96,14 +111,10 @@ Route::group(['prefix' =>'api/v1','namespace' =>'AhmadFatoni\ApiGenerator\Contro //Balance // Route::post('balance_bank_transfer','BalanceController@createBankTransfer'); - - - - - }); Route::get('bank-info', 'BanksApiController@getBankInfo'); Route::get('bank-types', 'BanksApiController@getBankTypes'); + }); diff --git a/plugins/default.htm b/plugins/default.htm deleted file mode 100644 index 147d5c0..0000000 --- a/plugins/default.htm +++ /dev/null @@ -1,93 +0,0 @@ -{% set user = __SELF__.user %} - -
-
-
-
-
Dükanyň sazlamalary
- -
-
-
-
- - - -
-
-
- - -
- -
- - - -
- -
-
-
-
- - -{% put scripts %} - -{% endput %} \ No newline at end of file diff --git a/plugins/rainlab/user/models/User.php b/plugins/rainlab/user/models/User.php index ead3372..be55c45 100644 --- a/plugins/rainlab/user/models/User.php +++ b/plugins/rainlab/user/models/User.php @@ -9,6 +9,7 @@ use Carbon\Carbon; use October\Rain\Auth\Models\User as UserBase; use RainLab\User\Models\Settings as UserSettings; use October\Rain\Auth\AuthException; +use TPS\Birzha\Models\Message; class User extends UserBase { @@ -65,7 +66,7 @@ class User extends UserBase 'comments' => ['TPS\Birzha\Models\Comment','table' => 'tps_birzha_comments'], 'orders' => ['TPS\Birzha\Models\Orders','table' => 'tps_birzha_orders'], 'vendor_sales' => ['TPS\Birzha\Models\VendorSales', 'key' => 'vendor_id', 'softDelete' => true], - + 'messages' => ['TPS\Birzha\Models\Message', 'key' => 'reciver_id', 'softDelete' => true], ]; /** @@ -225,6 +226,11 @@ class User extends UserBase '&d='.urlencode($default); } } + + public function getUnreadMessagesCount(){ + $count = Message::where('reciver_id', $this->id)->whereNull('read_at')->whereNull('deleted_at')->count(); + return $count; + } /** * Returns the name for the user's login. diff --git a/plugins/rainlab/user/models/user/fields.yaml b/plugins/rainlab/user/models/user/fields.yaml index d570365..56f1ab4 100644 --- a/plugins/rainlab/user/models/user/fields.yaml +++ b/plugins/rainlab/user/models/user/fields.yaml @@ -185,14 +185,11 @@ tabs: tab: 'Sosial Mediýalar' web1: label: 'Web-de sahypa gornushleri' - span: auto options: variant1: '1-nji Versia' variant2: '2-nji Versia' - variant3: '3-nji Versia' - variant4: '4-nji Versia' - variant5: '5-nji Versia' - variant6: '6-nji Versia' + span: auto + default: variant1 type: balloon-selector tab: 'Web Wariantlar' secondaryTabs: diff --git a/plugins/sms/sms/Plugin.php b/plugins/sms/sms/Plugin.php new file mode 100644 index 0000000..34d392f --- /dev/null +++ b/plugins/sms/sms/Plugin.php @@ -0,0 +1,14 @@ + + + + diff --git a/plugins/sms/sms/controllers/smssender/config_form.yaml b/plugins/sms/sms/controllers/smssender/config_form.yaml new file mode 100644 index 0000000..89d01b4 --- /dev/null +++ b/plugins/sms/sms/controllers/smssender/config_form.yaml @@ -0,0 +1,10 @@ +name: SmsSender +form: $/sms/sms/models/smssender/fields.yaml +modelClass: Sms\Sms\Models\SmsSender +defaultRedirect: sms/sms/smssender +create: + redirect: 'sms/sms/smssender/update/:id' + redirectClose: sms/sms/smssender +update: + redirect: sms/sms/smssender + redirectClose: sms/sms/smssender diff --git a/plugins/sms/sms/controllers/smssender/config_list.yaml b/plugins/sms/sms/controllers/smssender/config_list.yaml new file mode 100644 index 0000000..ccdb019 --- /dev/null +++ b/plugins/sms/sms/controllers/smssender/config_list.yaml @@ -0,0 +1,12 @@ +list: $/sms/sms/models/smssender/columns.yaml +modelClass: Sms\Sms\Models\SmsSender +title: SmsSender +noRecordsMessage: 'backend::lang.list.no_records' +showSetup: true +showCheckboxes: true +recordsPerPage: 20 +toolbar: + buttons: list_toolbar + search: + prompt: 'backend::lang.list.search_prompt' +recordUrl: 'sms/sms/smssender/update/:id' diff --git a/plugins/sms/sms/controllers/smssender/create.htm b/plugins/sms/sms/controllers/smssender/create.htm new file mode 100644 index 0000000..eecec31 --- /dev/null +++ b/plugins/sms/sms/controllers/smssender/create.htm @@ -0,0 +1,46 @@ + + + + +fatalError): ?> + + 'layout']) ?> + +
+ formRender() ?> +
+ +
+
+ + + + + +
+
+ + + + +

fatalError)) ?>

+

+ \ No newline at end of file diff --git a/plugins/sms/sms/controllers/smssender/index.htm b/plugins/sms/sms/controllers/smssender/index.htm new file mode 100644 index 0000000..ea43a36 --- /dev/null +++ b/plugins/sms/sms/controllers/smssender/index.htm @@ -0,0 +1 @@ +listRender() ?> diff --git a/plugins/sms/sms/controllers/smssender/preview.htm b/plugins/sms/sms/controllers/smssender/preview.htm new file mode 100644 index 0000000..b6f15a9 --- /dev/null +++ b/plugins/sms/sms/controllers/smssender/preview.htm @@ -0,0 +1,22 @@ + + + + +fatalError): ?> + +
+ formRenderPreview() ?> +
+ + +

fatalError) ?>

+ + +

+ + + +

\ No newline at end of file diff --git a/plugins/sms/sms/controllers/smssender/update.htm b/plugins/sms/sms/controllers/smssender/update.htm new file mode 100644 index 0000000..7d126b9 --- /dev/null +++ b/plugins/sms/sms/controllers/smssender/update.htm @@ -0,0 +1,54 @@ + + + + +fatalError): ?> + + 'layout']) ?> + +
+ formRender() ?> +
+ +
+
+ + + + + + + +
+
+ + + +

fatalError)) ?>

+

+ \ No newline at end of file diff --git a/plugins/sms/sms/lang/ru/lang.php b/plugins/sms/sms/lang/ru/lang.php new file mode 100644 index 0000000..14488f3 --- /dev/null +++ b/plugins/sms/sms/lang/ru/lang.php @@ -0,0 +1,6 @@ + [ + 'name' => 'SMS', + 'description' => '' + ] +]; \ No newline at end of file diff --git a/plugins/sms/sms/models/SmsSender.php b/plugins/sms/sms/models/SmsSender.php new file mode 100644 index 0000000..f7a3088 --- /dev/null +++ b/plugins/sms/sms/models/SmsSender.php @@ -0,0 +1,27 @@ +engine = 'InnoDB'; + $table->increments('id')->unsigned(); + $table->timestamp('created_at')->nullable(); + $table->timestamp('updated_at')->nullable(); + $table->timestamp('deleted_at')->nullable(); + $table->string('phone'); + $table->text('message')->nullable(); + }); + } + + public function down() + { + Schema::dropIfExists('sms_sms_otp'); + } +} diff --git a/plugins/sms/sms/updates/builder_table_update_sms_sms_otp.php b/plugins/sms/sms/updates/builder_table_update_sms_sms_otp.php new file mode 100644 index 0000000..bb58980 --- /dev/null +++ b/plugins/sms/sms/updates/builder_table_update_sms_sms_otp.php @@ -0,0 +1,23 @@ +boolean('status')->default(false); + }); + } + + public function down() + { + Schema::table('sms_sms_otp', function($table) + { + $table->dropColumn('status'); + }); + } +} diff --git a/plugins/sms/sms/updates/version.yaml b/plugins/sms/sms/updates/version.yaml new file mode 100644 index 0000000..9f15efa --- /dev/null +++ b/plugins/sms/sms/updates/version.yaml @@ -0,0 +1,8 @@ +1.0.1: + - 'Initialize plugin.' +1.0.2: + - 'Created table sms_sms_otp' + - builder_table_create_sms_sms_otp.php +1.0.3: + - 'Updated table sms_sms_otp' + - builder_table_update_sms_sms_otp.php diff --git a/plugins/tps/birzha/components/CategoryProfile.php b/plugins/tps/birzha/components/CategoryProfile.php index 97b2a03..ff5dc32 100644 --- a/plugins/tps/birzha/components/CategoryProfile.php +++ b/plugins/tps/birzha/components/CategoryProfile.php @@ -7,11 +7,19 @@ use TPS\Birzha\Models\City; use Session; use DB; +use TPS\Birzha\Models\Favourites; +use RainLab\User\Facades\Auth; +use ValidationException; +use Validator; +use Flash; + class CategoryProfile extends ComponentBase { public $category; public $users; + public $products; + public $subcategories; public function componentDetails() { return [ @@ -39,6 +47,7 @@ class CategoryProfile extends ComponentBase public function onRun() { $this->users = $this->getCategoryUsers(); $this->category = $this->getCategory(); + $this->subcategories = $this->getSubs(); } protected function getCategory(){ @@ -46,12 +55,48 @@ class CategoryProfile extends ComponentBase $category = Category::transWhere('slug', $cSlug, Session::get('rainlab.translate.locale'))->with('users')->first(); return $category; } + + protected function getSubs(){ + $cSlug = $this->property('categorySlug'); + $category = Category::transWhere('slug', $cSlug, Session::get('rainlab.translate.locale'))->with('users')->first(); + $subs = Category::where("primary_key", $category->id)->get(); + + foreach ($subs as $subcategory) { + $page = input('page', 1); + $products = $subcategory->products()->paginate(12, $page); + $subcategory->setRelation('products', $products); + } + + return $subs; + } protected function getCategoryUsers(){ $cSlug = $this->property('categorySlug'); $category = Category::where('slug', $cSlug)->first(); $users = $category->users()->get(); - // dd($users); return $users; } + + protected function getProducts(){ + $cSlug = $this->property('categorySlug'); + $category = Category::where('slug', $cSlug)->first(); + $users = $category->users()->get(); + return $users; + } + + public function onCreateFav() + { + $data = input(); + $validator = Validator::make($data, [ + 'product_id' => 'required' + ]); + if($validator->fails()) { + Flash::error("Haryt maglumatyny nädogry"); + } + $favourite = new Favourites; + $favourite->user_id = \Auth::user()->id; + $favourite->product_id = (int)$data['product_id']; + $favourite->save(); + Flash::success("Haryt halanlaryma goşuldy"); + } } diff --git a/plugins/tps/birzha/components/Checkout.php b/plugins/tps/birzha/components/Checkout.php index 353ff05..d9a14d1 100644 --- a/plugins/tps/birzha/components/Checkout.php +++ b/plugins/tps/birzha/components/Checkout.php @@ -6,12 +6,14 @@ use October\Rain\Exception\AjaxException; use October\Rain\Support\Facades\Event; use TPS\Birzha\Models\Payment; use RainLab\User\Facades\Auth; +use RainLab\User\Models\User as VendorModel; use Validator; use TPS\Birzha\Models\Product; use TPS\Birzha\Models\Orders; use TPS\Birzha\Models\OrderItems; use TPS\Birzha\Models\VendorSales; use Flash; +use Sms\Sms\Models\SmsSender; class Checkout extends ComponentBase { @@ -28,6 +30,7 @@ class Checkout extends ComponentBase $rules = [ 'note' => 'required', 'address' => 'required', + 'phone_custom' => 'required', 'items' => 'required', ]; @@ -38,28 +41,24 @@ class Checkout extends ComponentBase Flash::error('Haryt ýok. Ýalňyşlyk'); return 500; } - - - - $order = new Orders; - $order->user_id = \Auth::user()->id; $order->note = $data["note"]; $order->address = $data["address"]; + $order->phone = $data["phone_custom"]; $order->status = "new"; $order->save(); + $userPhone= \Auth::user()->username; - //[{"item":34,"qty":1},{"item":35,"qty":3}] - + $this->sendSMS($userPhone, "Siz üstünlikli sargyt etdiňiz."); + $orderItem = new OrderItems; $orderItem->order_id = $order->id; $orderItem->items = json_decode($data["items"]); $orderItem->save(); - //dd($orderItem->items[0]["item"]); - + for ($i = 0; $i < count($orderItem->items); $i++) { $vendorSale = new VendorSales; $vendorSale->order_id = $order->id; @@ -71,7 +70,12 @@ class Checkout extends ComponentBase $vendorSale->save(); } + $vendorPhones = VendorSales::where("order_id", $order->id)->with("vendor")->groupBy("vendor_id")->get(); + for ($x = 0; $x < count($vendorPhones); $x++) { + $this->sendSMS($vendorPhones[$x]->vendor->username, "Size Gurluşyk platformasyndan sargyt geldi"); + } + if ($order && $orderItem && $vendorSale){ Flash::success('Sargyt ugradyldy'); }else{ @@ -79,6 +83,15 @@ class Checkout extends ComponentBase return 500; } } + + protected function sendSMS($phone, $message){ + + $smsSender = new SmsSender(); + $smsSender->phone = (string)'+993'.$phone; + $smsSender->message = strval($message); + $smsSender->save(); + + } protected function validateForm($data, $rules) { $validator = Validator::make($data, $rules); diff --git a/plugins/tps/birzha/components/FilteredProducts.php b/plugins/tps/birzha/components/FilteredProducts.php index 79776d9..05be8c8 100644 --- a/plugins/tps/birzha/components/FilteredProducts.php +++ b/plugins/tps/birzha/components/FilteredProducts.php @@ -7,6 +7,12 @@ use TPS\Birzha\Models\City; use Session; use DB; +use TPS\Birzha\Models\Favourites; +use RainLab\User\Facades\Auth; +use ValidationException; +use Validator; +use Flash; + class FilteredProducts extends ComponentBase { /* @@ -155,4 +161,20 @@ class FilteredProducts extends ComponentBase $sort_direction ?? 'asc' ]; } + + public function onCreateFav() + { + $data = input(); + $validator = Validator::make($data, [ + 'product_id' => 'required' + ]); + if($validator->fails()) { + Flash::error("Haryt maglumatyny nädogry"); + } + $favourite = new Favourites; + $favourite->user_id = \Auth::user()->id; + $favourite->product_id = (int)$data['product_id']; + $favourite->save(); + Flash::success("Haryt halanlaryma goşuldy"); + } } diff --git a/plugins/tps/birzha/components/Messages.php b/plugins/tps/birzha/components/Messages.php index 7631d58..13ee086 100644 --- a/plugins/tps/birzha/components/Messages.php +++ b/plugins/tps/birzha/components/Messages.php @@ -71,7 +71,11 @@ class Messages extends ComponentBase $sellerId = Input::get('seller_id'); } - $this->loadMessages($sellerId); + if(\Auth::user()){ + $this->loadMessages($sellerId); + } + + //dd($this->chatrooms); } public function onChatroom() { @@ -122,6 +126,28 @@ class Messages extends ComponentBase 'latest_message_area' => $this->renderPartial('@latest_message') ]; } + + public function onMessageInUserProfile() { + $newMsg = new Message; + $newMsg->sender_id = Auth::user()->id; + $newMsg->reciver_id = Input::get('reciver_id'); + $newMsg->send_at = Carbon::now(); + $newMsg->message = Input::get('msg'); + $newMsg->chatroom_id = Input::get('chatroom_id'); + if($newMsg->save()){ + + Event::fire('tps.message.received', [User::find($newMsg->reciver_id), Auth::user()]); + + $this->page['latestMessage'] = $newMsg->message; + $this->page['latestMessageTime'] = $newMsg->send_at; + + }else + throw new AjaxException('Hat gitmedi. Nasazlyk yuze chykdy'); + + return [ + 'latest_message_area' => $this->renderPartial('@latest_message_profile') + ]; + } public function onDeleteChat() { diff --git a/plugins/tps/birzha/components/MyFavourites.php b/plugins/tps/birzha/components/MyFavourites.php index 17ecaf4..8d1fe21 100644 --- a/plugins/tps/birzha/components/MyFavourites.php +++ b/plugins/tps/birzha/components/MyFavourites.php @@ -5,6 +5,7 @@ use TPS\Birzha\Models\Product; use TPS\Birzha\Models\Favourites; use Input; use Flash; +use RainLab\User\Facades\Auth; class MyFavourites extends ComponentBase { diff --git a/plugins/tps/birzha/components/OfferForm.php b/plugins/tps/birzha/components/OfferForm.php index 1a98f0d..7684fee 100644 --- a/plugins/tps/birzha/components/OfferForm.php +++ b/plugins/tps/birzha/components/OfferForm.php @@ -103,7 +103,7 @@ class OfferForm extends ComponentBase }else{ $place = $data['state_id']; } - + $product = new Product; $product->name = $data['name']; $product->description = $data['description']; @@ -114,6 +114,8 @@ class OfferForm extends ComponentBase $product->price = $data['price']; $product->phone = $data['phone']; $product->is_file_product = $data['is_file']; + $product->created_at = Carbon::now(); + $product->updated_at = Carbon::now(); if($data['is_file'] == 1){ if(!$data['new_file']) { @@ -202,6 +204,7 @@ class OfferForm extends ComponentBase $product->price = $data['price']; $product->phone = $data['phone']; $product->is_file_product = $data['is_file']; + $product->updated_at = Carbon::now(); if(isset($data['new_file'])){ foreach($product->files as $file){ @@ -214,9 +217,9 @@ class OfferForm extends ComponentBase } if(isset($data['new_img'])){ - foreach($product->images as $image){ - $image->delete(); - } + //foreach($product->images as $image){ + // $image->delete(); + //} foreach($data['new_img'] ?? [] as $key => $img) { $product->images = $img; $product->save(); @@ -235,6 +238,7 @@ class OfferForm extends ComponentBase } $product->save(); Flash::success('Haryt maglumaty üýtgedildi. Tassyklanýança garaşmagyňyzy haýyş edýäris.'); + return \Redirect::back(); } // step 2 @@ -337,20 +341,10 @@ class OfferForm extends ComponentBase // after deleting a photo go the second form_step public function onImageDelete() { - // dd(Input::get('product_image_id')); - $product = Product::find(Input::get('being_edited_product_id')); - + $product = Product::find(Input::get('product_id')); $product->images()->find(Input::get('product_image_id'))->delete(); - - $this->page['measures'] = Measure::all(); - $this->page['paymentTerms'] = Term::where('type','payment')->get(); - $this->page['deliveryTerms'] = Term::where('type','delivery')->get(); - $this->page['currencies'] = Currency::all(); - $this->page['product'] = $product; - - return [ - '#form-steps' => $this->renderPartial('@second_step_form') - ]; + Flash::success('Surat üstünlikli pozuldy'); + return \Redirect::back(); } protected function validateFileType($data, $rules) { @@ -402,6 +396,7 @@ class OfferForm extends ComponentBase $this->states = City::where('primary_key','=', 0)->get(); $this->cities = City::where('primary_key','>', 0)->get(); $this->productIdOption = $this->property('productId'); + if($this->productIdOption) { $this->productForEditing = Product::where("vendor_id", \Auth::user()->id)->where("id", $this->productIdOption)->first(); diff --git a/plugins/tps/birzha/components/Offers.php b/plugins/tps/birzha/components/Offers.php index 05ed43a..050032a 100644 --- a/plugins/tps/birzha/components/Offers.php +++ b/plugins/tps/birzha/components/Offers.php @@ -7,6 +7,12 @@ use TPS\Birzha\Models\City; use Session; use DB; +use TPS\Birzha\Models\Favourites; +use RainLab\User\Facades\Auth; +use ValidationException; +use Validator; +use Flash; + class Offers extends ComponentBase { /* @@ -150,4 +156,23 @@ class Offers extends ComponentBase return $query ? $query->paginate($perPage) : null; } + + public function onCreateFav() + { + $data = input(); + $validator = Validator::make($data, [ + 'product_id' => 'required' + ]); + if($validator->fails()) { + Flash::error("Haryt maglumatyny nädogry"); + } + $favourite = new Favourites; + $favourite->user_id = \Auth::user()->id; + $favourite->product_id = (int)$data['product_id']; + $favourite->save(); + Flash::success("Haryt halanlaryma goşuldy"); + } + + + } diff --git a/plugins/tps/birzha/components/OrderDetail.php b/plugins/tps/birzha/components/OrderDetail.php index 4d7d830..15e04ea 100644 --- a/plugins/tps/birzha/components/OrderDetail.php +++ b/plugins/tps/birzha/components/OrderDetail.php @@ -7,6 +7,10 @@ use TPS\Birzha\Models\OrderItems; use RainLab\User\Facades\Auth; use Flash; +use TPS\Birzha\Models\Favourites; +use ValidationException; +use Validator; + class OrderDetail extends ComponentBase { public $order; @@ -43,4 +47,20 @@ class OrderDetail extends ComponentBase $order = OrderItems::where('order_id', $this->property('id'))->first(); return $order; } + + public function onCreateFav() + { + $data = input(); + $validator = Validator::make($data, [ + 'product_id' => 'required' + ]); + if($validator->fails()) { + Flash::error("Haryt maglumatyny nädogry"); + } + $favourite = new Favourites; + $favourite->user_id = \Auth::user()->id; + $favourite->product_id = (int)$data['product_id']; + $favourite->save(); + Flash::success("Haryt halanlaryma goşuldy"); + } } \ No newline at end of file diff --git a/plugins/tps/birzha/components/SearchOffers.php b/plugins/tps/birzha/components/SearchOffers.php index c92c86e..c0de028 100644 --- a/plugins/tps/birzha/components/SearchOffers.php +++ b/plugins/tps/birzha/components/SearchOffers.php @@ -6,6 +6,11 @@ use Input; use Flash; use RainLab\User\Models\User; +use TPS\Birzha\Models\Favourites; +use RainLab\User\Facades\Auth; +use ValidationException; +use Validator; + class SearchOffers extends ComponentBase { /** @@ -84,6 +89,22 @@ class SearchOffers extends ComponentBase $sort_direction ?? 'asc' ]; } + + public function onCreateFav() + { + $data = input(); + $validator = Validator::make($data, [ + 'product_id' => 'required' + ]); + if($validator->fails()) { + Flash::error("Haryt maglumatyny nädogry"); + } + $favourite = new Favourites; + $favourite->user_id = \Auth::user()->id; + $favourite->product_id = (int)$data['product_id']; + $favourite->save(); + Flash::success("Haryt halanlaryma goşuldy"); + } diff --git a/plugins/tps/birzha/components/Singleoffer.php b/plugins/tps/birzha/components/Singleoffer.php index 215a542..d57cd9c 100644 --- a/plugins/tps/birzha/components/Singleoffer.php +++ b/plugins/tps/birzha/components/Singleoffer.php @@ -6,6 +6,10 @@ use TPS\Birzha\Models\Comment; use RainLab\User\Facades\Auth; use Flash; +use TPS\Birzha\Models\Favourites; +use ValidationException; +use Validator; + class Singleoffer extends ComponentBase { public function componentDetails() @@ -62,6 +66,22 @@ class Singleoffer extends ComponentBase } return $totalRating == 0 ? $totalRating : round($totalRating/$product->comments->count()); } + + public function onCreateFav() + { + $data = input(); + $validator = Validator::make($data, [ + 'product_id' => 'required' + ]); + if($validator->fails()) { + Flash::error("Haryt maglumaty nädogry"); + } + $favourite = new Favourites; + $favourite->user_id = \Auth::user()->id; + $favourite->product_id = (int)$data['product_id']; + $favourite->save(); + Flash::success("Haryt halanlaryma goşuldy"); + } diff --git a/plugins/tps/birzha/components/UserOffers.php b/plugins/tps/birzha/components/UserOffers.php index 19b60ab..2884ef9 100644 --- a/plugins/tps/birzha/components/UserOffers.php +++ b/plugins/tps/birzha/components/UserOffers.php @@ -3,10 +3,16 @@ use Cms\Classes\ComponentBase; use TPS\Birzha\Models\Product; use TPS\Birzha\Models\Category; +use TPS\Birzha\Models\Chatroom; use Input; use Flash; use RainLab\User\Models\User; +use TPS\Birzha\Models\Favourites; +use RainLab\User\Facades\Auth; +use ValidationException; +use Validator; + class UserOffers extends ComponentBase { /** @@ -18,6 +24,9 @@ class UserOffers extends ComponentBase public $params; public $sliders; public $currentCat; + public $chatroom; + public $result; + public $authUser; public function componentDetails() { @@ -71,6 +80,16 @@ class UserOffers extends ComponentBase $this->userProducts = $this->loadProducts(); $this->sliders = $this->loadSliders(); $this->currentCat = $this->loadCurrentCategory(); + + if(\Auth::user()){ + $this->authUser = \Auth::user()->id; + $this->chatroom = $this->getChatroom(); + $this->result = $this->getMessages($this->chatroom ? $this->chatroom->id : null); + }else{ + $this->authUser = null; + $this->chatroom = null; + $this->result = null; + } } protected function loadProducts() { @@ -84,7 +103,7 @@ class UserOffers extends ComponentBase if($categorySlug){ $category = Category::where('slug', $categorySlug)->first(); } - $products = Product::query(); + $products = Product::query()->approved(); if($category){ @@ -152,6 +171,55 @@ class UserOffers extends ComponentBase $user = User::find($this->property('id')); return $user->sliders()->get(); } + + public function onCreateFav() + { + $data = input(); + $validator = Validator::make($data, [ + 'product_id' => 'required' + ]); + if($validator->fails()) { + Flash::error("Haryt maglumatyny nädogry"); + } + $favourite = new Favourites; + $favourite->user_id = \Auth::user()->id; + $favourite->product_id = (int)$data['product_id']; + $favourite->save(); + Flash::success("Haryt halanlaryma goşuldy"); + } + + protected function getChatroom() { + if(\Auth::user()->id == $this->property('id')){ + return null; + }else{ + $chatrooms = \Auth::user()->chatrooms; + foreach($chatrooms as $room) { + $room->message_partner = $room->users()->where('users.id','!=',\Auth::user()->id)->first(); + if($room->message_partner->id == $this->property('id')) { + return $room; + } + } + $seller = User::findOrFail($this->property('id')); + $chatroom = new Chatroom; + $chatroom->save(); + $chatroom->users()->attach($seller->id); + $chatroom->users()->attach(Auth::user()->id); + + $chatroom->message_partner = $seller; + return $chatroom; + } + } + + public function getMessages($chatroomId){ + if($chatroomId){ + $result = Chatroom::find($chatroomId)->messages()->latest('send_at')->limit(10)->get()->reverse(); + return $result; + }else{ + return null; + } + + } + diff --git a/plugins/tps/birzha/components/categoryprofile/default.htm b/plugins/tps/birzha/components/categoryprofile/default.htm index 45150d1..7cfd54a 100644 --- a/plugins/tps/birzha/components/categoryprofile/default.htm +++ b/plugins/tps/birzha/components/categoryprofile/default.htm @@ -1,5 +1,6 @@ {% set category = __SELF__.category %} {% set users = __SELF__.users %} +{% set subs = __SELF__.subcategories %}
@@ -8,6 +9,9 @@
Kategoriýa
@@ -25,14 +29,29 @@
@@ -49,7 +68,7 @@ {% for user in users %} -
+
@@ -69,133 +88,208 @@ -
-
-
- {% for category in category.subs %} - {% for product in category.products %} - -
-
- - - - - -
- - {% if user %} - - {% else %} - - {% endif %} - - -

{{product.vendor.shop_title}}

- {{ product.name }} -
{{ product.price }} TMT
-
-
-
- {% endfor %} - {% endfor %} +{% if category.subs.count == 0 %} +
+
+
+
+ Gurluşyk, Gurluşyk platform, bezeg gurluşyk, gipsler merkezi +
-
+
+
+

Şu wagtlykça bu bölümde haryt ýok

+
+
+
- - - -{% for category in category.subs %} - {% for product in category.products %} - -