

<?php


include_partial('show_cat_header',
    array(
        'alias'         => $alias,
        'breadcrumbs'   => $breadcrumbs,
        'parentId'      => $parentId,
        'cat_id'        => $cat_id,
        'order'         => $order,
        'inPage'        => $inPage,
        'sort'          => $sort,
        'view_type'     => $view_type,
        'productCount'  => $productCount
    )
);

?>

<i class="br20"></i>


<table style="padding: 20px" class="std_table js_cat_view" width="100%" cellspacing="0" cellpadding="0">
    <thead>
    <tr valign="bottom" align="left">
        <th colspan="2" style="text-align: left !important;">Название</th>
        <th style="text-align: left !important;">Артикул</th>
        <th>Мин.&nbsp;партия</th>
        <th>В&nbsp;наличии</th>
        <th style="text-align: right !important;">Цена</th>
        <th>&nbsp;</th>
        <th>&nbsp;</th>
    </tr>
    </thead>

    <tbody>
    <?php

    $productsIdsInBasket = $this->context->getUser()->getProductsIdsInBasket();

    foreach ($products as $product)
    {
        echo "<tr class='js_cat_view__ct__tr'>";
            echo "<td align='center' class='first_td'>";

                if ($product['sell_out'])
                {
                    echo '<div class="sale_out">Распродажа</div>';
                }


                echo "<a href='" . url_for('@catalog_show_prod?alias=' . $product['alias']) . "' style='border-bottom:none;'>";
                echo '<img class="js_cat_view__img image_view" src="' . url_for('@get_image?id=' . $product['id']) . '?small">';
                echo "</a>";
            echo "</td>";
            echo "<td class='js_cat_view_product_name__td'>";
                echo "<a href='" . url_for('@catalog_show_prod?alias=' . $product['alias']) . "'>" . $product['title'] . "</a>";
            echo "</td>";
            echo "<td>";
                echo $product['product_code'];
            echo "</td>";

            echo "<td>";
                echo $product['min_order'];
            echo "</td>";
                $stockCount = round($product['stockCount']);
                if($stockCount == 0)
                {

                    echo "<td align='center'>";
                    echo "Нет в наличии";
                    echo "</td>";
                    echo "<td><b>";
                    if ($product['price'])
                    {
                        echo number_format($product['price'],2,',',' ') . '<span class="rub" style="position:relative;top:0px;">a</span>';
                    }
                    echo "</b></td>";
                    echo "<td colspan='2'></td>";
                }
                else
                {

                    echo "<td>";
                    echo $stockCount;
                    echo "</td>";
                    echo "<td><b>";
                    if ($product['price'])
                    {
                        echo number_format($product['price'],2,',',' ') . '<span class="rub" style="position:relative;top:0px;">a</span>';
                    }
                    echo "</b></td>";



                    $value = 0;
                    $dopBtnClass = '';
                    $canAction = 'false';
                    if (key_exists($product['id'], $productsIdsInBasket))
                    {
                        $value = $productsIdsInBasket[$product['id']];
                        $dopBtnClass = 'disabledBtn';
                        $canAction = 'true';
                    }

                    ?>

                    <td colspan="2" class="last_td">
                        <ul class="counter"
                            data-product-count="<?php echo $stockCount ?>"
                            data-product-min="<?php echo $product['min_order'] ?>"
                            data-product-id="<?php echo $product['id'] ?>"
                            data-product-price="<?php echo $product['price'] ?>" style="height: 36px; padding-top: 2px; border: 1px solid #d8d8d8;">

                            <li onclick="basketSender.singleDownCount($(this))" action="true" class="btn_all counter__button counter_button_minus red_button2" ></li>
                            <li class="counter__num">
                                <input onfocus="basketSender.onfocusCheck($(this))"
                                       onkeyup="basketSender.keyUpCheck($(this))"
                                       onchange="basketSender.singleByInput($(this))"
                                       name="" value="<?php echo $value ?>" autocomplete="off" type="text">
                            </li>
                            <li onclick="basketSender.singleUpCount($(this));yaCounter42144289.reachGoal('CART');" class="btn_all counter__button counter_button_plus green_button2"></li>
                        </ul>
                    </td>

                    <?php

                }

        echo "</tr>";
    }

    ?>
    </tbody>


</table>

<i class="br20"></i>
<div class="borderForPostNavigation" style="margin: 0px 20px">
<div class="postNavigation">


    <?php

        $in = ($page * $inPage) - $inPage + 1;
        $to = $inPage + $in - 1 > $productCount ? $productCount : $inPage + $in - 1;

        if ($productCount == 0) {
            $in = 0;
        }

        echo $in . " — " . $to . " из " . $productCount;

    ?>


    <div class="postInPage">
        <b>Показать:</b>

        <?php

        $countInPage = array(30, 50, 100, 250);

        ?>

            <?php
//            echo '<a href="javascript:void(0);" class="slct">' . $inPage . '</a>';
//            echo '<ul class="drop">';
//
//                foreach ($countInPage as $count)
//                {
//                    if ($count != $inPage)
//                    {
//                        $url = url_for('@catalog_show_cat?alias=' . $alias) . '?inPage=' . $count . '&sort=' . $sort . '&order=' . $order ;
//                        echo '<li><a href="' . $url . '">' . $count . '</a></li>';
//                    }
//                }
//
//            echo '</ul>';

            echo "<select class='changeCountInPage' autocomplete='off'>";

                foreach ($countInPage as $count)
                {
                    if ($count == $inPage)
                    {
                        echo "<option value='noAction' selected='selected'>" . $count . "</option>";
                    }
                    else
                    {
                        $url = url_for('@catalog_show_cat?alias=' . $alias) . '?inPage=' . $count . '&sort=' . $sort . '&order=' . $order ;
                        ?>
                        <option value="<?php echo $url ?>"><?php echo $count ?></option>
                        <?php
                    }
                }

            echo "</select>";



            ?>

    </div>


    <script>

        $('.changeCountInPage').change(function () {
            var url = $(this).val();
            if (url != 'noAction')
            {
                window.location.href = url;
            }
        });

        // Select
        $('.slct').click(function(){
            /* Заносим выпадающий список в переменную */
            var dropBlock = $(this).parent().find('.drop');

            /* Делаем проверку: Если выпадающий блок скрыт то делаем его видимым*/
            if( dropBlock.is(':hidden') ) {
                dropBlock.css('display', 'inline-block');

                /* Выделяем ссылку открывающую select */
                $(this).addClass('active');

                /* Работаем с событием клика по элементам выпадающего списка */
                $('.drop').find('li').click(function(){

                    dropBlock.css('display', 'none');
                });

                /* Продолжаем проверку: Если выпадающий блок не скрыт то скрываем его */
            } else {
                $(this).removeClass('active');
                dropBlock.css('display', 'none');
            }

            /* Предотвращаем обычное поведение ссылки при клике */
            return false;
        });
    </script>

    <div class="postNavigation_changePage">

    <?php
    $class = "";
    $tag = "a";
    $href_previous = 'href="' . url_for('@catalog_show_cat?alias=' . $alias) . '?page=' . ($page - 1) . '&inPage=' . $inPage . '&sort=' . $sort . '&order=' . $order .'"';
    $href_first = 'href="' . url_for('@catalog_show_cat?alias=' . $alias) . '?page=1&inPage=' . $inPage . '&sort=' . $sort . '&order=' . $order .'"';
    if ($page == 1)
    {
        $class = "un_active";
        $tag = "b";
        $href_previous = "";
        $href_first = "";
    }
    ?>

    <?php

        if ($class != "un_active")
        {
            ?>
                <<?php echo $tag ?> class="page_link page_prev page_button <?php echo $class ?>" <?php echo $href_first ?>></<?php echo $tag ?>>
            <?php
        }

    ?>

    <?php
    if ($page - 2 >= 0)
    {
        for ($i = $page - 2; $i < $page; $i++)
        {
            if ($i == 0)
            {
                continue;
            }

            ?>

            <a class="page_link" href="<?php echo url_for('@catalog_show_cat?alias=' . $alias) ?>?page=<?php echo $i ?>&inPage=<?php echo $inPage ?>&sort=<?php echo $sort ?>&order=<?php echo $order ?>"><?php echo $i ?></a>

            <?php
        }
    }
    ?>

    <b class="page_active"><?php echo $page ?></b>

    <?php
        if ($page + 2 <= $countPage)
        {
            $maxPage = $page + 2;
        }
        else
        {
            $maxPage = $countPage;
        }
        for ($i = $page + 1; $i <= $maxPage; $i++)
        {
            ?>

            <a class="page_link" href="<?php echo url_for('@catalog_show_cat?alias=' . $alias) ?>?page=<?php echo $i ?>&inPage=<?php echo $inPage ?>&sort=<?php echo $sort ?>&order=<?php echo $order ?>"><?php echo $i ?></a>

            <?php
        }
    ?>


    <?php
    $class = "";
    $tag = "a";
    $href_next = 'href="' . url_for('@catalog_show_cat?alias=' . $alias) . '?page=' . ($page + 1) . '&inPage=' . $inPage . '&sort=' . $sort . '&order=' . $order .'"';
    $href_last = 'href="' . url_for('@catalog_show_cat?alias=' . $alias) . '?page=' . $countPage . '&inPage=' . $inPage . '&sort=' . $sort . '&order=' . $order .'"';
    if ($page == $countPage)
    {
        $class = "un_active";
        $tag = "b";
        $href_next = "";
        $href_last = "";
    }
    ?>

    <?php

        if ($class != "un_active")
        {
            ?>

                <<?php echo $tag ?> class="page_link page_next page_button <?php  echo $class ?>" <?php echo $href_last ?>></<?php echo $tag ?>>

            <?php
        }

    ?>


    </div>


</div>
</div>

<i class="br20"></i>
<div class="bottomText">
    <?php

    include_component('seo', 'seoBottom');

    ?>
</div>