Custom add to cart function to replace price val from imcart.js with in page val
Author: Cris I.Hello everyone,
I have modified a script to calculate price for a product based on free input values, not from default x5 cart engine. (scripts at the end)
I want to pass the new calculated price to the basket using custom code and if is possible the dimensions (new option values) too.
i found the custom code for the add to basket from here "https://helpcenter.websitex5.com/post/30607" but it doesn't help cause it is for custom option buttons.
Can anyone tell me which is the code when i click on "add to cart" to pass at the basket page my price (and the new option values, if possible) instead of the price that is in x5cart.js?
I use Website X5 12 pro.
Thank you in advance.
Here are the codes:
Calculation javascript code:
$(document).ready(function(){
$("input#length, input#width").change(function (){
var width_box = $('#width').val();
var length_box = $('#length').val();
var pricePerMeter = 40;
var dimension = Math.round((width_box)*(length_box));
var outputDimension = dimension/10000;
var actualDimension = outputDimension.toFixed(2);
var estimatedPrice = Math.round((actualDimension) * (pricePerMeter));
var actualPrice = estimatedPrice.toFixed(2);
var outputPrice = Math.round(outputPrice);
if ( length_box != '' && width_box != ''){
$("div#resultsq").html(actualDimension + " m<sup>2</sup>");
$("div#result").html(actualPrice);
$("input#result").val(actualPrice);
}
else{
$("div#resultsq").html("Δώστε τις διαστάσεις σε εκατοστά");
$("div#result").html("fill in the length to calculate the price");
}
});
});
Add to card custom code:
<script type="text/javascript">
var price = $('#result').val();
function addToCart() {
x5engine.cart.ui.addToCart.price('b4lji390', 1, 0, 0);
};
Html code:
<input type="text" id="width" name="width" placeholder="Give length in cm" class="input" /> x
<input type="text" id="length" name="length" placeholder="Give width in cm" class="input" /><br/>
<div id="result"></div>
<div style="text-align: right;">
<a href="[removed]addToCart();">Add to cart</a>
</div>
Hello Cris,
I apologise but I can not help you with this, it does not involve WebSite x5 functions therefore I can not assist.
Wait more information about this by another user of this communnity.
Thenk you.