diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/BlogPostsApiController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/BlogPostsApiController.php index b4f1057..60de2c9 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/BlogPostsApiController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/BlogPostsApiController.php @@ -18,6 +18,7 @@ use TPS\Birzha\Models\Favourites; use TPS\Birzha\Models\Notification; use TPS\Birzha\Models\Comment; use TPS\Birzha\Models\Sections; +use TPS\Birzha\Models\Category; use RainLab\User\Models\User; class BlogPostsApiController extends Controller @@ -35,6 +36,33 @@ class BlogPostsApiController extends Controller $this->helpers = $helpers; } + + public function getCategoryDatas(Request $request) + { + $path = 'https://gurlushyk.com.tm' . Config::get('cms.storage.media.path'); + + $data = $request->all(); + + + + $accounts = Category::select("id","name", "icon", "is_file_category", "primary_key")->where('id', $data["category"])->with("users:id,name,email,username,type,logo,shop_title,slogan,work_time,short_description,is_instagram")->get(); + + $banners = Category::select("id","name", "icon", "is_file_category", "primary_key")->where('id', $data["category"])->with(["users" => function($q){ + $q->where("is_category", 1)->select("category_id", "user_id", "logo", "banner", "is_instagram"); + }])->get(); + + + $data = array( + "path" => $path, + "accounts" => $accounts, + "banners" => $banners + ); + + + + return response()->json(array("data"=>$data), 200); + } + public function home(){ $path = 'https://gurlushyk.com.tm' . Config::get('cms.storage.media.path'); @@ -69,7 +97,7 @@ class BlogPostsApiController extends Controller }else if ($dataq->sections[$i]->section_type == "TPS\Birzha\Models\Product") { - $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')->with("place")->with([ + $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', @@ -287,6 +315,19 @@ class BlogPostsApiController extends Controller return response()->json($data, 200); } + public function getSubPlaces($id) + { + $data = City::where('primary_key', $id)->get()->toArray(); + + + array_unshift($data, array( + "id" => (0).$id, + "name" => "Ählisi", + "order" => 0, + )); + return $data; + } + public function getAccountDatas($id) { @@ -300,7 +341,11 @@ class BlogPostsApiController extends Controller ->with('sliders') ->first(); - $data->pathUrl = 'https://gurlushyk.com.tm' . \Config::get('cms.storage.media.path'); + $data->pathUrl = 'https://gurlushyk.com.tm' . \Config::get('cms.storage.media.path'); + $data->categories[0] = array( + "id" => 0, + "name"=> "Hemmesi", + ); return response()->json($data, 200); } diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/CategoriesAPIController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/CategoriesAPIController.php index 9ad1d12..88e4284 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/CategoriesAPIController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/CategoriesAPIController.php @@ -86,6 +86,11 @@ class CategoriesAPIController extends Controller } } + + public function subs($id){ + $subs = Category::where('primary_key', $id)->get(); + return $subs; + } // public function store(Request $request){ diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php index 7875ef8..c8209b7 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php @@ -77,8 +77,10 @@ class ProductsAPIController extends Controller $queryString = input('q'); $locale = input('locale'); + $type = input('type'); + $sortPrice = input('price'); - $place = intval(input('place')); + $place = input('place'); $seller = input('seller_id'); @@ -94,81 +96,89 @@ class ProductsAPIController extends Controller ->withCount(['comments as rating_avg' => function($query) { $query->select(DB::raw('avg(rating)')); }]) - ->approved() - ->orderBy('ends_at', $sortOrder); + ->approved(); + + + if($type){ + $query = $query->where("type", $type)->orderBy('ends_at', $sortOrder); + } + if($sortPrice) { // fetch offers by the category of the product - $query = $this->Product::with([ - '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' - ]) - ->withCount(['comments as rating_avg' => function($query) { - $query->select(DB::raw('avg(rating)')); - }]) - ->where('is_home', 1) - ->approved() - ->orderBy('price', $sortPrice) - ->orderBy('ends_at', $sortOrder); + $query = $query->orderBy('price', $sortPrice)->orderBy('ends_at', $sortOrder); } if($place) { // fetch offers by the category of the product - - $query = $this->Product::with([ - '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' - ]) - ->withCount(['comments as rating_avg' => function($query) { - $query->select(DB::raw('avg(rating)')); - }]) - ->where('is_home', 1) - ->approved() - ->where('place_id', $place) - ->orderBy('ends_at', $sortOrder); + + + if($place == (0).$place){ + + $allCity = City::where('primary_key', $place)->select("id")->get()->pluck('id')->toArray(); + + $query = $query->where("place_id", $allCity)->orderBy('ends_at', $sortOrder); + + }else{ + + $query = $query->where('place_id', $place)->orderBy('ends_at', $sortOrder); + + } + + } - if($sortPrice && $place) { - - $query = $this->Product::with([ + if($seller){ + + $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', 'place', - 'vendor:id,name,email,type,logo,banner,shop_title,slogan,is_instagram' - ]) - ->withCount(['comments as rating_avg' => function($query) { - $query->select(DB::raw('avg(rating)')); - }]) - ->where('is_home', 1) - ->approved() - ->where('place_id', $place) - ->orderBy('price', $sortPrice) - ->orderBy('ends_at', $sortOrder); - - } + ]) + ->withCount(['comments as rating_avg' => function($query) { + $query->select(DB::raw('avg(rating)')); + }]) + ->where('vendor_id', $seller) + ->approved(); + } + if($seller && $categorySeller) { $category = Category::find($categorySeller); + $sellerProducts = Product::where("vendor_id", $seller); + if($category) { - $query = $category->products() - ->with('categories:id,name') - ->with([ - 'translations:locale,model_id,attribute_data', - 'images:attachment_id,attachment_type,disk_name,file_name', - ]) - ->withCount(['comments as rating_avg' => function($query) { - $query->select(DB::raw('avg(rating)')); - }]) - ->where('vendor_id', $seller) - ->approved() - ->orderBy('ends_at', $sortOrder); + + if($categorySeller == 0){ + + $query = $sellerProducts->where('vendor_id', $seller)->with('categories:id,name') + ->with([ + 'translations:locale,model_id,attribute_data', + 'images:attachment_id,attachment_type,disk_name,file_name', + ])->approved()->orderBy('id', $sortOrder); + + }else{ + + $query = $category->products() + ->with('categories:id,name') + ->with([ + 'translations:locale,model_id,attribute_data', + 'images:attachment_id,attachment_type,disk_name,file_name', + ]) + ->withCount(['comments as rating_avg' => function($query) { + $query->select(DB::raw('avg(rating)')); + }]) + ->where('vendor_id', $seller) + ->approved() + ->orderBy('ends_at', $sortOrder); + + } + + } else { $query = null; } @@ -179,18 +189,40 @@ class ProductsAPIController extends Controller if($categoryId) { // fetch offers by the category of the product $category = Category::find($categoryId); if($category) { + $query = $category->products() - ->with('categories:id,name') - ->with([ - 'translations:locale,model_id,attribute_data', - 'images:attachment_id,attachment_type,disk_name,file_name', - 'place' - ]) - ->withCount(['comments as rating_avg' => function($query) { - $query->select(DB::raw('avg(rating)')); - }]) - ->approved() - ->orderBy('ends_at', $sortOrder); + ->with('categories:id,name') + ->with([ + 'translations:locale,model_id,attribute_data', + 'images:attachment_id,attachment_type,disk_name,file_name', + 'place' + ]) + ->withCount(['comments as rating_avg' => function($query) { + $query->select(DB::raw('avg(rating)')); + }]) + ->approved(); + + if($place) { // fetch offers by the category of the product + + if($place == (0).$place){ + + $allCity = City::where('primary_key', $place)->select("id")->get()->pluck('id')->toArray(); + + $query = $query->where("place_id", $allCity)->orderBy('ends_at', $sortOrder); + + }else{ + + $query = $query->where('place_id', $place)->orderBy('ends_at', $sortOrder); + + } + } + + if($sortPrice){ + + $query = $query->orderBy('price', $sortPrice)->orderBy('ends_at', $sortOrder); + } + + } else { $query = null; } diff --git a/plugins/ahmadfatoni/apigenerator/routes.php b/plugins/ahmadfatoni/apigenerator/routes.php index 91bc3c7..3bce04f 100644 --- a/plugins/ahmadfatoni/apigenerator/routes.php +++ b/plugins/ahmadfatoni/apigenerator/routes.php @@ -8,7 +8,7 @@ Route::group(['prefix' =>'api/v1','namespace' =>'AhmadFatoni\ApiGenerator\Contro Route::resource('categories', 'CategoriesAPIController', ['except' => ['destroy', 'create', 'edit']]); - // Route::get('categories/{id}/delete', ['as' => 'categories.delete', 'uses' => 'CategoriesAPIController@destroy']); + Route::get('category/{id}/subs', ['as' => 'category.subs', 'uses' => 'CategoriesAPIController@subs']); Route::get('products', ['as' => 'products.index', 'uses' => 'ProductsApiController@index']); @@ -35,6 +35,7 @@ Route::group(['prefix' =>'api/v1','namespace' =>'AhmadFatoni\ApiGenerator\Contro Route::get('sliders', 'BlogPostsApiController@getSliders'); Route::get('places', 'BlogPostsApiController@getPlaces'); + Route::get('places/{id}/subs', ['as' => 'place.subs', 'uses' => 'BlogPostsApiController@getSubPlaces']); Route::get('accounts', 'BlogPostsApiController@getAccounts'); @@ -46,7 +47,7 @@ Route::group(['prefix' =>'api/v1','namespace' =>'AhmadFatoni\ApiGenerator\Contro Route::get('account/{id}/products', 'BlogPostsApiController@getAccountProducts')->where(['id' => '[0-9]+']); Route::get('account/{id}/datas', 'BlogPostsApiController@getAccountDatas'); - + Route::get('get/category/datas', 'BlogPostsApiController@getCategoryDatas'); Route::middleware(['\Tymon\JWTAuth\Middleware\GetUserFromToken'])->group(function () { Route::delete('delete/account', 'VendorApiController@deleteVendor'); diff --git a/plugins/rainlab/user/models/user/fields.yaml b/plugins/rainlab/user/models/user/fields.yaml index a0613de..d570365 100644 --- a/plugins/rainlab/user/models/user/fields.yaml +++ b/plugins/rainlab/user/models/user/fields.yaml @@ -183,6 +183,18 @@ tabs: imageWidth: '220' type: mediafinder 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' + type: balloon-selector + tab: 'Web Wariantlar' secondaryTabs: fields: avatar: diff --git a/plugins/tps/birzha/Plugin.php b/plugins/tps/birzha/Plugin.php index 67d6cd0..4de8e48 100644 --- a/plugins/tps/birzha/Plugin.php +++ b/plugins/tps/birzha/Plugin.php @@ -59,6 +59,17 @@ class Plugin extends PluginBase ]; } + + + public function registerMarkupTags() + { + return [ + 'functions' => [ + 'getProductName' => ['TPS\Birzha\Classes\Product', 'getName'], + 'getProductImage' => ['TPS\Birzha\Classes\Product', 'getImage'], + ] + ]; + } public function moneyColumn($value, $column, $record){ return ''.number_format($value,2).' tmt'; @@ -341,13 +352,14 @@ class Plugin extends PluginBase 'TPS\Birzha\Components\Categories' => 'categories', 'TPS\Birzha\Components\Sliders' => 'sliders', 'TPS\Birzha\Components\Offers' => 'offers', - 'TPS\Birzha\Components\FilteredProducts' => 'filteredProducts', + 'TPS\Birzha\Components\FilteredProducts' => 'filteredproducts', 'TPS\Birzha\Components\Singleoffer' => 'singleoffer', 'TPS\Birzha\Components\ShopSettings' => 'shopsettings', 'TPS\Birzha\Components\OfferForm' => 'offerform', 'TPS\Birzha\Components\Messages' => 'messages', 'TPS\Birzha\Components\PaymentApi' => 'paymentapi', 'TPS\Birzha\Components\MyOffers' => 'myOffers', + 'TPS\Birzha\Components\MyOrders' => 'myorders', 'TPS\Birzha\Components\MyComments' => 'mycomments', 'TPS\Birzha\Components\MyFavourites' => 'myfavourites', 'TPS\Birzha\Components\UserOffers' => 'userOffers', @@ -360,6 +372,7 @@ class Plugin extends PluginBase 'TPS\Birzha\Components\Birzhadocs' => 'birzhadocs', 'TPS\Birzha\Components\CategoryProfile' => 'categoryprofile', 'TPS\Birzha\Components\Checkout' => 'checkout', + 'TPS\Birzha\Components\OrderDetail' => 'orderdetail', ]; } diff --git a/plugins/tps/birzha/classes/Product.php b/plugins/tps/birzha/classes/Product.php new file mode 100644 index 0000000..17ddbed --- /dev/null +++ b/plugins/tps/birzha/classes/Product.php @@ -0,0 +1,20 @@ +name; + } + + public static function getImage($id) + { + $product = ProductItem::find($id); + return $product->images[0]->path; + } +} \ No newline at end of file diff --git a/plugins/tps/birzha/components/FilteredProducts.php b/plugins/tps/birzha/components/FilteredProducts.php index 931ebcb..79776d9 100644 --- a/plugins/tps/birzha/components/FilteredProducts.php +++ b/plugins/tps/birzha/components/FilteredProducts.php @@ -58,6 +58,7 @@ class FilteredProducts extends ComponentBase { $allParams = \Input::all(); + $params = ''; foreach ($allParams as $key => $item) { @@ -102,6 +103,7 @@ class FilteredProducts extends ComponentBase $sortOrder = $sortOrderParam; $this->sortParam = $sortOrderParam; } + $perPage = $this->property('perPage'); $products = Product::query(); @@ -136,8 +138,7 @@ class FilteredProducts extends ComponentBase $products = $products->orderBy( $sort[0], $sort[1]); } - $products = $products->where('status', 'approved')->withCount("images")->orderBy('updated_at', $sortOrder); - + $products = $products->where('status', 'approved')->withCount("images"); return $products ? $products->paginate($perPage) : null; } diff --git a/plugins/tps/birzha/components/MyOrders.php b/plugins/tps/birzha/components/MyOrders.php new file mode 100644 index 0000000..d21c339 --- /dev/null +++ b/plugins/tps/birzha/components/MyOrders.php @@ -0,0 +1,51 @@ + 'MyOrders List', + 'description' => 'List of my orders' + ]; + } + + public function defineProperties() + { + return [ + 'perPage' => [ + 'title' => 'Number of offers', + 'description' => 'How many offers do you want to display', + 'default' => 12, + 'validationPattern' => '^[0-9]+$', + 'validationMessage' => 'Only numbers allowed' + ], + ]; + } + + + public function onRun() { + $this->orders = $this->loadOrders(); + } + + protected function loadOrders() { + $perPage = $this->property('perPage'); + return \Auth::user()->orders() + ->orderBy('updated_at', 'desc') + ->paginate($perPage); + } + + +} diff --git a/plugins/tps/birzha/components/OfferForm.php b/plugins/tps/birzha/components/OfferForm.php index 7cb4a91..1a98f0d 100644 --- a/plugins/tps/birzha/components/OfferForm.php +++ b/plugins/tps/birzha/components/OfferForm.php @@ -91,11 +91,18 @@ class OfferForm extends ComponentBase } $category = null; - if($data["subcategory_id"] != 'null'){ + if(isset($data["subcategory_id"]) && $data["subcategory_id"] != 'null'){ $category = Category::find($data['subcategory_id']); }else{ $category = Category::find($data['category_id']); } + + $place = null; + if(isset($data["city_id"]) && $data["city_id"] != 'null'){ + $place = $data['city_id']; + }else{ + $place = $data['state_id']; + } $product = new Product; $product->name = $data['name']; @@ -103,7 +110,7 @@ class OfferForm extends ComponentBase $product->short_description = $data['short_description']; $product->slug = \Str::slug($data['name'],'-'); $product->status = 'new'; - $product->place_id = $data['city_id'] == 'null' ? $data['state_id'] : $data['city_id']; + $product->place_id = $place; $product->price = $data['price']; $product->phone = $data['phone']; $product->is_file_product = $data['is_file']; diff --git a/plugins/tps/birzha/components/Offers.php b/plugins/tps/birzha/components/Offers.php index 97f17e0..05ed43a 100644 --- a/plugins/tps/birzha/components/Offers.php +++ b/plugins/tps/birzha/components/Offers.php @@ -119,7 +119,7 @@ class Offers extends ComponentBase $productSlug = $this->property('productSlug'); $offerId = $this->property('offerId'); - $query = Product::where('status', 'approved')->withCount("images") + $query = Product::where('status', 'approved')->with("vendor")->withCount("images") ->orderBy('ends_at', $sortOrder); if($cSlug != '') { diff --git a/plugins/tps/birzha/components/OrderDetail.php b/plugins/tps/birzha/components/OrderDetail.php new file mode 100644 index 0000000..4d7d830 --- /dev/null +++ b/plugins/tps/birzha/components/OrderDetail.php @@ -0,0 +1,46 @@ + 'Single order', + 'description' => 'Selected order' + ]; + } + + public function defineProperties() + { + return [ + 'id' => [ + 'title' => 'Order id', + 'description' => 'Order id', + 'type' => 'string', + 'default' => '{{ :id }}' + ] + ]; + } + + + public function onRun() { + $this->order = $this->loadOrder(); + } + + + + + protected function loadOrder() { + $order = OrderItems::where('order_id', $this->property('id'))->first(); + return $order; + } +} \ No newline at end of file diff --git a/plugins/tps/birzha/components/SearchOffers.php b/plugins/tps/birzha/components/SearchOffers.php index 5e03cb9..c92c86e 100644 --- a/plugins/tps/birzha/components/SearchOffers.php +++ b/plugins/tps/birzha/components/SearchOffers.php @@ -67,7 +67,7 @@ class SearchOffers extends ComponentBase $products = $products->where('name', 'like', '%'.$title.'%')->withCount("images"); } - $products = $products->paginate($perPage); + $products = $products->with("vendor")->paginate($perPage); return $products; } diff --git a/plugins/tps/birzha/components/UserOffers.php b/plugins/tps/birzha/components/UserOffers.php index 0c84658..19b60ab 100644 --- a/plugins/tps/birzha/components/UserOffers.php +++ b/plugins/tps/birzha/components/UserOffers.php @@ -14,8 +14,10 @@ class UserOffers extends ComponentBase */ public $userProducts; public $userCategories; - public $user; + public $userProfile; public $params; + public $sliders; + public $currentCat; public function componentDetails() { @@ -65,8 +67,10 @@ class UserOffers extends ComponentBase $this->params = $params; $this->userCategories = $this->loadCategories(); - $this->user = $this->loadUser(); + $this->userProfile = $this->loadUser(); $this->userProducts = $this->loadProducts(); + $this->sliders = $this->loadSliders(); + $this->currentCat = $this->loadCurrentCategory(); } protected function loadProducts() { @@ -75,10 +79,14 @@ class UserOffers extends ComponentBase $sort = \Input::get('sort'); $vendor_id = $this->property('id'); $categorySlug = $this->property('slug'); + $category = null; - $category = Category::where('slug', $categorySlug)->first(); + if($categorySlug){ + $category = Category::where('slug', $categorySlug)->first(); + } $products = Product::query(); + if($category){ if (isset($sort) && $sort != '') { $sort = self::getSort($sort); @@ -90,9 +98,14 @@ class UserOffers extends ComponentBase if (isset($sort) && $sort != '') { $sort = self::getSort($sort); $products = $products->where("vendor_id", $vendor_id)->withCount("images")->orderBy( $sort[0], $sort[1]); - } + }else{ + + $products = $products->where("vendor_id", $vendor_id)->withCount("images")->orderBy( "id", "DESC"); + + } } $products = $products->paginate($perPage); + return $products; } @@ -113,14 +126,33 @@ class UserOffers extends ComponentBase protected function loadCategories(){ $user = User::find($this->property('id')); - $categories = $user->categories()->get(); - return $categories; + if($user){ + $categories = $user->categories()->get(); + return $categories; + } + + return null; } - - protected function loadUser(){ - $user = User::find($this->property('id')); + + protected function loadCurrentCategory(){ + $currentCat = Category::where("slug", $this->property('slug'))->first(); + if($currentCat){ + return $currentCat; + } + + return null; + } + + public function loadUser(){ + $user = User::with("sliders")->find($this->property('id')); return $user; } + + protected function loadSliders(){ + $user = User::find($this->property('id')); + return $user->sliders()->get(); + } + diff --git a/plugins/tps/birzha/components/categories/with_images.htm b/plugins/tps/birzha/components/categories/with_images.htm index 6a93369..238c079 100644 --- a/plugins/tps/birzha/components/categories/with_images.htm +++ b/plugins/tps/birzha/components/categories/with_images.htm @@ -21,7 +21,7 @@ >