<?php
if (isset($product)) {
    $translation = $product['Translation'];
    $productImg = explode(';', $product['product_img']);
    $productImg = (count($productImg) > 0 ? $productImg[0] : false);
    $q = Doctrine::getTable('Product')->findOneById($product['id'])->getOffer();
    $discount_available = false;
    foreach ($q as $offer) {
        if ($offer->getDiscountAvailable() == 1) {
            $discount_available = true;
            break;
        }
    }
        echo '<div class="catalog_category_child_item ' . ($discount_available ? 'discount' : '') . '">';
        if ($discount_available) {
            echo '<div class="discount_available"><div class="discount_available_desc">Ищите наши QR-коды в видео и соц. сетях и забирайте скидку</div><div class="discount_available_title">Доступен со скидкой</div></div>';
        }
        echo '<' . ($product['is_detail'] ? 'a' : 'span') . ' href="' . url_for("@product_show?alias=" . $product['alias']) . '" class="anb">';
        if($productImg){
            echo '<img src="/i/n.gif" style="background-image: url(/u/i/' . Page::replaceImageSize($productImg, 'S') . ');" />';
        }else
        {
            $offerImg = '';
            foreach ($q as $offer) {
                if (strlen($offer->getImg()) > 3)
                $offerImg = $offer->getImg();
                break;
            }
            if (strlen($offerImg) > 3 )
            {
                echo '<img src="/i/n.gif" style="background-image: url(/u/i/' . $offerImg . '); background-size: cover" />';
            }else
            {
                echo '<img src="/i/n.gif" style="background-image: url(/i/no_photo.png);" />';
            }

        }
        echo '<span class="green_link">' . $translation[$sf_user->getCulture()]['title'] . '</span>';
        echo '</' . ($product['is_detail'] ? 'a' : 'span') . '>';
        echo '<i class="br20"></i>';
        echo '</div>';
}
?>