Jump to content
  • 0

Подскажите


Шишха
 Share

Question

Вот код компонента Список связанных элементов.Идея заключается в том,чтобы при вводе количества,в отдельном столбце подсчитывалась сумма.То есть пользователь вводит ко всем товарам количество,ему выдает к каждому сумму,потом выводит итоговую сумму,и он нажимает В корзину если все так как он хочет.Проблема значит в том,что количество меняет только к одному товару,ковыряюсь не могу понять почему.А если ко всем товарам ввести по 1 количеству и нажать в корзину,тоже добавляет только один товар.Подскажите что не так?

<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>
<div class="catalog-section">
<?if($arParams["DISPLAY_TOP_PAGER"]):?>
<p><?=$arResult["NAV_STRING"]?></p>
<?endif?>

<!—ИСПОЛНЯЮЩИЙ СКРИПТ—-->

<script>
function cost(){
var cost_p=document.getElementById('cost_p').innerHTML;
var amount_p=document.getElementById('amount_p').value;
document.getElementById('cost_out').innerHTML=cost_p*amount_p;
}
</script>

<!————————-->
<hr noshade color="indigo"></hr>
<table class="data-table" cellspacing="0" cellpadding="0" border="0" width="100%">
<thead>
<tr>
<td><b><?=GetMessage("CATALOG_TITLE")?></b></td>
<?if(count($arResult["ITEMS"]) > 0):
foreach($arResult["ITEMS"][0]["DISPLAY_PROPERTIES"] as $arProperty):?>
<td><?=$arProperty["NAME"]?></td>
<?endforeach;
endif;?>
<?foreach($arResult["PRICES"] as $code=>$arPrice):?>
<td><b><?=$arPrice["TITLE"]?></b></td>
<?endforeach?>
<?if(count($arResult["PRICES"]) > 0):?>


<?endif?>
<td><b>Количество</b></td>
<td><b>Сумма</b></td>
</tr>
</thead>
<?foreach($arResult["ITEMS"] as $arElement):?>
<?
$this->AddEditAction($arElement['ID'], $arElement['EDIT_LINK'], CIBlock::GetArrayByID($arParams["IBLOCK_ID"], "ELEMENT_EDIT"));
$this->AddDeleteAction($arElement['ID'], $arElement['DELETE_LINK'], CIBlock::GetArrayByID($arParams["IBLOCK_ID"], "ELEMENT_DELETE"), array("CONFIRM" => GetMessage('CT_BCS_ELEMENT_DELETE_CONFIRM')));
?>
<tr id="<?=$this->GetEditAreaId($arElement['ID']);?>">
<td>
<a href="<?=$arElement["DETAIL_PAGE_URL"]?>"><?=$arElement["NAME"]?></a>
<?if(count($arElement["SECTION"]["PATH"])>0):?>

<?foreach($arElement["SECTION"]["PATH"] as $arPath):?>
/<a href="<?=$arPath["SECTION_PAGE_URL"]?>"><?=$arPath["NAME"]?></a>
<?endforeach?>
<?endif?>
</td>
<?foreach($arElement["DISPLAY_PROPERTIES"] as $pid=>$arProperty):?>
<td>
<?if(is_array($arProperty["DISPLAY_VALUE"]))
echo implode(" / ", $arProperty["DISPLAY_VALUE"]);
elseif($arProperty["DISPLAY_VALUE"] === false)
echo " ";
else
echo $arProperty["DISPLAY_VALUE"];?>
</td>
<?endforeach?>
<?foreach($arResult["PRICES"] as $code=>$arPrice):?>
<td>
<?if($arPrice = $arElement["PRICES"][$code]):?>
<?if($arPrice["DISCOUNT_VALUE"] < $arPrice["VALUE"]):?>
<s><?=$arPrice["PRINT_VALUE"]?></s><br /><span class="catalog-price"><?=$arPrice["PRINT_DISCOUNT_VALUE"]?></span>
<?else:?>

<!———ОПРЕДЕЛЯЕМ ПЕРЕМЕННУЮ ЦЕНЫ———->
<div id="cost_p" class="catalog-price"><?=$arPrice["DISCOUNT_VALUE"]?></div>
<!———————————————->



<?endif?>
<?else:?>
 
<?endif;?>
</td>

<?endforeach;?>
<?if(count($arResult["PRICES"]) > 0):?>

<td>
<!—————ПОЛЕ ДЛЯ ВВОДА КОЛИЧЕСТВА————>

<input onkeyup=cost(); id=amount_p style='text-align:right;border:1px solid #999999' type="text" name="kolvo" value="0" size="1">

<!—————————————————->
</td>
<td>

<!—————--ЗДЕСЬ ВЫВОДИМ СУММУ—————->
<div id=cost_out>0</div>
<!—————————————————->
</td>
<td>




</td>

<?endif;?>
</tr>
<?endforeach;?>
</table>
<hr noshade color="indigo"></hr>
<noindex>
<?if($arElement["CAN_BUY"]):?>
<a href="<?echo $arElement["ADD_URL"]?>" rel="nofollow"><?echo GetMessage("CATALOG_ADD")?></a>
<?elseif((count($arResult["PRICES"]) > 0) || is_array($arElement["PRICE_MATRIX"])):?>
<?=GetMessage("CATALOG_NOT_AVAILABLE")?>
<?endif?>


 
</noindex>
<?if($arParams["DISPLAY_BOTTOM_PAGER"]):?>
<p><?=$arResult["NAV_STRING"]?></p>
<?endif?>
</div>

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy