Skip to content

Commit

Permalink
Merge pull request #46 from UVLabs/development
Browse files Browse the repository at this point in the history
v1.6.2
  • Loading branch information
UVLabs authored Aug 6, 2022
2 parents 4186c9f + b0a9221 commit 1667e80
Show file tree
Hide file tree
Showing 16 changed files with 335 additions and 76 deletions.
18 changes: 18 additions & 0 deletions assets/admin/js/lpac-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@
}
// hideSaveButtonOnExportTab();

/**
* Check if the Google Maps API Key has been entered on the settings page.
*/
function checkAPIKeyPresence() {
const field = $("#lpac_google_maps_api_key");

if (field.length < 1) {
return;
}

if (field.val().length > 10) {
return;
}

field.css("box-shadow", "1px 1px 10px 5px red");
}
checkAPIKeyPresence();

/**
* Toggle AutoDetect customer location option on Generals Settings page.
*/
Expand Down
2 changes: 1 addition & 1 deletion assets/admin/js/repeater-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
// to the server, etc. If a hide callback is not given the item
// will be deleted.
hide: function (deleteElement) {
if (confirm("Are you sure you want to delete this element?")) {
if (confirm("Are you sure you want to delete this entry?")) {
$(this).slideUp(deleteElement);
}
},
Expand Down
27 changes: 21 additions & 6 deletions assets/public/js/maps/checkout-page-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,13 +749,16 @@ function lpacSetLastOrderLocationCords() {
*/
function lpacSetLastOrderForAutocompleteWithoutMap() {
const hideMapForAutocomplete = mapOptions.lpac_places_autocomplete_hide_map;
const enablePlacesAutoComplete = mapOptions.lpac_enable_places_autocomplete;

if (!hideMapForAutocomplete) {
if (enablePlacesAutoComplete === false && hideMapForAutocomplete === false) {
return;
}

const field = document.querySelector("#lpac_order__origin_store_field");
field.classList.remove("hidden");
if (field) {
field.classList.remove("hidden");
}

lpacSetLastOrderLocationCords();
}
Expand Down Expand Up @@ -1012,8 +1015,13 @@ addPlacesAutoComplete();
*/
const hideMapForAutocomplete =
mapOptions.lpac_places_autocomplete_hide_map;
const enablePlacesAutoComplete =
mapOptions.lpac_enable_places_autocomplete;

if (!hideMapForAutocomplete) {
if (
enablePlacesAutoComplete === false &&
hideMapForAutocomplete === false
) {
return;
}

Expand Down Expand Up @@ -1079,9 +1087,10 @@ addPlacesAutoComplete();
* Weird bug with fluid checkout causing field to disappear if we try to move it too early.
*/
if (checkoutProvider === "fluidcheckout") {
setTimeout(() => {
$(document.body).on("updated_checkout", function () {
let field = $("#lpac_order__origin_store_field");
field.insertAfter("#shipping_address_1_field");
}, "1500");
});
}
}
moveStoreSelector();
Expand All @@ -1094,7 +1103,13 @@ addPlacesAutoComplete();
// In those cases we have no need to wait until a location is found from the map to show the field.
const hideMapForAutocomplete =
mapOptions.lpac_places_autocomplete_hide_map;
if (hideMapForAutocomplete) {
const enablePlacesAutoComplete =
mapOptions.lpac_enable_places_autocomplete;

if (
enablePlacesAutoComplete === true &&
hideMapForAutocomplete === true
) {
return;
}

Expand Down
4 changes: 4 additions & 0 deletions class-lpac-uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public static function remove_plugin_settings() {
'lpac_export_date_to',
'lpac_places_autocomplete_country_restrictions',
'lpac_places_autocomplete_type',
'lpac_enable_shipping_cost_by_distance_feature',
'lpac_distance_matrix_api_key',
'lpac_distance_matrix_store_origin_cords',
'lpac_distance_matrix_cost_per_unit',
Expand Down Expand Up @@ -139,6 +140,9 @@ public static function remove_plugin_settings() {
'lpac_enable_cost_by_store_location',
'lpac_cost_by_store_distance_delivery_prices',
'lpac_cost_by_store_location_delivery_prices',
'lpac_cost_by_store_location_shipping_methods',
'lpac_migrated__add_address_to_store_locations',
'lpac_show_selected_store_in_emails',
);

foreach ( $option_keys as $key ) {
Expand Down
42 changes: 31 additions & 11 deletions includes/Bootstrap/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
*/
namespace Lpac\Bootstrap;

if ( !defined( 'WPINC' ) ) {
die;
}
use Lpac\Bootstrap\Loader ;
use Lpac\Bootstrap\I18n ;
use Lpac\Bootstrap\Admin_Enqueues ;
Expand All @@ -42,6 +45,7 @@
use Lpac\Views\Frontend as Frontend_Display ;
use Lpac\Compatibility\WooFunnels\WooFunnels ;
use Lpac\Models\Location_Details ;
use Lpac\Models\Migrations ;
use Lpac\Controllers\API\Order as API_Order ;
/**
* Class Main.
Expand Down Expand Up @@ -152,6 +156,11 @@ private function define_admin_hooks()
$admin_settings_controller = new Admin_Settings_Controller();
$controller_map_visibility = new Map_Visibility_Controller();
$api_orders = new API_Order();
$migrations = new Migrations();
/**
* Plugin settings migrations
*/
$this->loader->add_action( 'admin_init', $migrations, 'add_address_field_to_store_locations' );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
// Notices
Expand Down Expand Up @@ -200,21 +209,12 @@ private function define_admin_hooks()
10,
3
);
/**
* Migrate old way of saving store locations to new array structure. Added @1.6.0
*/
$this->loader->add_action(
'admin_init',
$admin_settings_controller,
'migrate_old_store_locations',
10,
3
);
/* Custom elements created for WooCommerce settings */
$this->loader->add_action( 'woocommerce_admin_field_button', $plugin_admin_view, 'create_custom_wc_settings_button' );
$this->loader->add_action( 'woocommerce_admin_field_hr', $plugin_admin_view, 'create_custom_wc_settings_hr' );
$this->loader->add_action( 'woocommerce_admin_field_div', $plugin_admin_view, 'create_custom_wc_settings_div' );
$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_filter(
'plugin_action_links',
$this,
Expand Down Expand Up @@ -338,8 +338,18 @@ private function define_public_hooks()
2
);
}
/**
* Validate that a customer has selected a store location from the drop down selector.
*/
$this->loader->add_action(
'woocommerce_after_checkout_validation',
$controller_checkout_page,
'validate_store_location_selector_dropdown',
10,
2
);
/*
* Display map button link or qr code link in email.
* Display map button link, static map or qr code link in order emails email.
*/
$enable_map_link_in_email = get_option( 'lpac_enable_delivery_map_link_in_email' );

Expand All @@ -355,6 +365,16 @@ private function define_public_hooks()
);
}

/**
* Add selected store location to order emails.
*/
$this->loader->add_action(
'woocommerce_email_customer_details',
$controller_emails,
'add_store_location_to_email',
20,
4
);
/*
* Adds a notice for admin to checkout page
*/
Expand Down
4 changes: 4 additions & 0 deletions includes/Compatibility/Checkout_Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public function get_checkout_provider() {
$provider = 'fluidcheckout';
}

if ( defined( 'CFW_NAME' ) ) {
$provider = 'checkoutwc';
}

if ( class_exists( 'Orderable_Pro', false ) ) {
$settings = get_option( 'orderable_settings', array() );
$enable_custom_checkout = $settings['checkout_general_override_checkout'] ?? '';
Expand Down
36 changes: 0 additions & 36 deletions includes/Controllers/Admin_Settings_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,40 +87,4 @@ public function generate_store_id( array $values, array $option, array $raw_valu
return $values;
}

/**
* Migrate Store Locations from the old settings array to the new settings array.
* @return void
*/
public function migrate_old_store_locations() : void {

$installed_at_version = LPAC_INSTALLED_AT_VERSION;
$migrated = get_option( 'lpac_migrated_store_locations' );

// Only perform this migration prior to v1.6.0 when we had the old method of adding store locations.
if ( $installed_at_version >= '1.6.0' || ! empty( $migrated ) ) {
return;
}

$location_coordinates = get_option( 'lpac_store_locations_cords', array() );
$location_names = get_option( 'lpac_store_locations_labels', array() );
$location_icons = get_option( 'lpac_store_locations_icons', array() );

$location_coordinates_array = explode( '|', $location_coordinates );
$location_names_array = explode( '|', $location_names );
$location_icons_array = explode( '|', $location_icons );

$new_array_structure = array();

foreach ( $location_coordinates_array as $key => $cords ) {
$new_array_structure[] = array(
'store_location_id' => sanitize_text_field( 'store_location_' . $key ),
'store_name_text' => sanitize_text_field( $location_names_array[ $key ] ?? 'Branch Name' ),
'store_cords_text' => sanitize_text_field( $cords ),
'store_icon_text' => sanitize_text_field( $location_icons_array[ $key ] ?? '' ),
);
}

update_option( 'lpac_store_locations', $new_array_structure );
update_option( 'lpac_migrated_store_locations', true );
}
}
31 changes: 31 additions & 0 deletions includes/Controllers/Checkout_Page_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,41 @@ public function get_last_order_location() {
*
* @since 1.5.7
* @since 1.6.0 use new store locations array
* @see setup_global_js_vars()
* @return array
*/
public function get_store_locations() {
return get_option( 'lpac_store_locations', array() );
}

/**
* Check if the origin store dropdown has a selected value for Store location selector feature in Shipping Locations settings.
*
* @since 1.6.0
* @param array $fields The fields array.
* @param object $errors The errors object.
*
* @return void
*/
public function validate_store_location_selector_dropdown( array $fields, object $errors ) : void {

$enable_store_location_selector = get_option( 'lpac_enable_store_location_selector' );
$enable_store_location_selector = filter_var( $enable_store_location_selector, FILTER_VALIDATE_BOOL );

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

$origin_store = $_POST['lpac_order__origin_store'] ?? '';

$error_msg = '<strong>' . __( 'Please select the store location you would like to order from.', 'map-location-picker-at-checkout-for-woocommerce' ) . '</strong>';

$error_msg = apply_filters( 'lpac_checkout_empty_origin_store_msg', $error_msg );

if ( empty( $origin_store ) ) {
$errors->add( 'validation', $error_msg );
}

}

}
62 changes: 59 additions & 3 deletions includes/Controllers/Emails_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Lpac\Controllers;

use Lpac\Helpers\Functions as Functions_Helper;
use Lpac\Helpers\QR_Code_Generator;
use Lpac\Traits\Upload_Folders;

Expand All @@ -28,10 +27,14 @@ class Emails_Controller {

/**
* Outputs a Button or QR Code inside order emails.
*
* @param object $order
* @param bool $sent_to_admin
* @param bool $plain_text
* @param object $email
* @since 1.1.0
* @return void
*/
public function add_delivery_location_link_to_email( $order, $sent_to_admin, $plain_text, $email ) {
public function add_delivery_location_link_to_email( object $order, bool $sent_to_admin, bool $plain_text, object $email ) {

$allowed_emails = get_option( 'lpac_email_delivery_map_emails', array() );

Expand Down Expand Up @@ -183,4 +186,57 @@ private function create_delivery_location_static_map( $order_id, $map_link, $lat

}

/**
* Adds store location to order email
*
* @param object $order
* @param bool $sent_to_admin
* @param bool $plain_text
* @param object $email
* @since 1.6.2
* @return void
*/
public function add_store_location_to_email( object $order, bool $sent_to_admin, bool $plain_text, object $email ): void {

$show_in_emails = get_option( 'lpac_show_selected_store_in_emails', 'yes' );

if ( $show_in_emails !== 'yes' ) {
return;
}

$label = get_option( 'lpac_store_select_label' ) ?: esc_html( 'Deliver from', 'map-location-picker-at-checkout-for-woocommerce' );
$label = rtrim( $label, ':' );
$store_origin_name = get_post_meta( $order->get_id(), '_lpac_order__origin_store_name', true );

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

$store_locations = get_option( 'lpac_store_locations', array() );
$address = '';

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

$store_names = array_column( $store_locations, 'store_name_text' );
$key = array_search( $store_origin_name, $store_names );

if ( $key !== false ) {
$address = $store_locations[ $key ]['store_address_text'] ?? '';
$cords = $store_locations[ $key ]['store_cords_text'] ?? '';
}

$link = ( ! empty( $cords ) ) ? "https://www.google.com/maps/search/?api=1&query=$cords" : '#';

$markup = "<hr><p>
<span style='font-size: 18px'>$label:</span> <br/><br/>
<a style='font-weight: bold;' href='$link' target='_blank'>
$store_origin_name <br/>
$address <br/>
</a>
</p><hr><br/>";
echo $markup;
}

}
Loading

0 comments on commit 1667e80

Please sign in to comment.