Plugin Directory

Changeset 3005475


Ignore:
Timestamp:
12/05/2023 08:00:55 AM (2 years ago)
Author:
pikkoloatli
Message:

1.0.2

Location:
pikkolo/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pikkolo/trunk/assets/js/pikkolo.js

    r3003975 r3005475  
    2828            // Clear cookies if any
    2929            if (Cookies.get('pikkolo_station_id')) { Cookies.remove('pikkolo_station_id'); }
     30            if (Cookies.get('pikkolo_station_name')) { Cookies.remove('pikkolo_station_name'); }
    3031            if (Cookies.get('pikkolo_delivery_time_id')) { Cookies.remove('pikkolo_delivery_time_id'); }
    3132
     
    8384       
    8485        Cookies.set('pikkolo_station_id', station.id);
     86        Cookies.set('pikkolo_station_name', station.name);
    8587        Cookies.set('pikkolo_delivery_time_id', deliveryTime.id);
    8688    }
  • pikkolo/trunk/inc/functions.php

    r3003975 r3005475  
    1919function pikkolois_get_delivery_date( array $billing_fields ): string {
    2020    $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 );
    2222    if ( $d && $d->format( 'Y-m-d' ) === $delivery_date ) {
    2323        return $delivery_date;
     
    2525    return '';
    2626}
     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 */
     35function 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  
    44Plugin URI: https://pikkolo.is/
    55Description: Shipping method
    6 Version: 1.0.2
     6Version: 1.0.3
    77Author: Pikkoló ehf.
    88Text Domain: pikkolois
     
    105105
    106106                    // 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ó' ); 
    108108                    $this->method_title       = __( 'Pikkoló' );  // Title shown in admin.
    109109                    $this->method_description = __( 'Pikkoló provides self-service stations for groceries in your neighbourhood' ); // Description shown in admin
     
    607607            $pikkolo     = new Pikkolo_Shipping_Method();
    608608            $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;
    610610
    611611            $sdk_url = $pikkolo->api_url . '/sdk/pikkolo-sdk.min.js?environment=' . $environment . '&vendorId=' . $vendor_id;
     
    619619                'pikkolo-js',
    620620                esc_url( plugins_url( 'pikkolo/assets/js/pikkolo.js', __DIR__ ) ),
    621                 array( 'jquery' )
     621                array( 'jquery' ),
     622                '1.0.3'
    622623            );
    623624
     
    659660     */
    660661    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.
    662663        $shipping_methods = $data['shipping_method'];
    663664
    664         // If Pikkoló is not the chosen shipping method, return early
     665        // If Pikkoló is not the chosen shipping method, return early.
    665666        if ( ! $shipping_methods || ! in_array( 'pikkolois', $shipping_methods ) ) {
    666667            return;
    667668        }
    668669
    669         // Check if necessary cookies are set (indicating a Pikkoló location selection)
     670        // Check if necessary cookies are set (indicating a Pikkoló location selection).
    670671        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.
    672673            $errors->add(
    673674                'shipping',
     
    689690
    690691        $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 ) {
    692695            // Pikkoló is not the chosen shipping method.
    693696            return;
    694697        }
     698
    695699        $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 );
    697702
    698703        $result = pikkolo_send_order_to_api( $pikkolo, $post_fields, $log );
     
    790795        // $delivery_time_id = sanitize_text_field($_COOKIE['pikkolo_delivery_time_id']);
    791796
    792         // Get delivery date from checkout page if it exists
     797        // Get delivery date from checkout page if it exists.
    793798        $delivery_date_from_checkout = pikkolois_get_delivery_date( WC()->checkout()->get_posted_data() );
    794799
     
    813818            $ret['deliveryTimeId'] = $station_id . ':' . $delivery_date_from_checkout;
    814819        }
    815         return $ret;
     820        return $ret;
    816821    }
    817822
  • pikkolo/trunk/readme.txt

    r3003975 r3005475  
    88WC requires at least: 3.8.1
    99WC tested up to: 8.0.2
    10 Stable tag: 1.0.2
     10Stable tag: 1.0.3
    1111
    1212== Installation ==
     
    3434== Changelog ==
    3535
     36= 1.0.3 =
     37* Added station name to the shipping method title
     38
    3639= 1.0.2 =
    3740* Added logic to extract a delivery date from the checkout form.
Note: See TracChangeset for help on using the changeset viewer.