• Resolved greggorymark

    (@greggorymark)


    I am trying to load the configurator through an AJAX script that essentially just echos do_shortcode(‘[mkl_configurator product_id=”x”]’);

    What I’m trying to accomplish is to show all the products and then show the configurator inline.

    It does initialize, but I get the error “TypeError: PC.productData is undefined”

    Do you have any suggestions that could put me on the right path?

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Marc Lacroix

    (@marcusig)

    Hi there,

    Could you check if the script is loaded, either something like /wp-admin/admin-ajax.php?action=pc_get_data&data=init&view=js&fe=1&id=56&ver=1618554004 or wp-content/uploads/mkl_product_configurations/product_configuration_56.js? (the ids will obviously be different)

    If none of the above are loaded, you may want to include the data in your ajax call.

    So in your PHP you could do something like this:

    wp_send_json( 
    	[
    		'product_data' => mkl_pc( 'db' )->get_front_end_data( $product_id ),
    		'markup' => do_shortcode( '[mkl_configurator product_id='.$id.']' ),
    	]
    );

    then in your JS something like

    ajax.success( function( response ) {
    	var PC = PC || {};
    	PC.productData = PC.productData || {};
    	// Set the required data
    	PC.productData['prod_' + id] = response.data.product_data;
    	// Insert the shortcode
    	$( '#you-configurator-container' ).html( response.data.markup );
    } )

    (This code is not tested, you’ll have to adapt it to yours)

    Marc

    • This reply was modified 4 years, 11 months ago by Marc Lacroix. Reason: Fixed variable name
    Thread Starter greggorymark

    (@greggorymark)

    Yup, that did it! Thanks Marc!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Load Configurator Through Ajax’ is closed to new replies.