A
A
Anton2018-01-29 15:32:22
PHP
Anton, 2018-01-29 15:32:22

How to pass data to a script?

According to those tasks, you need to insert order values ​​into the script

<script type="text/javascript">
(window["rrApiOnReady"] = window["rrApiOnReady"] || []).push(function() {
try {
rrApi.order({
transaction: <transaction_id>,
items: [
{ id: <product_id>, qnt: <quantity>, price: <price>},
{ id: <product_id>, qnt: <quantity>, price: <price> }
]
});
} catch(e) {}
})
</script>

Where:
<transaction_id> - ID транзакции,
<product_id> - ID товара (должно совпадать с ID, передаваемом в YML),
<qnt> - количество единиц товара в заказе,
<price> - цена за единицу товара.

Example:
<script type="text/javascript">
(window["rrApiOnReady"] = window["rrApiOnReady"] || []).push(function() {
try {
rrApi.order({
transaction: 1235421421,
items: [
{ id: 12312, qnt: 4, price: 130 },
{ id: 64532, qnt: 1, price: 220 }
]
});
} catch(e) {}
})
</script>

Now on the page where I need to insert this script, I get the data:
<? echo "<pre>"; print_r($arResult[ORDER][ID]); echo "</pre>"; // ID транзакции
$obBasket = \Bitrix\Sale\Basket::getList(array('filter' => array('ORDER_ID' => $arResult[ORDER][ID])));
while($bItem = $obBasket->Fetch()){
     echo $bItem['ID'].'<br/>';  //  ID товара
     echo round($bItem['QUANTITY'],2).'<br/>'; //  количество единиц товара в заказе
     echo round($bItem['PRICE'],2).'<br/>'; //  цена за единицу товара
}
?>

Output example
12016 // ID транзакции
52280  //  ID товара
1 //  количество единиц товара в заказе
650 //  цена за единицу товара
52281 //  ID товара
1 //  количество единиц товара в заказе
650 //  цена за единицу товара
52282 //  ID товара
3 //  количество единиц товара в заказе
2790 //  цена за единицу товара

How can I correctly transfer all this to the script, in particular, I can’t figure out with mass items, there can be as many goods as you like.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Frank, 2018-01-30
@Akellacom

Pass the object with the goods, and on the side of the popup already disassemble it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question