Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have built a flash application where a user can customise a product. I currently have an 'add to basket' button within the flash application that doesn't do anything. I'd like it to add a product to the basket when clicked.

Writing a flash function with event clicks is no problem, but I'm not sure how to connect to the shopping basket and would appreciate any advice on how to do this.

It appears to be done in AJAX but I'm not confident in this. Any help would be greatly appreciated.

Thank you

Dean

EDIT AFTER MILO'S COMMENTS:

Thanks Milo. Once I understand how to invoke the existing "function wpsc_add_to_cart()" I'll try to make it more efficient and implement what you have suggested, but at the moment I'm struggling to invoke the existing one from within flash.

I've determined the JQuery I need to call from within Flash is the one below, but I don't know how to call it (it doesn't appear to have a function name like I'm used to seeing):

// Submit the product form using AJAX
jQuery("form.product_form").live('submit', function() {
    // we cannot submit a file through AJAX, so this needs to return true to submit the form normally if a file formfield is present
    file_upload_elements = jQuery.makeArray(jQuery('input[type=file]', jQuery(this)));
    if(file_upload_elements.length > 0) {
        return true;
    } else {
        form_values = jQuery(this).serialize();
        // Sometimes jQuery returns an object instead of null, using length tells us how many elements are in the object, which is more reliable than comparing the object to null
        if(jQuery('#fancy_notification').length == 0) {
            jQuery('div.wpsc_loading_animation',this).css('visibility', 'visible');
        }
        jQuery.post( 'index.php?ajax=true', form_values, function(returned_data) {
            eval(returned_data);
            jQuery('div.wpsc_loading_animation').css('visibility', 'hidden');

            if(jQuery('#fancy_notification') != null) {
                jQuery('#loading_animation').css("display", 'none');
            //jQuery('#fancy_notificationimage').css("display", 'none');
            }

        });
        wpsc_fancy_notification(this);
        return false;
    }
});

Any ideas how to call this JQuery from within Flash?

Thanks for your help so far

share|improve this question

1 Answer 1

this is a simple function that will add an item to the cart. you could tie this to an ajax call and pass whatever POST vars you want, obviously product id, quantity, etc..

function my_add_to_cart(){

    global $wpsc_cart;
    $product_id = 1;
    $args = array();
    $args['quantity'] = 1;
    $args['variation_values'] = null;
    $args['provided_price'] = null;
    $args['comment'] = null;
    $args['time_requested'] = null;
    $args['custom_message'] = null;
    $args['file_data'] = null;
    $args['is_customisable'] = false;
    $args['meta'] = null;
    $state = $wpsc_cart->set_item( $product_id, $args );

}
share|improve this answer
    
Thanks Milo. I'm trying to make sure I've understood this correctly... this code doesn't go in the flash file? it goes in it's own php file which flash should activate? I was thinking before that I could try and tap into the code that is already there (replicate the existing buttons submit actions and values?) –  Dean Rowe Aug 13 '11 at 13:34
    
this would be a php function that would go in your theme's functions.php or a plugin. your Flash app would call a javascript function, which would then invoke this function via AJAX. This is basically a very simplified version of the actual function WPeC uses, but WPeC does AJAX in a bad way that uses a lot more memory, it's better to look on this site for examples of proper use of AJAX in WP. –  Milo Aug 13 '11 at 14:47
    
edited original question as too much to fit in comment box. –  Dean Rowe Aug 13 '11 at 15:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.