{$gifts = $body->getPurchaseState()->getCustomData('gift')}
{$selected_products = []}
{foreach $gifts as $discountId => $selectedGifts}
    {$tmp_selected = array_filter(array_column($selectedGifts, 'id_product'))}
    {if $tmp_selected}
        {$selected_products = array_merge($selected_products, $tmp_selected)}
    {/if}
{/foreach}

{if $selected_products}
   {foreach $body->getPurchaseState()->getDiscountHandlers() as $handler}
      {$data = $handler->getData()}
      {* Pokud jsou varianty, `id_product` je id produktu a `gift` je id varianty.
         Bez variant je jen `gift` = id produktu. *}
      {$gift = $data['id_product']|default:$data['gift']}
      {if $gift and in_array($gift, $selected_products)}
         {$vars = $handler->getVars()}
         {$product = $vars['products'][$gift]}

         {if $product}
            {$product->fetchImages(4)}
            {$gift_variations = $product->variations}
            <div class="product">
               <div class="image">
                  <a href="{url s=product IDproduct=$product.id TITLE=$product.title}" title="{t}Zobrazit produkt{/t}">
                     <img src="{get_photo photo=$product.image size=4}" alt="{$product.title}"
                          class="img-responsive">
                  </a>
               </div>
               <div class="title">
                  <span class="variation">{$vars.title|default:"{t}Dárek zdarma{/t}"}</span>
                  <a href="{url s=product IDproduct=$product.id TITLE=$product.title}"
                     title="{t}Zobrazit produkt{/t}">{$product.title}</a>
                  {if $gift_variations[$data.gift]}
                     <span class="variation">{$gift_variations[$data.gift].title}</span>
                  {/if}
               </div>
               <div class="price-summary">
                  <p class="price-total price-total-summary">
                     <strong class="summary-gift-price">{if $vars.price && $vars.price->getPriceWithVat()->isZero()}{t}zdarma{/t}{else}{$vars.price|format_price}{/if}</strong>
                  </p>
                  <p class="pieces-summary">{$vars.data.gift_pieces|default:1}&nbsp;{t}ks{/t}</p>
               </div>
            </div>
         {/if}
      {/if}
   {/foreach}
{/if}
