diff --git a/composer.json b/composer.json index 98e408d..f061a9d 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ "october/system": "1.1.*", "october/backend": "1.1.*", "october/cms": "1.1.*", - "laravel/framework": "~6.0" + "laravel/framework": "~6.0", + "renatio/dynamicpdf-plugin": "^6.0" }, "require-dev": { "phpunit/phpunit": "^8.4|^9.3.3", diff --git a/config/app.php b/config/app.php index 5f2d8e9..6dee362 100644 --- a/config/app.php +++ b/config/app.php @@ -41,7 +41,7 @@ return [ | */ - 'url' => 'http://localhost', + 'url' => 'https://gurlushyk.com.tm', /* |-------------------------------------------------------------------------- diff --git a/config/dompdf.php b/config/dompdf.php new file mode 100644 index 0000000..692a131 --- /dev/null +++ b/config/dompdf.php @@ -0,0 +1,248 @@ + false, // Throw an Exception on warnings from dompdf + 'orientation' => 'portrait', + /* + * Dejavu Sans font is missing glyphs for converted entities, turn it off if you need to show € and £. + */ + 'convert_entities' => true, + 'defines' => array( + /** + * The location of the DOMPDF font directory + * + * The location of the directory where DOMPDF will store fonts and font metrics + * Note: This directory must exist and be writable by the webserver process. + * *Please note the trailing slash.* + * + * Notes regarding fonts: + * Additional .afm font metrics can be added by executing load_font.php from command line. + * + * Only the original "Base 14 fonts" are present on all pdf viewers. Additional fonts must + * be embedded in the pdf file or the PDF may not display correctly. This can significantly + * increase file size unless font subsetting is enabled. Before embedding a font please + * review your rights under the font license. + * + * Any font specification in the source HTML is translated to the closest font available + * in the font directory. + * + * The pdf standard "Base 14 fonts" are: + * Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique, + * Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique, + * Times-Roman, Times-Bold, Times-BoldItalic, Times-Italic, + * Symbol, ZapfDingbats. + */ + "font_dir" => storage_path('fonts'), // advised by dompdf (https://github.com/dompdf/dompdf/pull/782) + + /** + * The location of the DOMPDF font cache directory + * + * This directory contains the cached font metrics for the fonts used by DOMPDF. + * This directory can be the same as DOMPDF_FONT_DIR + * + * Note: This directory must exist and be writable by the webserver process. + */ + "font_cache" => storage_path('fonts'), + + /** + * The location of a temporary directory. + * + * The directory specified must be writeable by the webserver process. + * The temporary directory is required to download remote images and when + * using the PFDLib back end. + */ + "temp_dir" => sys_get_temp_dir(), + + /** + * ==== IMPORTANT ==== + * + * dompdf's "chroot": Prevents dompdf from accessing system files or other + * files on the webserver. All local files opened by dompdf must be in a + * subdirectory of this directory. DO NOT set it to '/' since this could + * allow an attacker to use dompdf to read any files on the server. This + * should be an absolute path. + * This is only checked on command line call by dompdf.php, but not by + * direct class use like: + * $dompdf = new DOMPDF(); $dompdf->load_html($htmldata); $dompdf->render(); $pdfdata = $dompdf->output(); + */ + "chroot" => realpath(base_path()), + + /** + * Whether to enable font subsetting or not. + */ + "enable_font_subsetting" => false, + + /** + * The PDF rendering backend to use + * + * Valid settings are 'PDFLib', 'CPDF' (the bundled R&OS PDF class), 'GD' and + * 'auto'. 'auto' will look for PDFLib and use it if found, or if not it will + * fall back on CPDF. 'GD' renders PDFs to graphic files. {@link + * Canvas_Factory} ultimately determines which rendering class to instantiate + * based on this setting. + * + * Both PDFLib & CPDF rendering backends provide sufficient rendering + * capabilities for dompdf, however additional features (e.g. object, + * image and font support, etc.) differ between backends. Please see + * {@link PDFLib_Adapter} for more information on the PDFLib backend + * and {@link CPDF_Adapter} and lib/class.pdf.php for more information + * on CPDF. Also see the documentation for each backend at the links + * below. + * + * The GD rendering backend is a little different than PDFLib and + * CPDF. Several features of CPDF and PDFLib are not supported or do + * not make any sense when creating image files. For example, + * multiple pages are not supported, nor are PDF 'objects'. Have a + * look at {@link GD_Adapter} for more information. GD support is + * experimental, so use it at your own risk. + * + * @link http://www.pdflib.com + * @link http://www.ros.co.nz/pdf + * @link http://www.php.net/image + */ + "pdf_backend" => "CPDF", + + /** + * PDFlib license key + * + * If you are using a licensed, commercial version of PDFlib, specify + * your license key here. If you are using PDFlib-Lite or are evaluating + * the commercial version of PDFlib, comment out this setting. + * + * @link http://www.pdflib.com + * + * If pdflib present in web server and auto or selected explicitely above, + * a real license code must exist! + */ + //"DOMPDF_PDFLIB_LICENSE" => "your license key here", + + /** + * html target media view which should be rendered into pdf. + * List of types and parsing rules for future extensions: + * http://www.w3.org/TR/REC-html40/types.html + * screen, tty, tv, projection, handheld, print, braille, aural, all + * Note: aural is deprecated in CSS 2.1 because it is replaced by speech in CSS 3. + * Note, even though the generated pdf file is intended for print output, + * the desired content might be different (e.g. screen or projection view of html file). + * Therefore allow specification of content here. + */ + "default_media_type" => "screen", + + /** + * The default paper size. + * + * North America standard is "letter"; other countries generally "a4" + * + * @see CPDF_Adapter::PAPER_SIZES for valid sizes ('letter', 'legal', 'A4', etc.) + */ + "default_paper_size" => "a4", + + /** + * The default font family + * + * Used if no suitable fonts can be found. This must exist in the font folder. + * @var string + */ + "default_font" => "serif", + + /** + * Image DPI setting + * + * This setting determines the default DPI setting for images and fonts. The + * DPI may be overridden for inline images by explictly setting the + * image's width & height style attributes (i.e. if the image's native + * width is 600 pixels and you specify the image's width as 72 points, + * the image will have a DPI of 600 in the rendered PDF. The DPI of + * background images can not be overridden and is controlled entirely + * via this parameter. + * + * For the purposes of DOMPDF, pixels per inch (PPI) = dots per inch (DPI). + * If a size in html is given as px (or without unit as image size), + * this tells the corresponding size in pt. + * This adjusts the relative sizes to be similar to the rendering of the + * html page in a reference browser. + * + * In pdf, always 1 pt = 1/72 inch + * + * Rendering resolution of various browsers in px per inch: + * Windows Firefox and Internet Explorer: + * SystemControl->Display properties->FontResolution: Default:96, largefonts:120, custom:? + * Linux Firefox: + * about:config *resolution: Default:96 + * (xorg screen dimension in mm and Desktop font dpi settings are ignored) + * + * Take care about extra font/image zoom factor of browser. + * + * In images, size in pixel attribute, img css style, are overriding + * the real image dimension in px for rendering. + * + * @var int + */ + "dpi" => 96, + + /** + * Enable inline PHP + * + * If this setting is set to true then DOMPDF will automatically evaluate + * inline PHP contained within tags. + * + * Enabling this for documents you do not trust (e.g. arbitrary remote html + * pages) is a security risk. Set this option to false if you wish to process + * untrusted documents. + * + * @var bool + */ + "enable_php" => false, + + /** + * Enable inline Javascript + * + * If this setting is set to true then DOMPDF will automatically insert + * JavaScript code contained within tags. + * + * @var bool + */ + "enable_javascript" => true, + + /** + * Enable remote file access + * + * If this setting is set to true, DOMPDF will access remote sites for + * images and CSS files as required. + * This is required for part of test case www/test/image_variants.html through www/examples.php + * + * Attention! + * This can be a security risk, in particular in combination with DOMPDF_ENABLE_PHP and + * allowing remote access to dompdf.php or on allowing remote html code to be passed to + * $dompdf = new DOMPDF(, $dompdf->load_html(..., + * This allows anonymous users to download legally doubtful internet content which on + * tracing back appears to being downloaded by your server, or allows malicious php code + * in remote html pages to be executed by your server with your account privileges. + * + * @var bool + */ + "enable_remote" => true, + + /** + * A ratio applied to the fonts height to be more like browsers' line height + */ + "font_height_ratio" => 1.1, + + /** + * Use the more-than-experimental HTML5 Lib parser + */ + "enable_html5_parser" => false, + ), + + +); diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/MessagesapiController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/MessagesapiController.php index 71c6594..bf1d38c 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/MessagesapiController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/MessagesapiController.php @@ -54,8 +54,15 @@ class MessagesapiController extends Controller return $chatroom; }); - if(count($chatrooms) < 0){ - $chatrooms[0]->path = 'https://gurlushyk.com.tm' . \Config::get('cms.storage.media.path'); + + + + if(count($chatrooms) > 0){ + + for ($i = 0; $i < count($chatrooms); $i++) { + $chatrooms[$i]->path = 'https://gurlushyk.com.tm' . \Config::get('cms.storage.media.path'); + } + } // dump(\DB::getQueryLog()); // dd($this->helpers->apiArrayResponseBuilder(200, 'success', ['chatrooms' => $chatrooms])); diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/OrderApiController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/OrderApiController.php index 70e7bcf..572fe1d 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/OrderApiController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/OrderApiController.php @@ -12,6 +12,8 @@ use TPS\Birzha\Models\VendorSales; use RainLab\User\Models\User as UserClient; use Sms\Sms\Models\SmsSender; use RainLab\Translate\Models\Message; +use App; +use Config; class OrderApiController extends Controller { @@ -26,7 +28,10 @@ class OrderApiController extends Controller $this->helpers = $helpers; } + + public function createOrder(Request $request){ + $data = $request->all(); $validator = Validator::make($data, [ @@ -53,7 +58,7 @@ class OrderApiController extends Controller $order->save(); - $this->sendSMS($currentUser->username, Message::trans('success.ordered')); + $this->sendSMS($currentUser->username, 'Siz üstünlikli sargyt etdiňiz. Menejerimiz siz bilen habarlaşar'); // [{"item":34,"qty":1},{"item":35,"qty":3}] $orderItem = new OrderItems; @@ -78,7 +83,7 @@ class OrderApiController extends Controller $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, Message::trans('success.ordered.vendor')); + $this->sendSMS($vendorPhones[$x]->vendor->username, 'Gurluşyk programmasyndan size sargyt edildi'); } @@ -100,24 +105,28 @@ class OrderApiController extends Controller $currentUser = \JWTAuth::parseToken()->authenticate(); - //$orders = Orders::where("user_id", $currentUser->id)->with(["order_items"])->orderBy('id', 'DESC')->paginate(12); - $orders = VendorSales::with("order")->whereHas('order', function ($query) use($currentUser) { - $query->where('user_id', $currentUser->id); - })->groupBy("order_id")->orderBy("id", "DESC")->paginate(12); - - for ($i = 0; $i < count($orders); $i++) { + $orders = Orders::where("user_id", $currentUser->id)->with('order_items')->orderBy('id', 'DESC')->paginate(12); + + for ($i = 0; $i < count($orders); $i++) { - $products = VendorSales::where("order_id", $orders[$i]->order_id)->with(["product" => function($q){ - $q->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', - ]); - }])->get(); + $product_items = $orders[$i]->order_items[0]->items; + $productsCollectId = []; + for ($ii = 0; $ii < count($product_items); $ii++) { + + $productsCollectId[] = (int)$product_items[$ii]["item"]; + + } - $orders[$i]->products = $products; + $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', + 'place',]) + ->withTrashed() + ->get(); + + $orders[$i]->makeHidden(['order_items']); } return response()->json($orders, 200); @@ -126,6 +135,127 @@ class OrderApiController extends Controller } + public function makeTemplate($sales) + { + //$asset = new \Cms\Classes\Asset($this->controller->getTheme()); + + + $html = " + + + + + SARGYT #NO:" . $sales[0]->order_id . " + + + + + + +
+ + + + + + +
Sargyt No: #".$sales[0]->order_id." Sene: ".$sales[0]->created_at->format('d.m.Y')."
+ + + + + + + + + + + + + + + + + + + +
Ady: ".$sales[0]->order->user->name."
Telefon: +993 ".$sales[0]->order->user->username."
Salgy: ".$sales[0]->order->address."
Telefon2: +993 ".$sales[0]->order->phone."
Bellik: ".$sales[0]->order->note."
+ +
+ +
+ + + + + + + + + + "; + + for ($ii = 0; $ii < count($sales); $ii++) { + + $html .=" + + + + "; + + } + + $html .="
#SuratyAdyBahasy
".($ii+1)." + ".$sales[$ii]->product->name."".$sales[$ii]->product->price." TMT
"; + + + return (string) $html; + } + + + + public function onSavePdf($sales) + { + + $pdf = App::make('dompdf.wrapper'); + $pdf->loadHTML($this->makeTemplate($sales))->setWarnings(false); + $pdf->stream(); + + $pdf->save('storage/app/media/pdf/invoice_no_' . $sales[0]->order_id . '_'.$sales[0]->order->user->username.'.pdf'); + + $path = Config::get('app.url') . '/storage/app/media/pdf/invoice_no_' . (string)$sales[0]->order_id . '_'.(string)$sales[0]->order->user->username.'.pdf'; + + return (string)$path; + } public function mySales(Request $request){ @@ -135,8 +265,6 @@ class OrderApiController extends Controller $validator = Validator::make($data, [ 'order_id' => 'required', ]); - - // $validator = $this->validateForm($data, $rules); if($validator->fails()) { @@ -148,9 +276,14 @@ class OrderApiController extends Controller $sales = VendorSales::where('vendor_id', $currentUser->id)->where('order_id', $data["order_id"])->with(['order.user', 'product.images:attachment_id,attachment_type,disk_name,file_name', 'product.place', 'product.vendor:id,name,email,type,logo,banner,shop_title,slogan,is_instagram'])->orderBy('id', 'DESC')->paginate(15); + if(count($sales) > 0){ + + $sales[0]->pdf_url = $this->onSavePdf($sales); + } + + + return response()->json($sales, 200); - return response()->json($sales, 200); - //return $this->helpers->apiArrayResponseBuilder(200, 'ok', [$orders]); } @@ -158,7 +291,7 @@ class OrderApiController extends Controller $currentUser = \JWTAuth::parseToken()->authenticate(); - $sales = VendorSales::select('id', 'order_id', 'created_at', 'status')->where('vendor_id', $currentUser->id)->groupBy('order_id')->orderBy('id', 'DESC')->paginate(15); + $sales = VendorSales::select('id', 'order_id', 'created_at', 'status')->with(['order.user:id,name,username', 'order:id,user_id,note,phone,address'])->where('vendor_id', $currentUser->id)->groupBy('order_id')->orderBy('id', 'DESC')->paginate(15); diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php index 5b23b6a..370c18a 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php @@ -17,6 +17,7 @@ use TPS\Birzha\Classes\MeasureResource; use TPS\Birzha\Classes\ProductResource; use DB; use Carbon\Carbon; +use ToughDeveloper\ImageResizer\Classes\Image; class ProductsAPIController extends Controller { @@ -50,8 +51,25 @@ class ProductsAPIController extends Controller $products = Product::where('keyword', 'like', "%".$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')->paginate(15); - + 'place',])->where('status', 'approved')->get(); + + $products = $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; + + return $product; + + }); + + // foreach($products as $product) { + /// $image = new Image($product->images[0]->path); + // $product->images[0]->path = $image->resize(200,200)->getCachedImagePath(true); + // } + + // dd($products[0]->images[0]); } catch (\Throwable $th) { return $this->helpers->apiArrayResponseBuilder(500, 'server error', ['message' => 'Something went wrong']); diff --git a/plugins/ahmadfatoni/apigenerator/routes.php b/plugins/ahmadfatoni/apigenerator/routes.php index b0eca35..0ef7eec 100644 --- a/plugins/ahmadfatoni/apigenerator/routes.php +++ b/plugins/ahmadfatoni/apigenerator/routes.php @@ -75,6 +75,7 @@ Route::group(['prefix' =>'api/v1','namespace' =>'AhmadFatoni\ApiGenerator\Contro Route::get('vendor/sales', 'OrderApiController@mySales'); Route::post('vendor/confirm/order', 'OrderApiController@confirmOrder'); Route::get('check/vendor/sales', 'OrderApiController@checkVendorSales'); + Route::get('pdf/order/products', 'OrderApiController@createPdf'); Route::post('update/vendor/data', 'VendorApiController@updateVendor'); diff --git a/plugins/sms/sms/models/smssender/columns.yaml b/plugins/sms/sms/models/smssender/columns.yaml index 47ee93a..9c03999 100644 --- a/plugins/sms/sms/models/smssender/columns.yaml +++ b/plugins/sms/sms/models/smssender/columns.yaml @@ -11,3 +11,9 @@ columns: status: label: status type: switch + created_at: + label: Created + type: datetime + updated_at: + label: 'Telefondan giden sene' + type: datetime diff --git a/plugins/tps/birzha/Plugin.php b/plugins/tps/birzha/Plugin.php index 3055063..0295cff 100644 --- a/plugins/tps/birzha/Plugin.php +++ b/plugins/tps/birzha/Plugin.php @@ -373,6 +373,7 @@ class Plugin extends PluginBase 'TPS\Birzha\Components\CategoryProfile' => 'categoryprofile', 'TPS\Birzha\Components\Checkout' => 'checkout', 'TPS\Birzha\Components\OrderDetail' => 'orderdetail', + 'TPS\Birzha\Components\VipProducts' => 'vipproducts', ]; } diff --git a/plugins/tps/birzha/components/Checkout.php b/plugins/tps/birzha/components/Checkout.php index ccf2f73..411d07b 100644 --- a/plugins/tps/birzha/components/Checkout.php +++ b/plugins/tps/birzha/components/Checkout.php @@ -15,6 +15,7 @@ use TPS\Birzha\Models\VendorSales; use Flash; use Sms\Sms\Models\SmsSender; use RainLab\Translate\Models\Message; +use ValidationException; class Checkout extends ComponentBase { diff --git a/plugins/tps/birzha/components/FilteredProducts.php b/plugins/tps/birzha/components/FilteredProducts.php index 5ffdca6..74801bc 100644 --- a/plugins/tps/birzha/components/FilteredProducts.php +++ b/plugins/tps/birzha/components/FilteredProducts.php @@ -127,7 +127,7 @@ class FilteredProducts extends ComponentBase $sortOrder = $sortOrderParam; $this->sortParam = $sortOrderParam; } - + $perPage = $this->property('perPage'); $products = Product::query(); diff --git a/plugins/tps/birzha/components/VipProducts.php b/plugins/tps/birzha/components/VipProducts.php new file mode 100644 index 0000000..c2b12b5 --- /dev/null +++ b/plugins/tps/birzha/components/VipProducts.php @@ -0,0 +1,258 @@ + 'Get products by type', + 'description' => 'Get products by type (new or vip)' + ]; + } + + public function defineProperties() + { + return [ + 'type' => [ + 'title' => 'Select by type (new or vip)', + 'description' => 'Select by type', + 'type' => 'string', + 'default' => '' + ], + 'perPage' => [ + 'title' => 'Number of offers', + 'description' => 'How many offers do you want to display', + 'default' => 1, + 'validationPattern' => '^[0-9]+$', + 'validationMessage' => 'Only numbers allowed' + ], + 'sortOrder' => [ + 'title' => 'Sort offers', + 'description' => 'How to sort offers', + 'type' => 'dropdown', + 'default' => 'desc' + ], + ]; + } + + public function getSortOrderOptions() { + return [ + 'asc' => 'Created date (ascending)', + 'desc' => 'Created date (descending)' + ]; + } + + public function onRun() { + $this->products = $this->loadProducts(); + $this->categories = $this->getCategories(); + $this->cities = $this->getCities(); + $this->type = $this->property('type'); + $this->category = $this->getCategory(); + $this->city = $this->getCity(); + $this->subCategory = $this->getSubCategory(); + } + + + protected function getCategories(){ + $categories = Category::where('primary_key', '=', 0)->get(); + return $categories; + } + + protected function getCategory() + { + $cSlug = \Input::get('category'); + $category = Category::transWhere('slug', $cSlug, Session::get('rainlab.translate.locale'))->first(); + return $category; + } + + protected function getSubCategory() + { + $cSlug = \Input::get('subcategory'); + $category = Category::transWhere('slug', $cSlug, Session::get('rainlab.translate.locale'))->first(); + return $category; + } + + protected function getCities(){ + $cities = City::all(); + return $cities; + } + + protected function getCity() + { + $cityId = \Input::get('city'); + $city = City::find($cityId); + return $city; + } + + protected function loadProducts() { + $sortOrderParam = strtolower(\Input::get('sort_order')); + // protect from sql injection + if($sortOrderParam != 'asc' && $sortOrderParam != 'desc') { + $sortOrder = $this->property('sortOrder'); + } else { + $sortOrder = $sortOrderParam; + $this->sortParam = $sortOrderParam; + } + + $type = $this->property('type'); + $perPage = $this->property('perPage'); + $subCat = \Input::get('subcategory'); + + $cSlug = null; + if(isset($subCat) && $subCat != ''){ + $cSlug = $subCat; + }else{ + $cSlug = \Input::get('category'); + } + $city = \Input::get('city'); + $minPrice = \Input::get('min_price'); + $maxPrice = \Input::get('max_price'); + $sort = \Input::get('sort'); + + $products = Product::query(); + + if (isset($cSlug) && $cSlug != '') { + $category = Category::transWhere('slug', $cSlug, Session::get('rainlab.translate.locale'))->first(); + if ($category) { + $products = $category->products(); + } else { + $products = null; + } + } + if (isset($city) && $city != '') { + $products = $products->where('place_id', $city); + } + if (isset($minPrice) && $minPrice != '') { + $products = $products->where('price', '>=', $minPrice); + } + if (isset($maxPrice) && $maxPrice != '') { + $products = $products->where('price', '<=', $maxPrice); + } + + if (isset($sort) && $sort != '') { + $sort = self::getSort($sort); + $products = $products->orderBy( $sort[0], $sort[1]); + } + + $products = $products->where("type", $type)->with('vendor')->withCount("images"); + return $products ? $products->paginate($perPage) : null; + } + + private static function getSort($sort): array + { + $sort_key = trim($sort, '-'); + + if (str_contains($sort, '-') && strpos($sort, '-') == 0) { + $sort_direction = 'desc'; + } + + return [ + $sort_key, + $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"); + } + + public function onGetCategorySubs(){ + $data = post(); + $catgegory = null; + if(strlen($data["mainCat"]) > 0){ + $category = Category::where('slug', $data["mainCat"])->first(); + } + + $subs = $this->getSubCatsq($category ? $category->id : $data["mainCat"]); + + $checkSubs = $this->checkSubs($subs); + + if($checkSubs == ''){ + $checkSubs = []; + } + + $allCats = $subs + $checkSubs; + + $subCatsAll = Category::whereIn("id", $allCats)->orderBy("primary_key", "ASC")->get(); + + return $subCatsAll; + + } + + protected function checkSubs($catIds){ + $data = ''; + $subCats = []; + foreach ($catIds as $id){ + $subs = $this->getSubCatsq($id); + if(count($subs) > 0){ + foreach($subs as $subId){ + array_unshift($subCats, $subId); + } + array_unshift($subCats, $id); + $data = $subCats; + } + } + return $data; + + } + + protected function getSubCatsq($catId){ + + $categoriesCustoms = Category::where("primary_key", $catId)->select("id", "primary_key")->get()->pluck("id")->toArray(); + return $categoriesCustoms; + + } + + protected function checking($catIds){ + $data=[]; + foreach ($catIds as $id){ + + $subs = $this->getSubCatsq($id); + $data[] = $id; + if(count($subs) > 0){ + $data[] = $subs; + } + + } + } + + + +} diff --git a/plugins/tps/birzha/components/categoryprofile/default.htm b/plugins/tps/birzha/components/categoryprofile/default.htm index e702c8b..fb2e5b9 100644 --- a/plugins/tps/birzha/components/categoryprofile/default.htm +++ b/plugins/tps/birzha/components/categoryprofile/default.htm @@ -118,8 +118,12 @@ -{% if category.subs.count == 0 and category.products.count == 0 %} - {% set counter = 0 %} +{% if category.subs.count == 0 %} + {% if category.products.count == 0 %} + {% set counter = 0 %} + {% else %} + {% set counter = counter + 1 %} + {% endif %} {% elseif category.subs.count > 0 %} {% for sub in category.subs %} {% if sub.products.count > 0 %} @@ -217,7 +221,7 @@ - + @@ -573,7 +577,11 @@ event.preventDefault(); let sort = document.getElementById("sort_input"); let value = sort.value; - submitForm(value); + if($('#filterButton').prop("disabled")){ + toastrCustomError("Kategoriýa saýlanmadyk"); + }else{ + submitForm(value); + } } function submitForm(value) { @@ -585,5 +593,37 @@ form.appendChild(sort); form.submit() } + + +$(document).ready(function() { + var category = $('#category').val(); + var subcategory = $('#subcategory').val(); + if(category == '' && subcategory == ''){ + $('#filterButton').attr('disabled','disabled'); + } + + + $('#category').on('change', function(e){ + category=e.target.value; + var subcategory = $('#subcategory').val(); + if(category == '' && subcategory == ''){ + $('#filterButton').attr('disabled','disabled'); + }else{ + $('#filterButton').attr('disabled',false); + } + }); + + $('#subcategory').on('change', function(e){ + subcategory=e.target.value; + var category = $('#category').val(); + if(category == '' && subcategory == ''){ + $('#filterButton').attr('disabled','disabled'); + }else{ + $('#filterButton').attr('disabled',false); + } + }); + +}); + {% endput %} diff --git a/plugins/tps/birzha/components/checkout/default.htm b/plugins/tps/birzha/components/checkout/default.htm index 016c038..1b27229 100644 --- a/plugins/tps/birzha/components/checkout/default.htm +++ b/plugins/tps/birzha/components/checkout/default.htm @@ -51,7 +51,7 @@
+993 - +
diff --git a/plugins/tps/birzha/components/filteredproducts/default.htm b/plugins/tps/birzha/components/filteredproducts/default.htm index 65b7b43..76428d4 100644 --- a/plugins/tps/birzha/components/filteredproducts/default.htm +++ b/plugins/tps/birzha/components/filteredproducts/default.htm @@ -31,6 +31,8 @@ - + @@ -402,7 +404,11 @@ event.preventDefault(); let sort = document.getElementById("sort_input"); let value = sort.value; - submitForm(value); + if($('#filterButton').prop("disabled")){ + toastrCustomError("Kategoriýa saýlanmadyk"); + }else{ + submitForm(value); + } } function submitForm(value) { @@ -414,5 +420,40 @@ form.appendChild(sort); form.submit() } + + +$(document).ready(function() { + var category = $('#category').val(); + var subcategory = $('#subcategory').val(); + if(category == '' && subcategory == ''){ + $('#filterButton').attr('disabled','disabled'); + } + + + $('#category').on('change', function(e){ + category=e.target.value; + var subcategory = $('#subcategory').val(); + if(category == '' && subcategory == ''){ + $('#filterButton').attr('disabled','disabled'); + }else{ + $('#filterButton').attr('disabled',false); + } + }); + + $('#subcategory').on('change', function(e){ + subcategory=e.target.value; + var category = $('#category').val(); + if(category == '' && subcategory == ''){ + $('#filterButton').attr('disabled','disabled'); + }else{ + $('#filterButton').attr('disabled',false); + } + }); + +}); + + + + {% endput %} diff --git a/plugins/tps/birzha/components/offers/default.htm b/plugins/tps/birzha/components/offers/default.htm index 23f7091..5fac77f 100644 --- a/plugins/tps/birzha/components/offers/default.htm +++ b/plugins/tps/birzha/components/offers/default.htm @@ -237,8 +237,8 @@
{{ 'productAdd.IkinjiKategoriya'|_ }}
- + {% for item in parentCategory.subs %} {% endfor %} @@ -273,7 +273,7 @@
- + @@ -430,7 +430,11 @@ event.preventDefault(); let sort = document.getElementById("sort_input"); let value = sort.value; - submitForm(value); + if($('#filterButton').prop("disabled")){ + toastrCustomError("Kategoriýa saýlanmadyk"); + }else{ + submitForm(value); + } } function submitForm(value) { @@ -442,5 +446,42 @@ form.appendChild(sort); form.submit() } + +$(document).ready(function() { + var category = $('#category').val(); + var subcategory = $('#subcategory').val(); + console.log(category); + console.log(subcategory); + if(category == '' && subcategory == ''){ + $('#filterButton').attr('disabled','disabled'); + } + + + $('#category').on('change', function(e){ + category=e.target.value; + var subcategory = $('#subcategory').val(); + console.log(category); + console.log(subcategory); + if(category == '' && subcategory == ''){ + $('#filterButton').attr('disabled','disabled'); + }else{ + $('#filterButton').attr('disabled',false); + } + }); + + $('#subcategory').on('change', function(e){ + subcategory=e.target.value; + var category = $('#category').val(); + console.log(category); + console.log(subcategory); + if(category == '' && subcategory == ''){ + $('#filterButton').attr('disabled','disabled'); + }else{ + $('#filterButton').attr('disabled',false); + } + }); + +}); + {% endput %} \ No newline at end of file diff --git a/plugins/tps/birzha/components/singleoffer/default.htm b/plugins/tps/birzha/components/singleoffer/default.htm index 47a2d40..6742d60 100644 --- a/plugins/tps/birzha/components/singleoffer/default.htm +++ b/plugins/tps/birzha/components/singleoffer/default.htm @@ -9,7 +9,34 @@
{{ 'modal.GinisleyinMaglumat'|_ }}
diff --git a/plugins/tps/birzha/components/useroffers/default.htm b/plugins/tps/birzha/components/useroffers/default.htm index 71979e9..1e7dd4d 100644 --- a/plugins/tps/birzha/components/useroffers/default.htm +++ b/plugins/tps/birzha/components/useroffers/default.htm @@ -195,7 +195,8 @@ } function showLatestMessage(data) { - $('.message_form2 input').val(''); + //$('.message_form2 input').val(''); + $("#order-notes").val(''); $(data.latest_message_area).insertBefore('.message_form2') var bottom= $('.chat_area-inner').height()+$('.chat_area-inner').prop('scrollHeight'); diff --git a/plugins/tps/birzha/components/vipproducts/default.htm b/plugins/tps/birzha/components/vipproducts/default.htm new file mode 100644 index 0000000..c8b8202 --- /dev/null +++ b/plugins/tps/birzha/components/vipproducts/default.htm @@ -0,0 +1,398 @@ +{% set products = __SELF__.products %} +{% set categories = __SELF__.categories %} +{% set cities = __SELF__.cities %} +{% set type = __SELF__.type %} +{% set city = __SELF__.city %} +{% set category = __SELF__.category %} +{% set subCategory = __SELF__.subCategory %} + + + +{% for product in products %} + + + +{% endfor %} + + + + + +
+
+
+
+
{{ 'breadcrumbHarytlar'|_ }}
+ +
+
+
+
+ + + +
+
+ + {% if products.count() == 0 %} +
+
+
+
+ Gurluşyk, Gurluşyk platform, bezeg gurluşyk, gipsler merkezi +
+
+
+
+

{{ 'product.SuwagtlykcaHarytYok'|_ }}

+
+
+
+
+ {% else %} +
+
+
+
+ +
+
{{ 'filter.Kategoriyalar'|_ }}
+
+ +
+
+ + +
+
{{ 'productAdd.IkinjiKategoriya'|_ }}
+
+ +
+
+ + +
+
{{ 'filter.Saherler'|_ }}
+
+ +
+
+ + +
+
{{ 'filter.Baha'|_ }}
+
+
+ +
+
+ +
+
+
+ + + +
+
+ +
+ +
+
+
+
+
+ +
+
+ + + + +
+ +
+
+ {% for product in products %} + +
+
+ + + + + +
+ + {% if user %} + + {% else %} + + {% endif %} + + +

{{product.vendor.shop_title}}

+ {{ product.name }} +
+ {% if product.vendor.web2 > 0 %} + {{ product.price }} TMT + {{ product.getDiscountedPrice(product.vendor.web2) }} TMT + {% else %} + {{ product.price }} TMT + {% endif %} +
+ {{ product.stock == 0 ? 'productAdd.ZakazaGelyar'|_ : 'productAdd.ElimizdeBar'|_ }} +
+
+
+ {% endfor %} + +
+
+ {% if products.hasPages %} +
+ +
+ {% endif %} + + +
+
+ {% endif %} +
+
+ + +{% put scripts %} + +{% endput %} \ No newline at end of file diff --git a/plugins/tps/birzha/controllers/Comment.php b/plugins/tps/birzha/controllers/Comment.php index a0b1e9c..c693a32 100644 --- a/plugins/tps/birzha/controllers/Comment.php +++ b/plugins/tps/birzha/controllers/Comment.php @@ -2,6 +2,9 @@ use Backend\Classes\Controller; use BackendMenu; +use TPS\Birzha\Models\Comment as CommentModel; +use Sms\Sms\Models\SmsSender; +use Flash; class Comment extends Controller { @@ -15,4 +18,25 @@ class Comment extends Controller parent::__construct(); BackendMenu::setContext('TPS.Birzha', 'birzha-menu', 'side-menu-item3'); } + + + + public function onSendSmsApprove($id){ + $comment = CommentModel::where("id", $id)->with(["product.vendor"])->first(); + + $smsSender = new SmsSender(); + $smsSender->phone = (string)'+993'.$comment->product->vendor->username; + $smsSender->message = strval((string) $comment->product->name.' teswir ýazyldy.'); + $smsSender->save(); + + if($smsSender){ + + Flash::info("Ustunlikli Habar edildi"); + //return $smsSender; + }else{ + + Flash::error("Ylanyshlyk yuze çykdy"); + //return $smsSender; + } + } } diff --git a/plugins/tps/birzha/controllers/comment/update.htm b/plugins/tps/birzha/controllers/comment/update.htm index edc865b..10bb5c9 100644 --- a/plugins/tps/birzha/controllers/comment/update.htm +++ b/plugins/tps/birzha/controllers/comment/update.htm @@ -15,6 +15,15 @@
+ +