Вставил такой кусок кода в basket_items.php
Код |
---|
<fo rm> <div class="cart-buttons"> <input type="hidden" type="text" name="QUANTITY_<?=$arBasketItems["ID"] ?>" value="<?=$arBasketItems["QUANTITY"]+1?>"> <input style="cursor: pointer;" type="s ubmit" value="+" name="BasketRefresh"> </div> </form> <fo rm> <div class="cart-buttons"> <input type="hidden" type="text" name="QUANTITY_<?=$arBasketItems["ID"] ?>" value="<?=$arBasketItems["QUANTITY"]-1?>"> <input style="cursor: pointer;" type="s ubmit" value="-" name="BasketRefresh"> </div> </form> |
Корректно работает только для одного элемента корзины.
Подскажите как правильно настроить работу скрипта.
Вот полный код
Код |
---|
<?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?><div class="cart-items" id="id-cart-list"> <?if(count($arResult["ITEMS"]["AnDelCanBuy"]) > 0):?> <h2>Название продукции</h2> <div id="prod_zakaz"> <table class="cart-items" cellspacing="0"> <thead> <tr class="bg_none"> <?if (in_array("NAME", $arParams["COLUMNS_LIST"])):?> <td id="zagolovok" class="cart-item-name">Товар</td> <?endif;?> <?if (in_array("QUANTITY", $arParams["COLUMNS_LIST"])):?> <td id="zagolovok" class="cart-item-quantity">кол-во</td> <?endif;?> <?if (in_array("PRICE", $arParams["COLUMNS_LIST"])):?> <td id="zagolovok" class="cart-item-price">стоимость</td> <?endif;?> <?if (in_array("VAT", $arParams["COLUMNS_LIST"])):?> <td id="zagolovok" class="cart-item-price">стоимость</td> <?endif;?> <?if (in_array("TYPE", $arParams["COLUMNS_LIST"])):?> <td class="cart-item-type"><?= GetMessage("SALE_PRICE_TYPE")?></td> <?endif;?> <?if (in_array("DISCOUNT", $arParams["COLUMNS_LIST"])):?> <td class="cart-item-discount"><?= GetMessage("SALE_DISCOUNT")?></td> <?endif;?> <?if (in_array("WEIGHT", $arParams["COLUMNS_LIST"])):?> <td class="cart-item-weight"><?= GetMessage("SALE_WEIGHT")?></td> <?endif;?> <td class="cart-item-actions"> <?if (in_array("DELETE", $arParams["COLUMNS_LIST"]) || in_array("DELAY", $arParams["COLUMNS_LIST"])):?> <?= GetMessage("SALE_ACTION")?> <?endif;?> </td> </tr> </thead> <tbody> <? $i=0; foreach($arResult["ITEMS"]["AnDelCanBuy"] as $arBasketItems) { ?> <tr> <?if (in_array("NAME", $arParams["COLUMNS_LIST"])):?> <td class="cart-item-name"><a href="jav * ascript:void(0)" id="minus"> </a><? if (strlen($arBasketItems["DETAIL_PAGE_URL"])>0): ?><a href="<?=$arBasketItems["DETAIL_PAGE_URL"] ?>"><? endif; ?><b><?=$arBasketItems["NAME"] ?></b><? if (strlen($arBasketItems["DETAIL_PAGE_URL"])>0): ?></a><? endif;?> <?if (in_array("PROPS", $arParams["COLUMNS_LIST"])) { foreach($arBasketItems["PROPS"] as $val) { echo "<br />".$val["NAME"].": ".$val["VALUE"]; } }?> </td> <?endif;?> <?if (in_array("QUANTITY", $arParams["COLUMNS_LIST"])):?> <td class="cart-item-quantity"><input id="plusminus" maxlength="18" type="text" name="QUANTITY_<?=$arBasketItems["ID"] ?>" value="<?=$arBasketItems["QUANTITY"]?>" size="3"> <fo rm> <div class="cart-buttons"> <input type="hidden" type="text" name="QUANTITY_<?=$arBasketItems["ID"] ?>" value="<?=$arBasketItems["QUANTITY"]+1?>"> <input style="cursor: pointer;" type="s ubmit" value="+" name="BasketRefresh"> </div> </form> <fo rm> <div class="cart-buttons"> <input type="hidden" type="text" name="QUANTITY_<?=$arBasketItems["ID"] ?>" value="<?=$arBasketItems["QUANTITY"]-1?>"> <input style="cursor: pointer;" type="s ubmit" value="-" name="BasketRefresh"> </div> </form> </td> <?endif;?> <?if (in_array("PRICE", $arParams["COLUMNS_LIST"])):?> <td class="cart-item-price"><?=$arBasketItems["PRICE_FORMATED"]?> <a href="jav * ascript:void(0)" id="plus"> </a> </td> <?endif;?> <?if (in_array("VAT", $arParams["COLUMNS_LIST"])):?> <td class="cart-item-price"><?=$arBasketItems["VAT_RATE_FORMATED"]?></td> <?endif;?> <?if (in_array("TYPE", $arParams["COLUMNS_LIST"])):?> <td class="cart-item-type"><?=$arBasketItems["NOTES"]?></td> <?endif;?> <?if (in_array("DISCOUNT", $arParams["COLUMNS_LIST"])):?> <td class="cart-item-discount"><?=$arBasketItems["DISCOUNT_PRICE_PERCENT_FORMATED"]?></td> <?endif;?> <?if (in_array("WEIGHT", $arParams["COLUMNS_LIST"])):?> <td class="cart-item-weight"><?=$arBasketItems["WEIGHT_FORMATED"]?></td> <?endif;?> <td class="cart-item-actions"> <?if (in_array("DELETE", $arParams["COLUMNS_LIST"])):?> <a class="cart-delete-item" href="<?=str_replace("#ID#", $arBasketItems["ID"], $arUrlTempl["delete"])?>" title="<?=GetMessage("SALE_DELETE_PRD")?>"></a> <?endif;?> <?if (in_array("DELAY", $arParams["COLUMNS_LIST"])):?> <a class="cart-shelve-item" href="<?=str_replace("#ID#", $arBasketItems["ID"], $arUrlTempl["shelve"])?>"><?=GetMessage("SALE_OTLOG")?></a> <?endif;?> </td> </tr> <? $i++; } ?> </tbody> </table> </div> <h2>Итого: <?if (in_array("PRICE", $arParams["COLUMNS_LIST"])):?> <span class="cart-item-price"> <?if (in_array("WEIGHT", $arParams["COLUMNS_LIST"])):?> <?=$arResult["allWeight_FORMATED"]?> <?endif;?> <?if (doubleval($arResult["DISCOUNT_PRICE"]) > 0):?> <?=$arResult["DISCOUNT_PRICE_FORMATED"]?> <?endif;?> <?if ($arParams['PRICE_VAT_SHOW_VALUE'] == 'Y'):?> <?=$arResult["allNOVATSum_FORMATED"]?> <?=$arResult["allVATSum_FORMATED"]?> <?endif;?> <b><?=$arResult["allSum_FORMATED"]?></b> </span> <?endif;?> </h2> <div id="prod_zakaz" class="prod_zakaz"> <table style="display: none;" class="cart-items" cellspacing="0"> <tfoot> <tr class="bg_none"> <?if (in_array("NAME", $arParams["COLUMNS_LIST"])):?> <td class="cart-item-name"> <?if (in_array("WEIGHT", $arParams["COLUMNS_LIST"])):?> <p><?echo GetMessage("SALE_ALL_WEIGHT")?>:</p> <?endif;?> <?if (doubleval($arResult["DISCOUNT_PRICE"]) > 0) { ?><p><?echo GetMessage("SALE_CONTENT_DISCOUNT")?><? if (strLen($arResult["DISCOUNT_PERCENT_FORMATED"])>0) echo " (".$arResult["DISCOUNT_PERCENT_FORMATED"].")";?>:</p><? }?> <?if ($arParams['PRICE_VAT_SHOW_VALUE'] == 'Y'):?> <p><?echo GetMessage('SALE_VAT_EXCLUDED')?></p> <p><?echo GetMessage('SALE_VAT_INCLUDED')?></p> <?endif;?> <p><b><?= GetMessage("SALE_ITOGO")?>:</b></p> </td> <?endif;?> <?if (in_array("QUANTITY", $arParams["COLUMNS_LIST"])):?> <td class="cart-item-quantity"> </td> <?endif;?> <?if (in_array("PRICE", $arParams["COLUMNS_LIST"])):?> <td class="cart-item-price"> <?if (in_array("WEIGHT", $arParams["COLUMNS_LIST"])):?> <p><?=$arResult["allWeight_FORMATED"]?></p> <?endif;?> <?if (doubleval($arResult["DISCOUNT_PRICE"]) > 0):?> <p><?=$arResult["DISCOUNT_PRICE_FORMATED"]?></p> <?endif;?> <?if ($arParams['PRICE_VAT_SHOW_VALUE'] == 'Y'):?> <p><?=$arResult["allNOVATSum_FORMATED"]?></p> <p><?=$arResult["allVATSum_FORMATED"]?></p> <?endif;?> <p><b><?=$arResult["allSum_FORMATED"]?></b></p> </td> <?endif;?> <?if (in_array("TYPE", $arParams["COLUMNS_LIST"])):?> <td class="cart-item-type"> </td> <?endif;?> <?if (in_array("VAT", $arParams["COLUMNS_LIST"])):?> <td class="cart-item-type"> </td> <?endif;?> <?if (in_array("DISCOUNT", $arParams["COLUMNS_LIST"])):?> <td class="cart-item-discount"> </td> <?endif;?> <?if (in_array("WEIGHT", $arParams["COLUMNS_LIST"])):?> <td class="cart-item-weight"> </td> <?endif;?> <?if (in_array("DELETE", $arParams["COLUMNS_LIST"]) || in_array("DELAY", $arParams["COLUMNS_LIST"])):?> <td class="cart-item-actions"> </td> <?endif;?> </tr> </tfoot> </table> </div> <div class="cart-ordering"> <?if ($arParams["HIDE_COUPON"] != "Y"):?> <div class="cart-code"> <input <?if(empty($arResult["COUPON"])):?>on click="if (this.value=='<?=GetMessage("SALE_COUPON_VAL")?>')this.value=''" on blur="if (this.value=='')this.value='<?=GetMessage("SALE_COUPON_VAL")?>'"<?endif;?> value="<?if(!empty($arResult["COUPON"])):?><?=$arResult["COUPON"]?><?else:?><?=GetMessage("SALE_COUPON_VAL")?><?endif;?>" name="COUPON"> </div> <?endif;?> <div class="cart-buttons"> <a href="/pechat-zakaza/"><img src="<?=SITE_TEMPLATE_PATH?>/images/print.png"></a> <a id="p_z" href="/pechat-zakaza/">распечатать ваш заказ</a> <span id="qwer"><input type="s ubmit" value="<?echo " "?>" name="BasketOrder" id="basketOrderButton2"></span> </div> </div> <?else: echo ShowNote(GetMessage("SALE_NO_ACTIVE_PRD")); endif;?></div> |
Если элементов в корзине несколько, то при нажатии на + (1 в списке товар) - происходит увеличение товара на 1. Если же нажимать на + у других товаров (кроме первого в списке[последнего добавленного]
, или на - у всех товаров, то происходит обновление корзины и остается только тот товар, количество которого мы увеличивали