Created
February 19, 2020 02:52
-
-
Save Elvinz/744baa39d6527cf8fd098c402239141b to your computer and use it in GitHub Desktop.
Обновление корзины без перезагрузки страницы
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Для этого в header.php шаблона сайта добавляем следующий скрипт, предварительно подключив jQuery: | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script> | |
<script type="text/javascript"> | |
$(document).ready( | |
function(){ | |
function getBasketHTML(html) | |
{ | |
txt = html.split('<!--start--><div id="bid">'); | |
txt = txt[2]; | |
txt = txt.split('</div><!--end-->'); | |
txt = txt[0]; | |
return txt; | |
} | |
$('input[name*="actionADD2BASKET"]').click( | |
function(){ | |
parent = $(this).parent(); | |
quantity_val = $('input[name*=quantity]').attr('value'); | |
id_val = $('input[name*=id]').attr('value'); | |
$.ajax({ | |
type: "post", | |
url: parent.attr('action'), | |
data: {quantity: quantity_val, id: id_val, actionADD2BASKET: 'В корзину', action: "BUY"}, | |
dataType: "html", | |
success: function(out){ | |
$("#bid").html(getBasketHTML(out)); | |
alert("Товар добавлен в корзину"); | |
} | |
}); | |
return false; | |
} | |
); | |
} | |
); | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Далее открываем для редактирования template.php малой корзины, которую предварительно вывели на сайт в требуемом по дизайну месте и сверстали внешний вид. И обворачиваем в <!--start--><div id="bid"> </div><!--end--> | |
<!--start--><div id="bid"> | |
<?php if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?> | |
<?php | |
function getNumEnding($number, $endingArray) | |
{ | |
$number = $number % 100; | |
if ($number>=11 && $number<=19) | |
{ | |
$ending=$endingArray[2]; | |
} else { | |
$i = $number % 10; | |
switch ($i) { | |
case (1): $ending = $endingArray[0]; break; | |
case (2): case (3): case (4): $ending = $endingArray[1]; break; | |
default: $ending=$endingArray[2]; } | |
} | |
return $ending; | |
} | |
?> | |
<?php $defaultCurr = CSaleLang::GetLangCurrency(SITE_ID); ?> | |
<?php | |
$quant='0';$price='0'; | |
foreach ($arResult["ITEMS"] as $v) | |
{ | |
if ($v["DELAY"]=="N" && $v["CAN_BUY"]=="Y") | |
{ | |
$quant=$quant+$v["QUANTITY"]; | |
$pr=$v["QUANTITY"]*$v["PRICE"]; | |
$price=$price+$pr; | |
} | |
} | |
if($quant==0){?> | |
<span>В Вашей корзине<br/> | |
пока нет товаров.</span> | |
<?php }else{?> | |
<span>У Вас <a href="/basket/">в корзине</a> | |
<?=$quant?> <?php echo getNumEnding($quant, array("товар", "товара", "товаров")); ?></br> | |
на <?php echo SaleFormatCurrency($price, $defaultCurr); ?></span> | |
<?php } ?> | |
</div><!--end--> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment