
<?php
$price = "";
if (count($product->getProductPrice()) > 0)
{
    $price = $product->getProductPrice()->getFirst()->getValue() . 'р';
}
$title = $breadcrumbs[count($breadcrumbs) - 1]['title'] . " купить в Уфе  " . $price . ", бесплатная доставка по РБ";
$desc = "Купить " . $breadcrumbs[count($breadcrumbs) - 1]['title'] . " в Уфе. Широкий выбор. Бесплатная доставка. Привлекательные цены.";

slot('default_meta_description', $desc);
slot('title', $title);
?>

<div class="er_rows" style="padding-bottom: 0;">
    <div class="breadcrumbs">
        <div class="breadcrumbs">
            <span><a href="/" title="Главная">Главная</a>&nbsp;/&nbsp;</span><!--
         --><span><a href="<?php echo url_for('@catalog') ?>">Каталог</a></span><!--
         --><?php

            if ($breadcrumbs)
            {
                $lastBreadcrumbsCounter = 1;
                foreach ($breadcrumbs as $crumb)
                {
                    if ($crumb['title'])
                    {
                        if ($lastBreadcrumbsCounter == count($breadcrumbs))
                        {
                            echo '<span>&nbsp;/&nbsp;' . Page::niceTitleView($crumb['title']) . '</span>';
                        }
                        else
                        {
                            echo '<span>&nbsp;/&nbsp;<a href="' . url_for('@catalog_show_cat?alias=' . $crumb['alias']) . '">' . Page::niceTitleView($crumb['title']) . '</a></span>';
                        }
                    }
                    $lastBreadcrumbsCounter++;
                }
            }

            ?>

        </div>
        <style type="text/css">
            .er_content__main__search{display: block;}
            .js_cat_view__ct__tr td {
                height: 63px;
            }
        </style>
    </div>
</div>


<div class="er_rows" style="padding-left: 0;">

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

    <table class="er_rows_card_item" width="100%" cellspacing="0" cellpadding="0">

        <tr>

            <?php

            if ($product->getProductImage())
            {

                ?>

                <td width="420px">
                    <style>
                        .photo_corusel_active_photo_block {
                            height: 290px;
                            margin-bottom: 20px;
                            display: table-cell;
                            vertical-align: middle;
                            text-align: center;
                            width: 425px;
                        }

                        .photo_corusel_active {
                            display: block;
                            margin: 0 auto;
                        }

                        .photo_corusel_unactive {
                            width: 95px;
                            height: 70px;
                            margin-right: 15px;
                            cursor: pointer;
                            background-size: cover !important;
                            display: inline-block;
                            background-position: 50% 50% !important;
                        }

                        .photo_corusel_unactive:nth-child(6) {
                            margin-right: 0px;
                        }
                    </style>
                    <div class="er_gallery">

                        <?php
                        if ($product->getProductImage()) {
                            $imgs = explode(';', $product->getProductImage());

                            echo '<div class="photo_corusel_active_photo_block ">';
                            echo '<div class="zoom" style="cursor: default">';
                            echo '<img class="photo_corusel photo_corusel_active " src="/u/i/' . str_replace('.', '-XL.', $imgs[0]) . '">';
                            echo '</div>';
                            echo '</div><i class="br20"></i>';
                            if (count($imgs) > 1) {

                                foreach ($imgs as $img) {
                                    echo '<div class="photo_corusel photo_corusel_unactive" data-img="' . str_replace('.', '-XL.', $img) . '" style=" background: url(/u/i/' . str_replace('.', '-XL.', $img) . ')"></div>';
                                }
                            }
                        } else {
                            echo '<div class="photo_corusel_active_photo_block ">';

                            echo '<img class="photo_corusel photo_corusel_active " src="' . url_for('@get_image?id=' . $product->getId()) . '" >';

                            echo '</div><i class="br20"></i>';
                        }
                        ?>

                    </div>
                    <script type="text/javascript">
                        $(document).ready(function () {

                            $('.photo_corusel_unactive').click(function () {
                                var active = $('.photo_corusel_active');
                                active.attr('src', '/u/i/' + $(this).data('img'));
                                //$('.zoom').trigger('zoom.destroy');
                                //$('.zoom').zoom({url: active.attr('src').replace('-XL.', '.')});


                            });

                            //$('.zoom').zoom({url: $('.photo_corusel_active').attr('src').replace('-XL.', '.')});


                            //$('.er_gallery').each(function(k, tab){
                            //    var itemLink = $(tab).find('.er_gallery__prev__item'),
                            //        rSliderMain = $(tab).find('.er_gallery__main_img'),
                            //        itemImg = $('.er_gallery__prev__item__img');
                            //    $(itemLink).click(function(){
                            //        $(rSliderMain).stop();
                            //        $(itemImg).removeClass('er_gallery_active');
                            //        $(this).find('img').addClass('er_gallery_active');
                            //        hrefLink = $(this).attr('href');
                            //        $(rSliderMain).css({
                            //            'display' : 'none',
                            //            'background-image' : 'url('+ hrefLink +')',
                            //        }).fadeIn(400);
                            //        return false;
                            //    });
                            //});
                        });
                    </script>
                </td>

                <td width="40px">
                </td>


                <?php

            }

            ?>

            <td>
                <div style="display:block;padding:0;position:relative;" class="inner_view">
                    <table width="100%" cellspacing="0" cellpadding="0">
                        <tbody>
                        <tr valign="top">
                            <td height="1">
                                <div style="display:inline-block;padding:0 0px 10px 0;">
                                    <i class="br1"></i>
                                    <h1 class="lato_bold_text" style="font-size: 25px">
                                        <?php
                                            echo $breadcrumbs[count($breadcrumbs) - 1]['title'];

                                            if ($product->getSellOut())
                                            {
                                                echo '<div class="sale_out" style="display: inline-block;position: relative;left: 10px;bottom: 4px;">Распродажа</div>';
                                            }

                                        ?>

                                    </h1>
                                    <i class="br50"></i>
                                </div>
                            </td>
                        </tr>
                        <tr valign="top">
                            <td colspan="2" style="">

                                <div style="font-size: 30px; color: #4f4f4f;">
                                    <b class="product_price">
                                        <?php

                                        if (count($product->getProductPrice()) > 0)
                                        {
                                            $default_price_type = Doctrine::getTable('PriceType')->findOneByIsDefault(1);

                                            $default_price = 0;
                                            foreach ($product->getProductPrice() as $price)
                                            {
                                                if ($price->getPriceTypeId() == $default_price_type->getId())
                                                {
                                                    $default_price = $price->getValue();
                                                }
                                            }
                                            echo number_format($default_price,2,',',' ');
                                        }
                                        ?>
                                    </b>
                                    <span class="rub">a</span>
                                </div>


                                <?php

                                $stockCount = round($product->getProductStockCount()->getFirst()->getValue());
                                if ($stockCount != 0)
                                {



                                    $value = 0;
                                    $dopBtnClass = '';
                                    $canAction = 'false';
                                    $productsIdsInBasket = $this->context->getUser()->getProductsIdsInBasket();
                                    if (key_exists($product['id'], $productsIdsInBasket))
                                    {
                                        $value = $productsIdsInBasket[$product['id']];
                                        $dopBtnClass = 'disabledBtn';
                                        $canAction = 'true';
                                    }


                                    ?>
                                        <i class="br20"></i>
                                        <div class="inner_view__control" style="visibility: visible;">
                                            <table cellspacing="0" cellpadding="0" style="display: inline-block; margin-right: 15px">
                                                <tbody>
                                                <tr>
                                                    <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 $default_price ?>" style="height: 36px; padding-top: 2px; border: 1px solid #d8d8d8;">

                                                            <li onclick="basketSender.pageDownCount($(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.pageByInput($(this))"
                                                                       name="" value="<?php echo $value ?>" autocomplete="off" type="text">
                                                            </li>
                                                            <li onclick="basketSender.pageUpCount($(this))" action="<?php echo $canAction ?>" class="btn_all counter__button counter_button_plus green_button2"></li>
                                                        </ul>

                                                    </td>
                                                </tr>
                                                </tbody>
                                            </table>
                                            <button
                                                style="display: inline-block; width: 110px; height: 35px"
                                                onclick="basketSender.pageSendButton($(this));yaCounter42144289.reachGoal('CART');"
                                                class="green_button er_goods_item_bleat__add_cart <?php echo $dopBtnClass ?>"
                                            ><?php echo $value == 0 ? 'В корзинуqs' : 'В корзинe';?>

                                            </button>
                                        </div>
                                    <?php

                                }
                                ?>

                                <i class="br15"></i>
                                <span>Артикул: <?php echo $product->getProduct_code(); ?></span>
                                <i class="br10"></i>
                                <span class="er_goods_item_bleat__info__min">Минимальная партия: <?php echo $product->getMinOrder() ?></span>
                                <i class="br10"></i>
                                <?php
                                if ($stockCount == 0)
                                {
                                    echo '<span class="er_goods_item_bleat__info__max">Нет в наличии</span>';
                                }
                                else
                                {
                                    echo '<span class="er_goods_item_bleat__info__max">В наличии: ' . $stockCount . '</span>';
                                }
                                ?>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </td>
        </tr>
        <tr>

            <?php


            if(count($product->getProductPropValue()) > 0)
            {

            ?>

            <td width="420px">

                <?php

                $validProps = array();

                $counter = 0;
                $props = $product->getProductPropValue();
                foreach ($props as $prop)
                {
                    if ($prop->getValue() !== "0" && $prop->getValue() != "")
                    {

                        if ($prop->getProductProp()->getIsList())
                        {
                            foreach ($prop->getProductProp()->getProductPropList() as $list_elem)
                            {
                                if ($list_elem->getId() == $prop->getValue())
                                {
                                    $validProps[$counter]['title'] = $prop->getProductProp();
                                    $validProps[$counter]['value'] = $list_elem->getVariant();
                                }
                            }
                        }
                        else
                        {

                            $validProps[$counter]['title'] = $prop->getProductProp();
                            $validProps[$counter]['value'] = $prop->getValue();
                        }
                        $counter++;
                    }
                }

                if(count($validProps) > 0)
                {
                    echo '<i class="br30"></i><div class="lato_bold_text">Характеристика</div><i class="br15"></i>';
                    echo '<table width="100%" cellspacing="0" cellpadding="0">';

                    foreach ($validProps as $prop)
                    {
                        echo '<tr>';
                            echo '<td style="border-bottom: 1px dashed; font-size: 15px">';
                                echo '<span style="top: 1px;position: relative;background: #fff;">' . $prop['title'] . ':</span>';
                                echo '<span style="float: right;top: 1px;position: relative;background: #fff;">' . $prop['value'] . '</span>';
                            echo '</td>';
                        echo '</tr>';
                        echo '<tr><td><i class="br5"></i></td></tr>';
                    }

                    echo '</table>';

                }


                ?>
            </td>
            <td width="40px">
            </td>

            <?php

            }

            ?>

            <td>
                <?php

                if ($product->getDescription())
                {
                    echo '<i class="br30"></i><div class="lato_bold_text">Описание</div><i class="br15"></i>';
                    echo '<div style="font-size: 15px">' . $product->getDescription() . '</div>';

                }

                ?>
            </td>
        </tr>

    </table>

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

            include_component('seo', 'seoBottom');

        ?>
    </div>

</div>