<div class="row catalog-row" data-tracking-view='{get_gtm_data encode=true type='ecommerce' method='ProductsImpressions' data=['products' => $products, 'listType' => $listType, 'listId' => $listId]}'>

   {get_stats type='free_delivery' assign='free_delivery'}

   {$products->fetchPhotos(2, ['N', 'K', 'V', 'O'])}

   {foreach $products as $product}
      <div class="col-lg-6 col-xxs-12">
         <div class="catalog catalog-top10" id="prod-{$product@iteration}">
            {get_ratings assign=ratings id_product=$product.id}

            {assign var='hash' value="#`$product.id`"}

            {$display_discount = $product.display_discount->asFloat()}
            {$product_discount = $product.discount->asFloat()}

            {if $dbcfg.increase_discount >= 1}
               {$display_discount = $display_discount + $dbcfg.increase_discount}
            {/if}

            {$discountSum = 0}

            {if $product_discount > 0 or $display_discount > 0}
               {$discountSum = $product_discount}

               {if $display_discount > 0}
                  {$discountBase = 1 - ($product_discount / 100)}
                  {$discountSum =  ($display_discount * $discountBase) + $product_discount}  {*mame-li 20% slevu, discount bude 0.8*}
               {/if}
            {/if}

            <div class="product-link" title="{$product.title}" data-gallery-wrapper>

               {if !empty($product.modelProducts)}
                  {get_prices_sizes_etc modelProducts=$product.modelProducts assign=additional_info}
                  {$product.additional_info=$additional_info}
               {/if}

               <div class="catalog-top10-gallery">
                  <a href="{get_photo photo=$product.image size=0}" title="{$product.title}" data-rel="gallery"
                     class="img main-image" >
                     {$photo_dimensions = $cfg.Photo.types['product_detail'].size}
                     <img src="{get_photo photo=$product.image size='product_detail'}" alt="{$product.title}"
                          width="{$photo_dimensions[0]}" height="{$photo_dimensions[1]}" class="img-responsive">

                     {block "product-flags"}
                        <div class="catalog-flags flags">
                           {$campaigns = getCampaigns()}

                           <span class="flag flag-bestseller">{$cfg.Sections.Flags['TT'].show_name|default:"{t}Top 10{/t}"}</span>

                           {if $product.campaign_codes.Z or ($free_delivery and $additional_info.prices.min > $free_delivery and !$product->isVirtual())}
                              <span class="flag flag-delivery" title="{t}Doprava zdarma{/t}"><i class="fc icons_free_delivery"></i></span>
                           {/if}

                           {if $product.campaign_codes['N']}
                              <span class="flag flag-new">{$product.campaign_codes['N'].singular}</span>
                           {/if}

                            {foreach $product.campaign_codes as $flag}
                                {if $flag.catalog_class}
                                   <span class="flag flag-{$flag.catalog_class}">{$flag.singular}</span>
                                {/if}
                            {/foreach}
                        </div>
                     {/block}

                     {if $discountSum|round >= 3 and $product.producer.data.hidePriceLineThrough != "Y"}
                        <span class="flag flag-discount {if $dbcfg.black_friday == true and $product.campaign_codes.BF}flag-blackfriday{/if}">-{$discountSum|round}%</span>
                     {/if}

                     {if $product.sex}
                        <div class="gender">
                           {if $product.sex == 'W'}
                              <span class="fc icons_gender-female" title="{t}Pro ženy{/t}"></span>
                           {elseif $product.sex == 'M'}
                              <span class="fc icons_gender-male" title="{t}Pro muže{/t}"></span>
                           {elseif $product.sex == 'U'}
                              <span class="fc icons_gender-unisex" title="{t}Unisex{/t}"></span>
                           {elseif $product.sex == 'K'}
                              <span class="fc icons_gender-child" title="{t}Pro děti{/t}"></span>
                           {/if}
                        </div>
                     {/if}

                     {$shade_photo = $product.photos|sort_photos:['O']}
                     {if $product.shade and $shade_photo}
                        <div class="shade">
                           <figure>
                              {$photo_dimensions = $cfg.Photo.types["swatch"].size}
                              <img src="{get_photo photo=$shade_photo[0] size='swatch'}" alt="{$product.title}" width="{$photo_dimensions[0]}" height="{$photo_dimensions[1]}" loading="lazy" class="img-responsive">
                           </figure>
                           <strong>{$product.shade}</strong>
                        </div>
                     {/if}
                  </a>

                  {*
                     'Y' => 'Hlavní produkt',
                     'N' => 'Hlavní varianta',
                     'K' => 'Krabička',
                     'G' => '360°',
                     'V' => 'Vedlejší varianta',
                     'O' => 'Odstín',
                   *}
                  {$sorted_photos = $product.photos|sort_photos:['V', 'Y', 'K',  'G']}

                  <div class="gallery">
                     {$photo_dimensions = $cfg.Photo.types["product_gallery"].size}
                      {if $sorted_photos|count>1}
                     {foreach $sorted_photos|array_slice:0:2 as $photo}
                        <a href="{get_photo photo=$photo size=0}" title="{$product.title}" data-rel="gallery" class="img">
                           <img src="{get_photo photo=$photo size='product_gallery'}" alt="{$product.title}" class="img-responsive" width="{$photo_dimensions[0]}" height="{$photo_dimensions[1]}">
                        </a>
                     {/foreach}
                     {/if}
                  </div>
               </div>
            </div>

            <a href="{url s=product IDmodel=$product.model_old_id TITLE=$product.model_title}{$hash}" class="title h3">
               {$product.model_short_title}
            </a>

            <div class="subtitle-wrapper">
               <p class="subtitle">
                  {$product.model_section}
                  {if $additional_info.size|count and $product.modelProducts|count}
                     {foreach $additional_info.size as $size}{$size}{if !$size@last}<i> | </i>{/if}{/foreach}
                  {else}
                     {$product.title|replace:$product.model_title:''}
                  {/if}
               </p>

               {if $ratings.rating_count >= 5}
                  {$stars = $ratings.rating|round}
                  <div class="reviews-count">
                     <div class="review-stars rating-{$stars}" title="{t}Hodnocení{/t} {$ratings.rating|format_float:-1}
                        {t plural="hvězdičky" plural5="hvězdiček" count=$stars}hvězdička{/t}">
                        {for $i=1 to 5}
                           <span class="fc icons_star{if $i > $ratings.rating|round}-empty{/if}"></span>
                        {/for}
                     </div>
                     <span>{$ratings.rating_count} {t plural="hodnocení" plural5="hodnocení" count=$ratings.rating_count}hodnocení{/t}</span>
                  </div>
               {/if}
            </div>

            {function sumDiscountTopTen}
               {* skrtlou cenu nezobrazovat u modelu *}
               {if $discountSum|round >= 3 and $product.producer.data.hidePriceLineThrough != "Y"}
                  {$discount =  1 - ($product_discount / 100) } {* mame-li 20% slevu, discount bude 0.8 *}
                  {$beforeDiscount = ($product.price_array.value_with_vat->asFloat() / $discount)} {* cena pred slevou *}

                  {* pokud je sleva i u varianty, cena pred slevou se vypocita jeste jednou *}
                  {if $display_discount > 0}
                     {$discount =  1 - ($display_discount/ 100)}
                     {$beforeDiscount = ($beforeDiscount / $discount)}
                  {/if}

                  {block priceTranslation}
                     {$commonPriceTranslation = "{t}Běžná cena{/t}"}
                  {/block}

                  {if $beforeDiscount|format_price == $product.price_array|format_price}
                     <span class="strike-price">{$commonPriceTranslation} <del>{$beforeDiscount|format_price:"ceil=no"}</del></span>
                  {else}
                     <span class="strike-price">{$commonPriceTranslation} <del>{$beforeDiscount|format_price}</del></span>
                  {/if}
               {/if}
            {/function}

            <div class="catalog-top10-buy-box">
               <div class="price-wrap">
                  {block "price"}
                     {sumDiscountTopTen}
                     <p class="price">{$product.price_array|format_price}</p>
                  {/block}
               </div>

               <form action="{url s=cart}" method="get" class="buy-form" data-buy-form>
                  <input type="hidden" name="act" value="add">
                  <input type="hidden" name="redir" value="1">
                  <input type="hidden" name="IDproduct" value="{$product.id}">

                  <div class="submit-block">
                     <input type="hidden" name="No" value="1">

                     {block "buy_btn"}
                        <button type="submit" value="{t}Do košíku{/t}" class="btn btn-ctr btn-insert"
                                title="{t}Do košíku{/t} {$product.title}"{if $dbcfg.analytics.google_tag_manager.gtm_dl_version == '2'} data-tracking-click='{get_gtm_data encode=true type='ecommerce' method='ClickAddToCart' data=['product' => $product, 'listType' => $listType, 'listId' => $listId]}'{/if}>{t}Do košíku{/t}</button>
                     {/block}
                  </div>
               </form>
            </div>

            <a href="{url s=product IDmodel=$product.model_old_id TITLE=$product.model_title}{$hash}" class="btn btn-link">{t}další produkty{/t}</a>

            <div class="descr">
               {if $product.parameters}
                  {$product.parameters|strip_tags}
               {else}
                  {$description = ""}
                  {if $product.longDescr}
                     {$description = $product.longDescr|markdown2html|strip_tags|trim}
                  {elseif $product.model_data.descr}
                     {$description = $product.model_data.descr|markdown2html|strip_tags|trim}
                  {elseif $product.serie_data.descr}
                     {$description = $product.serie_data.descr|markdown2html|strip_tags|trim}
                  {/if}

                  {$descrList = preg_split("/\./", $description)} {* rozdelim popis do pole podle ". " *}

                  {if $descrList|count > 1 or $descrList[0]|count_characters > 2} {* vyfiltruje prazdny popisy, kdyz zustane <p> *}
                     {$charCount = 0}

                     {foreach $descrList as $sentence}
                        {$clean_sentence = $sentence|strip_tags|trim}
                        {if $charCount + $clean_sentence|count_characters > 275}{break}{/if} {* pokud to presanhne 400 znaku, prestavam vypisovat vety *}
                        {if $clean_sentence|count_characters > 0} {* preskocim prazdne polozky v poli *}
                           {$clean_sentence nofilter}.
                           {$charCount = $charCount + $clean_sentence|count_characters}
                        {/if}
                     {/foreach}
                  {/if}
               {/if}
            </div>
         </div>
      </div>
   {/foreach}
</div>
