Esempio n. 1
0
 public function checkoutStep4()
 {
     $obj = new helpers();
     $shp_address = array();
     $sitesettings = DB::table('sitesettings')->get();
     if (!empty($sitesettings)) {
         foreach ($sitesettings as $each_sitesetting) {
             if ($each_sitesetting->name == 'shipping_rate') {
                 $shipping_rate = (double) $each_sitesetting->value;
             }
             if ($each_sitesetting->name == 'free_discount_rate') {
                 $free_discount_rate = (double) $each_sitesetting->value;
             }
         }
     }
     if (Request::isMethod('post')) {
         Session::put('name_card', Input::get('name_card'));
         //Input::get('name_card');
         Session::put('card_number', Input::get('card_number'));
         //Input::get('card_number'); //"4042760173301988";//
         Session::put('card_exp_month', Input::get('card_exp_month'));
         // "03"; //
         Session::put('card_exp_year', Input::get('card_exp_year'));
         // "19"; //
         //checkout as guest
         if (!Session::has('member_userid')) {
             $guestdata = Session::get('guest_array');
             $shiping_address = array('address_title' => 'default address', 'first_name' => $guestdata["guest_fname"], 'last_name' => $guestdata["guest_lname"], 'email' => $guestdata["guest_email"], 'phone' => $guestdata["guest_phone"], 'address' => $guestdata["guest_address"], 'address2' => $guestdata["guest_address2"], 'city' => $guestdata["guest_city"], 'zone_id' => $guestdata["guest_state"], 'country_id' => $guestdata["guest_country_id"], 'postcode' => $guestdata["guest_zip_code"]);
             $want_reg = Request::input('register_user');
             if ($want_reg == 'register') {
                 //register the member
                 Session::put('guest_username_sess', Request::input('guest_username'));
                 $brandmember = Brandmember::create(['fname' => $guestdata['guest_fname'], 'lname' => $guestdata['guest_lname'], 'email' => $guestdata['guest_email'], 'username' => Request::input('guest_username'), 'password' => Hash::make(Request::input('guest_password')), 'role' => 0, 'admin_status' => 1, 'status' => 1, 'updated_at' => date('Y-m-d H:i:s'), 'created_at' => date('Y-m-d H:i:s')]);
                 $lastInsertedId = $brandmember->id;
                 $shiping_address['mem_brand_id'] = $brandmember->id;
                 $shp_address = Address::create($shiping_address);
                 $lastAddressId = DB::getPdo()->lastInsertId();
                 $user_id = $brandmember->id;
                 // Update Address id in brandmember table
                 $addressId = $shp_address->id;
                 $dataUpdateAddress = DB::table('brandmembers')->where('id', $brandmember->id)->update(['address' => $addressId]);
             } else {
                 //set userid for not loggedin users to pass the order
                 $user_id = NULL;
                 $shp_address['id'] = NULL;
                 $shp_address = (object) $shp_address;
                 //print_r($shp_address); exit;
             }
             // End of registration ==================================================
             /* To get the country code And Zone code */
             $shp_country = DB::table('countries')->where('country_id', $guestdata["guest_country_id"])->first();
             $shp_zone = DB::table('zones')->where('zone_id', $guestdata["guest_state"])->first();
             $shiping_address = array('address_title' => 'default address', 'first_name' => $guestdata["guest_fname"], 'last_name' => $guestdata["guest_lname"], 'email' => $guestdata["guest_email"], 'phone' => $guestdata["guest_phone"], 'address' => $guestdata["guest_address"], 'address2' => $guestdata["guest_address2"], 'city' => $guestdata["guest_city"], 'zone_id' => $shp_zone->code, 'country_id' => $shp_country->iso_code_3, 'postcode' => $guestdata["guest_zip_code"]);
             //print_r($shiping_address); exit;
             $shiping_address_serial = serialize($shiping_address);
         } else {
             //for logged-in users
             $shp_address = DB::table('addresses')->leftjoin('countries', 'countries.country_id', '=', 'addresses.country_id')->leftjoin('zones', 'zones.zone_id', '=', 'addresses.zone_id')->select('addresses.*', 'countries.name as country_name', 'countries.iso_code_3 as country_code', 'zones.name as zone_name', 'zones.code as zone_code')->where('mem_brand_id', Session::get('member_userid'))->where('id', Session::get('selected_address_id'))->first();
             //echo "<pre>111111";print_r($shp_address); exit;
             // Serialize the Shipping Address because If user delete there address from "addresses" table,After that the address also store in the "order" table for  getting order history//
             $shiping_address = array('address_title' => $shp_address->address_title, 'mem_brand_id' => $shp_address->mem_brand_id, 'first_name' => $shp_address->first_name, 'last_name' => $shp_address->last_name, 'email' => $shp_address->email, 'phone' => $shp_address->phone, 'address' => $shp_address->address, 'address2' => $shp_address->address2, 'city' => $shp_address->city, 'zone_id' => $shp_address->zone_code, 'country_id' => $shp_address->country_code, 'postcode' => $shp_address->postcode);
             $shiping_address_serial = serialize($shiping_address);
             //echo "pm= ".Session::get('payment_method'); exit;
             $user_id = Session::get('member_userid');
         }
         $order = Order::create(['order_total' => Request::input('grand_total'), 'sub_total' => Request::input('sub_total'), 'discount' => Request::input('discount'), 'redeem_amount' => Request::input('redeem_amount'), 'order_status' => 'pending', 'shipping_address_id' => $shp_address->id, 'shipping_cost' => Request::input('shipping_rate'), 'shipping_type' => 'flat', 'user_id' => $user_id, 'ip_address' => $_SERVER['REMOTE_ADDR'], 'payment_method' => Session::get('payment_method'), 'transaction_id' => '', 'transaction_status' => '', 'shiping_address_serialize' => $shiping_address_serial, 'created_at' => date('Y-m-d H:s:i'), 'updated_at' => date('Y-m-d H:s:i')]);
         $last_order_id = $order->id;
         $obj = new helpers();
         $order_number = 'ORD-' . $obj->random_string(5) . '-' . $last_order_id;
         // Generate random String for order number
         $update_order_number = DB::table('orders')->where('id', $last_order_id)->update(['order_number' => $order_number]);
         Session::put('order_number', $order_number);
         Session::put('order_id', $last_order_id);
         ///we are not storing new registered cart in cart table as it will be destroyed soon
         if (Session::has('member_userid')) {
             $allCart = DB::table('carts')->where('user_id', Session::get('member_userid'))->get();
         } else {
             $allCart = $obj->content();
             foreach ($allCart as $each_content) {
                 $each_content->product_id = $each_content->id;
                 $each_content->form_factor = $each_content->options->form_factor;
                 $each_content->row_id = $each_content->rowid;
                 $each_content->product_name = $each_content->name;
                 $each_content->quantity = $each_content->qty;
                 $each_content->amount = $each_content->price;
                 $each_content->duration = $each_content->options->duration;
                 $each_content->sub_total = $each_content->subtotal;
                 $each_content->no_of_days = $each_content->options->no_of_days;
             }
         }
         foreach ($allCart as $eachCart) {
             $product_details = DB::table('products')->where('id', $eachCart->product_id)->first();
             // echo $each_content->brandmember_id; exit;
             $brandmember_deatils = DB::table('products')->leftJoin('brandmembers', 'brandmembers.id', '=', 'products.brandmember_id')->select('products.*', 'brandmembers.fname', 'brandmembers.lname', 'brandmembers.username', 'brandmembers.email', 'brandmembers.slug', 'brandmembers.pro_image', 'brandmembers.brand_details', 'brandmembers.brand_sitelink', 'brandmembers.status', 'brandmembers.admin_status')->where('products.id', '=', $eachCart->product_id)->first();
             //echo "<pre>";print_r($brandmember_deatils); exit;
             //echo $brandmember->slug ; exit;
             $brand_member_name = $brandmember_deatils->fname ? $brandmember_deatils->fname . ' ' . $brandmember_deatils->lname : $brandmember_deatils->username;
             $formfactor = DB::table('form_factors')->where('id', '=', $eachCart->form_factor)->first();
             $order_item = OrderItems::create(['order_id' => $last_order_id, 'brand_id' => $brandmember_deatils->brandmember_id, 'brand_name' => $brand_member_name, 'brand_email' => $brandmember_deatils->email, 'product_id' => $eachCart->product_id, 'product_name' => $eachCart->product_name, 'product_image' => $product_details->image1, 'quantity' => $eachCart->quantity, 'price' => $eachCart->amount, 'form_factor_id' => $formfactor->id, 'form_factor_name' => $formfactor->name, 'duration' => $eachCart->duration, 'no_of_days' => $eachCart->no_of_days]);
             //All Cart deleted from cart table after inserting all data to order and order_item table.
             if (Session::has('member_userid')) {
                 $deleteCart = DB::table('carts')->where('user_id', '=', Session::get('member_userid'))->delete();
             }
             Cart::destroy();
             // After inserting all cart data into Order and Order_item Table database
         }
         //set points for users on purchase
         if (Session::get('payment_method') == 'creditcard') {
             return redirect('/checkout-authorize/' . $last_order_id);
         } elseif (Session::get('payment_method') == 'paypal') {
             return redirect('/checkout-paypal/' . $last_order_id);
         }
     }
     //end of post
     /*
     		
     
     // All Cart Contain  In Session Will Display Here //
     $content = DB::table('carts')->where('user_id',Session::get('member_userid'))->get();
     //echo "<pre>";print_r($content); exit;
     foreach($content as $each_content)
     	        {
     	            
     	            $product_res = DB::table('products')->where('id',$each_content->product_id)->first();
     	           // echo $each_content->brandmember_id; exit;
     	            $brandmember = DB::table('products')
     	                                ->leftJoin('brandmembers', 'brandmembers.id', '=', 'products.brandmember_id')
     	                                ->select('products.*', 'brandmembers.fname', 'brandmembers.lname', 'brandmembers.username', 'brandmembers.slug', 'brandmembers.pro_image', 'brandmembers.brand_details', 'brandmembers.brand_sitelink', 'brandmembers.status', 'brandmembers.admin_status')
     	                                ->where('products.id','=',$each_content->product_id)
     	                                ->first();
     	                                //echo "<pre>";print_r($brandmember); 
     	                                //echo $brandmember->slug ; exit;
     	            $brand_name = ($brandmember->fname)?($brandmember->fname.' '.$brandmember->lname):$brandmember->username;
     
     	            $formfactor = DB::table('form_factors')->where('id','=',$each_content->form_factor)->first();
     	            $formfactor_name = $formfactor->name;
     	            $formfactor_id = $formfactor->id;
     
     	            $cart_result[] = array('rowid'=>$each_content->row_id,
     	                'product_name'=>$each_content->product_name,
     	                'product_slug'=>$brandmember->product_slug,
     	                'product_image'=>$product_res->image1,
     	                'qty'=>$each_content->quantity,
     	                'price'=>$each_content->amount,
     	                'duration'=>$each_content->duration,
     	                'formfactor_name'=>$formfactor_name,
     	                'formfactor_id'=>$formfactor_id,
     	                'brand_name'=>$brand_name,
     	                'brand_slug'=>$brandmember->slug,
     	                'subtotal'=>$each_content->sub_total);
     
     	        }
     	    
     
                 //echo "sph= ".$shipping_rate; exit;
     return view('frontend.checkout.checkout_setp4',compact('body_class','cart_result','shipping_rate'),array('title'=>'MIRAMIX | Checkout-Step4'));
     */
 }
Esempio n. 2
0
 public function showAllCart()
 {
     /*----- Only Member Will Access This Page ----*/
     $obj = new helpers();
     if (!$obj->checkMemberLogin() && $obj->checkBrandLogin()) {
         return redirect('home');
     }
     //$content = Cart::content();
     $content = $obj->content();
     //echo "<pre>";print_r($content);exit;
     /* Site Setting Start */
     $sitesettings = DB::table('sitesettings')->get();
     $all_sitesetting = array();
     foreach ($sitesettings as $each_sitesetting) {
         $all_sitesetting[$each_sitesetting->name] = $each_sitesetting->value;
     }
     foreach ($content as $each_content) {
         $product_res = DB::table('products')->where('id', $each_content->id)->first();
         // echo $each_content->brandmember_id; exi
         $brandmember = DB::table('products')->leftJoin('brandmembers', 'brandmembers.id', '=', 'products.brandmember_id')->select('products.*', 'brandmembers.fname', 'brandmembers.lname', 'brandmembers.username', 'brandmembers.slug', 'brandmembers.pro_image', 'brandmembers.brand_details', 'brandmembers.brand_sitelink', 'brandmembers.status', 'brandmembers.admin_status')->where('products.id', '=', $each_content->id)->first();
         //echo "<pre>";print_r($brandmember);
         //echo $brandmember->slug ; exit;
         $brand_name = $brandmember->fname ? $brandmember->fname . ' ' . $brandmember->lname : $brandmember->username;
         $formfactor = DB::table('form_factors')->where('id', '=', $each_content->options->form_factor)->first();
         $formfactor_name = $formfactor->name;
         $formfactor_id = $formfactor->id;
         /* Discount Share Start */
         // $user_share = DB::table('product_shares')
         //                     ->where('user_email','=',Session::get('member_user_email'))
         //                     ->where('product_id','=',$each_content->id)
         //                     ->count();
         //print_r($user_share); exit;
         if (Session::has('product_id')) {
             $share_discount = $all_sitesetting['discount_share'];
         } else {
             $share_discount = '';
         }
         /* Discount Share End */
         $cart_result[] = array('rowid' => $each_content->rowid, 'product_name' => $each_content->name, 'product_slug' => $brandmember->product_slug, 'product_image' => $product_res->image1, 'qty' => $each_content->qty, 'price' => $each_content->price, 'duration' => $each_content->options->duration, 'formfactor_name' => $formfactor_name, 'formfactor_id' => $formfactor_id, 'brand_name' => $brand_name, 'brand_slug' => $brandmember->slug, 'share_discount' => $share_discount, 'subtotal' => $each_content->subtotal);
     }
     $cartcontent = Cart::content();
     $member = array();
     $redemctrl = array("min" => 5, "max" => 100, "step" => 5);
     if (Session::has('member_userid')) {
         $member = DB::table('brandmembers')->where("id", Session::get('member_userid'))->first();
         $setting_point = DB::table('sitesettings')->where('name', 'points_for_price')->first();
         $step = $member->user_points;
         $redemctrl = array("min" => $setting_point->value, "max" => $step, "step" => $setting_point->value);
     }
     return view('frontend.product.showAllCart', compact('cart_result', 'cartcontent', 'member', 'redemctrl'), array('title' => 'cart product'));
 }