Forum Replies Created

Viewing 15 replies - 1 through 15 (of 17 total)
  • I think it is because the altitude data is stored in the DB but is not in the gpx/xml when it is exported.
    Infunction send_as_gps in class-trackserver.php near the bottom of the function

    
    $occ_iso = $occurred->format( 'c' );
    /* added by kab */
    $trkpt->appendChild( $dom->createElement( 'ele', $row['altitude'] ) );
    $trkpt->appendChild( $dom->createElement( 'time', $occ_iso ) );
    }
    

    this adds it to the gpx file.

    have to edit the plugin file. don’t know how to do this otherwise.
    Not good but it works.

    Thread Starter kabouton

    (@kabouton)

    Gosh, I’m blushing. Not to worry. I have gotten so much help myself over the forums it’s nice to payitforward. Glad it did the trick.

    Thread Starter kabouton

    (@kabouton)

    This works for me. Good luck

    add_action( 'woocommerce_admin_order_data_after_order_details', 'sample_after_order_fn' );
    
    function sample_after_order_fn( $order ){ 
    
    $date_completed_ts = get_post_meta( $order->get_id(), '_date_completed', true ); //timestamp
    $formatted_date = $date_completed_ts ? date('Y-m-d H:i:s', $date_completed_ts+( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS )) : 'Not completed';
    ?>
    
    <br class="clear" />
    <h4>Update Date Paid <a href="#" class="edit_address">Edit</a></h4>
    <div class="address">
    	<p<?php if( empty( $date_paid ) ) echo ' class="none_set"' ?>>
    	<strong>Date Paid:</strong><?php echo $formatted_date; ?>
    	</p>
    	</div>
    	<div class="edit_address">
    <?php 
    woocommerce_wp_text_input( array(
    	'id' => '_date_paid',
    	'label' => 'Date Paid:',
    	'placeholder'=> 'YYYY-MM-DD', 
    	'wrapper_class'=> 'form-field-wide',
    	'class' => 'date-picker',
    	'style'	=> 'width: 100%',
    	'description' => 'The day payment was made.'
    	) 
    ); 
    ?></div><?php
    }
    
    add_action( 'woocommerce_process_shop_order_meta', 'sample_save', 45, 2 ); // 45 sets it so run after order data saved
    
    function sample_save( $order_id, $post ){
    $order = wc_get_order( $order_id );
    $newStatus = wc_clean( $_POST[ 'order_status' ] ); 
    $oldStatus = wc_clean( $_POST[ 'original_post_status' ] ); 
    $newDatePaid = wc_clean( $_POST[ '_date_paid' ] ); 
    $datePaid = $newDatePaid ? $newDatePaid : '';
    	
    	// LOAD THE WC LOGGER
    $logger = wc_get_logger();
        
    if( $order ){
    	if ( in_array( $oldStatus, array('wc-on-hold', 'wc-processing', 'wc-completed') ) && $newStatus == 'wc-pending' ) {
    	$order->set_date_paid(null);
    	$order->set_date_completed($null);
    	$logger->info( "Status is now pending so set paid date to null", array( 'source' => 'gk3-testing' ) );
    	} 
    	if ( $datePaid  && $newStatus !== 'wc-pending' ) {
    	$order->set_date_paid($newDatePaid);
    	$order->set_date_completed($newDatePaid);
    	$logger->info( "set paid date to new date if not pending", array( 'source' => 'gk3-testing' ) );
    	}	
    	$order->save();
    	}
    }
    Thread Starter kabouton

    (@kabouton)

    Found this, which combined with datepicker seems to work.
    woocommerce_admin_order_data_after_order_details

    Any other suggestions/possibilities?

    Thread Starter kabouton

    (@kabouton)

    Thanks

    Thread Starter kabouton

    (@kabouton)

    Thanks for the quick response. Does help indeed. -K

    Thread Starter kabouton

    (@kabouton)

    Thread Starter kabouton

    (@kabouton)

    I finally sat down to try to figure this out for myself. Took me a few days but now is the time I guess.

    First I discovered it fails because Garmin exports their gpx lat/lon with 25 decimal point precision!!! What!! And PHP LibXML doesn’t like that (it doesn’t want more than 19 or something like that)

    So I wrote an xslt file to transform the garmin export gpx, shortening both the lat and lon to decimal precision to 7. Note the use of the gpx namespace. (This took me a while)

    <xsl:stylesheet version="1.0" xmlns:xsl="https://www.w3.org/1999/XSL/Transform" xmlns:gpx="https://www.topografix.com/GPX/1/1">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="gpx:trkpt/@lat">
            <xsl:attribute name="lat">
             <xsl:value-of select="format-number(number(),'0.0000000')" />
            </xsl:attribute>
        </xsl:template>
    <xsl:template match="gpx:trkpt/@lon">
            <xsl:attribute name="lon">
             <xsl:value-of select="format-number(number(),'0.0000000')" />
            </xsl:attribute>
        </xsl:template>
    <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
    </xsl:stylesheet>

    I then changed class-trackserver.php function validate_gpx_file($filename) around Line 2935 to take the incoming gpx file, see if it is creator=Garmin Connect and if it is then transform the gpx using the xslt and use that as the new xml file to import.

    function validate_gpx_file( $filename ) {
    	$xml = new DOMDocument();
    	$xml->load( $filename );		
    	/*
    	 * KAB
    	 * Garmin exports their lat/lon gpx with 28 decial point precision!!
    	 * PHP can't handle it. So write a xslt to transform it to 7 decimal points
    	 * 
    	 */
    	$creator = $xml->documentElement->getAttribute('creator');
    	if ($creator == "Garmin Connect") {	
    		$xslt_file = plugin_dir_path( __FILE__ ) . '/garmin-gpx.xslt';
    		$stylesheet = new DOMDocument; 
    		$stylesheet->load($xslt_file);
    		$xsl = new XSLTProcessor();			
    		$xsl->importStylesheet( $stylesheet );
    		if($output = $xsl->transformToXML($xml)) {
    			file_put_contents('transformed.xml', $output);	
    			$xml = new DOMDocument();
    			$xml->load( 'transformed.xml' );
    		} 
    	} 
    	return $this->validate_gpx_data( $xml);				
    }

    Seems to have solved the problem for me. It imports without a GPX1.1 validation error, and displays on the map as it should.
    Someone might find this useful.

    Thread Starter kabouton

    (@kabouton)

    Has worked perfect using the ts_link. Get it via ajax, and use it to create the elevation. Lovely. Thanks for the tip. Happy to send you what I have if you’d like.

    • This reply was modified 5 years ago by kabouton.
    Thread Starter kabouton

    (@kabouton)

    Step 1)
    I just added one line to class.trackserver.php to get the ele data out line 3466 above time
    $trkpt->appendChild( $dom->createElement( ‘ele’, $row[‘altitude’] ) );.

    Pace etc I think is a calculation based on time and distance. will keep you posted.
    Thanks again for your quick responses.
    This is my stay at home project. ??

    Thread Starter kabouton

    (@kabouton)

    Just had a look in the db and see altitude there. Could it be exprted in gpx file download?

    Thread Starter kabouton

    (@kabouton)

    Ah thanks. Didn’t do the trick cause as I mentioned in the original post I use the elevation data, pace, mileage etc and that doesn’t seem to be in the downloaded file. Nice though. Thanks.

    Thread Starter kabouton

    (@kabouton)

    will give it a go. Ta

    Thread Starter kabouton

    (@kabouton)

    Thanks. Nice to see it is in the plans.
    Regards
    K

    Sinhex
    Thats the same plugin I use. Please keep us posted how you do it. Thanks

Viewing 15 replies - 1 through 15 (of 17 total)