Google Maps delivery link

Error on Order - Google Maps delivery link

Error on Order

by cristiangliga » Wed Jun 29, 2022 9:10 pm

Hello,

I'm getting the following error on Phoenix 1.0.8.14:

On page:

mywebsite/admin/orders.php

I get this error:

Notice: Trying to get property 'delivery' of non-object in mywebsite/includes/hooks/admin/orders/deliveryLink.php on line 31

Please take a look.

Thank you.
User avatar
cristiangliga
VIP Member
VIP Member
Posts: 9
Joined: Tue Feb 09, 2021 7:19 am
Contact:

Re: Error on Order

by raiwa » Thu Jun 30, 2022 5:01 am

Is this a virtual order without shipping address?
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
raiwa
PhoenixCart Developer
PhoenixCart Developer
Posts: 1212
Joined: Sat Dec 21, 2019 8:08 am
Contact:

Re: Error on Order

by raiwa » Thu Jun 30, 2022 11:46 am

O.K. I could reproduce this for virtual orders and if not any order is in the list.
To fix it, wrap in the hook the whole function code with the following check in line 27:

Code: Select all

    if (!empty($order->delivery)) {
So the whole function looks like:

Code: Select all

  function listen_injectSiteEnd() {
    global $order;

    if (!empty($order->delivery)) {
      $current_version = Versions::get('Phoenix');

      $replace_array = [',', 'Nº','C/','c/', 'nº', 'planta', 'piso', 'dcha.', 'izqa', 'Dcha', 'Izda', 'Izq','izq', 'º', 'ª'];

      $google_address = str_replace($replace_array, ' ', $order->delivery['street_address']) . ', ' . $order->delivery['city'] . ', ' . $order->delivery['postcode'] . ', ' . $order->delivery['state'] . ', ' . $order->delivery['country']['title'];
      if ($current_version > '1.0.8.0') {
        $google_button = '<a target="_blank" href="https://www.google.es/maps/place/' . $google_address . '">' . new Button(HOOK_DELIVERY_LINK_BUTTON_GOOGLE_MAPS, 'fas fa-search', 'btn-light') . '</a>';
      } elseif ($current_version > '1.0.3.0') {
        $google_button = '<a target="_blank" href="https://www.google.es/maps/place/' . $google_address . '">' . tep_draw_bootstrap_button(HOOK_DELIVERY_LINK_BUTTON_GOOGLE_MAPS, 'fas fa-search', '', '', [], 'btn-light') . '</a>';
      }

      $output = <<<EOD
  <script>
  $(function() {
  $('#orderTabs #section_summary_content table tbody:eq(0) tr td:nth-child(2)').append('{$google_button}');
  });
  </script>
  EOD;

      return $output;
    }
  }
Please confirm and I'll upload the update with this.
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
raiwa
PhoenixCart Developer
PhoenixCart Developer
Posts: 1212
Joined: Sat Dec 21, 2019 8:08 am
Contact:

Re: Error on Order

by cristiangliga » Thu Jun 30, 2022 8:24 pm

Thank you very much, @raiwa! The error dissapears after wrapping the content of the function with the "if" condition (check).

However, none of the orders are virtual and they all have a shipping address. The error showed not only on the admin/orders.php link (page), but also on the admin/orders.php?oID=1, when an order was actually selected. When clicking on Edit or Delete and the orders.php had an action, for example on admin/orders.php?oID=1&action=edit, the error wasn't showing.

Thank you again for the solution!

Best regards,
Cristian
User avatar
cristiangliga
VIP Member
VIP Member
Posts: 9
Joined: Tue Feb 09, 2021 7:19 am
Contact: