-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version 2.5.5
- Loading branch information
Showing
14 changed files
with
441 additions
and
607 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,90 @@ | ||
|
||
if (!window.wasaKreditMonthlyCostWidget) { | ||
if ( ! window.wasaKreditMonthlyCostWidget ) { | ||
var monthlyCostWidget = { | ||
showWasaKreditFinancingModal: function (guid, monthlyCost) { | ||
const es = document.querySelector(`.wasa-kredit-information-overlay[data-id='${guid}']`); | ||
es.setAttribute('style', 'display:block;'); | ||
if (window.wasaKreditAnalyticsTracker) { | ||
window.wasaKreditAnalyticsTracker.trackEvent({ | ||
action: 'Read more', | ||
category: 'Monthly Cost Widget', | ||
label: 'Monthly Cost Widget 2.0', | ||
value: monthlyCost | ||
}); | ||
window.wasaKreditAnalyticsTracker.lastOpenModal = Math.floor(Date.now() / 1000); | ||
showWasaKreditFinancingModal: function ( guid, monthlyCost ) { | ||
const es = document.querySelector( `.wasa-kredit-information-overlay[data-id='${ guid }']` ) | ||
es.setAttribute( "style", "display:block;" ) | ||
if ( window.wasaKreditAnalyticsTracker ) { | ||
window.wasaKreditAnalyticsTracker.trackEvent( { | ||
action: "Read more", | ||
category: "Monthly Cost Widget", | ||
label: "Monthly Cost Widget 2.0", | ||
value: monthlyCost, | ||
} ) | ||
window.wasaKreditAnalyticsTracker.lastOpenModal = Math.floor( Date.now() / 1000 ) | ||
} | ||
}, | ||
closeWasaKreditFinancingModal: function (e) { | ||
if (e.target === e.currentTarget) { | ||
const es = document.getElementsByClassName("wasa-kredit-information-overlay"); | ||
for (let i = 0; i < es.length; i++) { | ||
es[i].removeAttribute('style'); | ||
closeWasaKreditFinancingModal: function ( e ) { | ||
if ( e.target === e.currentTarget ) { | ||
const es = document.getElementsByClassName( "wasa-kredit-information-overlay" ) | ||
for ( let i = 0; i < es.length; i++ ) { | ||
es[ i ].removeAttribute( "style" ) | ||
} | ||
if (window.wasaKreditAnalyticsTracker) { | ||
const overlay_open_in_seconds = Math.floor(Date.now() / 1000) - window.wasaKreditAnalyticsTracker.lastOpenModal; | ||
window.wasaKreditAnalyticsTracker.trackEvent({ | ||
action: 'Closed', | ||
category: 'Monthly Cost Widget', | ||
label: 'Monthly Cost Widget 2.0', | ||
value: overlay_open_in_seconds | ||
}); | ||
if ( window.wasaKreditAnalyticsTracker ) { | ||
const overlay_open_in_seconds = | ||
Math.floor( Date.now() / 1000 ) - window.wasaKreditAnalyticsTracker.lastOpenModal | ||
window.wasaKreditAnalyticsTracker.trackEvent( { | ||
action: "Closed", | ||
category: "Monthly Cost Widget", | ||
label: "Monthly Cost Widget 2.0", | ||
value: overlay_open_in_seconds, | ||
} ) | ||
} | ||
} | ||
} | ||
}; | ||
window.wasaKreditMonthlyCostWidget = monthlyCostWidget; | ||
}, | ||
} | ||
window.wasaKreditMonthlyCostWidget = monthlyCostWidget | ||
|
||
if ( wasaKreditParams !== undefined ) { | ||
jQuery( function ( $ ) { | ||
const widget = { | ||
update_monthly_widget: function ( price ) { | ||
const url = new URL( wasaKreditParams.wasa_kredit_update_monthly_widget_url, window.location ) | ||
$.ajax( { | ||
url: url.href, | ||
type: "POST", | ||
data: { | ||
price: price.toFixed( 2 ), | ||
nonce: wasaKreditParams.wasa_kredit_update_monthly_widget_nonce, | ||
}, | ||
dataType: "json", | ||
crossDomain: false, | ||
success: function ( res ) { | ||
const container = $( ".wasa-kredit-product-widget-container" ) | ||
container.replaceWith( $.parseHTML( res.data ) ) | ||
}, | ||
complete: function ( res ) { | ||
console.log( res ) | ||
}, | ||
} ) | ||
}, | ||
} | ||
|
||
$( document ).on( "found_variation", function ( e, variation ) { | ||
let price = Math.round( variation.display_price ) | ||
const quantity = parseInt( $( "form.cart input[name=quantity]" ).val() ) | ||
if ( ! isNaN( quantity ) ) { | ||
price *= quantity | ||
} | ||
widget.update_monthly_widget( price ) | ||
} ) | ||
|
||
$( "form.cart" ).on( "change", "input.qty", function () { | ||
const quantity = parseInt( $( this ).val() ) | ||
|
||
let price = $( "form.cart .woocommerce-variation-price .amount" ) | ||
if ( 0 === price.length ) { | ||
price = $( ".summary .price .amount" ) | ||
} | ||
|
||
const unit_price = parseFloat( price.text().replace( /[^\d.,]+/g, "" ) ) | ||
|
||
if ( quantity > 0 ) { | ||
const total_price = quantity * unit_price | ||
if ( ! isNaN( total_price ) ) { | ||
widget.update_monthly_widget( total_price ) | ||
} | ||
} | ||
} ) | ||
} ) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* Ajax class file. | ||
* | ||
* @package Wasa_Kredit_Checkout/Classes | ||
*/ | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; // Exit if accessed directly. | ||
} | ||
|
||
/** | ||
* Ajax class. | ||
*/ | ||
class Wasa_Kredit_Ajax extends WC_AJAX { | ||
/** | ||
* Hook in ajax handlers. | ||
*/ | ||
public static function init() { | ||
self::add_ajax_events(); | ||
} | ||
|
||
/** | ||
* Hook in methods - uses WordPress ajax handlers (admin-ajax). | ||
*/ | ||
public static function add_ajax_events() { | ||
$ajax_events = array( | ||
'wasa_kredit_update_monthly_widget' => true, | ||
); | ||
foreach ( $ajax_events as $ajax_event => $nopriv ) { | ||
add_action( 'wp_ajax_woocommerce_' . $ajax_event, array( __CLASS__, $ajax_event ) ); | ||
if ( $nopriv ) { | ||
add_action( 'wp_ajax_nopriv_woocommerce_' . $ajax_event, array( __CLASS__, $ajax_event ) ); | ||
// WC AJAX can be used for frontend ajax requests. | ||
add_action( 'wc_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); | ||
} | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Update the monthly widget with new price. | ||
* | ||
* @return void An HTML snippet with the updated cost. | ||
*/ | ||
public static function wasa_kredit_update_monthly_widget() { | ||
$nonce = isset( $_POST['nonce'] ) ? sanitize_key( $_POST['nonce'] ) : ''; | ||
if ( ! wp_verify_nonce( $nonce, 'wasa_kredit_update_monthly_widget' ) ) { | ||
wp_send_json_error( 'bad_nonce' ); | ||
} | ||
|
||
$price = filter_input( INPUT_POST, 'price', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ); | ||
if ( empty( $price ) ) { | ||
wp_send_json_error( 'invalid price' ); | ||
} | ||
|
||
$price = number_format( $price, 2, '.', '' ); | ||
$product_widget = Wasa_Kredit_WC()->product_widget->get_product_widget( $price ); | ||
empty( $product_widget ) ? wp_send_json_error( 'widget update failed' ) : wp_send_json_success( $product_widget ); | ||
|
||
} | ||
} | ||
Wasa_Kredit_Ajax::init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.