Долго вымучивал по форумам как передать количество товаров из списка категории в корзину через js. Задача была сделать так что бы можно было указать количество товаров которое требуется положить в корзину (купить) в определенном поле нажать на кнопку купить и без перезагрузки страницы увидеть свою покупку в мини корзине.
Открываем файл: /bitrix/templates/ШАБЛОН/components/bitrix/catalog/ ШАБЛОН_в_моем_случае_template1/bitrix/catalog.section/.default/template.php И меняем код который отвечает за вывод кнопки купить в моем случае это:
<?if($arElement["CAN_BUY"]):?>
<a class="bt3 addtoCart" href="<?echo $arElement["ADD_URL"]?>" rel="nofollow" onclick="return addToCart(this, 'list', '<?=GetMessage("CATALOG_IN_CART")?>', 'cart');" id="catalog_add2cart_link_<?=$arElement['ID']?>"><span></span><?=GetMessage("CATALOG_BUY")?></a>
<?elseif ($arNotify[SITE_ID]['use'] == 'Y'):?>
<?if ($USER->IsAuthorized()):?>
<noindex><a href="<?echo $arElement["SUBSCRIBE_URL"]?>" rel="nofollow" class="bt2 bt2_right" onclick="return addToSubscribe(this, '<?=GetMessage("CATALOG_IN_SUBSCRIBE")?>');" id="catalog_add2cart_link_<?=$arElement['ID']?>"><span></span><?echo GetMessage("CATALOG_SUBSCRIBE")?></a></noindex>
<?else:?>
<noindex><a href="javascript:void(0)" rel="nofollow" class="bt2 right" onclick="showAuthForSubscribe(this, <?=$arElement['ID']?>, '<?echo $arElement["SUBSCRIBE_URL"]?>')" id="catalog_add2cart_link_<?=$arElement['ID']?>"><span></span><?echo GetMessage("CATALOG_SUBSCRIBE")?></a></noindex>
<?endif;?>
На это
<script type="text/javascript">
$(document).ready(function() {
$('input.quantity').change(function() {
var obAddToCartLink = $('a.addtoCart:first', $(this).parent());
obAddToCartLink.attr('href', obAddToCartLink.attr('href').replace( /(quantity=)[0-9]+/ig, '$1'+$(this).val() ));
});
$('input.quantity').keypress(function() {
$(this).trigger('change');
});
$('a.minus1, a.plus1').click(function(e){
e.preventDefault();
e.stopPropagation();
var oThisQuntityInput = $('input.quantity:first', $(this).parent().parent());
var iThisQuantity = parseInt(oThisQuntityInput.val());
var iSubtrahend = 1;
if ($(this).hasClass("minus1"))
{
if (iThisQuantity < 2)
{
return false;
}
iSubtrahend = iSubtrahend * (-1);
}
var iThisQuantityNew = iThisQuantity + iSubtrahend;
oThisQuntityInput.val(iThisQuantityNew);
oThisQuntityInput.trigger('change');
});
});
</script>
<input class="quantity" maxlength="18" type="text" name="QUANTITY_<?=$arElement['ID']?>" value="1" size="2" id="QUANTITY_<?=$arElement['ID']?>"/>
<div class="count_nav">
<a href="javascript:void(0)" class="plus" onclick="BX('QUANTITY_<?=$arElement['ID']?>').value++;"></a>
<a href="javascript:void(0)" class="minus" onclick="if (BX('QUANTITY_<?=$arElement['ID']?>').value > 1) BX('QUANTITY_<?=$arElement['ID']?>').value--;"></a>
</div>
<a href="<?echo $arElement["ADD_URL"]?>&quantity=1" rel="nofollow" class="addtoCart bt4" onclick="return addToCart(this, 'list', '<?=GetMessage("CATALOG_IN_CART")?>', 'noCart');" id="catalog_add2cart_link_<?=$arElement['ID']?>"><?=GetMessage("CATALOG_BUY")?></a>
<? }
?>
Источник: http://dev.1c-bitrix.ru/community/forums/forum6/topic53640/
