Answer the question
In order to leave comments, you need to log in
How to get values from json correctly?
How to correctly get values from json
product: {
"id":48597847,
"price_kinds":[
{"id":11467,"price_index":1,"value":2},
{"id":11468,"price_index":2,"value":5}
],
"variants":[
{"prices":[1290.0,999.0],"price":"1490.0","price2":1290.0,"price3":999.0}
]
},
$(function(){
var
$config = {
product: {{ product | json }},
};
var
self = this,
prices = [],
price_kinds = [];
Events( 'onQuantity_Change' ).subscribe( function( $data ){
// вытаскиваем правила для типов цен
$.each( $config.product.price_kinds, function( index, $price_kind ) {
price_kinds[ $price_kind.price_index ] = $price_kind.value;
});
self.price_kinds = price_kinds;
// массив цена правило
// дальше не работает
prices[ 0 ] = {
price: parseFloat( $config.product.price ),
value: 0,
};
$.each( $config.product.variants, function( index, price ){
prices[ index +1 ] = {
price: price,
value: self.price_kinds[ index +1 ],
};
});
self.prices = prices;
console.log( 'onBuyButton_Active: ', self.price_kinds );
console.log( 'onBuyButton_Active: ', self.prices );
});
Answer the question
In order to leave comments, you need to log in
Something is not visible $config.product.price - price is not there, maybe like this: it's
better to look so where you have or lose
console.log($config);
console.log($config.product);
console.log($config.product.variants);
How to correctly get values from json
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question