Skip to content

Commit

Permalink
Merge pull request #56 from UVLabs/development
Browse files Browse the repository at this point in the history
v1.6.11
  • Loading branch information
UVLabs authored Nov 16, 2022
2 parents 379777e + bb34626 commit 55fd3b1
Show file tree
Hide file tree
Showing 18 changed files with 434 additions and 285 deletions.
6 changes: 6 additions & 0 deletions assets/admin/js/order-map.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/**
* Globals:
* mapOptions, locationDetails
*/
function lpacSetupShopOrderMap() {
/** These values are coming from the base-map.js enqueued from our maps folder */
const map = window.lpac_map;
map.setMapTypeId(mapOptions.lpac_admin_order_screen_default_map_type);

const marker = window.lpac_marker;
const infowindow = window.lpac_infowindow;

Expand Down
Binary file added assets/img/delivery-and-pickup-scheduling.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 15 additions & 8 deletions assets/public/js/maps/checkout-page-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
*/
/* Get our global map variables from base-map.js */
const map = window.lpac_map;
map.setMapTypeId(mapOptions.lpac_checkout_page_map_default_type);

const marker = window.lpac_marker;
const infowindow = window.lpac_infowindow;

const geocoder = new google.maps.Geocoder();

const find_location_btn = document.querySelector("#lpac-find-location-btn");
Expand Down Expand Up @@ -789,9 +790,9 @@ function lpacHideShowMap() {
}

/**
* Fill in coordinatee fields for last order.
* Fill in coordinate fields for last order.
*/
function lpacSetLastOrderLocationCords() {
function lpacSetLastOrderLocationDetails() {
if (typeof lpacLastOrder === "undefined" || lpacLastOrder === null) {
return;
}
Expand All @@ -806,8 +807,11 @@ function lpacSetLastOrderLocationCords() {
lng: parseFloat(lpacLastOrder.longitude),
};

let latitude = document.querySelector("#lpac_latitude");
let longitude = document.querySelector("#lpac_longitude");
const latitude = document.querySelector("#lpac_latitude");
const longitude = document.querySelector("#lpac_longitude");
const places_autocomplete_field = document.querySelector(
"#lpac_places_autocomplete"
);

if (typeof latitude === "undefined" || latitude === null) {
console.log(
Expand All @@ -825,6 +829,9 @@ function lpacSetLastOrderLocationCords() {

// Set the checkout fields lat and long value
lpac_fill_in_latlng(latlng);

// Set the last order value for the places autocomplete field
places_autocomplete_field.value = lpacLastOrder.used_places_autocomplete;
}

/**
Expand All @@ -846,7 +853,7 @@ function lpacSetLastOrderForAutocompleteWithoutMap() {
field.classList.remove("hidden");
}

lpacSetLastOrderLocationCords();
lpacSetLastOrderLocationDetails();
}

/**
Expand All @@ -859,7 +866,7 @@ function lpacSetLastOrderMarker() {

// Wait for map to load then add our marker
google.maps.event.addListenerOnce(map, "tilesloaded", function () {
lpacSetLastOrderLocationCords();
lpacSetLastOrderLocationDetails();

const latlng = {
lat: parseFloat(lpacLastOrder.latitude),
Expand Down Expand Up @@ -1246,7 +1253,7 @@ addPlacesAutoComplete();

/**
* For guest checkout we're storing the preferred store location in localStorage
* For logged in users we're replacing the store_origin_id with the one selected from the shortcode if it's been used, see Lpac\Controllers\Checkout_Page_Controller::get_last_order_location()
* For logged in users we're replacing the store_origin_id with the one selected from the shortcode if it's been used, see Lpac\Controllers\Checkout_Page\Controller::get_last_order_details()
*/
if (isLoggedIn === true) {
// This might be null if the user has never ordered from this site before.
Expand Down
7 changes: 7 additions & 0 deletions assets/public/js/maps/order-details-map.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
/**
* Globals:
*
* mapOptions
*/
function lpac_setup_order_details_map() {
const map = window.lpac_map;
map.setMapTypeId(mapOptions.lpac_past_order_page_default_map_type);

const marker = window.lpac_marker;
const infowindow = window.lpac_infowindow;

Expand Down
7 changes: 7 additions & 0 deletions assets/public/js/maps/order-received-map.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
/**
* Globals:
*
* mapOptions
*/
function lpac_setup_order_received_map() {
const map = window.lpac_map;
map.setMapTypeId(mapOptions.lpac_thank_you_page_default_map_type);

const marker = window.lpac_marker;
const infowindow = window.lpac_infowindow;

Expand Down
13 changes: 9 additions & 4 deletions class-lpac-uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ public static function remove_plugin_settings() {
}

$option_keys = array(
// General Settings
'lpac_enabled',
'lpac_google_maps_api_key',
'lpac_force_map_use',
'lpac_allow_clicking_on_map_icons',
// Display Settings
'lpac_map_starting_coordinates',
'lpac_general_map_zoom_level',
'lpac_allow_clicking_on_map_icons',
'lpac_map_background_color',
'lpac_checkout_map_orientation',
'lpac_checkout_page_map_height',
Expand All @@ -68,14 +70,17 @@ public static function remove_plugin_settings() {
'lpac_order_received_page_map_height',
'lpac_order_received_page_map_width',
'lpac_display_map_on_view_order_page',
'lpac_store_locations_cords',
'lpac_store_locations_labels',
'lpac_store_locations_icons',
'lpac_view_order_page_map_height',
'lpac_view_order_page_map_width',
'lpac_order_received_page_map_id',
'lpac_view_order_page_map_id',
'lpac_checkout_page_map_id',
'lpac_checkout_page_map_default_view',
// Store Locations
'lpac_store_locations_cords',
'lpac_store_locations_labels',
'lpac_store_locations_icons',
//
'lpac_autofill_billing_fields',
'lpac_email_delivery_map_emails',
'lpac_email_delivery_map_link_location',
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"suin/phpcs-psr4-sniff": "^3.0"
},
"require": {
"freemius/wordpress-sdk": "2.4.5",
"freemius/wordpress-sdk": "2.5.2",
"endroid/qr-code": "4.3.5",
"mjaschen/phpgeo": "4.0",
"wpbp/pointerplus": "1.0.4"
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions includes/Bootstrap/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
use Lpac\Controllers\Emails_Controller ;
use Lpac\Controllers\Map_Visibility_Controller ;
use Lpac\Controllers\Admin_Settings_Controller ;
use Lpac\Controllers\Checkout_Page_Controller ;
use Lpac\Controllers\Checkout_Page\Validation as Checkout_Page_Validation ;
use Lpac\Controllers\Shortcodes as Shortcodes_Controller ;
use Lpac\Views\Admin as Admin_Display ;
use Lpac\Notices\Admin as Admin_Notices ;
Expand Down Expand Up @@ -213,6 +213,7 @@ private function define_admin_hooks()
$this->loader->add_action( 'woocommerce_admin_field_repeater', $plugin_admin_view, 'create_custom_wc_settings_repeater' );
$this->loader->add_action( 'woocommerce_admin_field_info_text', $plugin_admin_view, 'create_custom_wc_settings_info_text' );
$this->loader->add_action( 'woocommerce_admin_field_upsell_banner', $plugin_admin_view, 'create_custom_wc_settings_upsell_banner' );
$this->loader->add_action( 'woocommerce_admin_field_lpac_image', $plugin_admin_view, 'create_custom_wc_settings_image' );
$this->loader->add_filter(
'plugin_action_links',
$this,
Expand Down Expand Up @@ -260,7 +261,7 @@ private function define_public_hooks()
$plugin_public_display = new Frontend_Display();
$controller_emails = new Emails_Controller();
$controller_map_visibility = new Map_Visibility_Controller();
$controller_checkout_page = new Checkout_Page_Controller();
$controller_checkout_page_validation = new Checkout_Page_Validation();
$model_location_details = new Location_Details();
$controller_shortcodes = new Shortcodes_Controller();
/*
Expand Down Expand Up @@ -341,7 +342,7 @@ private function define_public_hooks()
if ( $validate_lat_long_fields === 'yes' ) {
$this->loader->add_action(
'woocommerce_after_checkout_validation',
$controller_checkout_page,
$controller_checkout_page_validation,
'validate_location_fields',
10,
2
Expand All @@ -352,7 +353,7 @@ private function define_public_hooks()
*/
$this->loader->add_action(
'woocommerce_after_checkout_validation',
$controller_checkout_page,
$controller_checkout_page_validation,
'validate_store_location_selector_dropdown',
10,
2
Expand Down
131 changes: 131 additions & 0 deletions includes/Controllers/Checkout_Page/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php

/**
* Handles checkout page related logic.
*
*
* Author: Uriahs Victor
* Created on: 06/11/2021 (d/m/y)
*
* @link https://uriahsvictor.com
* @since 1.3.4
* @package Lpac
*/

namespace Lpac\Controllers\Checkout_Page;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}

use Lpac\Helpers\Functions;

/**
* Class Checkout Page Controller.
*
*/
class Controller {

/**
* Map settings.
*
* @since 1.0.0
*/
public function get_map_options() {

$options = Functions::set_map_options();

$data = array(
'lpac_map_default_latitude' => $options['latitude'],
'lpac_map_default_longitude' => $options['longitude'],
'lpac_map_zoom_level' => $options['zoom_level'],
'lpac_map_clickable_icons' => $options['clickable_icons'] === 'yes' ? true : false,
'lpac_map_background_color' => $options['background_color'],
'lpac_remove_address_plus_code' => $options['remove_address_plus_code'] === 'yes' ? true : false,
'lpac_enable_places_autocomplete' => $options['enable_places_search'] === 'yes' ? true : false,
'lpac_places_autocomplete_fields' => $options['places_search_fields'],
'lpac_places_autocomplete_hide_map' => $options['places_autocomplete_hide_map'] === 'yes' ? true : false,
'lpac_places_fill_shipping_fields' => $options['places_fill_shipping_fields'],
'lpac_places_fill_billing_fields' => $options['places_fill_billing_fields'],
'lpac_auto_detect_location' => $options['auto_detect_location'] === 'yes' ? true : false,
'lpac_wc_shipping_destination_setting' => $options['wc_shipping_destination_setting'],
'lpac_checkout_page_map_default_type' => $options['lpac_checkout_page_map_default_type'],
'lpac_thank_you_page_default_map_type' => $options['lpac_thank_you_page_default_map_type'],
'lpac_past_order_page_default_map_type' => $options['lpac_past_order_page_default_map_type'],
'lpac_admin_order_screen_default_map_type' => $options['lpac_admin_order_screen_default_map_type'],
);

return apply_filters( 'lpac_map_stored_public_settings', $data );

}

/**
* Get the details of the last order places by a customer including the coordinates of the last order.
*
* @since 1.3.4
* @return void|array
*/
public function get_last_order_details() {

if ( ! is_user_logged_in() ) {
return;
}

$user_id = get_current_user_id();

// Get the WC_Customer instance Object for the current user
$customer = new \WC_Customer( $user_id );

$last_order = $customer->get_last_order();

if ( empty( $last_order ) ) {
return;
}

// Backwards compatibility, prior to v1.5.4 we stored location coords as private meta.
// TODO: Remove backwards compatibility once we're satisfied users have updated the plugin. This was added in v1.5.4
$latitude = $last_order->get_meta( 'lpac_latitude', true ) ?: $last_order->get_meta( '_lpac_latitude', true );
$longitude = $last_order->get_meta( 'lpac_longitude', true ) ?: $last_order->get_meta( '_lpac_longitude', true );

$user_preferred_store = get_user_meta( $user_id, 'lpac_user_preferred_store_location_id', true );

// If the user has selected a preferred store...then we should override the last order with the preferred store.
if ( empty( $user_preferred_store ) ) {
$store_origin_id = $last_order->get_meta( '_lpac_order__origin_store_id', true ) ?: ''; // Value exists if the customer selected an origin store.
} else {
$store_origin_id = $user_preferred_store;
}

$address = '';

if ( $last_order->has_shipping_address() ) {
$address = apply_filters( 'lpac_last_order_address', $last_order->get_shipping_address_1(), $last_order );
} else { // Highly likely that the user didnt check the "Shipping to a different address?" option, so shipping fields wouldnt be present.
$address = apply_filters( 'lpac_last_order_address', $last_order->get_billing_address_1(), $last_order );
}

$autocomplete_used = $last_order->get_meta( '_lpac_places_autocomplete' );

return array(
'address' => $address,
'latitude' => $latitude,
'longitude' => $longitude,
'store_origin_id' => $store_origin_id,
'used_places_autocomplete' => $autocomplete_used,
);

}

/**
* Combine store locations with their labels.
*
* @since 1.5.7
* @since 1.6.0 use new store locations array
* @see Lpac\Views\Frontend::setup_global_js_vars()
* @return array
*/
public function get_store_locations() {
return get_option( 'lpac_store_locations', array() );
}

}
Loading

0 comments on commit 55fd3b1

Please sign in to comment.