I just tested the google maps api to codeigniter but with an error that I did not understand.
Severity: Notice
Message: Undefined variable: map
the code is from here
http://biostall.com/demos/google-maps-v3-api-codeigniter-library/
if (isset($_GET["w1"]) && isset($_GET["w2"]))
{
$config['center'] = $lat = $_GET["w1"].','.$lng = $_GET["w2"];
$marker = array();
$marker['position'] = $lat = $_GET["w1"].','.$lng = $_GET["w2"];
$latlng = $_GET["w1"].','.$_GET["w2"];
$request = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address=.$latlng.&key=AIzaSyAOAR94QMB9YdE8RXHG-8NE28cz6wdUw2I');
$json = json_decode($request, true);
$marker['infowindow_content'] = implode("|", $json);
$this->googlemaps->add_marker($marker);
}
Related
For some reason, I still get a warning message: Creating default object from empty value.
Product controller
public function update(Request $request, $id)
{
$products = new Product();
$products = Product::find($id);
if ($request->hasFile('image'))
{
$path = 'assets/uploads/products/'.$products->image;
if (File::exists($path))
{
File::delete($path);
}
$file = $request->file('image');
$ext = $file->getClientOriginalExtension();
$filename = time().'.'.$ext;
$file->move('assets/uploads/products/',$filename);
$products->image = $filename;
}
$products->name = $request->input('name');
$products->slug = $request->input('slug');
$products->small_description = $request->input('small_description');
$products->description = $request->input('description');
$products->origanl_price = $request->input('origanl_price');
$products->selling_price = $request->input('selling_price');
$products->qty = $request->input('qty');
$products->tax = $request->input('tax');
$products->status = $request->input('status') == TRUE? '1':'0';
$products->trending = $request->input('trending') == TRUE? '1':'0';
$products->meta_title = $request->input('meta_title');
$products->meta_keywords = $request->input('meta_keywords');
$products->meta_description = $request->input('meta_description');
$products->update();
return redirect('/products')
->with('success', 'Product updated Successfully');
}
When I update the product, the page returns an error.
Creating default object from empty value.
How can I properly initialize the new empty object?
I am using paypal integration in my web application everything is working fine . Checkout is working properly but when i apply the coupon then the paypal throws the exception of 400 error. Below is my code
I am using the daryldecode/cart for the checkout. The only problem is when I apply the coupon and move forward towards the paypal
public function paywithPaypal(Request $request)
{
// dd($request->all());
if(Auth::guest()){
if(Session::has('user_id')){
$sessionUserId = Session::get('user_id');
echo $sessionUserId;
}
$checkEmail= User::where('email',$request->billing_email )->first();
if(empty($checkEmail)) {
$user = User::create( [
'first_name' => $request->billing_first_name,
'last_name' => $request->billing_last_name,
'email' => $request->billing_email,
'username' => $request->billing_first_name,
'password' => bcrypt( 123456 ),
'province' => $request->billing_state,
'city' => $request->billing_town,
'address' => $request->billing_address_1,
'role' => 'Member',
] );
$userId = $user->id;
}else{
$userId = $checkEmail->id;
}
}else{
//user login
$sessionUserId = $userId = Auth::user()->id;
}
$items = [];
\Cart::session($sessionUserId)->getContent()->each(function($item) use (&$items)
{
$items[] = $item;
});
$subtotal = \Cart::session($sessionUserId)->getSubTotal();
// dd($subtotal);
$line1 = $request->billing_address_1;
$line2 = $request->billing_address_2;
$fullname = $request->billing_first_name ." ". $request->billing_last_name;
$state = $request->billing_state;
$zip = $request->billing_zip;
$phone = $request->billing_phone;
$email = $request->billing_email;
$city = $request->billing_town;
//invoke new order
$order = new Orders ;
$order->id = $order->generateID('INV');
$saved_order_id = $order->id;
$shippingAddress= Paypalpayment::shippingAddress();
$shippingAddress->setLine1($line1)
->setLine2($line2)
->setCity($city)
->setState($state)
->setPostalCode($zip)
->setCountryCode("US")
->setPhone($phone)
->setRecipientName($fullname);
// ### Payer
// A resource representing a Payer that funds a payment
// Use the List of `FundingInstrument` and the Payment Method
// as 'credit_card'
$payer = Paypalpayment::payer();
$payer->setPaymentMethod("paypal");
$listitem = array();
$fees=HandlingFee::find(1);
$fee = $fees->fee;
$shipping = $request->shipping_fee;
foreach($items as $key=>$item){
$listitem[$key] = Paypalpayment::item();
$listitem[$key]->setName($item->name)
->setCurrency('USD')
->setQuantity($item->quantity)
->setPrice($item->price);
$item_detail = new Order_Item_Details;
$item_detail->order_id = $saved_order_id;
$item_detail->item_id = $item->id;
$item_detail->qty = $item->quantity;
$item_detail->save();
}
$itemList = Paypalpayment::itemList();
$itemList->setItems($listitem)
->setShippingAddress($shippingAddress);
$details = Paypalpayment::details();
$details->setShipping($shipping)
->setHandlingFee($fee)
//total of items prices
->setSubtotal($subtotal);
$grandTotal = $subtotal + $fee + $shipping;
//dd($grandTotal);
//Payment Amount
$amount = Paypalpayment::amount();
$amount->setCurrency("USD")
// the total is $17.8 = (16 + 0.6) * 1 ( of quantity) + 1.2 ( of Shipping).
->setTotal($grandTotal)
->setDetails($details);
//dd($amount);
// ### Transaction
// A transaction defines the contract of a
// payment - what is the payment for and who
// is fulfilling it. Transaction is created with
// a `Payee` and `Amount` types
$transaction = Paypalpayment::transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription("Payment description")
->setInvoiceNumber($saved_order_id)
->setCustom($request->shipping_service);
// dd($transaction);
// ### Payment
// A Payment Resource; create one using
// the above types and intent as 'sale'
$redirectUrls = Paypalpayment::redirectUrls();
$redirectUrls->setReturnUrl(url("/payments/success"))
->setCancelUrl(url("/payments/fails"));
$payment = Paypalpayment::payment();
$payment->setIntent("sale")
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions([$transaction]);
$order->status = 1;
$order->user_id = $userId;
$order->total = $grandTotal;
$order->subtotal = $subtotal;
$order->shipping = $shipping;
if($request->coupon_code == ""){
$order->isCoupon = 0;
}
else{
$order->isCoupon = 1;
}
$order->isBillingDetail = 1;
if($request->shipping_first_name <> ""){
$order->isShippingDetail = 1;
}
if($request->has('order_notes')){
$order->notes = $request->order_notes;
}
$order->save();
$order_billing = new Order_Billing_Details;
$order_billing->order_id = $order->id;
$order_billing->first_name = $request->billing_first_name ;
$order_billing->last_name = $request->billing_last_name ;
$order_billing->company = $request->billing_company_name ;
$order_billing->address_line_1 = $line1;
$order_billing->address_line_2 = $line2;
$order_billing->state = $state;
$order_billing->city = $city;
$order_billing->postal_code = $zip;
$order_billing->email = $email;
$order_billing->phone = $phone;
$order_billing->save();
if($request->shipping_first_name <> ""){
$order_shipping = new Order_Shipping_Details;
$order_shipping->order_id = $order->id;
$order_shipping->first_name = $request->shipping_first_name ;
$order_shipping->last_name = $request->shipping_last_name ;
$order_shipping->company = $request->shipping_company_name ;
$order_shipping->address_line_1 = $request->shipping_address_1 ;
$order_shipping->address_line_2 = $request->shipping_address_2 ;
$order_shipping->state = $request->shipping_state ;
$order_shipping->city = $request->shipping_town ;
$order_shipping->postal_code = $request->shipping_zip ;
$order_shipping->email = $email ;
$order_shipping->phone = $request->shipping_phone ;
$order_shipping->save();
}
else{
$order_shipping = new Order_Shipping_Details;
$order_shipping->order_id = $order->id;
$order_shipping->first_name = $request->billing_first_name ;
$order_shipping->last_name = $request->billing_last_name ;
$order_shipping->company = $request->billing_company_name ;
$order_shipping->address_line_1 = $line1;
$order_shipping->address_line_2 = $line2;
$order_shipping->state = $state;
$order_shipping->city = $city;
$order_shipping->postal_code = $zip;
$order_shipping->email = $email;
$order_shipping->phone = $phone;
$order_shipping->save();
}
try {
// ### Create Payment
// Create a payment by posting to the APIService
// using a valid ApiContext
// The return object contains the status;
//dd(Paypalpayment::apiContext());
$payment->create(Paypalpayment::apiContext());
// dd($payment);
$arrpayment = $payment->toArray();
$order = Orders::find($saved_order_id);
$order->paypal_invoice = $arrpayment['id'];
$order->save();
} catch (\PPConnectionException $ex) {
echo $ex->getCode(); // Prints the Error Code
echo $ex->getData();
dd($ex);
return response()->json(["error" => $ex->getMessage()], 400);
}
catch (PayPal\Exception\PayPalConnectionException $ex) {
echo $ex->getCode(); // Prints the Error Code
echo $ex->getData(); // Prints the detailed error message
}
$email=$request->billing_email;
$fees=HandlingFee::find(1);
$fee = $fees->fee;
$data=array(
'order' => $order,
'name' => $request->billing_first_name.' '.$request->billing_last_name,
'email'=>$email,
'fee'=>$fee,
'payPalLink' => $payment->getApprovalLink(),
);
Mail::send('email.placed', $data, function($message) use ($email) {
$message->subject('New Order Received');
$message->from('no-reply#blurack.com', 'BluRack');
$message->to($email);
});
$admins=DB::table('users')
->select('updates_email')
->where('receiving_updates',1)
->where(function($q) {
$q->where('role','Administrator')
->orWhere('role','Retailer');
})->get()->toArray();
// ->where('role','Administrator')
// ->orWhere('role','Retailer')
// dd($admins);
foreach($admins as $admin){
$admin_mail=$admin->updates_email;
//dd($admin_mail);
Mail::send('email.orderplaced',$data, function($message) use ($admin_mail) {
$message->subject('New Order Received');
$message->from('no-reply#blurack.com', 'BluRack');
$message->to($admin_mail);
});
}
return redirect($payment->getApprovalLink());
// return response()->json([$payment->toArray(), 'approval_url' => $payment->getApprovalLink()],
200);
}
I think the issue is with try catch problem?
I was trying to use Str_slug but it is not working in laravel 5.8.
I am using PhpStorm latest version.
$product->slug = Str_slug('$request->title');
Check the image for more
public function ProductStore(StoreValidation $request){
$product = new product();
$product->category_id = 1;
$product->brand_id = 1;
$product->title = $request->title;
$product->desc = $request->desc;
$product->slug = Str_slug('$request->title');
$product->quantity = $request->quantity;
$product->price = $request->price;
$product->offer_price = $request->offer;
$product->status = 1;
$product->admin_id = 1;
// Saving Product information into product table
$product->save();
if ($request->hasFile('uploadFile')){
$image = $request->file('uploadFile');
$img = time() . '.' . $image->getClientOriginalExtension();
$location = public_path('image/product/' .$img);
$img_ins = Image::make($image)->resize(220,294);
$img_ins->save($location);
$product_img = new product_image();
$product_img->product_id = $product->id;
$product_img->image_name = $img;
$product_img->save();
}
return redirect()->route('admin_panel.pages.admin-addProduct');
}
You should use Str::slug() (Illuminate\Support\Str) instead of deprecated str_slug().
https://laravel.com/docs/5.8/helpers#method-str-slug
I trying to get facebook login functionality to work. My problem is that the userid is returning 0. Below is my code.
include_once APPPATH."libraries/facebook-api-php-codexworld/facebook.php";
$appId = 'xxxxx';
$appSecret = 'xxxxx';
$redirectUrll = base_url() . 'register/';
$fbPermissions = 'email';
$facebook = new Facebook(array(
'appId' => $appId,
'secret' => $appSecret
));
$_REQUEST += $_GET;
$fbuser = $facebook->getUser();
print_r($fbuser);
if ($fbuser) {
$userProfile = $facebook->api('/me?fields=id,first_name,last_name,email,gender,locale,picture');
// Preparing data for database insertion
$userData1['oauth_provider'] = 'facebook';
$userData1['oauth_uid'] = $userProfile['id'];
$userData1['fname'] = $userProfile['first_name'];
$userData1['lname'] = $userProfile['last_name'];
$userData1['email'] = $userProfile['email'];
$userData1['status'] = 'Active';
//$userData['gender'] = $userProfile['gender'];
//$userData['locale'] = $userProfile['locale'];
// $userData['profile_url'] = 'https://www.facebook.com/'.$userProfile['id'];
//$userData['picture_url'] = $userProfile['picture']['data']['url'];
// Insert or update user data
$userID = $this->home->checkUser($userData1);
if(!empty($userID)){
$data['userData1'] = $userData1;
$this->session->set_userdata('userData1',$userData1);
} else {
$data['userData1'] = array();
}
} else {
$fbuser = '';
$data['authUrl'] = $facebook->getLoginUrl(array('redirect_uri'=>$redirectUrll,'scope'=>$fbPermissions));
}
You can add this code:
$facebook = new Facebook(array(
'appId' => $appid,
'secret' => $secret,
'cookie' => true
));
$userId = $this->facebook->getUser();
if($userId == 0){
$access['scope'] = 'email,publish_actions,user_birthday,user_location,user_about_me,user_hometown';
$access['redirect_uri'] = base_url() . 'register/';
$url = $this->facebook->getLoginUrl($access);
redirect($url);
}
else
{
$access = $this->facebook->getAccessToken();
$user = $this->facebook->api('/me?fields=first_name,last_name,email,birthday,gender,locale,picture',array('access_token'=>$access));
//echo "<pre>";print_r($user);exit;
$userData1['oauth_provider'] = 'facebook';
$userData1['oauth_uid'] = $user['id'];
$userData1['fname'] = $user['first_name'];
$userData1['lname'] = $user['last_name'];
$userData1['email'] = $user['email'];
$userData1['status'] = 'Active';
$userID = $this->home->checkUser($userData1);
if(!empty($userID))
{
$data['userData1'] = $userData1;
$this->session->set_userdata('userData1',$userData1);
}
else {
$data['userData1'] = array();
}
redirect('/login');//Redirect To Success Page
}
I hope it will work for you!!
I am using Google Analytics, and I have created a custom dashboard. I want get this dashboard's graphs or data so that I can show it on my site.
I have tried some code to display the total page count, but don't know how to get the dashboard data. Is this possible? Any idea how to do this?
My code is as follows:
$db_data = array();
define('ga_profile_id',$ga_profile_id);
$ga = new gapi(ga_email,ga_password);
$dimensions = array('pagePath');
$metrics = array('uniquePageviews');
$sort = '-uniquePageviews';
$fromDate = date('Y-m-d', strtotime('-30 days'));
$toDate = date('Y-m-d');
$mostPopular = $ga->requestReportData(ga_profile_id,$dimensions, $metrics, $sort, null, $fromDate, $toDate, 1, 10);
$i = 0;
foreach($ga->getResults() as $result)
{
$db_data['landing_page'][$i]['page_views'] = $result->getUniquePageviews();
$db_data['landing_page'][$i]['path'] = $result->getPagePath();
$i++;
}
$sort ="";
$fromDate = date('Y-m-d', strtotime('-30 days'));
$toDate = date('Y-m-d');
$mostPopular1 = $ga->requestReportData(ga_profile_id,array('browser','mobileDeviceModel'),array('pageviews','visits'), $sort, null, $fromDate, $toDate, 1, 10);
$db_data['mobile_users'] = $ga->getVisits();
$data['content']=$this->load->view('client/analytics_report',$db_data,true);
$data['active_menu']='clients';
$data['page_title']='Client Listings';