<script src="https://core.robotint.net/s.js"></script>
<script>
var aRobotintOptions={
tintSettings:{
CLIENT_ID:1234,
SECRET:"xxxxxxxx",
WITH_PRICE: 1
},
siteSettings:{
colorSelect: funcСolorSelect,
basketURL: "/personal/cart/"
}
};
obColorer.setOptions(aRobotintOptions);
</script>
{
BASE_TYPE_INT: 1,
BASKET_ID: 0,
COLLECTION_ID: 131,
COLLECTION_NAME: "Sample Collection Name",
COLOR_ID: 65712,
COLOR_NAME: "TVT F346",
COLOR_PRICE: 120,
PRICE_PER_LITER:40,
PRICE_PER_CAN:120,
HEX: "#e4e1ed",
VOLUME: 3,
VOLUME_UNIT: "l",
COLLECTION_VENDOR_ID: 3,
action: "add"
}
{
"BARCODE":"xxxx",
"PRODUCT_PRICE":370,
"PRODUCT_ID":123,
"VOLUME":3
}
<tint-button disabled="disabled" data-basket-id='0' data-tint-button="1" data-tint-button-vertical="1" data-tint-data='JSON Array' onclick="obColorer.show(this)">
<tint-span>choose</tint-span>
<tint-span>color</tint-span>
</tint-button>
<tint-button disabled="disabled" data-tint-button="1" data-tint-button-horizontal="1" data-tint-data='JSON Array' data-basket-id="0" onclick="obColorer.show(this)">
<tint-span>choose color</tint-span>
</tint-button>
function selectRobotintColor(data) {
var iProductID = parseInt(data.PRODUCT_ID); // getting the ID of the tinted product in the database of the online store
var $itemObject = obColorer.itemObject;
if (iProductID) { //if chosen product is allowed to be tinted
var basketAction = "add"; //by default, consider that a new tinting service is being added to the basket
var iBasketID = data.BASKET_ID; //get the value with the id of the item in the cart, if this value is passed
if (iBasketID) { //if the ID of the item in the cart is passed
basketAction = "update"; //it means that a tint has already been selected for this product. Set action to update the selected tint
-- update
obColorer.close(); //close RoboTint
}
data.basketAction = basketAction; //define the operation to be executed in the current object
$.ajax({ //send the request
type: "POST", // POST-method
url: "/some/dir/path/ajax.php", //path to the script for adding/updating the color and product in the cart (depends on the CMS you use)
data: data, //pass an object with all the dataset returned
timeout: 15000, //wait for a response from the server within 15 seconds. After that -- stop waiting
beforeSend: function () { //a function that can be used to execute custom logics while waiting for a response from the server. For example, showing a spinner
...
},
success: function (data, textstatus) { //the result of the ajax request will be returned into this function
...
},
error: function () { //
ajax request error handler function if something went wrong
...
}
});
}
}
<script>
options.siteSettings = {
bgZindex: 10000,
colorSelect: obRobotint.select, // callback-function for transferring the item to the cart
processPrice: obRobotint.processPrice // callback-function for processing the tinting price
};
obColorer.setOptions(options);
</script>
var obRobotint = {
prices:[], // this variable will contain all the settings for the price handler options configurators listed below
processPrice: function($priceObj, data){
// this function will be passed to obColorer in order to process the prices before displaying them to the customer
// $priceObj - price calculation data
// data - tints collection data
var data_raw = $priceObj.data();
var ppl_raw = parseFloat(data_raw.pricePerLitr);
var ppc_raw = parseFloat(data_raw.pricePerCan);
var ppl = ppl_raw; // saving into a separate variable that will be processed
var ppc = ppc_raw; // saving into a separate variable that will be processed
var ref_vol = parseFloat(data_raw.priceRef_can_volume); // volume of tinted product according to the database
// volume of the tinted product
var iVolume = ref_vol ;
CVID = data.COLLECTION_VENDOR_ID
// stub if for some reason there is no Vendor ID
if(!CVID) CVID = 2 // USE COLLECTION_VENDOR_ID from the vendor list
// here we will store the selected config, but for now it is false
var cur_set = false;
// bypass the prices from the config in order to select the desired
// in the corresponding price range and the corresponding syste
for(var i in obRobotint.prices) {
// configuration array of price levels and rounding
rt_price = obRobotint.prices[i];
if(rt_price['tint_system'] == CVID){
// if the price falls within the range, then this section is selected within the pricing configurator
if(ppl > rt_price.price_from ){
cur_set = rt_price
}
}
}
// if the config is not set, then set the default values
if(!cur_set){
cur_set = {
'price_from': 0,
'tint_system': CVID , // here we have our chosen COLLECTION_VENDOR_ID
'set_price': false,
'round': false,
'scale': false, };
}
// update the price to the level
if(cur_set.set_price){
ppl = cur_set.set_price; // setting PricePerLiter
}
// rounding
if(cur_set.round){
// if precision of rounding is not specified then =1
// scale possible values 1,10,100,1000
cur_set.scale = parseInt(cur_set.scale);
// also processing the possible errors
if(!cur_set.scale || cur_set.scale == 0){
cur_set.scale = 1;
}
// rounding types
if(cur_set.round == 'math'){
ppl = Math.round(ppl/cur_set.scale)*cur_set.scale;
}else if(cur_set.round == 'up'){
ppl = Math.ceil(ppl/cur_set.scale)*cur_set.scale;
}else if(cur_set.round == 'down'){
ppl = Math.floor(ppl/cur_set.scale)*cur_set.scale;
}else{
ppl = Math.round(ppl/cur_set.scale)*cur_set.scale;
}
}
ppc = ppl*iVolume; // tinting price per can = price per liter * volume of the can
if(ppc!=ppc_raw){
// rewrite the value of the button to the calculated one, adjusted to the desired level
$priceObj.attr("data-price-shop",price);
$priceObj.text(obRobotint.numberFormat(ppc,0,"."," ")+" $");
}
},
numberFormat: function ( number, decimals, dec_point, thousands_sep ) {
// this function will format the price as we need
// Format a number with grouped thousands
//
// + original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfix by: Michael White (http://crestidg.com)
var i, j, kw, kd, km;
// input sanitation & defaults
if( isNaN(decimals = Math.abs(decimals)) ){
decimals = 2;
}
if( dec_point == undefined ){
dec_point = ",";
}
if( thousands_sep == undefined ){
thousands_sep = ".";
}
i = parseInt(number = (+number || 0).toFixed(decimals)) + "";
if( (j = i.length) > 3 ){
j = j % 3;
} else{
j = 0;
}
km = (j ? i.substr(0, j) + thousands_sep : "");
kw = i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep);
//kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).slice(2) : "");
kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).replace(/-/, 0).slice(2) : "");
return km + kw + kd;
},
// this function to add to cart, you have already seen it above
select: function (data) {
//...
}
};
obRobotint.prices = [ {
'price_from': 0, // for all prices from 0 dollars
'tint_system': 3, // apply only for a specific tinting system
'set_price': 30, // set price 30 for all colors from 0 dollars
'round': false,
'scale': false,
}, {
'price_from': 0,
'tint_system': 6, // rule is valid for Ceresit only
'set_price': 30,
'round': false,
'scale': false,
}, {
'price_from': 30, // for all prices from 30 dollars
'tint_system': 3,
'set_price': false, // do not set a fixed price
'round': 'up', // rounding up, down , math
'scale': 10, // round up to 1 / 10 / 100 dollars
}, {
'price_from': 500,
'tint_system': 3,
'set_price': false,
'round': 'up', // rounding in up, down , math
'scale': 100, // round up to 1 / 10 / 100 dollars
}, {
'price_from': 1000,
'tint_system': 3,
'set_price': false,
'round': 'down', // rounding in up, down , math
'scale': 100, // round up to 1 / 10 / 100 dollars
} ];
obRobotint.prices = [
{
'price_from': 0,
'tint_system': 3,
'set_price': 30,
'round': false,
'scale': false,
},{
'price_from': 30,
'tint_system': 3,
'set_price': 50,
'round': false,
'scale': false,
},{
'price_from': 50,
'tint_system': 3,
'set_price': 100,
'round': false,
'scale': false,
},{
'price_from': 100,
'tint_system': 3,
'set_price': false,
'round': 'up', // rounding up, down , math
'scale': 10, // round up to 1 / 10 / 100 dollars
}
]
var obRobotint = {
// ...
processPrice: function($priceObj, data){
var data_raw = $priceObj.data();
var ppl_raw = parseFloat(data_raw.pricePerLitr);
var ppc_raw = parseFloat(data_raw.pricePerCan);
var ppl = ppl_raw; // save it in a separate variable, which we will use
var ppc = ppc_raw; // save it in a separate variable, which we will use
var ref_vol = parseFloat(data_raw.priceRef_can_volume); // volume of product to be tinted .. according to the database
var iVolume = ref_vol ;
CVID = data.COLLECTION_VENDOR_ID
if(!CVID) CVID = 3 // in this case we take Tikkurila
var cur_set = false;
for(var i in obRobotint.prices) {
// config array of price levels and roundings
rt_price = obRobotint.prices[i];
if(rt_price['tint_system'] == CVID){
// if the price falls within the range, then take this block of the price configurator
if(ppc > rt_price.price_from ){
cur_set = rt_price
}
}
}
if(!cur_set){
cur_set = {
'price_from': 0,
'tint_system': CVID , // in this case we take Tikkurila
'set_price': false,
'round': false,
'scale': false,
};
}
if(cur_set.set_price){
ppc = cur_set.set_price;
}
if(cur_set.round){
cur_set.scale = parseInt(cur_set.scale);
if(!cur_set.scale || cur_set.scale == 0){
cur_set.scale = 1;
}
if(cur_set.round == 'math'){
ppc = Math.round(ppc/cur_set.scale)*cur_set.scale;
}else if(cur_set.round == 'up'){
ppc = Math.ceil(ppc/cur_set.scale)*cur_set.scale;
}else if(cur_set.round == 'down'){
ppc = Math.floor(ppc/cur_set.scale)*cur_set.scale;
}else{
ppc = Math.round(ppc/cur_set.scale)*cur_set.scale;
}
}
// price of tinting per liter
ppl = ppc/iVolume;
if(ppc!=ppc_raw){
// rewrite the button value to client values, adjusted to the level we need
$priceObj.attr("data-price-shop",ppc);
$priceObj.text(obRobotint.numberFormat(ppc,0,"."," ")+" $");
}
},
// ....
}
$client = new HttpClient();
$client->setHeader("Authorization", "e2727d915b415************************************1fa2975ba507ba");
$client->setHeader("Content-type", "application/json");
$arData = [
"CLIENT_ID" => "4",
"COLOR_ID" => "140660",
"BARCODE" => "6408070012765",
"action" => "get-color-price"
];
$result = $client->post("https://core.robotint.ru/exchange/", json_encode($arData));