Last active
November 30, 2018 06:25
-
-
Save Ginnw2/7dc5998c9ec3d41a17a66a026efc4553 to your computer and use it in GitHub Desktop.
This file contains 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
<? require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include.php");?> | |
<? | |
if (CModule::IncludeModule("sale") && CModule::IncludeModule("catalog")) | |
{ | |
if (isset($_REQUEST['id'])&&isset($_REQUEST['q'])) { | |
$PRODUCT_ID = intval($_REQUEST['id']); | |
$QUANTITY = intval($_REQUEST['q']); | |
Add2BasketByProductID( | |
$PRODUCT_ID, | |
$QUANTITY | |
); | |
//LocalRedirect("/personal/basket.php"); //путь в Вашей корзине | |
} | |
else { | |
echo "Нет параметров "; | |
} | |
} | |
else { | |
echo "Не подключены модули"; | |
} | |
?> |
This file contains 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
<div class="quantity"> | |
<input type="number" value="1" min="1" class="qu"> | |
</div> | |
<a href="javascript:void(0);" id="<?=$arResult[ID];?>" class="buy btn btn--white"><span>Купить</span></a> | |
<script> | |
$(document).ready(function(){ | |
$('<div class="quantity-nav"><div class="quantity-button quantity-up">+</div><div class="quantity-button quantity-down">-</div></div>').insertAfter('.quantity input'); | |
$('.quantity').each(function() { | |
var spinner = jQuery(this), | |
input = spinner.find('input[type="number"]'), | |
btnUp = spinner.find('.quantity-up'), | |
btnDown = spinner.find('.quantity-down'), | |
min = input.attr('min'), | |
max = input.attr('max'); | |
btnUp.click(function() { | |
var oldValue = parseFloat(input.val()); | |
if (oldValue >= max) { | |
var newVal = oldValue; | |
} else { | |
var newVal = oldValue + 1; | |
} | |
spinner.find("input").val(newVal); | |
spinner.find("input").trigger("change"); | |
}); | |
btnDown.click(function() { | |
var oldValue = parseFloat(input.val()); | |
if (oldValue <= min) { | |
var newVal = oldValue; | |
} else { | |
var newVal = oldValue - 1; | |
} | |
spinner.find("input").val(newVal); | |
spinner.find("input").trigger("change"); | |
}); | |
}); | |
$(".buy").click(function(){ | |
var id = $(this).attr('id'); | |
var q = parseInt($(".qu").val()); | |
var form_data = new FormData(); | |
form_data.append('id', id); | |
form_data.append('q', q); | |
$.ajax({ | |
url: '/api/add-basket.php', | |
dataType: 'text', | |
cache: false, | |
contentType: false, | |
processData: false, | |
data: form_data, | |
type: 'post', | |
success: function(php_script_response){ | |
$(".ans").html("Товар добавлен в корзину"); | |
$(".ans").fadeIn(1000); | |
setTimeout($(".ans").fadeOut(600), 5000); | |
var inC = parseInt($(".top-cart span").text()); | |
var updute = inC+q; | |
$(".top-cart span").text(updute); | |
} | |
}); | |
event.preventDefault(); // Полная остановка происходящего | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment