Answer the question
In order to leave comments, you need to log in
Adding Bitrix to cart not working?
Good afternoon!
Through CIBlockSection::GetList I display sections of the directory. By clicking on each section, I get the SECTION_ID and through ajax I insert the result of the bitrix:catalog.section component into the
page. Everything is fine, the products are updated and displayed on the page. But "add to cart" does not work. If the component is simply inserted on the page, then everything works.
How can the problem be solved? Is there any way to add a product to the shopping cart by standard means?
Or is it easier to write your add to cart handler?
Answer the question
In order to leave comments, you need to log in
1. First option:
- put bitrix:catalog
- file sections.php in it you display your filter by sections ( the section in the filter must be a link ) and catalog.section, in front of it is a global filter for your brand (if you don’t know how, write, explain), for catalog.section you specify the parameters
'INCLUDE_SUBSECTIONS' => 'Y',
'SHOW_ALL_WO_SECTION' => 'Y',
'BY_LINK' => 'Y'
'AJAX_MODE' => 'Y',
'AJAX_OPTION_STYLE' => 'Y',
'AJAX_OPTION_HISTORY' => 'Y'
//.......
url: '<?=$APPLICATION->GetCurDir()?>'
data: {SECTION_ID: idSection, BRAND_AJAX: 'Y'}
//.......
<?
$request = \Bitrix\Main\Application::getInstance()->getContext()->getRequest();
$bBrandAjax = $request->isAjaxRequest() && isset($request['BRAND_AJAX']) && $request['BRAND_AJAX'] == 'Y';
?>
<?// оборачиваешь в div для простоты вставки через js, можно поколдовать и сделать без этого контейнера, но тут уже сам))?>
<div id="ajax_brand_container">
<?
if($bBrandAjax) {
$APPLICATION->RestartBuffer();
}
// твой ajax-вый контент (вероятно только catalog.section)
if($bBrandAjax) {
die();
}
?>
</div>
var ajaxContainer = document.querySelector('#ajax_brand_container');
BX.ajax({
//........
onsuccess: async function(data) {
if(ajaxContainer) {
var obResult = BX.processHTML(data);
await !(function() {
ajaxContainer.innerHTML = data;
})();
BX.ajax.processScripts(obResult.SCRIPT);
}
}
//........
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question