Skip to content

Commit

Permalink
Merge pull request #19 from UVLabs/development
Browse files Browse the repository at this point in the history
- [New] Added Dummy Settings for PRO features.
- [Fix] Coordinates were not being retrieved when only "Billing Address 1" was selected for the Places Autocomplete field.
  • Loading branch information
UVLabs authored Dec 27, 2021
2 parents bf7f253 + 3bff8d3 commit 01802ec
Show file tree
Hide file tree
Showing 17 changed files with 703 additions and 123 deletions.
21 changes: 20 additions & 1 deletion assets/admin/css/lpac-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,23 @@
#lpac_export_btn{
cursor: pointer;
padding: 10px;
}
}

hr{
border-top: 8px solid #dcdcde !important;
}

.titledesc.premium-subsection, .titledesc.premium-dummy-subsection{
font-size: 18px;
}

.premium-subsection:before{
font-size: 20px;
margin-right: 5px;
color: gold;
}

.premium-dummy-subsection:before{
font-size: 20px;
margin-right: 5px;
}
7 changes: 7 additions & 0 deletions assets/public/css/lpac-public.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@
text-align: center;
}

#lpac-saved-addresses ul{
margin-left: 0;
}

#edit-saved-addresses{
font-size: 16px;
}
2 changes: 1 addition & 1 deletion assets/public/js/maps/base-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if (typeof lpac_pro_js !== 'undefined') {

if( x_anchor.length == 0 ){
// Likely values to make the anchor appear ideal.
// The x axis anchor is usually half of the image width, the y is usally 3px over the image width
// The x axis anchor is usually half of the image width, the y is usually 3px over the image height
x_anchor = marker_icon_width / 2;
y_anchor = marker_icon_height + 3;
}
Expand Down
19 changes: 14 additions & 5 deletions assets/public/js/maps/checkout-page-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ function lpacSetLastOrderMarker(){
}

/**
* Places AutoComplete feature.
* Places Autocomplete feature.
*
* https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete
*
Expand Down Expand Up @@ -774,11 +774,20 @@ function addPlacesAutoComplete(){
}

const options = {
// componentRestrictions: { country: ["us", "ca"] }, // TODO let users control this
fields: ["address_components", "formatted_address", "geometry"],
types: ["address"],
}

/*
* Add country restrictions set in pro plugin settings
* lpac_pro_js is in global scope
*/
if( typeof (lpac_pro_js) !== 'undefined' && lpac_pro_js !== null){
options.componentRestrictions = {
country: lpac_pro_js.places_autocomplete_restrictions
}
}

const autoComplete = new google.maps.places.Autocomplete(field, options);

/* Bind the map's bounds (viewport) property to the autocomplete object,
Expand All @@ -792,7 +801,7 @@ function addPlacesAutoComplete(){

const latlng = {
lat: parseFloat( results[0].geometry.location.lat() ),
lng: parseFloat( results[0].geometry.location.lng() ),
lng: parseFloat( results[0].geometry.location.lng() ),
}

if( fieldID.includes('shipping') ){
Expand All @@ -814,15 +823,15 @@ function addPlacesAutoComplete(){
lpac_map_listen_to_clicks();
}else{

if( mapOptions.lpac_places_fill_shipping_fields ){
if( mapOptions.lpac_places_fill_billing_fields ){
lpac_fill_in_billing_fields(results);
}

/*
* When Shipping destination is set as "Force shipping to the customer billing address" in WooCommerce->Shipping->Shipping Options
* We would want to adjust the map as needed.
*/
if( mapOptions.lpac_wc_shipping_destination_setting === 'billing_only'){
if( mapOptions.lpac_wc_shipping_destination_setting === 'billing_only' || ( fields.length === 1 && fields.includes('billing_address_1') ) ){
lpac_fill_in_latlng(latlng);
map.setCenter(latlng);
marker.setPosition(latlng);
Expand Down
22 changes: 22 additions & 0 deletions class-lpac-uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ class Lpac_Uninstall {
*/
public static function remove_plugin_settings() {

/**
* If the free version and PRO version exist then don't delete the settings.
* This ensures that users do not accidentally delete their settings when installing PRO plugin.
*/
if ( ! function_exists( 'get_plugins' ) ) {
include ABSPATH . '/wp-admin/includes/plugin.php';
}

$plugins = get_plugins();

if ( array_key_exists( 'map-location-picker-at-checkout-for-woocommerce/lpac.php', $plugins ) && array_key_exists( 'map-location-picker-at-checkout-for-woocommerce-pro/lpac.php', $plugins ) ) {
return;
}

$should_delete_settings = get_option( 'lpac_delete_settings_on_uninstall' );

if ( $should_delete_settings !== 'yes' ) {
Expand Down Expand Up @@ -84,9 +98,17 @@ public static function remove_plugin_settings() {
'lpac_remove_address_plus_code',
'lpac_enable_places_autocomplete',
'lpac_places_autocomplete_fields',
'lpac_places_autocomplete_hide_map',
'lpac_auto_detect_location',
'lpac_export_date_from',
'lpac_export_date_to',
'lpac_places_autocomplete_country_restrictions',
'lpac_distance_matrix_api_key',
'lpac_distance_matrix_store_origin_cords',
'lpac_distance_matrix_cost_per_unit',
'lpac_distance_matrix_distance_unit',
'lpac_distance_matrix_travel_mode',
'lpac_distance_matrix_shipping_methods',
);

foreach ( $option_keys as $key ) {
Expand Down
10 changes: 5 additions & 5 deletions composer.lock

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

5 changes: 3 additions & 2 deletions includes/Bootstrap/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ private function define_admin_hooks()
10,
3
);
/* Custom button created for WooCommerce settings */
$this->loader->add_action( 'woocommerce_admin_field_button', $plugin_admin_view, 'create_customer_wc_settings_button' );
/* 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' );
}

/**
Expand Down
12 changes: 6 additions & 6 deletions includes/Controllers/Admin_Settings_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ class Admin_Settings_Controller {
/**
* Sanitize the map default coordinates option before saving.
*
* @param mixed $value
* @param mixed $option
* @param mixed $raw_value
* @param string $value
* @param array $option
* @param string $raw_value
* @return string
*/
public function sanitize_default_map_coordinates( $value, $option, $raw_value ) {

// Remove letters from input
$value = preg_replace( '/[^0-9,.]/', '', $value );
// Remove letters from input, allow dots and commas
$value = preg_replace( '/[^0-9,.-]/', '', $value );

$value = sanitize_text_field( $value );
$value = trim( $value, ' ,' );
$value = trim( $value, ' ,' ); // Remove spaces or commas infront and after value

return $value;

Expand Down
43 changes: 34 additions & 9 deletions includes/Controllers/Emails_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
namespace Lpac\Controllers;

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

/**
* Class emails.
Expand All @@ -23,6 +24,7 @@
*
*/
class Emails_Controller {
use Upload_Folders;

/**
* Outputs a Button or QR Code inside order emails.
Expand All @@ -40,7 +42,13 @@ public function add_delivery_location_link_to_email( $order, $sent_to_admin, $pl

$latitude = get_post_meta( $order->get_id(), '_lpac_latitude', true );
$longitude = get_post_meta( $order->get_id(), '_lpac_longitude', true );
$map_link = apply_filters( 'lpac_email_map_link_provider', "https://www.google.com/maps/search/?api=1&query=${latitude},${longitude}", $latitude, $longitude );

// If we have no results return.
if ( empty( $latitude ) or empty( $longitude ) ) {
return;
}

$map_link = apply_filters( 'lpac_email_map_link_provider', "https://www.google.com/maps/search/?api=1&query=${latitude},${longitude}", $latitude, $longitude );

$map_link_type = get_option( 'lpac_email_delivery_map_link_type' );

Expand All @@ -49,7 +57,7 @@ public function add_delivery_location_link_to_email( $order, $sent_to_admin, $pl
} elseif ( $map_link_type === 'qr_code' ) {
$this->create_delivery_location_link_qrcode( $map_link, $order->get_id() );
} elseif ( $map_link_type === 'static_map' ) {
$this->create_delivery_location_static_map( $map_link, $latitude, $longitude );
$this->create_delivery_location_static_map( $order->get_id(), $map_link, $latitude, $longitude );
} else {
$this->create_delivery_location_link_button( $map_link );
}
Expand Down Expand Up @@ -88,6 +96,9 @@ private function create_delivery_location_link_button( $link ) {
*/
private function create_delivery_location_link_qrcode( $link, $order_id ) {

$folder_name = 'qr-codes';

// TODO allow controlling of these figures
$options = array(
'qr_code_data' => $link,
'qr_code_foreground_rgb' => '0,0,0',
Expand All @@ -97,17 +108,17 @@ private function create_delivery_location_link_qrcode( $link, $order_id ) {
/*
* Generate and save QR Code
*/
QR_Code_Generator::lpac_generate_qr_code( $options, $order_id );
( new QR_Code_Generator )->lpac_generate_qr_code( $options, $order_id );

/*
* https://example.com/wp-content/uploads/lpac/qr-codes/Y/m/d/order_id.jpg
* https://example.com/wp-content/uploads/lpac/qr-codes/order_id.jpg
*/
$qr_code_link = Functions_Helper::lpac_get_qr_codes_directory( 'baseurl' ) . $order_id . '.jpg';
$qr_code_link = $this->get_resource_url( $folder_name, $order_id, '.jpg' );
$delivery_location_text = __( 'Delivery Location', 'map-location-picker-at-checkout-for-woocommerce' );
$delivery_location_text = apply_filters( 'lpac_email_map_location_link_button_text', $delivery_location_text );

echo "<div style='text-align: center !important'>
<img style='display: block !important; margin: 0 auto !important; text-align: center !important;' src='{$qr_code_link}'/>
<a href='$link' target='_blank'><img style='display: block !important; margin: 0 auto !important; text-align: center !important;' src='{$qr_code_link}'/></a>
<p style='text-align: center !important; font-size: 20px; margin-bottom: 40px'>{$delivery_location_text}</p>
</div>";

Expand All @@ -121,7 +132,9 @@ private function create_delivery_location_link_qrcode( $link, $order_id ) {
* @return void
* @since 1.4.0
*/
private function create_delivery_location_static_map( $map_link, $latitude, $longitude ) {
private function create_delivery_location_static_map( $order_id, $map_link, $latitude, $longitude ) {

$folder_name = 'static-maps';

$center = $latitude . ',' . $longitude;
$center = sanitize_text_field( apply_filters( 'lpac_email_static_map_center', $center ) );
Expand All @@ -143,6 +156,18 @@ private function create_delivery_location_static_map( $map_link, $latitude, $lon
$api_key
);

$save_path = $this->create_upload_folder( $folder_name );

$file_name = $save_path . $order_id . '.jpg';

$image = file_put_contents( $file_name, file_get_contents( $full_link ) );

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

$image_src = $this->get_resource_url( $folder_name, $order_id, '.jpg' );

$width = '';
$height = '';

Expand All @@ -152,7 +177,7 @@ private function create_delivery_location_static_map( $map_link, $latitude, $lon
$height = $size_parts[1];
}

$image = "<a href='$map_link' target='_blank'><img style='display: block !important; margin-bottom: 40px !important; margin-left: auto !important; margin-right: auto !important; postition: relative !important;' src='$full_link' width='$width' height='$height'/></a>";
$image = "<a href='$map_link' target='_blank'><img style='display: block !important; margin-bottom: 40px !important; margin-left: auto !important; margin-right: auto !important; postition: relative !important;' src='$image_src' width='$width' height='$height'/></a>";
echo $image;

}
Expand Down
35 changes: 7 additions & 28 deletions includes/Helpers/QR_Code_Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeMargin;
use Endroid\QrCode\Writer\PngWriter;
use Endroid\QrCode\Label\Font\NotoSans;
use Lpac\Traits\Upload_Folders;
// use Endroid\QrCode\Label\Font\OpenSans;

class QR_Code_Generator {

use Upload_Folders;

/**
* Creates a QR code
*
Expand All @@ -33,9 +36,11 @@ class QR_Code_Generator {
*
* @since 1.1.0
*/
public static function lpac_generate_qr_code( $options, $order_id ) {
public function lpac_generate_qr_code( $options, $order_id ) {

$folder_name = 'qr-codes';

$path = self::lpac_qr_codes_directory();
$path = $this->create_upload_folder( $folder_name );

if ( empty( $path ) ) {
error_log( 'Location Picker At Checkout for WooCommerce: QR Code directory path returned empty. See Lpac_Qr_Code_Generator::lpac_generate_qr_code()' );
Expand Down Expand Up @@ -91,30 +96,4 @@ public static function lpac_generate_qr_code( $options, $order_id ) {

}

/**
* Creates a QR code
*
* @since 1.1.0
*/
public static function lpac_qr_codes_directory() {

$upload_dir = wp_upload_dir();
$qr_codes_dir = '';

if ( ! empty( $upload_dir['basedir'] ) ) {

$qr_codes_dir = $upload_dir['basedir'] . '/lpac/qr-codes/' . date( 'Y' ) . '/' . date( 'm' ) . '/' . date( 'd' ) . '/';
$qr_codes_dir = apply_filters( 'lpac_qrcodes_path', $qr_codes_dir );

if ( ! file_exists( $qr_codes_dir ) ) {
wp_mkdir_p( $qr_codes_dir );
}

return $qr_codes_dir;
}

return $qr_codes_dir;

}

}
Loading

0 comments on commit 01802ec

Please sign in to comment.