Answer the question
In order to leave comments, you need to log in
How to remove a duplicate in an array?
Simplified version of the question
<?
$obBasket = \Bitrix\Sale\Basket::getList(array('filter' => array('ORDER_ID' => 13329)));
while($bItem = $obBasket->Fetch())
{echo $bItem[PRODUCT_ID].' - '.$bItem[QUANTITY].'</br>';};
?>
покажет
30955 - 1
30955 - 1
154835 - 1
А как сделать так?:
30955 - 2
154835 - 1
<?
$obBasket = \Bitrix\Sale\Basket::getList(array('filter' => array('ORDER_ID' => $orderId)));
while($bItem = $obBasket->Fetch()){
$price_s = round($bItem[PRICE],2);
$kolvo_s = round($bItem[QUANTITY],2);
{?>$.post(
"https://www.google-analytics.com/collect",
{
v: '1',
tid: 'UA-xxxxxxxxxxxx-1',
cid: '<?=$result_idcode?>',
t: 'item',
ti: '<?=$orderId?>',
in: '<?=$bItem[NAME]?>',
ip: '<?=$price_s?>',
iv: '<?=$nn?>',
iq: '<?=$kolvo_s?>',
ic: '<?=$bItem[PRODUCT_ID]?>'
},
)
<?};
}
?>
$.post(
"https://www.google-analytics.com/collect",
{
v: '1',
tid: 'UA-xxxxxxxxxxxx-1',
cid: 'xxxxxxxxxxxx.xxxxxxxxxxxx",
t: 'item',
ti: '1000', //ID номер заказа
in: 'Товар 1', //название
ip: '999', // цена
iv: 'Категория',
iq: '1', // Количество этого товара
ic: '10020' // ID Товара
},
)
$.post(
"https://www.google-analytics.com/collect",
{
v: '1',
tid: 'UA-xxxxxxxxxxxx-1',
cid: 'xxxxxxxxxxxx.xxxxxxxxxxxx",
t: 'item',
ti: '1000', //ID номер заказа
in: 'Товар 2', //название
ip: '100', // цена
iv: 'Категория Б',
iq: '1', // Количество этого товара
ic: '10099' // ID Товара
},
)
$.post(
"https://www.google-analytics.com/collect",
{
v: '1',
tid: 'UA-xxxxxxxxxxxx-1',
cid: '<?=$result_idcode?>',
t: 'item',
ti: '1000', //ID номер заказа
in: 'Товар 2', //название
ip: '100', // цена
iv: 'Категория Б',
iq: '1', // Количество этого товара
ic: '10099' // ID Товара
},
)
iq: '2', // Количество этого товара
$.post(
"https://www.google-analytics.com/collect",
{
v: '1',
tid: 'UA-xxxxxxxxxxxx-1',
cid: '<?=$result_idcode?>',
t: 'item',
ti: '1000', //ID номер заказа
in: 'Товар 1', //название
ip: '999', // цена
iv: 'Категория',
iq: '1', // Количество этого товара
ic: '10020' // ID Товара
},
)
$.post(
"https://www.google-analytics.com/collect",
{
v: '1',
tid: 'UA-xxxxxxxxxxxx-1',
cid: 'xxxxxxxxxxxx.xxxxxxxxxxxx",
t: 'item',
ti: '1000', //ID номер заказа
in: 'Товар 2', //название
ip: '100', // цена
iv: 'Категория Б',
iq: '2', // Количество этого товара - ДОБАВИЛИ КОЛИЧЕСТВО
ic: '10099' // ID Товара
},
)
Answer the question
In order to leave comments, you need to log in
And why not fill in a temporary array in the loop, in which the product IDs will be the keys, and in the value of the parameters and when the product is duplicated, just increase the number?
Well, then on the array already build the data output
As for the head-on question: why not use the SUM aggregate function to calculate the total and group by PRODUCT_ID?
As for the formal side: this is not the best option, because you can have 2 products sold at different prices. Those. goods 3022 sold at 130 rubles in the amount of 2 pieces and 1 more piece. goods 3022 for 100 rubles (for example, when buying 2x, a discount on the third item is 30 rubles).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question