

<?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>

    <div class="product_card_wrap">
    <?php

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

    foreach ($products as $product)
    {
        echo '<div class="product_card">';


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


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

            echo '<i class="br10"></i>';

            echo '<div class="product_card_title">';
                echo "<a href='" . url_for('@catalog_show_prod?alias=' . $product['alias']) . "'>" . $product['title'] . "</a>";
            echo '</div>';

            ?>

            <i class="br15"></i>
            <table class="product_card_table_dopInfo" cellpadding="0" cellspacing="0">
                <tr>
                    <td colspan="2">
                        Артикул: <?php echo $product['product_code']; ?>
                    </td>
                </tr>
                <tr>
                    <td colspan="2"><i class="br10"></i></td>
                </tr>
                <tr>
                    <td>
                        Мин. партия: <?php echo $product['min_order']; ?>
                    </td>
                    <td class="product_card_table_dopInfo_priceTd">
                        <?php

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

                        ?>
                    </td>
                </tr>
            </table>



            <i class="br10"></i>


            <?php

            $stockCount = round($product['stockCount']);
            if($stockCount == 0)
            {
                echo "<div class='notStockCount'>Нет в наличии</div>";
            }
            else
            {

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


                ?>

                <table class="product_card_table_buy" cellspacing="0" cellpadding="0">
                    <tr>
                        <td style="text-align: left">
                            <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.downCount($(this))" action="<?php echo $canAction ?>" 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.byInput($(this))"
                                           name="" value="<?php echo $value ?>" autocomplete="off" type="text">
                                </li>
                                <li onclick="basketSender.upCount($(this))" action="<?php echo $canAction ?>" class="btn_all counter__button counter_button_plus green_button2"></li>
                            </ul>
                        </td>
                        <td style="text-align: right">
                            <button
                                style="display: inline-block; width: 110px; height: 35px"
                                onclick="basketSender.sendByButton($(this));yaCounter42144289.reachGoal('CART');"
                                class="green_button er_goods_item_bleat__add_cart <?php echo $dopBtnClass ?>"
                            >
                                <?php
                                if ($value == 0)
                                {
                                    echo 'В корзину';
                                }
                                else
                                {
                                    echo 'В корзине';
                                }
                                ?>

                            </button>
                        </td>
                    </tr>

                </table>


                <?php
            }

        echo '</div>';

    }

    ?>
    </div>

<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>