В /catalog/ используется компонент catalog.sections.top
Шаблон переделан под прайс-лист, то есть в виде таблицы отображаются разделы и элементы каталога.
Пользователь заполняет поле "Количество" к каждому нужному товару, нажимает "Оформить заказ" и его отправляет в корзину.
Сейчас появилась задача сделать ajax корзину с редиректом, то есть заполнив все позиции в /catalog/ он добавляет товары и его перенаправляет в /devices/ где тот же самый компонент с тем же самым шаблоном, только уже элементы другого каталога.
Код |
---|
$catalog_props='';
$rsProps = CIBlockProperty::GetList(Array("sort"=>"asc"), $arFilter);
while($arProps = $rsProps->GetNext())
{
if(in_array($arProps["CODE"], $arCatalogPropsCodes))
{
$catalog_props.= '<td class="item_prop item_prop_'.$arProps["CODE"].'">'.$arProps["NAME"].'</td>';
}
}
foreach($arResult["PRICES"] as $code=>$arPrice)
{
$catalog_prices.='<td class="header_item_price '.$code.'">'.$arPrice["TITLE"].'</td>';
$catalog_summs.='<td class="header_item_summ '.$code.'">'.$arPrice["TITLE"].' сумма</td>';
}
$catalog_head=
'<div id="price_page">'.
//'<fo rm action="'.$arParams["BASKET_URL"].'" method="post" class="add_form">'.
'<fo rm action="'.POST_FORM_ACTION_URI.'" method="post">'.
'<table cellspacing="1" cellpadding="0">'.
'<thead>'.
'<tr class="catalog_header">'.
'<td class="header_item_title">Наименование</td>'.
$catalog_props.
$catalog_prices.
'<td class="header_item_amount">Добавить</td>'.
$catalog_summs.
'</tr>'.
'</thead>';
echo $catalog_head;
foreach($arResult["SECTIONS"] as $arSection)
{
if(count($arSection["ITEMS"]))
{
$section_title='<tr class="section_title"><td colspan="'.(2+(count($arParams["PRICE_CODE"])*2)+count($arParams["PROPERTY_CODE"])).'">'.$arSection["NAME"].'</td></tr>';
echo $section_title;
$odd=0;
foreach($arSection["ITEMS"] as $arElement)
{
$item_name=$arElement["NAME"];
$item_name=''.$arElement["NAME"].'';
$item_name='<td class="item_name">'.$item_name.'</td>';
$item_prices='';
$item_props='';
$item_summs='';
foreach($arParams["PROPERTY_CODE"] as $code)
{
if(isset($arElement["DISPLAY_PROPERTIES"][$code]))
{
$item_props.='<td class="item_prop item_prop_'.$code.'">'.$arElement["DISPLAY_PROPERTIES"][$code]["VALUE"].'</td>';
}
else
{
$item_props.='<td class="item_prop empty item_prop_'.$code.'"></td>';
}
}
foreach($arElement["PRICES"] as $code=>$arPrice)
{
$item_prices.='<td class="item_price '.$code.' item_price_'.$code.'">'.$arPrice["DISCOUNT_VALUE"].'</td>';
$item_summs.='<td class="item_summ '.$code.' item_summ_'.$code.'" ><span>0</span> руб.</td>';
}
$item_amount=
'<td class="item_amount">'.
'<input type="text" value="0" size="5" maxlength="5" name="element_'.$arElement["ID"].'">'.
'</td>';
$item_summ='';
$odd++;
$item='<tr id="item_'.$arElement["ID"].'" class="item '.(($odd % 2) ? 'odd' : 'even').'">'.$item_name.$item_props.$item_prices.$item_amount.$item_summs.'</tr>';
echo $item;
}
}
}
$catalog_totalsumms='';
foreach($arResult["PRICES"] as $code=>$arPrice)
{
$catalog_totalsumms.='<td class="catalog_summ '.$code.'"><span class="summ_number">0</span></td>';
}
echo
'<tr class="total"><td class="label" colspan="'.((count($arParams["PRICE_CODE"])*2)+count($arParams["PROPERTY_CODE"])).'"><b>Всего:</b></td>'.$catalog_totalsumms.'</tr>'.
'</table>'.
'<input type="s ubmit" name="priceaddtobasket" value="Оформить заказ">'.
'<div id="debug"></div>'.
'</form>'
;
|
ЖС находится также в шаблоне
Код |
---|
$(docu ment).ready(f unction()
{
var $catalog_price_h=$("div#price_page");
function TotalSumm()
{
$("td.catalog_summ", $catalog_price_h).each(f unction()
{
var total=0;
arClasses=$(this).attr('class').split(' ');
$("td.item_summ_"+arClasses[1]+" span", $catalog_price_h).each(f unction(){total+=parseInt($(this).html())});
$("span", $(this)).html(total);
});
var total=0;
}
$("tr.item", $catalog_price_h).each(f unction()
{
var $item_h = $(this);
var $input_h = $(".item_amount input", $item_h);
var $prices_h = $("td.item_price", $item_h);
var $summs_h = $("td.item_summ", $item_h);
var $button_plus_h = $("span.plus", $item_h);
var $button_minus_h = $("span.minus", $item_h);
$input_h.numeric();
$input_h.bind("keyup change", f unction(event)
{
if(event.keyCode == '38')
{
var newval = parseInt($input_h.val(),10)+1;
if(!isNaN(newval))
{
$input_h.val(newval);
}
else
{
$input_h.val(1);
}
}else if(event.keyCode == '40')
{
var newval = (parseInt($input_h.val(),10)-1);
if(newval >= 0 && (!isNaN(newval)))
{
$input_h.val(newval);
}
else
{
$input_h.val(0);
}
}
$prices_h.each(f unction()
{
$arClasses=$(this).attr('class').split(' ');
$summs_h.filter("."+$arClasses[1]).html('<span>'+parseInt($(this).html())*$input_h.val()+'</span> руб.');
});
TotalSumm();
if($input_h.val()>0)
{
$item_h.addClass('selected');
}
else
{
$item_h.removeClass('selected');
}
});
$input_h.bind("focusin", f unction()
{
if($input_h.val()==0)
{
$input_h.val("");
}
});
$input_h.bind("focusout", f unction()
{
if($input_h.val()=="")
{
$input_h.val(0);
}
});
$button_plus_h.click(f unction()
{
$input_h.trigger($.Event("keyup", { keyCode: 38 }));
});
$button_minus_h.click(f unction()
{
$input_h.trigger($.Event("keyup", { keyCode: 40 }));
});
});
});
|