<?php

/**
 * Copyright © 2019 Wyomind. All rights reserved.
 * See LICENSE.txt for license details.
 */

/** @var \Wyomind\ElasticsearchCore\Helper\Cart $cartHelper */
$cartHelper = $this->helper('Wyomind\ElasticsearchCore\Helper\Cart');
/** @var \Wyomind\ElasticsearchCore\Helper\Data $dataHelper */
$dataHelper = $this->helper('Wyomind\ElasticsearchCore\Helper\Data');
/** @var \Wyomind\ElasticsearchLayeredNavigation\Helper\Toolbar $toolbarHelper */
$toolbarHelper = $this->helper('Wyomind\ElasticsearchLayeredNavigation\Helper\Toolbar');
/** @var \Magento\Wishlist\Helper\Data $wishlistHelper */
$wishlistHelper = $this->helper('Magento\Wishlist\Helper\Data');
/** @var \Wyomind\ElasticsearchLayeredNavigation\Helper\Config $configHelper */
$configHelper = $this->helper('Wyomind\ElasticsearchLayeredNavigation\Helper\Config');
/** @var \Wyomind\ElasticsearchLayeredNavigation\Helper\Frontend $frontendHelper */
$frontendHelper = $this->helper('Wyomind\ElasticsearchLayeredNavigation\Helper\Frontend');
/** @var \Magento\Framework\Pricing\Helper\Data $priceHelper */
$priceHelper = $this->helper('Magento\Framework\Pricing\Helper\Data');
/** @var \Wyomind\Core\Helper\Data $coreHelper */
$coreHelper = $this->helper('Wyomind\Core\Helper\Data');

/** @var int $storeId */
$storeId = $dataHelper->getCurrentStoreId();

/** @var boolean $edd */
$edd = $coreHelper->moduleIsEnabled("Wyomind_EstimatedDeliveryDate") && $coreHelper->getStoreConfig("estimateddeliverydate/common/enabled", $storeId);

/** @var string $uenc */
$uenc = $cartHelper->getUenc();

/** @var string $currentMode */
$currentMode = $toolbarHelper->getCurrentMode();

/** @var boolean $wishlistAllow */
$wishlistAllow = $wishlistHelper->isAllow();

/** @var array $labels */
$labels = $configHelper->getLabels($storeId);

?>
<?php
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$theme = $this->helper('Infortis\Base\Helper\Data');
$helperLabels = $this->helper('Infortis\Base\Helper\Labels');
$helperImage = $this->helper('Infortis\Infortis\Helper\Image');
$helperAddToLinks = $this->helper('Infortis\Base\Helper\AddToLinks');


// Variables for both modes
$gc = $theme->getCfgGroup('category_grid');

// Vars for only one mode - but because the HTML is shared by both modes
// the vars need to be declared no matter what mode it is.
$listMode = false;
$itemgridClasses = '';
$productNameClasses = '';
$actionsClasses = '';
$swatchesExist = null; // TODO: only for grid mode

// List mode
if ($currentMode == 'list') {
    $listMode = true;
    $viewMode = 'list';
    $imageTypeId = 'category_page_list';
    $showDescription = true;
    $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::FULL_VIEW;
    $wrapperClasses = " {$viewMode} products-list products-list-ext";

    // List classes
    if ($theme->getCfg('category_list/hover_effect')) {
        $wrapperClasses .= ' hover-effect';
    }

    // "Add to" links
    $addtolinksPosition = false; //$theme->getCfg('category_list/addtolinks_position');
    $displayAddtolinks = 1;
} else // Grid mode
{
    $viewMode = 'grid';
    $imageTypeId = 'itemgrid_category_page_grid'; // Image dimensions declared in this entry (in view.xml) override Magento's default dimensions

    $showDescription = false;
    $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
    $wrapperClasses = " {$viewMode} items-grid items-grid-partitioned category-products-grid";
    $itemgridClasses = ' itemgrid';

    // If "column count" param is set, add classes for adaptive grid: itemgrid-adaptive and itemgrid-(X)col
    $gridColumnCount = $this->getData('grid_column_count');
    if ($gridColumnCount !== null) {
        $gridColumnCount = intval($gridColumnCount);
        $itemgridClasses .= " itemgrid-adaptive itemgrid-{$gridColumnCount}col";
    }

    // Grid classes
    if ($gc['display_name'] == 1 && $gc['display_name_single_line'] == true)
        $wrapperClasses .= '';// single-line-name';
    if ($gc['display_name'] == 2)
        $productNameClasses .= ' display-onhover';
    if ($gc['centered'])
        $wrapperClasses .= ' centered';
    if ($gc['hover_effect'])
        $wrapperClasses .= ' hover-effect';
    if ($gc['equal_height'])
        $wrapperClasses .= ' equal-height';

    // Size of item's elements
    $size = $this->getData('size');
    if ($size !== null) {
        $size = strtolower($size);
        $wrapperClasses .= ' size-' . $size;
    } else {
        if ($gc['elements_size']) {
            $wrapperClasses .= ' size-' . $gc['elements_size'];
        }
    }

    // If "Add to cart" button was set as "Display on hover", add proper class
    if ($gc['display_addtocart'] == 2) {
        //$actionsClasses = ' display-onhover';
    }

    // "Add to" links
    $addtolinksPosition = $gc['addtolinks_position'];
    $displayAddtolinks = $gc['display_addtolinks'];

} // end: grid mode

// Product image dimensions
$paramImgWidth = $this->getData('img_width');
$paramImgHeight = $this->getData('img_height');
if ($paramImgWidth || $paramImgHeight) {
    // Use values from params
    $imgWidth = intval($paramImgWidth);
    $imgHeight = intval($paramImgHeight);
} else {
    // Get values from config
    if ($currentMode == 'list') // List mode
    {
        $imgWidth = intval($theme->getCfg('category_list/image_width'));
        $imgHeight = intval($theme->getCfg('category_list/image_height'));
    } else // Grid mode
    {
        $imgWidth = intval($theme->getCfg('category_grid/image_width'));
        $imgHeight = intval($theme->getCfg('category_grid/image_height'));
    }
}

// If value equals zero or not set, replace it with null
if (empty($imgWidth)) {
    $imgWidth = "208";
}
if (empty($imgHeight)) {
    $imgHeight = "260";
}

// Number of dimensions
$imageDimensions = 0;
if (empty($imgWidth) && empty($imgHeight)) // No dimensions specified
{
    $imageDimensions = 0;
} elseif (!empty($imgWidth) && !empty($imgHeight)) // Both dimensions specified
{
    $imageDimensions = 2;
} else // Only one dimension specified
{
    $imageDimensions = 1;
}

// Alternative product image
$showAltImage = $theme->getCfg('category/alt_image');

// Product labels classes
$wrapperClasses .= ' ' . $helperLabels->getLabelsClasses();
?>


<span id="eln-product-products">
    <?php $count = $block->getData('count'); ?>
    <?php $noMoreProduct = $block->getData('noMoreProduct'); ?>
    <?php $products = $block->getData('products'); ?>
    <?php $customerGroupId = $block->getData('customerGroupId'); ?>
    <?php $ajaxCartEnabled = $block->getData('ajaxCartEnabled'); ?>
    <?php $addToCompareEnabled = $block->getData('addToCompareEnabled'); ?>
    <div class="ultimo products wrapper<?= $wrapperClasses ? $wrapperClasses : ""; ?>">
        <?php if ($count > 0) : ?>
        <ol class="products list items product-items<?= $itemgridClasses ? $itemgridClasses : "" ?>">
            <?php foreach ($products

            as $product) : ?>
            <li class="item product product-item">
                    <div class="loader"></div>
                    <div class="ajax-cart-message message"></div>
                    <div class="product-item-info imgdim-<?php echo $imgWidth . 'x' . $imgHeight; ?>"
                         data-container="product-grid">
                        <div class="product-item-img">
                            <a href="<?= $product['url'] ?>" class="product photo product-item-photo" tabindex="-1">
                                <span class="product-image-container" style="width:<?php echo $imgWidth; ?>px">
                                    <span class="product-image-wrapper" style="padding-bottom: 125%;">
                                        <img id="product-image-<?= $product['id'] ?>"
                                             src="<?= $product['base_image'] ?? $product['image'] ?>"
                                             width="<?php echo $imgWidth; ?>" height="<?php echo $imgHeight; ?>">
                                    </span>
                                </span>
                                <?php if ($coreHelper->getStoreConfig("quickview/settings/enabled")): ?>
                                    <a name='quickview-anchor-<?= $product['id'] ?>' class='quickview' id='quickview-<?= $product['id'] ?>' data-quickview-id='<?= $product['id'] ?>'></a>
                                <?php endif; ?>
                            </a>

                            <?php // Add-to links
                            $addtoLinksClasses = '';
                            if ($addtolinksPosition == true && $displayAddtolinks != 0) {
                                $addtoLinksClasses = ' addto-links addto-links-icons addto-onimage'; // Always display
                                if ($displayAddtolinks == 2) {
                                    $addtoLinksClasses .= ' onhover'; // Display only on hover
                                }
                            }
                            ?>
                            <?php if ($addtoLinksClasses): ?>
                                <div data-role="add-to-links"
                                     class="actions-secondary<?= $addtoLinksClasses; ?>">
                                     <?php if ($wishlistAllow): ?>
                                         <a title="<?= __("Add to Wish List"); ?>"
                                            href="<?= $block->getUrl("wishlist/index/add", ["form_key" => $dataHelper->getFormKey(), "uenc" => $uenc, "product" => $product['id']]); ?>"
                                            class="eln-ajax-add-to-wishlist action towishlist">
                                            <span class="icon ib ib-hover ic ic-heart "></span>
                                            <span class="label"><?= __("Add to Wish List"); ?></span>
                                        </a>
                                     <?php endif; ?>
                                    <?php if ($addToCompareEnabled) : ?>
                                        <a title="<?= __("Add to Compare"); ?>"
                                           href="<?= $block->getUrl("catalog/product_compare/add", ["form_key" => $dataHelper->getFormKey(), "uenc" => $uenc, "product" => $product['id']]); ?>"
                                           class="eln-ajax-add-to-compare action tocompare">
                                            <span class="icon ib ib-hover ic ic-compare "></span>
                                            <span class="label"><?= __("Add to Compare"); ?></span>
                                        </a>
                                    <?php endif; ?>
                                 </div>
                            <?php endif; ?>
                        </div>

                        <div class="product details product-item-details eln-product-item-details">
                            <?php if ($gc['display_name'] != 0): ?>
                                <strong class="product name product-item-name product-name">
                                    <a class="product-item-link"
                                       href="<?= $product['url'] ?>"><?= $product['name'] ?></a>
                                </strong>
                            <?php endif; ?>


                            <?php if (isset($product['configurable_options'])) : ?>
                                <div class="swatch-opt">
                                    <div class='eln-message-options-error'><?= __("Please select options before adding the product to the cart.") ?></div>
                                    <?php // visual swatch before text swatch ?>
                                    <?php foreach ($product['configurable_options'] as $attributeCode => $option): ?>
                                        <?php if ($option['visualSwatch']) : ?>
                                            <div class="swatch-attribute color">
                                                    <div class="swatch-attribute-options clearfix">
                                                        <?php foreach ($option['values'] as $value): ?>
                                                            <div class="swatch-option color"
                                                                 option-tooltip-value="<?= $value['swatch'] ?>"
                                                                 product-id=<?= $product['id'] ?> attribute-id="<?= $option['id'] ?>"
                                                                 option-id="<?= $value['id'] ?>"
                                                                 style="background: <?= $value['swatch'] ?> no-repeat center; background-size: initial;">
                                                        </div>
                                                        <?php endforeach; ?>
                                                    </div>
                                                </div>
                                        <?php endif; ?>
                                    <?php endforeach; ?>
                                    <?php foreach ($product['configurable_options'] as $attributeCode => $option): ?>
                                        <?php if ($option['textSwatch']) : ?>
                                            <div class="swatch-attribute text">
                                                    <div class="swatch-attribute-options clearfix">
                                                        <?php foreach ($option['values'] as $value): ?>
                                                            <div class="swatch-option text"
                                                                 product-id=<?= $product['id'] ?> attribute-id="<?= $option['id'] ?>"option-id="<?= $value['id'] ?>"><?= $value['swatch'] ?>
                                                            </div>
                                                        <?php endforeach; ?>
                                                    </div>
                                                </div>
                                        <?php endif; ?>
                                    <?php endforeach; ?>
                                </div>
                            <?php endif; ?>

                            <?php if ($product['review_count'] > 0) : ?>
                                <div class="product-reviews-wrapper">
                                <div class="product-reviews-summary short">
                                    <div class="rating-summary">
                                        <span class="label"><span><?= __('Rating:'); ?></span></span>
                                        <div class="rating-result" title="<?= $product['rating'] ?>%">
                                            <span style="width:<?= $product['rating'] ?>%"><span><?= $product['rating'] ?>
                                                    %</span></span>
                                        </div>
                                    </div>
                                    <div class="reviews-actions">
                                        <a class="action view"
                                           href="<?= $product['url'] ?>#reviews"><?= $product['review_count'] ?>
                                            &nbsp;<span><?= __('Reviews'); ?></span></a>
                                    </div>
                                </div>
                            </div>
                            <?php endif; ?>

                            <?php if ($listMode == false): // Price is displayed here only in grid mode ?>
                                <?php $product['prices'] = $product['prices_' . $customerGroupId]; ?>
                                <div class="price-box price-final_price">
                                    <?php if (isset($product['prices_' . $customerGroupId])) : ?>
                                        <?php if (!isset($product['tax_class_id'])) : $product['tax_class_id'] = 0; endif; ?>
                                        <span class="price-container price-final_price tax weee">
                                            <span class="price-wrapper">
                                            <?php if ($product['type_id'] == "configurable") : ?>
                                                <?php if ($product['prices']['min_price'] != $product['prices']['max_price']) : ?>
                                                    <span><?php echo __('From: '); ?></span><span
                                                            class="price"><?= $priceHelper->currency($frontendHelper->getPrice($product['prices']['final_price']), true, false) ?></span>
                                                <?php else: ?>
                                                    <span class="price"><?= $priceHelper->currency($frontendHelper->getPrice($product['prices']['final_price']), true, false) ?></span>
                                                <?php endif; ?>
                                            <?php else: ?>
                                                <?php if ($product['type_id'] == "grouped") : ?>
                                                    <span class="price"><?php echo __('From: '); ?></span>
                                                    <span><?= $priceHelper->currency($frontendHelper->getPrice($product['prices']['min_price']), true, false) ?></span>
                                                <?php else: ?>
                                                    <?php if ($product['type_id'] == "bundle") : ?>
                                                        <span><?php echo __('From: '); ?></span><span
                                                                class="price"><?= $priceHelper->currency($frontendHelper->getPrice($product['prices']['min_price']), true, false) ?></span>
                                                        <span><?php echo __('To: '); ?></span><span
                                                                class="price"><?= $priceHelper->currency($frontendHelper->getPrice($product['prices']['max_price']), true, false) ?></span>
                                                    <?php else: ?>
                                                        <span class="price"><?= $priceHelper->currency($frontendHelper->getPrice($product['prices']['final_price']), true, false) ?></span>
                                                    <?php endif; ?>
                                                <?php endif; ?>
                                            <?php endif; ?>
                                            </span>
                                        </span>
                                    <?php endif; ?>
                                </div>
                            <?php else: ?>
                                <div class="price-box price-final_price data-product"
                                     data-product-id="<?= $product['id'] ?>"></div>
                            <?php endif; ?>

                            <?php if ($showDescription): ?>
                                <div class="product description product-item-description">
                                    <span class="inner-description"><?= $product['description'] ?? ''; ?></span>
                                    <a href="<?= $product['url'] ?>"
                                       class="action more"><?php echo __('Learn More') ?></a>
                                </div>
                            <?php endif; ?>

                            <?php if ($listMode): ?>
                            <?php // In list mode, close "product-item-details" element here (so that "product-item-inner" become a sibling of "product-item-details") ?>
                            </div> <!-- end: product-item-details -->
                        <?php endif; ?>

                        <?php if ($edd): ?>
                            <div class="edd-loading" id='estimated-delivery-date-<?= $product['id'] ?>'></div>
                        <?php endif; ?>

                        <div class="product-item-inner">

                        <?php if ($listMode): ?>
                        <?php // In list mode, add another div ?>
                            <div class="product-item-inner-content">
                                <?php $product['prices'] = $product['prices_' . $customerGroupId]; ?>
                                <div class="price-box price-final_price">
                                    <?php if (isset($product['prices_' . $customerGroupId])) : ?>
                                        <?php if (!isset($product['tax_class_id'])) : $product['tax_class_id'] = 0; endif; ?>
                                        <span class="price-container price-final_price tax weee">
                                            <span class="price-wrapper">
                                            <?php if ($product['type_id'] == "configurable") : ?>
                                                <?php if ($product['prices']['min_price'] != $product['prices']['max_price']) : ?>
                                                    <span><?php echo __('From: '); ?></span><span
                                                            class="price"><?= $priceHelper->currency($frontendHelper->getPrice($product['prices']['final_price']), true, false) ?></span>
                                                <?php else: ?>
                                                    <span class="price"><?= $priceHelper->currency($frontendHelper->getPrice($product['prices']['final_price']), true, false) ?></span>
                                                <?php endif; ?>
                                            <?php else: ?>
                                                <?php if ($product['type_id'] == "grouped") : ?>
                                                    <span class="price"><?php echo __('From: '); ?></span>
                                                    <span><?= $priceHelper->currency($frontendHelper->getPrice($product['prices']['min_price']), true, false) ?></span>
                                                <?php else: ?>
                                                    <?php if ($product['type_id'] == "bundle") : ?>
                                                        <span><?php echo __('From: '); ?></span><span
                                                                class="price"><?= $priceHelper->currency($frontendHelper->getPrice($product['prices']['min_price']), true, false) ?></span>
                                                        <span><?php echo __('To: '); ?></span><span
                                                                class="price"><?= $priceHelper->currency($frontendHelper->getPrice($product['prices']['max_price']), true, false) ?></span>
                                                    <?php else: ?>
                                                        <span class="price"><?= $priceHelper->currency($frontendHelper->getPrice($product['prices']['final_price']), true, false) ?></span>
                                                    <?php endif; ?>
                                                <?php endif; ?>
                                            <?php endif; ?>
                                            </span>
                                        </span>
                                    <?php endif; ?>
                                </div>
                                <?php endif; ?>
                                <div class="product actions product-item-actions <?php echo $actionsClasses; ?>">

                                    <?php if ($gc['display_addtocart'] != 0): ?>
                                        <div class="actions-primary">
                                            <?php if ($ajaxCartEnabled): ?>
                                            <div data-role="tocart-form" method="post"
                                                 action="<?= str_replace("productId", $product['id'], $cartHelper->getAddUrlPlaceHolder()) ?>">
                                            <?php else: ?>
                                                <form data-role="tocart-form" method="post"
                                                      action="<?= str_replace("productId", $product['id'], $cartHelper->getAddUrlPlaceHolder()) ?>">
                                            <?php endif; ?>
                                                    <input type="hidden" name="product" value="<?= $product['id'] ?>">
                                                    <input type="hidden" name="uenc" value="<?php echo $uenc; ?>">
                                                    <input type="hidden" name="qty" value="1">
                                                    <?php if ($ajaxCartEnabled): ?><input type="hidden" name="isAjax"
                                                                                          value="1"><?php endif; ?>
                                                    <?php if (isset($product['configurable_options'])): ?>
                                                        <?php foreach ($product['configurable_options'] as $attributeCode => $option) : ?>
                                                            <input class="swatch-input super-attribute-select"
                                                                   id="cart-super-attribute-<?= $product['id'] ?>-<?= $option['id'] ?>"
                                                                   name="super_attribute[<?= $option['id'] ?>]"
                                                                   type="text"
                                                                   value="">
                                                        <?php endforeach; ?>
                                                    <?php endif; ?>
                                                    <?= $block->getBlockHtml('formkey') ?>
                                                    <button type="submit"
                                                            title="<?= (isset($product['quantity_and_stock_status_ids']) && $product['quantity_and_stock_status_ids'] == 0) ? __("The product is not available") : __("Add to Cart"); ?>"
                                                            class="eln-ajax-add-to-cart action tocart primary <?= (isset($product['quantity_and_stock_status_ids']) && $product['quantity_and_stock_status_ids'] == 0) ? disabled : "" ?>">
                                                        <span><?= __('Add to Cart') ?></span>
                                                    </button>
                                                    <?php if ($ajaxCartEnabled): ?>
                                                </div>
                                        <?php else: ?>
                                            </form>
                                        <?php endif; ?>
                                        </div>
                                    <?php endif; ?>

                                    <?php // Add-to links
                                    $addtoLinksClasses = '';
                                    if ($addtolinksPosition == false && $displayAddtolinks != 0) {
                                        $addtoLinksClasses = ' addto-links addto-links-icons'; // Always display
                                        // if ($displayAddtolinks == 2)
                                        //     $addtoLinksClasses .= ' display-onhover'; // Display only on hover
                                    } ?>
                                    <?php if ($addtoLinksClasses): ?>
                                        <div data-role="add-to-links"
                                             class="actions-secondary<?php echo $addtoLinksClasses; ?>">
                                            <?php if ($wishlistAllow) : ?>
                                                <a title="<?php echo __("Add to Wish List"); ?>"
                                                   href="<?= $block->getUrl("wishlist/index/add", ["form_key" => $dataHelper->getFormKey(), "uenc" => $uenc, "product" => $product['id']]); ?>"
                                                   class="eln-ajax-add-to-wishlist action towishlist">
                                                    <span class="icon ib ib-hover ic ic-heart "></span>
                                                    <span class="label"><?= __('Add to Wish List') ?></span>
                                                </a>
                                            <?php endif; ?>
                                            <?php if ($addToCompareEnabled) : ?>
                                                <a title="<?= __("Add to Compare"); ?>"
                                                   href="<?= $block->getUrl("catalog/product_compare/add", ["form_key" => $dataHelper->getFormKey(), "uenc" => $uenc, "product" => $product['id']]); ?>"
                                                   class="eln-ajax-add-to-compare action tocompare">
                                                    <span class="icon ib ib-hover ic ic-compare "></span>
                                                    <span class="label"><?= __('Add to Compare') ?></span>
                                                </a>
                                            <?php endif; ?>
                                        </div>
                                    <?php endif; ?>

                                </div>

                                <?php if ($listMode): ?>
                                <?php // In list mode, close the additional div ?>
                                </div> <!-- end: product-item-inner-content -->
                        <?php endif; ?>

                         </div>
                        <?php if ($listMode == false): ?>
                        <?php // If not in list mode, close "product-item-details" element here (so that "product-item-inner" is inside "product-item-details") ?>
                </div> <!-- end: product-item-details -->
                <?php endif; ?>

            </div>
    </li>
    <?php endforeach; ?>
    </ol>
    <?php else : ?>
    <div class="message notice">
            <div><?= __('Your search returned no results.') ?></div>
        </div>
    <?php endif; ?>
    </div>
    <div class="eln-infinite-scroll-loader" id="eln-infinite-scroll-loader"></div>
    <div class="eln-infinite-scroll-end <?= $noMoreProduct ? "active" : "" ?>" id="eln-infinite-scroll-end">
        <div class="message-warning warning message">
            <div>
                <?= $labels['no_more_product'] ?>
            </div>
        </div>
    </div>
</span>


<script id="eln-product-items-template" type="text/x-magento-template">
    <div class="ultimo products wrapper<?php if ($wrapperClasses) echo $wrapperClasses; ?>">
        <% if (count > 0) { %>
        <ol class="products list items product-items<?php if ($itemgridClasses) echo $itemgridClasses; ?>">
        </ol>
        <% } else { %>
        <div class="message notice">
            <div><?= __('Your search returned no results.') ?></div>
        </div>
        <% } %>
    </div>
    <div class="eln-infinite-scroll-loader" id="eln-infinite-scroll-loader"></div>
    <div class="eln-infinite-scroll-end <?= $noMoreProduct ? "active" : "" ?>" id="eln-infinite-scroll-end">
        <div class="message-warning warning message">
            <div>
                <?= $labels['no_more_product'] ?>
            </div>
        </div>
    </div>
</script>
<script id="eln-product-item-template" type="text/x-magento-template">
    <li class="item product product-item">
        <div class="loader"></div>
        <div class="ajax-cart-message message"></div>
        <div class="product-item-info imgdim-<?php echo $imgWidth . 'x' . $imgHeight; ?>" data-container="product-grid">
            <div class="product-item-img">
                <a href="<%= product.url %>" class="product photo product-item-photo" tabindex="-1">
                    <span class="product-image-container" style="width:<?php echo $imgWidth; ?>px">
                        <span class="product-image-wrapper" style="padding-bottom: 125%;">
                            <img id="product-image-<%= product.id %>" src="<% if (typeof product.base_image != "undefined") { %><%= product.base_image %><% } else { %><%= product.image %><% } %>"
                                 width="<?php echo $imgWidth; ?>" height="<?php echo $imgHeight; ?>">
                        </span>
                    </span>
                    <?php if ($coreHelper->getStoreConfig("quickview/settings/enabled")): ?>
                        <a  data-mage-init='{"Wyomind_QuickView/js/quickview":{"url":"<?=  $block->getUrl("quickview/product/view"); ?>","page":""}}' name='quickview-anchor-<%= product.id %>' class='quickview' id='quickview-<%= product.id %>' data-quickview-id='<%= product.id %>'></a>
                    <?php endif; ?>
                </a>

                <?php // Add-to links
                $addtoLinksClasses = '';
                if ($addtolinksPosition == true && $displayAddtolinks != 0) {
                    $addtoLinksClasses = ' addto-links addto-links-icons addto-onimage'; // Always display
                    if ($displayAddtolinks == 2)
                        $addtoLinksClasses .= ' onhover'; // Display only on hover
                }
                ?>
                <?php if ($addtoLinksClasses): ?>
                    <div data-role="add-to-links" class="actions-secondary<?php echo $addtoLinksClasses; ?>">
                        <?php if ($wishlistAllow) : ?>
                            <a title="<?php echo __("Add to Wish List"); ?>"
                               href="<%= ("<?php echo $block->getUrl("wishlist/index/add", ["form_key" => $dataHelper->getFormKey(), "uenc" => $uenc, "product" => "productId"]); ?>").replace("productId",product.id) %>" class="eln-ajax-add-to-wishlist action towishlist">
                            <span class="icon ib ib-hover ic ic-heart "></span>
                            <span class="label"><?= __('Add to Wish List') ?></span>
                            </a>
                        <?php endif; ?>
                        <% if (addToCompareEnabled) { %>
                        <a title="<?php echo __("Add to Compare"); ?>"
                           href="<%= ("<?php echo $block->getUrl("catalog/product_compare/add", ["form_key" => $dataHelper->getFormKey(), "uenc" => $uenc, "product" => "productId"]); ?>
                        ").replace("productId",product.id) %>" class="eln-ajax-add-to-compare action tocompare">
                        <span class="icon ib ib-hover ic ic-compare "></span>
                        <span class="label"><?= __('Add to Compare') ?></span>
                        </a>
                        <% } %>
                    </div>
                <?php endif; ?>

            </div>

            <div class="product details product-item-details eln-product-item-details">


                <?php if ($gc['display_name'] != 0): ?>
                    <strong class="product name product-item-name product-name">
                        <a class="product-item-link" href="<%= product.url %>"><%= product.name%></a>
                    </strong>
                <?php endif; ?>


                <% if (product.configurable_options) { %>
                <div class="swatch-opt">
                    <div class='eln-message-options-error'><?= __("Please select options before adding the product to the cart.") ?></div>
                    <?php // visual swatch before text swatch ?>
                    <% _.each(product.configurable_options, function(option, attributeCode) { %>
                    <% if (option.visualSwatch) { %>
                    <div class="swatch-attribute color">
                        <div class="swatch-attribute-options clearfix">
                            <% _.each(option.values, function(value) { %>
                            <div class="swatch-option color" option-tooltip-value="<%= value.swatch %>" product-id=<%=
                                 product.id %> attribute-id="<%= option.id %>" option-id="<%= value.id %>"
                                style="background: <%= value.swatch %> no-repeat center; background-size: initial;">
                            </div>
                            <% }) %>
                        </div>
                    </div>
                    <% } %>
                    <% }) %>
                    <% _.each(product.configurable_options, function(option, attributeCode) { %>
                    <% if (option.textSwatch) { %>
                    <div class="swatch-attribute text">
                        <div class="swatch-attribute-options clearfix">
                            <% _.each(option.values, function(value) { %>
                            <div class="swatch-option text" product-id=<%= product.id %> attribute-id="<%= option.id %>"
                                option-id="<%= value.id %>"><%= value.swatch %>
                            </div>
                            <% }) %>
                        </div>
                    </div>
                    <% } %>
                    <% }) %>
                </div>
                <% } %>

                <?php // if ($gc['display_rating']>0): ?>
                <% if (product.review_count > 0) { %>
                <div class="product-reviews-wrapper">
                    <div class="product-reviews-summary short">
                        <div class="rating-summary">
                            <span class="label"><span>Rating:</span></span>
                            <div class="rating-result" title="<%= product.rating %>%">
                                <span style="width:<%= product.rating %>%"><span><%= product.rating %>%</span></span>
                            </div>
                        </div>
                        <div class="reviews-actions">
                            <a class="action view" href="<%= product.url %>#reviews"><%= product.review_count
                                %>&nbsp;<span>Reviews</span></a>
                        </div>
                    </div>
                </div>
                <% } %>
                <?php // endif; ?>

                <?php if ($listMode == false): // Price is displayed here only in grid mode ?>
                    <% product.prices = product['prices_'+customerGroupId]; %>
                    <div class="price-box price-final_price">
                        <% if (typeof product['prices_'+customerGroupId] !== "undefined") { %>
                        <span class="price-container price-final_price tax weee">
                            <span class="price-wrapper">
                                <% if (product.type_id == "configurable") { %>
                                    <% if (product.prices.min_price != product.prices.max_price) { %>
                                        <span><?php echo __('From: '); ?></span><span class="price"><%= _.getFormattedPrice(product.prices.final_price) %></span>
                                    <% } else { %>
                                        <span class="price"><%= _.getFormattedPrice(product.prices.final_price) %></span>
                                    <% } %>
                                <% } else { %>
                                    <% if (product.type_id == "grouped") { %>
                                        <span class="price"><?php echo __('From: '); ?></span><span><%= _.getFormattedPrice(product.prices.min_price) %></span>
                                    <% } else { %>
                                        <% if (product.type_id == "bundle") { %>
                                            <span><?php echo __('From: '); ?></span><span class="price"><%= _.getFormattedPrice(product.prices.min_price) %></span>
                                            <span><?php echo __('To: '); ?></span><span class="price"><%= _.getFormattedPrice(product.prices.max_price) %></span>
                                        <% } else { %>
                                            <span class="price"><%= _.getFormattedPrice(product.prices.final_price) %></span>
                                        <% } %>
                                    <% } %>
                                <% } %>
                            </span>
                        </span>
                        <% } %>
                    </div>
                <?php else: ?>
                    <div class="price-box price-final_price data-product" data-product-id="<%= product.id %>"></div>
                <?php endif; ?>

                <?php if ($showDescription): ?>
                    <div class="product description product-item-description">
                        <span class="inner-description"><% if (typeof product.description != "undefined") { %><%= jQuery.truncate(product.description,{words:true,length:150}) %><% } %></span>
                        <a href="<%= product.url %>" class="action more"><?php echo __('Learn More') ?></a>
                    </div>
                <?php endif; ?>

                <?php if ($listMode): ?>
                <?php // In list mode, close "product-item-details" element here (so that "product-item-inner" become a sibling of "product-item-details") ?>
            </div> <!-- end: product-item-details -->
            <?php endif; ?>
            <?php if ($edd): ?>
                <div class='edd-loading' id='estimated-delivery-date-<%= product.id %>'></div>
            <?php endif; ?>
            <div class="product-item-inner">

                <?php if ($listMode): ?>
            <?php // In list mode, add another div ?>
                <div class="product-item-inner-content">
                    <% product.prices = product['prices_'+customerGroupId]; %>
                    <div class="price-box price-final_price">
                        <% if (typeof product['prices_'+customerGroupId] !== "undefined") { %>
                        <span class="price-container price-final_price tax weee">
                                <span class="price-wrapper">
                                    <% if (product.type_id == "configurable") { %>
                                        <% if (product.prices.min_price != product.prices.max_price) { %>
                                            <span><?php echo __('From: '); ?></span><span class="price"><%= _.getFormattedPrice(product.prices.final_price) %></span>
                                        <% } else { %>
                                            <span class="price"><%= _.getFormattedPrice(product.prices.final_price) %></span>
                                        <% } %>
                                    <% } else { %>
                                        <% if (product.type_id == "grouped") { %>
                                            <span class="price"><?php echo __('From: '); ?></span><span><%= _.getFormattedPrice(product.prices.min_price) %></span>
                                        <% } else { %>
                                            <% if (product.type_id == "bundle") { %>
                                                <span><?php echo __('From: '); ?></span><span class="price"><%= _.getFormattedPrice(product.prices.min_price) %></span>
                                                <span><?php echo __('To: '); ?></span><span class="price"><%= _.getFormattedPrice(product.prices.max_price) %></span>
                                            <% } else { %>
                                                <span class="price"><%= _.getFormattedPrice(product.prices.final_price) %></span>
                                            <% } %>
                                        <% } %>
                                    <% } %>
                                </span>
                            </span>
                        <% }%>
                    </div>
                    <?php endif; ?>

                    <div class="product actions product-item-actions <?php echo $actionsClasses; ?>">

                        <?php if ($gc['display_addtocart'] != 0): ?>
                        <div class="actions-primary">
                            <% if (ajaxCartEnabled) { %>
                            <div data-role="tocart-form" method="post"
                                 action="<%= ("<?php echo $cartHelper->getAddUrlPlaceHolder(); ?>
                            ").replace("productId",product.id) %>">
                            <% } else { %>
                            <form data-role="tocart-form" method="post"
                                  action="<%= ("<?php echo $cartHelper->getAddUrlPlaceHolder(); ?>
                            ").replace("productId",product.id) %>">
                            <% } %>
                            <input type="hidden" name="product" value="<%= product.id %>">
                            <input type="hidden" name="uenc" value="<?php echo $uenc; ?>">
                            <input type="hidden" name="qty" value="1">
                            <% if (ajaxCartEnabled) { %><input type="hidden" name="isAjax" value="1"><% } %>
                            <% _.each(product.configurable_options, function(option, attributeCode) { %>
                            <input class="swatch-input super-attribute-select"
                                   id="cart-super-attribute-<%= product.id %>-<%= option.id %>"
                                   name="super_attribute[<%= option.id %>]" type="text" value=""
                                   style="/*visibility: hidden; position:absolute; left:-1000px*/">
                            <% }) %>
                            <?php echo $block->getBlockHtml('formkey') ?>
                            <button type="submit"
                                    title="<% if (typeof product.quantity_and_stock_status_ids  != "undefined" && product.quantity_and_stock_status_ids == 0) { %><?php echo __("The product is not available"); ?><% } else { %><?php echo __("Add to Cart"); ?><% } %>"
                                    class="eln-ajax-add-to-cart action tocart primary <% if (typeof product.quantity_and_stock_status_ids  != "undefined" && product.quantity_and_stock_status_ids == 0) { %>disabled<% } %>">
                                <span>Add to Cart</span>
                            </button>
                            <% if (ajaxCartEnabled) { %>
                        </div>
                        <% } else { %>
                        </form>
                        <% } %>
                    </div>
                <?php endif; ?>

                    <?php // Add-to links
                    $addtoLinksClasses = '';
                    if ($addtolinksPosition == false && $displayAddtolinks != 0) {
                        $addtoLinksClasses = ' addto-links addto-links-icons'; // Always display
                        // if ($displayAddtolinks == 2)
                        //     $addtoLinksClasses .= ' display-onhover'; // Display only on hover
                    } ?>
                    <?php if ($addtoLinksClasses): ?>
                        <div data-role="add-to-links" class="actions-secondary<?php echo $addtoLinksClasses; ?>">
                            <?php if ($wishlistAllow) : ?>
                                <a title="<?php echo __("Add to Wish List"); ?>"
                                   href="<%= ("<?php echo $block->getUrl("wishlist/index/add", ["form_key" => $dataHelper->getFormKey(), "uenc" => $uenc, "product" => "productId"]); ?>").replace("productId",product.id) %>" class="eln-ajax-add-to-wishlist action towishlist">
                                <span class="icon ib ib-hover ic ic-heart "></span>
                                <span class="label">Add to Wish List</span>
                                </a>
                            <?php endif; ?>
                            <% if (addToCompareEnabled) { %>
                            <a title="<?php echo __("Add to Compare"); ?>"
                               href="<%= ("<?php echo $block->getUrl("catalog/product_compare/add", ["form_key" => $dataHelper->getFormKey(), "uenc" => $uenc, "product" => "productId"]); ?>
                            ").replace("productId",product.id) %>" class="eln-ajax-add-to-compare action tocompare">
                            <span class="icon ib ib-hover ic ic-compare "></span>
                            <span class="label">Add to Compare</span>
                            </a>
                            <% } %>
                        </div>
                    <?php endif; ?>

                </div>

                <?php if ($listMode): ?>
                <?php // In list mode, close the additional div ?>
            </div> <!-- end: product-item-inner-content -->
        <?php endif; ?>

        </div>
        <?php if ($listMode == false): ?>
            <?php // If not in list mode, close "product-item-details" element here (so that "product-item-inner" is inside "product-item-details") ?>
            </div> <!-- end: product-item-details -->
        <?php endif; ?>

        </div>

        </div>
    </li>
</script>