{function sumDiscount}
   {* skrtlou cenu nezobrazovat u modelu + zobrazuju jen slevy vyšší nebo rovno 3 % *}
   {if $body.category.list_models != "Y" and $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}

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

<div class="row {$row_class|default:'catalog-row'}" {if $body.pager and !$no_pager}data-page="{$body.pager.number}" data-products-row{/if}
     data-tracking-view='{get_gtm_data encode=true type='ecommerce' method='ProductsImpressions' data=['products' => $products, 'listType' => $listType, 'listId' => $listId]}'>
   {$products->fetchPhotos(13, ['O'])}

   {foreach $products as $product}
      {product_can_buy product=$product assign='canBuy'}

      {$display_discount = $product.display_discount->asFloat()} {* sleva z abry *}
      {$product_discount = $product.discount->asFloat()} {* sleva z adminu *}

      {* fejková sleva z nastavení shopu, uměle zvedne ceny před slevou, finální ceny zůstanou stejné *}
      {if $dbcfg.increase_discount >= 1}
         {$display_discount = $display_discount + $dbcfg.increase_discount}
      {/if}

      {$discountSum = 0}

      {* "sečtení slev" - nejdřív zlevním o slevu v abře a pak zlevněnou cenu ponížím o slevu v adminu *}
      {if $product_discount > 0 or $display_discount > 0}
         {$discountSum = $product_discount}

         {if $display_discount > 0}
            {* máme-li 20% slevu v abře, discountBase bude 0.8 *}
            {$discountBase = 1 - ($product_discount / 100)}
            {* ke slevě z abry přičtu slevu z adminu. Pokud je display_discount 5%, discountSum bude 24 *}
            {$discountSum =  ($display_discount * $discountBase) + $product_discount}
         {/if}
      {/if}

      {* stejná logina pro modely, pokud je v sekci zobrazeni modelů místo produktů *}
      {$model_discount = 0}
      {$model_display_discount = $product.model_display_discount}

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

      {if $product.model_discount > 0 or $product.model_display_discount > 0}
         {$model_discount = $product.model_discount}

         {if $model_display_discount > 0}
            {$modelDiscountBase = 1 - ($product.model_discount / 100)}
            {$model_discount = ($model_display_discount * $modelDiscountBase) + $product.model_discount} {* koeficient ceny modelu *}
         {/if}
      {/if}

      {* Pokud je zobrazení modelů a je zároveň sleva na modelu i na produktu, zobrazuju tu vyšší *}
      {if $model_discount >= 3 and $model_discount|round >= $discountSum|round}
         {$discountSum = $model_discount} {* do discountSum uložím nejvyšší slevu v % *}
      {/if}

      {if $product.banner}
         <div class="{$catalog_class|default:"col-lg-3 col-xxs-6"}">
            <div class="catalog-banner" data-tracking-click="{['event'=>'catalogue_bannerClick']|json_encode}">
               <a href="{$product.banner.link}" style="background-image: url('{get_photo photo=$product.banner.photo size='slider'}');"></a>
            </div>
         </div>
      {/if}

      {if $body.category.list_models == 'N' or $body.category == null}
         {$hash="#`$product.id`"}
      {elseif $body.filter_active and $product.matched_id_product}
         {$hash="#`$product.matched_id_product`"}
      {else}
         {$hash=""}
      {/if}

      {* Pokud je zobrazení modelů a je zároveň sleva na modelu i na produktu, zobrazuju tu vyšší *}
      {if $model_discount >= 3 and $model_discount|round >= $discountSum|round}
         {$hash = "#"|cat:$product.model_discount_product} {* předvybrání produktu s nejvyšší slevou *}
      {/if}

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

      {$campaigns = getCampaigns()}
      <div class="{if $product.topProduct}col-lg-6 col-xxs-12{else}{$catalog_class|default:"col-lg-3 col-xxs-6"}{/if}">
         <div class="catalog">

            {*{include 'product/product.add-to-favorite.tpl' modify_class='btn-fav-rounded'}*}

            <a href="{url s=product IDmodel=$product.model_old_id TITLE=$product.model_title}{$hash}"
                    {if $dbcfg.analytics.google_tag_manager.gtm_dl_version == '2'}
                       data-tracking-click='{get_gtm_data encode=true type='ecommerce' method='ProductClick' data=['product' => $product, 'position' => $product@iteration, 'listType' => $listType, 'listId' => $listId]}'
                    {else}
                       data-tracking-click="{['event'=>'productBox']|json_encode}"
                    {/if}
               >
               {$photo_dimensions = $cfg.Photo.types['product_catalog'].size}

               <div class="img">
                  <img src="{get_photo photo=$product.image size='product_catalog'}" alt="{$product.title}"
                       width="{$photo_dimensions[0]}" height="{$photo_dimensions[1]}" class="img-responsive">
                  <div class="catalog-flags flags">
                     {block "free-delivery-flag"}
                        {if $product.campaign_codes.Z or ($free_delivery and (($additional_info.prices.min and $additional_info.prices.min > $free_delivery) or (!$additional_info.prices.min and $product.price_array.value_with_vat > $free_delivery)) and !$product->isVirtual())}
                           <span class="flag flag-delivery" title="{t}Doprava zdarma{/t}"><span
                                      class="fc icons_delivery"></span> {t}zdarma{/t}</span>
                        {/if}
                     {/block}
                     {* {if $body.category.list_models == "N" or $body.category.campaign.Y}
                         {if $product.campaign_codes.Z or ($free_delivery and $product.price_array.value_with_vat > $free_delivery and !$product->isVirtual())}
                            <span class="flag flag-delivery" title="{t}Doprava zdarma{/t}"><i class="fc icons_free_delivery"></i></span>
                         {/if}
                      {else}
                         {if $product.campaign_codes.Z or ($free_delivery and $additional_info.prices.min > $free_delivery)}
                            <span class="flag flag-delivery" title="{t}Doprava zdarma{/t}"><i class="fc icons_free_delivery"></i></span>
                         {/if}
                      {/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}

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

                     {if (getAdminUser() or $cfg.special.public) and $dbcfg.special_event == true}
                        {$products->fetchSections()|silent}
                        {foreach $product.sections as $section}
                           {if $section.parent.parent.id == $cfg.special.catId or $section.parent.id == $cfg.special.catId}
                              <span title="{$cfg.special.name}" class="special-product-flag"></span>
                              {break}
                           {/if}
                        {/foreach}
                     {elseif $dbcfg.valentine == true}
                        {$products->fetchSections()|silent}
                        {foreach $product.sections as $section}
                           {if $section.parent.parent.id == $cfg.special.valentine.catId or $section.parent.id == $cfg.special.valentine.catId}
                              <span title="{t}Tip na Valentýna{/t}" class="special-product-flag flag-valentine"></span>
                              {break}
                           {/if}
                        {/foreach}
                     {/if}
                  </div>

                  {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}
               </div>

               <div class="content">
                  <div class="title-wrapper">
                     <h3 class="title">{$product.model_short_title|default:$product.title}</h3>
                     <span class="section">{$product.descr|default:$product.model_section}</span>
                  </div>

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

                        {block "catalog-delivery"}
                           <p class="delivery">
                              {if $canBuy}
                                 {if $body.category.list_models == "N"}
                                    {if $product.inStore > 0 && $product.inStore < 4}
                                       {t}skladem 1-3 kusy{/t}
                                    {else}
                                       {$product.deliveryTimeText}
                                    {/if}
                                 {else}
                                    {$product.deliveryTimeText}
                                    {if $product.modelProducts|count > 1}
                                       {$product.modelProducts|count}&nbsp;{t plural="varianty" plural5="variant" count=$product.modelProducts|count}varianta{/t}
                                    {/if}
                                 {/if}
                              {else}
                                 &nbsp;
                              {/if}
                           </p>
                        {/block}
                     </div>

                     <div class="right">
                        {block "price"}
                           {sumDiscount}
                           {if !is_null($additional_info.prices.min)}
                              <p class="price">
                                 {if $additional_info.prices.min->lessThan($additional_info.prices.max)}
                                    {t}od{/t}
                                 {/if}
                                 {$additional_info.prices.min|format_price}
                              </p>
                           {else}
                              <p class="price">{$product.price_array|format_price}</p>
                           {/if}
                        {/block}
                     </div>
                  </div>
               </div>
            </a>
         </div>
      </div>
   {/foreach}

   {if $show_more_banner_link}
      <div class="{$catalog_class|default:"col-lg-3 col-xxs-6"}">
         <div class="catalog catalog-show-more-banner">
            <a href="{$show_more_banner_link}">
               <div class="img">
                  {block "show-more-banner-image"}
                     <img src="/static/images/home-products-more.jpg" class="img-responsive" alt="{t}Zobrazit celou nabídku{/t}" width="240" height="240" loading="lazy">
                  {/block}
               </div>
               <span class="btn btn-link">{t escape=false}Zobrazit<br>celou nabídku{/t}</span>
            </a>
         </div>
      </div>
   {/if}
</div>
