Last active
May 23, 2018 19:32
-
-
Save MillerMedia/c3eaabc5712c5c3c5a91421fc65f30c0 to your computer and use it in GitHub Desktop.
Volusion - Reload selected product options when clicking back to product page from Shopping Cart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(!VOLUSION_HELPERS){ | |
throw new Error('Volusion Helpers functions not available. Aborting.'); | |
} | |
var PRODUCT_PAGE_OPTIONS = PRODUCT_PAGE_OPTIONS || {}; | |
PRODUCT_PAGE_OPTIONS.ajax = { | |
updateOptions: function( cartItemUrl ){ | |
jQuery.get( cartItemUrl, function( data ) { | |
// Parse the list items | |
var list_items = jQuery('li', jQuery(data)); | |
var options = []; | |
jQuery.each(list_items, function(){ | |
option_text = jQuery(this).text(); | |
var matches = option_text.match(/^(.*?)(:)(.*)/); | |
/* | |
* Appended a colon to the end of the option name | |
* because that's how we will match it on the product | |
* page. | |
*/ | |
var option_name = matches[1] + ':'; | |
var option_value = matches[3]; | |
// Find the option name on the page | |
var option_row = jQuery('#options_table tr:contains(' + option_name + ')'); | |
/* | |
* @todo Need to deal with instances where this option name matches | |
* more than one option row. | |
*/ | |
if(option_row.length > 1){ | |
return; | |
} | |
// Change the value | |
var option_item = option_row.find('select, input'); | |
// Handle for select items | |
if(option_item.is('select')){ | |
option_item.find('option').each(function(){ | |
if( jQuery(this).text().indexOf(option_value) >= 0){ | |
var option_number_value = jQuery(this).val(); | |
option_item.val(option_number_value); | |
return false; | |
} | |
}); | |
} | |
// Handle for text inputs | |
if(option_item.is('input')){ | |
} | |
}); | |
}); | |
}, | |
deleteOriginalFromCart: function(){ | |
jQuery.get( removeFromCartLink, function( data ) { | |
console.log('removed!'); | |
}); | |
} | |
} | |
jQuery(document).ready(function(){ | |
if( VOLUSION_HELPERS.detect.isProductPage() ){ | |
if( VOLUSION_HELPERS.helper.getParameterByName('CartID') != '' && VOLUSION_HELPERS.helper.getParameterByName('CartID') != null ){ | |
var CartID = VOLUSION_HELPERS.helper.getParameterByName('CartID'); | |
var cartItemUrl = "/Help_CartItemDetails.asp?CartID=" + CartID; | |
var removeFromCartLink = "/ShoppingCart.asp?remove=" + CartID; | |
PRODUCT_PAGE_OPTIONS.ajax.updateOptions( cartItemUrl ); | |
jQuery('input[name="btnaddtocart"]').click(function(){ | |
PRODUCT_PAGE_OPTIONS.ajax.deleteOriginalFromCart(); | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Keep in mind that this has not been heavily tested so any updates would be great.
This also depends on our Volusion Javascript helper class which can be found here:
https://github.com/Miller-Media/volusion-javascript-helper-class