Changeset 3005475
- Timestamp:
- 12/05/2023 08:00:55 AM (2 years ago)
- Location:
- pikkolo/trunk
- Files:
-
- 4 edited
-
assets/js/pikkolo.js (modified) (2 diffs)
-
inc/functions.php (modified) (2 diffs)
-
pikkolo.php (modified) (8 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pikkolo/trunk/assets/js/pikkolo.js
r3003975 r3005475 28 28 // Clear cookies if any 29 29 if (Cookies.get('pikkolo_station_id')) { Cookies.remove('pikkolo_station_id'); } 30 if (Cookies.get('pikkolo_station_name')) { Cookies.remove('pikkolo_station_name'); } 30 31 if (Cookies.get('pikkolo_delivery_time_id')) { Cookies.remove('pikkolo_delivery_time_id'); } 31 32 … … 83 84 84 85 Cookies.set('pikkolo_station_id', station.id); 86 Cookies.set('pikkolo_station_name', station.name); 85 87 Cookies.set('pikkolo_delivery_time_id', deliveryTime.id); 86 88 } -
pikkolo/trunk/inc/functions.php
r3003975 r3005475 19 19 function pikkolois_get_delivery_date( array $billing_fields ): string { 20 20 $delivery_date = $billing_fields['billing_delivery_date']; 21 $d = DateTime::createFromFormat( 'Y-m-d', $delivery_date );21 $d = DateTime::createFromFormat( 'Y-m-d', $delivery_date ); 22 22 if ( $d && $d->format( 'Y-m-d' ) === $delivery_date ) { 23 23 return $delivery_date; … … 25 25 return ''; 26 26 } 27 28 /** 29 * Get the station name from the cookies and add it to the shipping method title. 30 * 31 * @param WC_Order $order The order object. 32 * @param array $cookies The cookies array. 33 * @return bool 34 */ 35 function pikkolois_add_station_name_to_shipping_method_title( $order, array $cookies ): string { 36 $found_pikkolo = false; 37 foreach ( $order->get_shipping_methods() as $shipping_method ) { 38 if ( $shipping_method->get_method_id() === 'pikkolois' ) { 39 $found_pikkolo = true; 40 // Add the station name to the shipping method title. 41 $station_name = ''; 42 if ( isset( $_COOKIE['pikkolo_station_name'] ) ) { 43 $station_name = sanitize_text_field( wp_unslash( $cookies['pikkolo_station_name'] ) ); 44 } 45 $shipping_method->set_method_title( ( 'Pikkoló - ' . $station_name ) ); 46 } 47 } 48 return $found_pikkolo; 49 } -
pikkolo/trunk/pikkolo.php
r3003975 r3005475 4 4 Plugin URI: https://pikkolo.is/ 5 5 Description: Shipping method 6 Version: 1.0. 26 Version: 1.0.3 7 7 Author: Pikkoló ehf. 8 8 Text Domain: pikkolois … … 105 105 106 106 // TODO: Find out why these strings are not added to .pot file 107 $this->title = __( 'Pikkoló - Self service station' ); // This can be added as an setting but for this example its forced.107 $this->title = __( 'Pikkoló' ); 108 108 $this->method_title = __( 'Pikkoló' ); // Title shown in admin. 109 109 $this->method_description = __( 'Pikkoló provides self-service stations for groceries in your neighbourhood' ); // Description shown in admin … … 607 607 $pikkolo = new Pikkolo_Shipping_Method(); 608 608 $environment = $pikkolo->get_env(); 609 $vendor_id = $environment == 'production' ? $pikkolo->vendor_id : $pikkolo->vendor_id_test;609 $vendor_id = $environment === 'production' ? $pikkolo->vendor_id : $pikkolo->vendor_id_test; 610 610 611 611 $sdk_url = $pikkolo->api_url . '/sdk/pikkolo-sdk.min.js?environment=' . $environment . '&vendorId=' . $vendor_id; … … 619 619 'pikkolo-js', 620 620 esc_url( plugins_url( 'pikkolo/assets/js/pikkolo.js', __DIR__ ) ), 621 array( 'jquery' ) 621 array( 'jquery' ), 622 '1.0.3' 622 623 ); 623 624 … … 659 660 */ 660 661 function pikkolo_validate_location( array $data, WP_Error $errors ) { 661 // Check if a shipping method is chosen 662 // Check if a shipping method is chosen. 662 663 $shipping_methods = $data['shipping_method']; 663 664 664 // If Pikkoló is not the chosen shipping method, return early 665 // If Pikkoló is not the chosen shipping method, return early. 665 666 if ( ! $shipping_methods || ! in_array( 'pikkolois', $shipping_methods ) ) { 666 667 return; 667 668 } 668 669 669 // Check if necessary cookies are set (indicating a Pikkoló location selection) 670 // Check if necessary cookies are set (indicating a Pikkoló location selection). 670 671 if ( ! isset( $_COOKIE['pikkolo_station_id'], $_COOKIE['pikkolo_delivery_time_id'] ) ) { 671 // Add an error indicating the need to select a Pikkoló location 672 // Add an error indicating the need to select a Pikkoló location. 672 673 $errors->add( 673 674 'shipping', … … 689 690 690 691 $order = wc_get_order( $order_id ); 691 if ( $order->get_shipping_method() !== $pikkolo->title ) { 692 693 $found_pikkolo = pikkolois_add_station_name_to_shipping_method_title( $order, $_COOKIE ); 694 if ( ! $found_pikkolo ) { 692 695 // Pikkoló is not the chosen shipping method. 693 696 return; 694 697 } 698 695 699 $products_data = pikkolo_get_products_data( $order ); 696 $post_fields = pikkolo_prepare_post_fields( $order, $products_data ); 700 701 $post_fields = pikkolo_prepare_post_fields( $order, $products_data ); 697 702 698 703 $result = pikkolo_send_order_to_api( $pikkolo, $post_fields, $log ); … … 790 795 // $delivery_time_id = sanitize_text_field($_COOKIE['pikkolo_delivery_time_id']); 791 796 792 // Get delivery date from checkout page if it exists 797 // Get delivery date from checkout page if it exists. 793 798 $delivery_date_from_checkout = pikkolois_get_delivery_date( WC()->checkout()->get_posted_data() ); 794 799 … … 813 818 $ret['deliveryTimeId'] = $station_id . ':' . $delivery_date_from_checkout; 814 819 } 815 return $ret;820 return $ret; 816 821 } 817 822 -
pikkolo/trunk/readme.txt
r3003975 r3005475 8 8 WC requires at least: 3.8.1 9 9 WC tested up to: 8.0.2 10 Stable tag: 1.0. 210 Stable tag: 1.0.3 11 11 12 12 == Installation == … … 34 34 == Changelog == 35 35 36 = 1.0.3 = 37 * Added station name to the shipping method title 38 36 39 = 1.0.2 = 37 40 * Added logic to extract a delivery date from the checkout form.
Note: See TracChangeset
for help on using the changeset viewer.