Skip to content

Instantly share code, notes, and snippets.

@steveosoule
Last active May 8, 2020 19:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveosoule/db4198dd56a41016a181f62c50086428 to your computer and use it in GitHub Desktop.
Save steveosoule/db4198dd56a41016a181f62c50086428 to your computer and use it in GitHub Desktop.
Update SearchSpring Results with the Customer's actual Miva-Pricing
<mvt:comment>
<!--
g.Product_Codes is a comma separated list of product codes being sent as a query-string parameter
-->
</mvt:comment>
<mvt:assign name="l.settings:product_codes" value="miva_array_deserialize(g.Product_Codes)" />
<mvt:foreach iterator="code" array="product_codes">
<mvt:do name="l.result" file="g.Module_Library_DB" value="Product_Load_Code( l.settings:code, l.settings:product )" />
<mvt:do file="g.Module_Feature_TUI_UT" name="l.result" value="CommonComponentFields_Initialize_Product_Runtime( l.settings:product )" />
<mvt:assign name="l.index" value="miva_array_insert( l.settings:products, l.settings:product, -1 )" />
</mvt:foreach>
<mvt:do file="g.Module_Feature_TUI_UT" name="l.result" value="CommonComponentFields_Initialize_Product_Discounts_Runtime(l.settings:products, miva_array_elements(l.settings:products) )" />
<mvt:assign name="l.result" value="miva_output_header( 'Content-Type', 'application/json' )" />
<mvt:do file="g.Module_JSON" name="l.success" value="JSON_Output( l.settings:products )" />
/*
Update SearchSpring Results with the Customer's actual Miva-Pricing
1.) When the SearchSpring's afterResultsChange fires
2.) Get all of the product codes that SearchSpring Loaded
3.) Send those product codes to a Miva page
4.) On the Miva page, calculate their Runtime/Sale-Pricing
5.) Return the sale pricing as JSON
6.) Update the price of each product in the SearchSpring Results
*/
var update_searchspring_prices = function(){
var product_codes = $('.category-product').map(function(){
return $(this).attr('data-product-code');
}).toArray();
$.ajax({
url: '/searchspring-prices.html',
type: 'GET',
dataType: 'json',
data: {
Product_Codes: product_codes
}
})
.done(function(products) {
products.forEach(function(product){
var $product = $('.category-product[data-product-code="' + product.code + '"]');
$product.find('.category-product-price').text(product.formatted_price);
});
});
};
SearchSpring.Catalog.init({
// other store-specific options go here...
afterResultsChange: function(){
update_searchspring_prices();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment