Всем Привет! Есть скрипт для google remarketing, который должен собирать данные из корзины (список ID товаров, сумма корзины) Не могу понять как вывести цикл, '<?=$arBasketItemstag["PRODUCT_ID"]?> выводит только первый один ID, вероятно первый в корзине вот наглядная картинка Сам код корзины, и строка в которой нужно создать цикл: Код (Javascript): ecomm_prodid: '<?=$arBasketItemstag["PRODUCT_ID"]?>', PHP: <script type="text/javascript"> window.ad_products = [ <?foreach($arResult["ITEMS"]["AnDelCanBuy"] as $arBasketItemstag){?> { "id": "<?=$arBasketItemstag["PRODUCT_ID"]?>", // required "number": "<?=intval($arBasketItemstag["QUANTITY"])?>" }, <?}?> // other products ]; window._retag = window._retag || []; window._retag.push({code: "14862345ed", level: 3}); (function () { var id = "admitad-retag"; if (document.getElementById(id)) {return;} var s = document.createElement("script"); s.async = true; s.id = id; var r = (new Date).getDate(); s.src = (document.location.protocol == "https:" ? "https:" : "http:") + "//cdn.lenmit.com/static/js/retag.min.js?r="+r; var a = document.getElementsByTagName("script")[0] a.parentNode.insertBefore(s, a); })() </script> <script> window.APRT_DATA = { pageType: 4, basketProducts: [ <?foreach($arResult["ITEMS"]["AnDelCanBuy"] as $arBasketItemstag3){?> { id: <?=$arBasketItemstag3["PRODUCT_ID"]?>, name: "<?=$arBasketItemstag3["NAME"]?>", price: <?=$arBasketItemstag3["PRICE"]?>, quantity: <?=intval($arBasketItemstag3["QUANTITY"])?> }, <?}?> ] }; </script> <!----Gooogle-RemarketingTag----> <script type="text/javascript"> var google_tag_params = { ecomm_prodid: '<?=$arBasketItemstag["PRODUCT_ID"]?>', ecomm_pagetype: 'cart', ecomm_totalvalue: <?=$arResult["allSum_FORMATED"]?> }; </script> <!---Gooogle-RemarketingTag---->
вместо Код (Text): <?foreach($arResult["ITEMS"]["AnDelCanBuy"] as $arBasketItemstag){?> { "id": "<?=$arBasketItemstag["PRODUCT_ID"]?>", // required "number": "<?=intval($arBasketItemstag["QUANTITY"])?>" }, <?}?> надо PHP: <?php $arr = []; foreach($arResult["ITEMS"]["AnDelCanBuy"] as $arBasketItemstag){ $arr[] = $arBasketItemstag["PRODUCT_ID"]; } echo implode (', ', $arr); ?> --- Добавлено --- в данном случае тебе видимо их надо скопить в массив и сконвертировать в json и вывести в js в переменную запихать.
Как это вывести? в 1 посте не весь код корзины, вот полный: PHP: <?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?> <?//echo "<pre>";print_r($arBasketItems);echo "</pre>"; global $basket_set; $basket_set = $arParams['BASKET_PHOTO'];?> <input type="hidden" value="" name="BasketOrder" id="basketOrderButton2"> <?$i=0; foreach($arResult["ITEMS"]["AnDelCanBuy"] as $arBasketItems) $i = $i + $arBasketItems["QUANTITY"]; $a=-1; foreach($arResult["ITEMS"]["AnDelCanBuy"] as $arBasketItems): $a++; $test[$a]['id'] .= iconv('cp1251', 'utf-8', $arBasketItems['ID']); $test[$a]['name'] .= iconv('cp1251', 'utf-8',$arBasketItems['NAME']); $test[$a]['price'] .= iconv('cp1251', 'utf-8',$arBasketItems['PRICE']); $test[$a]['type'] .= iconv('cp1251', 'utf-8','Äðóãîå'); endforeach;?> <?//=json_encode($test, JSON_UNESCAPED_UNICODE);?> <script> var item =1; var arrProducts = new Array(); arrProducts[0] = { id : '2515', name : '1', price: '65990', type: 'Íîóòáóêè' }; arrProducts[1] = { id : '743', name : '2', price: '24680', type: 'Ìîáèëüíûå òåëåôîíû' }; arrProducts[2] = { id : '1306', name : '3', price: '5910.15', type: 'Áûòîâàÿ òåõíèêà' }; console.log(arrProducts); arrProducts2 = JSON.parse('<?=utf8win1251(json_encode($test, JSON_UNESCAPED_UNICODE));?>'); console.log(arrProducts2); function kredit_buy() { DCLoans(partnerID, 'getCredit', { products: arrProducts2, order: '123' }, function(result){ console.log(result.error); console.log(result.status); }); } </script> <script type="text/javascript"> window.ad_products = [ <?foreach($arResult["ITEMS"]["AnDelCanBuy"] as $arBasketItemstag){?> { "id": "<?=$arBasketItemstag["PRODUCT_ID"]?>", // required "number": "<?=intval($arBasketItemstag["QUANTITY"])?>" }, <?}?> // other products ]; window._retag = window._retag || []; window._retag.push({code: "35453569ed", level: 3}); (function () { var id = "admitad-retag"; if (document.getElementById(id)) {return;} var s = document.createElement("script"); s.async = true; s.id = id; var r = (new Date).getDate(); s.src = (document.location.protocol == "https:" ? "https:" : "http:") + "//cdn.lenmit.com/static/js/retag.min.js?r="+r; var a = document.getElementsByTagName("script")[0] a.parentNode.insertBefore(s, a); })() </script> <script> window.APRT_DATA = { pageType: 4, basketProducts: [ <?foreach($arResult["ITEMS"]["AnDelCanBuy"] as $arBasketItemstag3){?> { id: <?=$arBasketItemstag3["PRODUCT_ID"]?>, name: "<?=$arBasketItemstag3["NAME"]?>", price: <?=$arBasketItemstag3["PRICE"]?>, quantity: <?=intval($arBasketItemstag3["QUANTITY"])?> }, <?}?> ] }; </script> <!----Gooogle-RemarketingTag----> <script type="text/javascript"> var google_tag_params = { ecomm_prodid: '<?=$arBasketItemstag["PRODUCT_ID"]?>', ecomm_pagetype: 'cart', ecomm_totalvalue: <?=$arResult["allSum_FORMATED"]?> }; </script> <!---Gooogle-RemarketingTag----> <?global $USER; $email = $USER->GetEmail();?> <?//$iblocks = array("179", "180", "181", "184", "185", "186", "187", "189", "190", "192", "195", "196", "198", "199", "200", "201", "202", "203", "272", "283", "263", "281", "271", "221", "282", "291", "273", "278", "255", "286", "264", "257", "268", "269", "270", "275", "295" );?> <?//if(!empty($USER->GetEmail())){?> <?//$newarray = array();?> <?//foreach($arResult["ITEMS"]["AnDelCanBuy"] as $arBasketItemstag){?> <?//if(in_array($arBasketItemstag['CATALOG']['IBLOCK_ID'], $iblocks) && $arBasketItemstag["PRODUCT_ID"] != "19252"){?> <?//$newarray[] = $arBasketItemstag;?> <?//}?> <?//}?> <?if(count($arResult["ITEMS"]["AnDelCanBuy"]) > 0){?> <script type="text/javascript"> window.criteo_q = window.criteo_q || []; window.criteo_q.push( { event: "setAccount", account: 29398 }, { event: "setEmail", email: "<?=$email?>" }, { event: "setSiteType", type: "d" }, { event: "viewBasket", item: [ <?foreach($arResult["ITEMS"]["AnDelCanBuy"] as $arBasketItemstag2){?> { id: "<?=$arBasketItemstag2["PRODUCT_ID"];?>", price: "<?=$arBasketItemstag2["PRICE"];?>", quantity: "<?=$arBasketItemstag2["QUANTITY"];?>" }, <?}?> ]} ); </script> <?}?> <?//}?> <table> <?$i=0; foreach($arResult["ITEMS"]["AnDelCanBuy"] as $arBasketItems): $i++; $arBasketItems['PRICE'] = str_replace(GetMessage('RUB_REPLACE'), '<span class="rubl">'.GetMessage('RUB').'</span>', $arBasketItems['PRICE_FORMATED']);?> <tr> <td class="ibimg"> <input type="hidden" name="DELETE_<?=$arBasketItems["ID"] ?>" id="DELETE_I_<?=$i?>" value="" /> <input type="hidden" name="DELAY_<?=$arBasketItems["ID"] ?>" id="DELAY_<?=$i?>" value="" /> <img src="<?=$arBasketItems['PRODUCT_PICTURE_SRC'];?>" alt="" /> </td> <td class="ibname"> <h3><a href="<?=$arBasketItems["DETAIL_PAGE_URL"]?>"><?=$arBasketItems["NAME"] ?></a></h3> <?foreach($arBasketItems['PROPS'] as $prop):?> <b><?=$prop['NAME'];?>: <?=$prop['VALUE'];?></b> <br /> <?endforeach;?> </td> <td class="ibprice"> <span class="price"><?=$arBasketItems["PRICE"];?></span> </td> <td class="ibcount"> <input type="text" name="QUANTITY_<?=$arBasketItems["ID"]?>" id="QUANTITY_<?=$i?>" value="<?=$arBasketItems["QUANTITY"]?>" class="txt w32" /> <button onclick="setQuantity('#QUANTITY_<?=$i?>', '+'); return false;" class="button4">+</button> <button onclick="setQuantity('#QUANTITY_<?=$i?>', '-'); return false;" class="button5">-</button> </td> <td class="ibdel"> <button onclick="setDelay('#DELAY_<?=$i?>', 'Y'); return false;" class="button6 sym" title="<?=GetMessage('SALE_OTLOG')?>">{</button> </td> <td class="ibdel"> <button onclick="setDelete('#DELETE_I_<?=$i?>'); return false;" class="button6 sym" title="<?=GetMessage('SALE_DELETE')?>">Î</button> </td> </tr> <?endforeach;?> </table> <div class="make_order"> <?if(!$USER->IsAdmin()){?> <style type="text/css"> .coupon_new{ background: url("/bitrix/templates/bitronic_1.10.0/static/img/coupon2.png") top left no-repeat; width: 250px; height: 127px; position: absolute; left: 50%; margin-left: -125px; } .coupon_new_inp{ position: relative; top: 50px; left: -70px; width: 107px; height: 29px; border: none; outline: none; background-color: transparent; font-size: 19px; padding-left: 5px } </style> <div class="coupon_new"> <?if ($arParams["HIDE_COUPON"] != "Y"):?> <input class="coupon_new_inp" type="text" name="COUPON" value="<?=$arResult["COUPON"]?>" size="8"> <?endif;?> </div><!--.cupon--> <?}else{?> <div class="cupon" style="width: 380px;"> <?if ($arParams["HIDE_COUPON"] != "Y"):?> <label><?= GetMessage("STB_COUPON_PROMT") ?></label> <input class="txt w180" type="text" name="COUPON" value="<?=$arResult["COUPON"]?>" size="20"> <?endif;?> </div><!--.cupon--> <?}?> <br /> <br /> <span class="sum"> <?= GetMessage("SALE_ITOGO")?>: <strong><?=str_replace(GetMessage('RUB_REPLACE'), '<span class="rubl">'.GetMessage('RUB').'</span>', $arResult["allSum_FORMATED"]);?></strong> </span> <!--<button onclick="$('#basket_form').attr('action', '<?=$arParams[PATH_TO_ORDER]?>').submit(); return false;" class="button3"><?echo GetMessage("SALE_ORDER")?></button>--> <input type="submit" value="<?echo GetMessage("SALE_ORDER")?>" class="button3" name="BasketOrder" id="basketOrderButton"> </div> <!--.make_order--> <!-- BUY ONE CLICK COMPONENT /--> <style> #SALE_ORDER { background: none repeat scroll 0 0 #ff9318 !important; border: 2px solid black; border-radius: 5px; bottom: 100px; color: white !important; font-size: 14px; font-weight: bolder; line-height: 37px; position: absolute; } </style> <?$APPLICATION->IncludeComponent("westpower:sale.order.oneclick", "template2", array( "IBLOCK_TYPE" => "dict", "IBLOCK_ID" => "179", "OFFERS_PROPERTY_CODE" => array( 0 => "", 1 => "", ), "IS_JQUERY" => "Y", "PERSON_TYPE" => "1", "PERSON_TYPE_PROPS" => array( 0 => "1", 1 => "2", 2 => "3", ), "ORDER_PRODUCT" => "1", "PAYSYSTEM" => "1", "DELIVERY" => "1", "USE_USER" => "N", "USE_COMMENT" => "N", "EVENT_MESSAGE_ID" => "", "USE_CAPTCHA" => "N", "TITLE_POPUP" => "Îôîðìëåíèå çàêàçà â îäèí êëèê", "CONFIRM_ORDER" => "Ñïàñèáî. Âàø çàêàç ïðèíÿò.", "IMAGE_WIDTH" => "130", "IMAGE_HEIGHT" => "130", "HIDE_BUTTON" => "Y" ), false, array( "ACTIVE_COMPONENT" => "N" ) );?> <!-- BUY ONE CLICK END COMPONENT /-->
А если так? Код (Javascript): <script type="text/javascript"> var google_tag_params = { ecomm_prodid: , ecomm_pagetype: 'cart', ecomm_totalvalue: <?=$arResult["allSum_FORMATED"]?> }; google_tag_params["ecomm_prodid"]=window.ad_products; </script>