/
home
/
sjslayjy
/
public_html
/
theweavenest
/
app
/
Helpers
/
Upload File
HOME
<?php use Illuminate\Support\Facades\DB; function prx($arr){ echo "<pre>"; print_r($arr); die(); } function getTopNavCat() { // Fetch categories and their subcategories $categories = DB::table('categories') ->where(['status' => 1]) ->get(); $arr = []; foreach ($categories as $category) { $arr[$category->id]['CategoryName'] = $category->CategoryName; $arr[$category->id]['Category_Id'] = $category->id; // Assuming 'id' is the primary key // Fetch subcategories for this category $subcategories = DB::table('sub_category') ->where(['Category_Id' => $category->id, 'status' => 1]) ->get(); foreach ($subcategories as $subcategory) { $arr[$category->id]['subcategories'][] = [ 'Sub_Category_Name' => $subcategory->Sub_Category_Name, 'Sub_Category_Id' => $subcategory->id, // Assuming 'id' is the primary key ]; } } // Initialize HTML variable $html = '<ul class="nav navbar-nav">'; // Home // Shop $html .= '<li class="dropdown dropdown-slide"> <a href="#!" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-delay="350" role="button" aria-haspopup="true" aria-expanded="false">All Category <span class="tf-ion-ios-arrow-down"></span></a> <div class="dropdown-menu"> <div class="row">'; foreach ($arr as $category) { $html .= '<div class="col-lg-6 col-md-6 mb-sm-3">'; $html .= '<ul><li class="dropdown-header">' . $category['CategoryName'] . '</li>'; if (isset($category['subcategories']) && !empty($category['subcategories'])) { foreach ($category['subcategories'] as $subcategory) { $url = url("/category/" . $subcategory['Sub_Category_Name']); $html .= '<li><a href="' . $url . '">' . $subcategory['Sub_Category_Name'] . '</a></li>'; } } $html .= '</ul></div>'; } $html .= '</div></div></li>'; // Pages return $html; } function getUserTempId(){ if(!session()->has('USER_TEMP_ID')){ $rand=rand(111111111,999999999); session()->put('USER_TEMP_ID',$rand); return $rand; }else{ return session()->get('USER_TEMP_ID'); } } function getAddToCartTotalItem(){ if(session()->has('FRONT_USER_LOGIN')){ $uid=session()->get('FRONT_USER_ID'); $user_type="Reg"; }else{ $uid=getUserTempId(); $user_type="Not-Reg"; } $result=DB::table('cart') ->leftJoin('products','products.id','=','cart.product_id') ->leftJoin('products_attr','products_attr.id','=','cart.product_attr_id') ->leftJoin('sizes','sizes.id','=','products_attr.size_id') ->leftJoin('colors','colors.id','=','products_attr.color_id') ->where(['user_id'=>$uid]) ->where(['user_type'=>$user_type]) ->select('cart.qty','products.name','products.image','sizes.size','colors.color','products_attr.price','products.slug','products.id as pid','products_attr.id as attr_id') ->get(); return $result; } function apply_coupon_code($coupon_code){ $totalPrice=0; $result=DB::table('coupons') ->where(['code'=>$coupon_code]) ->get(); if(isset($result[0])){ $value=$result[0]->value; $type=$result[0]->type; $getAddToCartTotalItem=getAddToCartTotalItem(); foreach($getAddToCartTotalItem as $list){ $totalPrice=$totalPrice+($list->qty*$list->price); } if($result[0]->status==1){ if($result[0]->is_one_time==1){ $status="error"; $msg="Coupon code already used"; }else{ $min_order_amt=$result[0]->min_order_amt; if($min_order_amt>0){ if($min_order_amt<$totalPrice){ $status="success"; $msg="Coupon code applied"; }else{ $status="error"; $msg="Cart amount must be greater then $min_order_amt"; } }else{ $status="success"; $msg="Coupon code applied"; } } }else{ $status="error"; $msg="Coupon code deactivated"; } }else{ $status="error"; $msg="Please enter valid coupon code"; } $coupon_code_value=0; if($status=='success'){ if($type=='Value'){ $coupon_code_value=$value; $totalPrice=$totalPrice-$value; }if($type=='Per'){ $newPrice=($value/100)*$totalPrice; $totalPrice=round($totalPrice-$newPrice); $coupon_code_value=$newPrice; } } return json_encode(['status'=>$status,'msg'=>$msg,'totalPrice'=>$totalPrice,'coupon_code_value'=>$coupon_code_value]); } function getCustomDate($date){ if($date!=''){ $date=strtotime($date); return date('d-M Y',$date); } } function getAvaliableQty($product_id,$attr_id){ $result=DB::table('orders_details') ->leftJoin('orders','orders.id','=','orders_details.orders_id') ->leftJoin('products_attr','products_attr.id','=','orders_details.products_attr_id') ->where(['orders_details.product_id'=>$product_id]) ->where(['orders_details.products_attr_id'=>$attr_id]) ->select('orders_details.qty','products_attr.qty as pqty') ->get(); return $result; } ?>