diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/BlogPostsApiController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/BlogPostsApiController.php index d9cbc81..fd1d087 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/BlogPostsApiController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/BlogPostsApiController.php @@ -20,6 +20,7 @@ use TPS\Birzha\Models\Comment; use TPS\Birzha\Models\Sections; use TPS\Birzha\Models\Category; use RainLab\User\Models\User; +use ToughDeveloper\ImageResizer\Classes\Image; class BlogPostsApiController extends Controller { @@ -101,6 +102,7 @@ class BlogPostsApiController 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,web2', 'place' ]) ->withCount(['comments as rating_avg' => function($query) { @@ -110,6 +112,19 @@ class BlogPostsApiController extends Controller ->orderBy("id", "DESC") ->paginate(12); + $products->map(function ($product) { + + $image = new Image($product->images[0]->path); + $product->images[0]->compressed_image = $image->resize([ 'quality' => 50])->getCachedImagePath(true); + + return $product; + //foreach($product->images as $compressImage){ + // $image = new Image($compressImage->path); + // $compressImage->compressed_image = $image->resize([ 'quality' => 50])->getCachedImagePath(true); + //} + + }); + return response()->json(array("data"=>$products), 200); } @@ -180,7 +195,7 @@ class BlogPostsApiController extends Controller $modified = $dataq->sections[$i]->section_type::where('type', $dataq->sections[$i]->product_type)->select('id', 'name', 'price', 'description', 'place_id', 'vendor_id', 'number_of_views', 'is_home', 'short_description', 'type')->with("place")->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', + 'vendor:id,name,email,type,logo,banner,shop_title,slogan,is_instagram,web2', ])->limit(10)->get(); // $modified->makeHidden(['created_at', 'updated_at', 'deleted_at']); $product_section = array( @@ -349,10 +364,18 @@ class BlogPostsApiController extends Controller $favourite = $this->Favourites::where('user_id', $currentUser->id) ->with(['product' => function($q){ - $q->approved()->withTrashed()->with(['images', 'place', 'files', 'translations:locale,model_id,attribute_data']); + $q->approved()->withTrashed()->with(['images:attachment_id,attachment_type,disk_name,file_name', 'place', 'files', 'translations:locale,model_id,attribute_data', 'vendor:id,name,email,type,logo,banner,shop_title,slogan,is_instagram,web2',]); }])->paginate(9); //dd($favourite); - + + $favourite->map(function ($fav) { + + $image = new Image($fav->product->images[0]->path); + $fav->product->images[0]->compressed_image = $image->resize([ 'quality' => 50])->getCachedImagePath(true); + + return $fav; + }); + return response()->json($favourite, 200); } @@ -379,6 +402,19 @@ class BlogPostsApiController extends Controller ->approved() ->paginate(9); + $data->map(function ($product) { + + $image = new Image($product->images[0]->path); + $product->images[0]->compressed_image = $image->resize([ 'quality' => 50])->getCachedImagePath(true); + + return $product; + //foreach($product->images as $compressImage){ + // $image = new Image($compressImage->path); + // $compressImage->compressed_image = $image->resize([ 'quality' => 50])->getCachedImagePath(true); + //} + + }); + return response()->json($data, 200); } @@ -422,7 +458,7 @@ class BlogPostsApiController extends Controller //$data = User::find($id)->first; - $data = User::where('id', $id)->select('id', 'name', 'email', 'username', 'type', 'logo', 'shop_title', 'slogan', 'work_time', 'short_description', 'description', 'map', 'banner', 'is_instagram', 'tiktok', 'instagram', 'site', 'qr') + $data = User::where('id', $id) ->with(['categories' => function($q){ $q->with('translations:locale,model_id,attribute_data'); }]) diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/OrderApiController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/OrderApiController.php index 572fe1d..a1b90d8 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/OrderApiController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/OrderApiController.php @@ -121,7 +121,7 @@ class OrderApiController extends Controller $orders[$i]->products = Product::whereIn("id", $productsCollectId) ->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', + 'vendor:id,name,email,type,logo,banner,shop_title,slogan,is_instagram,web2', 'place',]) ->withTrashed() ->get(); diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php index 370c18a..6b9ee33 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php @@ -48,20 +48,16 @@ class ProductsAPIController extends Controller $perPage = intval(input('custom_per_page')); // intval protects from injection try { - $products = Product::where('keyword', 'like', "%".$data["key"]."%")->orWhere('name', 'like', "%".$data["key"]."%")->orWhere('slug','LIKE','%'.$data["key"].'%')->with(['translations:locale,model_id,attribute_data', + $products = Product::where('keyword', 'like', "%".(string)$data["key"]."%")->orWhere('name', 'like', "%".$data["key"]."%")->orWhere('slug','LIKE','%'.$data["key"].'%')->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',])->where('status', 'approved')->get(); + 'vendor:id,name,email,type,logo,banner,shop_title,slogan,is_instagram,web2', + 'place',])->where('status', 'approved')->paginate(15); - $products = $products->map(function ($product) { - + $products->map(function ($product) { $image = new Image($product->images[0]->path); - $imageResized = $image->resize(200,200)->getCachedImagePath(true); - $product->images[0]->path2 = $imageResized; - $product->images[0]->path = $imageResized; + $product->images[0]->compressed_image = $image->resize([ 'quality' => 50])->getCachedImagePath(true); return $product; - }); // foreach($products as $product) { @@ -110,7 +106,7 @@ class ProductsAPIController extends Controller $query = Product::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', + 'vendor:id,name,email,type,logo,banner,shop_title,slogan,is_instagram,web2', 'place', ]) ->withCount(['comments as rating_avg' => function($query) { @@ -155,7 +151,7 @@ class ProductsAPIController extends Controller $query = Product::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', + 'vendor:id,name,email,type,logo,banner,shop_title,slogan,is_instagram,web2', 'place', ]) ->withCount(['comments as rating_avg' => function($query) { @@ -179,7 +175,7 @@ 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', + 'vendor:id,name,email,type,logo,banner,shop_title,slogan,is_instagram,web2', 'place', ])->approved()->orderBy('id', $sortOrder); @@ -190,7 +186,7 @@ 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', + 'vendor:id,name,email,type,logo,banner,shop_title,slogan,is_instagram,web2', 'place', ]) ->withCount(['comments as rating_avg' => function($query) { @@ -219,6 +215,7 @@ 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,web2', 'place' ]) ->withCount(['comments as rating_avg' => function($query) { @@ -258,7 +255,7 @@ class ProductsAPIController extends Controller 'translations:locale,model_id,attribute_data', 'images:attachment_id,attachment_type,disk_name,file_name', 'place', - 'vendor:id,name,email,type,logo,banner,shop_title,slogan,is_instagram' + 'vendor:id,name,email,type,logo,banner,shop_title,slogan,is_instagram,web2' ]) ->withCount(['comments as rating_avg' => function($query) { $query->select(DB::raw('avg(rating)')); @@ -309,7 +306,20 @@ class ProductsAPIController extends Controller $data = $query ? $query->orderBy('id', "DESC")->orderBy('ends_at', $sortOrder)->paginate($perPage) : null; - + $data->map(function ($product) { + + $image = new Image($product->images[0]->path); + $product->images[0]->compressed_image = $image->resize(500)->getCachedImagePath(true); + + return $product; + + //foreach($product->images as $compressImage){ + // $image = new Image($compressImage->path); + // $compressImage->compressed_image = $image->resize([ 'quality' => 50])->getCachedImagePath(true); + //} + + }); + return response()->json($data, 200); } @@ -323,7 +333,7 @@ class ProductsAPIController extends Controller $data = $this->Product::with([ 'translations:locale,model_id,attribute_data', 'images:id,attachment_id,attachment_type,disk_name,file_name', - 'vendor:id,name,surname,email,username,logo,banner,type', + 'vendor:id,name,surname,email,username,logo,banner,type,web2', 'files', 'place', 'categories:id,name,slug,primary_key,icon' ]) //->withCount('comments')->withAvg('comments', 'rating') diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/VendorApiController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/VendorApiController.php index 450c5e4..3d92948 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/VendorApiController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/VendorApiController.php @@ -62,7 +62,10 @@ class VendorApiController extends Controller } //dd($data); $currentUser = \JWTAuth::parseToken()->authenticate(); - $vendor = Vendor::find($currentUser->id)->first(); + $vendor = Vendor::where("id", $currentUser->id)->with(['categories' => function($q){ + $q->with('translations:locale,model_id,attribute_data'); + }]) + ->with('sliders')->first(); //dd($vendor->type); @@ -72,9 +75,25 @@ class VendorApiController extends Controller $vendor->slogan = $data["slogan"]; $vendor->work_time = $data["work_time"]; $vendor->description = $data["description"]; + $vendor->short_description = $data["short_description"] ?? ""; + $vendor->web2 = (int) $data["discount"]; + $vendor->tiktok = $data["tiktok"]; + $vendor->instagram = $data["instagram"]; + $vendor->site = $data["site"]; $vendor->save(); - return $this->helpers->apiArrayResponseBuilder(200, 'ok', [$vendor]); + $vendor->pathUrl = 'https://gurlushyk.com.tm' . \Config::get('cms.storage.media.path'); + + + $all = array( + "id" => 0, + "name"=> "Hemmesi", + ); + + + $vendor->categories->prepend($all); + + return response()->json($vendor, 200); }else{ diff --git a/plugins/tps/birzha/components/CategoryProfile.php b/plugins/tps/birzha/components/CategoryProfile.php index ecee6b3..93cfcb3 100644 --- a/plugins/tps/birzha/components/CategoryProfile.php +++ b/plugins/tps/birzha/components/CategoryProfile.php @@ -73,21 +73,22 @@ class CategoryProfile extends ComponentBase 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(); + $subs = $category ? Category::where("primary_key", $category->id)->get() : null; - foreach ($subs as $subcategory) { - $page = input('page', 1); - $products = $subcategory->products()->paginate(12, $page); - $subcategory->setRelation('products', $products); + if($subs){ + 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(); + $users = $category ? $category->users()->get() : null; return $users; } diff --git a/plugins/tps/birzha/components/ShopSettings.php b/plugins/tps/birzha/components/ShopSettings.php index 470337e..7d979b5 100644 --- a/plugins/tps/birzha/components/ShopSettings.php +++ b/plugins/tps/birzha/components/ShopSettings.php @@ -24,7 +24,7 @@ class ShopSettings extends ComponentBase public function onRun() { - $this->user = $this->loadShopSettings(); + //$this->user = $this->loadShopSettings(); } @@ -32,6 +32,13 @@ class ShopSettings extends ComponentBase $user = User::find(\Auth::user()->id); return $user; } + + public function onDelete(){ + $user = User::find(\Auth::user()->id); + $user->delete(); + Flash::success('Hasabyňyz pozuldy'); + return \Redirect::back(); + } public function onSave(){ @@ -48,14 +55,19 @@ class ShopSettings extends ComponentBase $user = User::find(\Auth::user()->id); + $user->instagram = $data['instagram']; + $user->tiktok = $data['tiktok']; + $user->site = $data['website']; $user->shop_title = $data['vendorName']; $user->slogan = $data['slogan']; + $user->short_description = $data['short_description']; $user->description = $data['description']; $user->work_time = $data['workTime']; $user->web2 = $data['discount'] ? number_format($data['discount'], 2, '.', '') : null; $user->save(); Flash::success('Maglumatlar üýtgedildi'); + return \Redirect::back(); } protected function validateForm($data, $rules) { diff --git a/plugins/tps/birzha/components/shopsettings/default.htm b/plugins/tps/birzha/components/shopsettings/default.htm index 37dbe2a..0e31e51 100644 --- a/plugins/tps/birzha/components/shopsettings/default.htm +++ b/plugins/tps/birzha/components/shopsettings/default.htm @@ -1,4 +1,3 @@ -{% set user = __SELF__.user %}
{{ product.description|raw }}