<?php
    $generateHelper = $this->helper('MGS\Fbuilder\Helper\Generate');
    use Magento\Framework\App\Action\Action;
?>
<?php if ($generateHelper->getCurrentTheme() == "Smartwave/porto"): ?>
    <?php
        $_helper = $this->helper('Magento\Catalog\Helper\Output');
        $_imagehelper = $this->helper('Magento\Catalog\Helper\Image');
        // Daily deal Helper
        $_dailydealhelper =$this->helper('Smartwave\Dailydeals\Helper\Data');
        $_portohelper = $this->helper('Smartwave\Porto\Helper\Data');
        $_category_config = $_portohelper->getConfig('porto_settings/category');
        $_category_grid_config = $_portohelper->getConfig('porto_settings/category_grid');
        $_product_label_config = $_portohelper->getConfig('porto_settings/product_label');
        $_lazyload = $_portohelper->getConfig('porto_settings/optimization/lazyload');
        $_product = $this->getLoadProduct($this->getProductId());
        $_helper = $this->helper('Magento\Catalog\Helper\Output');
        $builderHelper = $this->helper('MGS\Fbuilder\Helper\Data');
        $hideName = $this->getBlockData('hide_name');
        $hideReview = $this->getBlockData('hide_review');
        $hidePrice = $this->getBlockData('hide_price');
        $hideAddCart = $this->getBlockData('hide_addcart');
        $hideAddWishlist = $this->getBlockData('hide_addwishlist');
        $hideAddCompare = $this->getBlockData('hide_addcompare');
        $htmlStructure = $builderHelper->getStoreConfig('fbuilder/html_structure/product_grid');
        $viewMode = 'grid';
        $image = 'category_page_grid';
        $hover_image = 'category_page_grid-hover';
        $showDescription = false;
        $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
        $columns = 'columns'.$_category_grid_config['columns'];
        $product_type = $_category_grid_config['product_type'];
    if ($product_type == null) {
        $product_type = 1;
    }
        $image_width = ($_category_config['ratio_width'])?$_category_config['ratio_width']:300;
        $image_height = ($_category_config['ratio_height'])?$_category_config['ratio_height']:300;
        $aspect_ratio = $_category_config['aspect_ratio'];
    if ($aspect_ratio) {
        $image_height = $image_width;
    }
    ?>
    <div class="product-item-info type<?php echo $product_type; ?>" data-container="product-grid">
        <?php // Product Image ?>
        <div class="product photo product-item-photo">
            <a href="<?php echo $_product->getProductUrl() ?>" tabindex="-1">
            <?php
            if ($aspect_ratio) {
                $productImage = $_imagehelper->init($_product, $image)->constrainOnly(false)->keepAspectRatio(true)->keepFrame(false)->resize($image_width);
            } else { $productImage = $_imagehelper->init($_product, $image)->resize($image_width, $image_height);
            }
                $productImageUrl = $productImage->getUrl();
            ?>
                <img class="product-image-photo default_image <?php if (!$_lazyload): ?>porto-lazyload<?php endif;?>" <?php if (!$_lazyload): ?>data-<?php endif; ?>src="<?php echo $productImageUrl; ?>" width="<?php echo $image_width; ?>" height="<?php echo $image_height; ?>" alt=""/>
            <?php if ($_category_config['alternative_image']): ?>
                <?php
                if ($aspect_ratio) {
                    $productHoverImage = $_imagehelper->init($_product, $hover_image)->constrainOnly(false)->keepAspectRatio(true)->keepFrame(false)->resize($image_width);
                } else { $productHoverImage = $_imagehelper->init($_product, $hover_image)->resize($image_width, $image_height);
                }
                $productHoverImageUrl = $productHoverImage->getUrl();
                ?>
                <?php if ($productImageUrl != str_replace("/thumbnail/", "/small_image/", $productHoverImageUrl)): ?>
                <img class="product-image-photo hover_image" src="<?php echo $productHoverImageUrl; ?>" alt=""/>
                <?php endif; ?>
            <?php endif; ?>
            </a>
            <?php
                $product_label = "";
            if ($_product_label_config['sale_label']) {
                $orgprice = $_product->getPrice();
                $specialprice = $_product->getSpecialPrice();
                $specialfromdate = $_product->getSpecialFromDate();
                $specialtodate = $_product->getSpecialToDate();
                $today = time();
                if (!$specialprice) {
                    $specialprice = $orgprice;
                }
                if ($specialprice < $orgprice) {
                    if ((is_null($specialfromdate) && is_null($specialtodate)) || ($today >= strtotime($specialfromdate) && is_null($specialtodate)) || ($today <= strtotime($specialtodate) && is_null($specialfromdate)) || ($today >= strtotime($specialfromdate) && $today <= strtotime($specialtodate))) {
                        if ($_product_label_config['sale_label_percent']) {
                            $save_percent = 100-round(($specialprice/$orgprice)*100);
                            $product_label .= '<div class="product-label sale-label">'.'-'.$save_percent.'%'.'</div>';
                        } else {
                            $product_label .= '<div class="product-label sale-label">'.$_product_label_config['sale_label_text'].'</div>';
                        }
                    }
                }
            }
            if ($_product_label_config['new_label']) {
                $now = date("Y-m-d");
                $newsFrom= substr($_product->getData('news_from_date'), 0, 10);
                $newsTo=  substr($_product->getData('news_to_date'), 0, 10);

                if ($newsTo != '' || $newsFrom != '') {
                    if (($newsTo != '' && $newsFrom != '' && $now>=$newsFrom && $now<=$newsTo) || ($newsTo == '' && $now >=$newsFrom) || ($newsFrom == '' && $now<=$newsTo)) {
                        $product_label .= '<div class="product-label new-label">'.$_product_label_config['new_label_text'].'</div>';
                    }
                }
            }
            if ($product_label) {
                echo '<div class="product-labels">'.$product_label.'</div>';
            }
            ?>
            <?php if ($product_type == 3 || $product_type == 5 || $product_type == 6 || $product_type == 7 || $product_type == 8 || $product_type == 9): ?>
            <div class="product-item-inner">
                <div class="product actions product-item-actions">
                <?php if (!$hideAddCart): ?>
                    <div class="actions-primary">
                        <?php if ($_product->isSaleable()): ?>
                            <?php $postParams = $block->getAddToCartPostParams($_product); ?>
                            <form data-role="tocart-form" action="<?php echo $postParams['action']; ?>" method="post">
                                <input type="hidden" name="product" value="<?php echo $postParams['data']['product']; ?>">
                                <input type="hidden" name="<?php echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
                                <?php if (isset($_category_config['qty_field']) && $_category_config['qty_field']):?>
                                    <div class="qty-box">
                                        <a href="javascript:void(0)" class="qtyminus"><i class="porto-icon-minus"></i></a>
                                        <input type="text" name="qty" id="qty" maxlength="12" value="<?php /* @escapeNotVerified */ echo $block->getProductDefaultQty() * 1 ?>" title="<?php /* @escapeNotVerified */ echo __('Qty') ?>" class="input-text qty" data-validate="<?php echo $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"/>
                                        <a href="javascript:void(0)" class="qtyplus"><i class="porto-icon-plus"></i></a>
                                    </div>
                                <?php endif;?>
                                <?php echo $block->getBlockHtml('formkey')?>
                                <button type="submit"
                                        title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
                                        class="action tocart primary">
                                    <span><?php echo __('Add to Cart') ?></span>
                                </button>
                            </form>
                        <?php else: ?>
                            <?php if ($_product->getIsSalable()): ?>
                                <div class="stock available"><span><?php echo __('In stock') ?></span></div>
                            <?php else: ?>
                                <div class="stock unavailable"><span><?php echo __('Out of stock') ?></span></div>
                            <?php endif; ?>
                        <?php endif; ?>
                    </div>
                <?php endif ?>

                    <?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow() && !$hideAddWishlist): ?>
                        <a href="#"
                        class="action towishlist actions-secondary"
                        title="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
                        aria-label="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
                        data-post='<?php echo $block->getAddToWishlistParams($_product); ?>'
                        data-action="add-to-wishlist"
                        role="button">
                            <span><?php echo __('Add to Wish List') ?></span>
                        </a>
                    <?php endif; ?>

                    <?php if (!$hideAddCompare): ?>
                        <?php
                        $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
                        ?>
                    <a href="#"
                    class="action tocompare actions-secondary"
                    title="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
                    aria-label="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
                    data-post='<?php echo $compareHelper->getPostDataParams($_product); ?>'
                    role="button">
                        <span><?php echo __('Add to Compare') ?></span>
                    </a>
                    <?php endif; ?>
                </div>
            </div>
            <?php endif; ?>

        </div>
        <div class="product details product-item-details">
            <?php
                $_productNameStripped = $block->stripTags($_product->getName(), null, true);
            ?>
            <?php if (!$hideName): ?>
                <strong class="product name product-item-name">
                    <a class="product-item-link"
                    href="<?php echo $_product->getProductUrl() ?>">
                        <?php echo $_helper->productAttribute($_product, $_product->getName(), 'name'); ?>
                    </a>
                </strong>
            <?php endif ?>
            <?php if (!$hideReview): ?>
                <?php
                $review_html = $block->getReviewsSummaryHtml($_product, $templateType);
                ?>
                <?php if ($review_html): ?>
                    <?php echo $block->getReviewsSummaryHtml($_product, $templateType); ?>
            <?php else: ?>
            <div class="product-reviews-summary short">
                <div class="rating-summary">
                    <span class="label"><span>Rating:</span></span>
                    <div class="rating-result" title="0%">
                        <span style="width:0"><span>0%</span></span>
                    </div>
                </div>
            </div>
            <?php endif; ?>
            <?php endif; ?>

            <?php if ($showDescription):?>
                <div class="product description product-item-description">
                    <?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
                    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped ?>"
                    class="action more"><?php echo __('Learn More') ?></a>
                </div>
            <?php endif; ?>
            <?php if (!$hidePrice): ?>
                <?php echo $block->getProductPrice($_product) ?>
            <?php endif; ?>
            <?php echo $block->getProductDetailsHtml($_product); ?>

            <?php if ($product_type != 3 && $product_type != 5 && $product_type != 6 && $product_type != 7 && $product_type != 8 && $product_type != 9): ?>
            <div class="product-item-inner">
                <div class="product actions product-item-actions">

                    <?php if (!$hideAddWishlist && $product_type != 4): ?>
                        <?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()): ?>
                            <a href="#"
                            class="action towishlist actions-secondary <?php if (isset($_category_config['qty_field']) && $_category_config['qty_field']):?>has-qty<?php endif;?>"
                            title="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
                            aria-label="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
                            data-post='<?php echo $block->getAddToWishlistParams($_product); ?>'
                            data-action="add-to-wishlist"
                            role="button">
                                <span><?php echo __('Add to Wish List') ?></span>
                            </a>
                        <?php endif; ?>
                    <?php endif; ?>

                    <?php if (!$hideAddCart): ?>
                        <div class="actions-primary">
                            <?php if ($_product->isSaleable()): ?>
                                <?php $postParams = $block->getAddToCartPostParams($_product); ?>
                                <form data-role="tocart-form" action="<?php echo $postParams['action']; ?>" method="post">
                                    <input type="hidden" name="product" value="<?php echo $postParams['data']['product']; ?>">
                                    <input type="hidden" name="<?php echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
                                    <?php if (isset($_category_config['qty_field']) && $_category_config['qty_field']):?>
                                        <div class="qty-box">
                                            <a href="javascript:void(0)" class="qtyminus"><i class="porto-icon-minus"></i></a>
                                            <input type="text" name="qty" id="qty" maxlength="12" value="<?php /* @escapeNotVerified */ echo $block->getProductDefaultQty() * 1 ?>" title="<?php /* @escapeNotVerified */ echo __('Qty') ?>" class="input-text qty" data-validate="<?php echo $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"/>
                                            <a href="javascript:void(0)" class="qtyplus"><i class="porto-icon-plus"></i></a>
                                        </div>
                                    <?php endif;?>
                                    <?php echo $block->getBlockHtml('formkey')?>
                                    <button type="submit"
                                            title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
                                            class="action tocart primary">
                                        <span><?php echo __('Add to Cart') ?></span>
                                    </button>
                                </form>
                            <?php else: ?>
                                <?php if ($_product->getIsSalable()): ?>
                                    <div class="stock available"><span><?php echo __('In stock') ?></span></div>
                                <?php else: ?>
                                    <div class="stock unavailable"><span><?php echo __('Out of stock') ?></span></div>
                                <?php endif; ?>
                            <?php endif; ?>
                        </div>
                    <?php endif ?>

                    <?php if (!$hideAddWishlist && $product_type == 4): ?>
                        <?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()): ?>
                            <a href="#"
                            class="action towishlist actions-secondary <?php if (isset($_category_config['qty_field']) && $_category_config['qty_field']):?>has-qty<?php endif;?>"
                            title="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
                            aria-label="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
                            data-post='<?php echo $block->getAddToWishlistParams($_product); ?>'
                            data-action="add-to-wishlist"
                            role="button">
                                <span><?php echo __('Add to Wish List') ?></span>
                            </a>
                        <?php endif; ?>
                    <?php endif; ?>


                    <?php if (!$hideAddCompare): ?>
                        <?php
                        $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
                        ?>
                    <a href="#"
                    class="action tocompare actions-secondary <?php if (isset($_category_config['qty_field']) && $_category_config['qty_field']):?>has-qty<?php endif;?>"
                    title="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
                    aria-label="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
                    data-post='<?php echo $compareHelper->getPostDataParams($_product); ?>'
                    role="button">
                        <span><?php echo __('Add to Compare') ?></span>
                    </a>
                    <?php endif; ?>
                </div>
            </div>
            <?php endif; ?>
        </div>
    </div>
<?php elseif ($generateHelper->getCurrentTheme() == "Sm/market"): ?>
    <?php
        $viewMode = 'grid';
        $image = 'category_page_grid';
        $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
        $_product = $this->getLoadProduct($this->getProductId());
        $_productNameStripped = $block->stripTags($_product->getName(), null, true);
        $productImage = $block->getImage($_product, $image);
        $_helper = $this->helper('Magento\Catalog\Helper\Output');
        $builderHelper = $this->helper('MGS\Fbuilder\Helper\Data');
        $hideName = $this->getBlockData('hide_name');
        $hideReview = $this->getBlockData('hide_review');
        $hidePrice = $this->getBlockData('hide_price');
        $hideAddCart = $this->getBlockData('hide_addcart');
        $hideAddWishlist = $this->getBlockData('hide_addwishlist');
        $hideAddCompare = $this->getBlockData('hide_addcompare');
        $htmlStructure = $builderHelper->getStoreConfig('fbuilder/html_structure/product_grid');
    ?>
    <div class="product-item-info" data-container="product-grid">
        <div class="item-inner">
            <div class="box-image">
                <a href="<?php echo /* @escapeNotVerified */ $_product->getProductUrl() ?>" class="product photo product-item-photo" tabindex="-1">
                    <?php echo $productImage->toHtml() ?>
                </a>
            </div>

            <div class="product details product-item-details box-info">
                <?php if ($hideName!=1): ?>
                    <h2 class="product name product-item-name product-name">
                        <a class="product-item-link"
                        href="<?php echo $_product->getProductUrl() ?>">
                            <?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?>
                        </a>
                    </h2>
                <?php endif ?>
                <?php if ($hideReview!=1): ?>
                    <?php echo $block->getReviewsSummaryHtml($_product, $templateType) ?>
                <?php endif ?>

                <?php if ($hidePrice!=1): ?>
                    <?php echo $block->getProductPrice($_product) ?>
                <?php endif ?>

                <?php echo $this->getLayout()->createBlock('Magento\Swatches\Block\Product\Renderer\Listing\Configurable')->setProduct($_product)->setTemplate('Magento_Swatches::product/listing/renderer.phtml')->toHtml() ?>

                <?php //echo $block->getProductDetailsHtml($_product) ?>

                <?php if (($hideAddCart!=1) || ($hideAddWishlist!=1) || ($hideAddCompare!=1)): ?>
                    <div class="bottom-action">

                        <?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow() && ($hideAddWishlist!=1)): ?>
                            <a href="#" class="action towishlist btn-action link-wishlist" title="<?php echo $block->escapeHtmlAttr(__('Add to Wish List')) ?>" aria-label="<?php echo $block->escapeHtmlAttr(__('Add to Wish List')) ?>" data-post='<?php echo /* @noEscape */ $block->getAddToWishlistParams($block->getProduct()) ?>' data-action="add-to-wishlist" role="button">
                                <span><?php echo $block->escapeHtml(__('Add to Wish List')) ?></span>
                            </a>
                        <?php endif ?>

                        <?php if ($hideAddCart!=1 && $_product->isSaleable()): ?>
                            <?php $postParams = $block->getAddToCartPostParams($_product); ?>
                            <form data-role="tocart-form" data-product-sku="<?php echo  /* @NoEscape */ $_product->getSku() ?>" action="<?php echo /* @NoEscape */ $postParams['action'] ?>" method="post">
                                <input type="hidden" name="product" value="<?php echo /* @escapeNotVerified */ $postParams['data']['product'] ?>">
                                <input type="hidden" name="<?php echo /* @escapeNotVerified */ Action::PARAM_NAME_URL_ENCODED ?>" value="<?php echo /* @escapeNotVerified */ $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">
                                <?php echo $block->getBlockHtml('formkey') ?>
                                <button type="submit" title="<?php echo $block->escapeHtml(__('Add to Cart')) ?>" class="action tocart primary btn-action btn-cart">
                                    <span><?php echo /* @escapeNotVerified */ __('Add to Cart') ?></span>
                                </button>
                            </form>
                        <?php endif ?>

                        <?php if ($hideAddCompare!=1): ?>
                            <?php $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare'); ?>
                            <a href="#" class="action tocompare btn-action link-compare" title="<?php echo $block->escapeHtml(__('Add to Compare')) ?>" aria-label="<?php echo $block->escapeHtml(__('Add to Compare')) ?>" data-post='<?php echo /* @escapeNotVerified */ $compareHelper->getPostDataParams($_product) ?>' role="button">
                                <span><?php echo /* @escapeNotVerified */ __('Add to Compare') ?></span>
                            </a>
                        <?php endif ?>
                    </div>
                <?php endif ?>
            </div>
        </div>


    </div>
<?php else: ?>
    <?php
    $viewMode = 'grid';
    $image = 'category_page_grid';
    $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
    $_product = $this->getLoadProduct($this->getProductId());
    $_productNameStripped = $block->stripTags($_product->getName(), null, true);
    $productImage = $block->getImage($_product, $image);
    $_helper = $this->helper('Magento\Catalog\Helper\Output');
    $builderHelper = $this->helper('MGS\Fbuilder\Helper\Data');
    $hideName = $this->getBlockData('hide_name');
    $hideReview = $this->getBlockData('hide_review');
    $hidePrice = $this->getBlockData('hide_price');
    $hideAddCart = $this->getBlockData('hide_addcart');
    $hideAddWishlist = $this->getBlockData('hide_addwishlist');
    $hideAddCompare = $this->getBlockData('hide_addcompare');

    $htmlStructure = $builderHelper->getStoreConfig('fbuilder/html_structure/product_grid');
    ?>
    <?php if ($htmlStructure!=''): ?>
        <?php
        $productImage = '<a href="'.$_product->getProductUrl().'" class="product photo product-item-photo" tabindex="-1">'.$productImage->toHtml().'</a>';

        $productName = '';
        if ($hideName!=1) {
            $productName = '<strong class="product name product-item-name"><a class="product-item-link" href="'.$_product->getProductUrl().'">'.$_helper->productAttribute($_product, $_product->getName(), 'name').'</a></strong>';
        }

        $productReivew = '';
        if ($hideReview!=1) {
            $productReivew = $block->getReviewsSummaryHtml($_product, $templateType);
        }

        $productPrice = '';
        if ($hidePrice!=1) {
            $productPrice = $block->getProductPrice($_product);
        }

        $addToCart = '';
        if ($hideAddCart!=1) {
            $addToCart = '<div class="actions-primary">';
            if ($_product->isSaleable()) {
                $postParams = $block->getAddToCartPostParams($_product);
                $addToCart .= '<form data-role="tocart-form" data-product-sku="'.$_product->getSku().'" action="'.$postParams['action'].'" method="post">';
                $addToCart .= '<input type="hidden" name="product" value="'.$postParams['data']['product'].'"><input type="hidden" name="'.Action::PARAM_NAME_URL_ENCODED.'" value="'.$postParams['data'][Action::PARAM_NAME_URL_ENCODED].'">';
                $addToCart .= $block->getBlockHtml('formkey');

                $addToCart .= '<button type="submit" title="'.$block->escapeHtml(__('Add to Cart')).'" class="action tocart primary"><span>' . __('Add to Cart') . '</span></button></form>';

            } else {
                if ($_product->isAvailable()) {
                    $addToCart .= '<div class="stock available"><span>' . __('In stock') . '</span></div>';
                } else {
                    $addToCart .= '<div class="stock unavailable"><span>' . __('Out of stock') . '</span></div>';
                }
            }
            $addToCart .= '</div>';
        }

        $swatches = $this->getLayout()->createBlock('Magento\Swatches\Block\Product\Renderer\Listing\Configurable')->setProduct($_product)->setTemplate('MGS_Fbuilder::products/swatches/renderer.phtml')->toHtml();

        $addtoWishlist = '';

        if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow() && ($hideAddWishlist!=1)) {
            $addtoWishlist = '<a href="#" class="action towishlist" title="'.$block->escapeHtmlAttr(__('Add to Wish List')).'" aria-label="'.$block->escapeHtmlAttr(__('Add to Wish List')).'" data-post="'.$block->getAddToWishlistParams($block->getProduct()).'" data-action="add-to-wishlist" role="button"><span>'.$block->escapeHtml(__('Add to Wish List')).'</span></a>';
        }

        $addtoCompare = '';
        if ($hideAddCompare!=1) {
            $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
            $addtoCompare = '<a href="#" class="action tocompare" title="'.$block->escapeHtml(__('Add to Compare')).'" aria-label="'.$block->escapeHtml(__('Add to Compare')).'" data-post="'.$compareHelper->getPostDataParams($_product).'" role="button"><span>' . __('Add to Compare') . '</span></a>';
        }

        $from=['{{product_image}}', '{{product_name}}', '{{product_review}}', '{{product_price}}', '{{swatches}}', '{{add_to_cart}}', '{{add_to_wishlist}}', '{{add_to_compare}}'];
        $to=[$productImage, $productName, $productReivew, $productPrice, $swatches, $addToCart, $addtoWishlist, $addtoCompare];
        echo str_replace($from, $to, $htmlStructure);
        ?>
<?php else: ?>

    <div class="product-item-info" data-container="product-grid">
        <a href="<?php echo /* @escapeNotVerified */ $_product->getProductUrl() ?>" class="product photo product-item-photo" tabindex="-1">
            <?php echo $productImage->toHtml() ?>
        </a>
        <div class="product details product-item-details">
            <?php if ($hideName!=1): ?>
                <strong class="product name product-item-name">
                    <a class="product-item-link"
                       href="<?php echo $_product->getProductUrl() ?>">
                        <?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?>
                    </a>
                </strong>
            <?php endif ?>
            <?php if ($hideReview!=1): ?>
                <?php echo $block->getReviewsSummaryHtml($_product, $templateType) ?>
            <?php endif ?>

            <?php if ($hidePrice!=1): ?>
                <?php echo $block->getProductPrice($_product) ?>
            <?php endif ?>

            <?php echo $this->getLayout()->createBlock('Magento\Swatches\Block\Product\Renderer\Listing\Configurable')->setProduct($_product)->setTemplate('MGS_Fbuilder::products/swatches/renderer.phtml')->toHtml() ?>

            <?php //echo $block->getProductDetailsHtml($_product) ?>

            <?php if (($hideAddCart!=1) || ($hideAddWishlist!=1) || ($hideAddCompare!=1)): ?>
                <div class="product-item-inner">
                    <div class="product actions product-item-actions">
                        <?php if ($hideAddCart!=1): ?>
                            <div class="actions-primary">
                                <?php if ($_product->isSaleable()): ?>
                                    <?php $postParams = $block->getAddToCartPostParams($_product); ?>
                                    <form data-role="tocart-form" data-product-sku="<?php echo  /* @NoEscape */ $_product->getSku() ?>" action="<?php echo /* @NoEscape */ $postParams['action'] ?>" method="post">
                                        <input type="hidden" name="product" value="<?php echo /* @escapeNotVerified */ $postParams['data']['product'] ?>">
                                        <input type="hidden" name="<?php echo /* @escapeNotVerified */ Action::PARAM_NAME_URL_ENCODED ?>" value="<?php echo /* @escapeNotVerified */ $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">
                                        <?php echo $block->getBlockHtml('formkey') ?>
                                        <button type="submit" title="<?php echo $block->escapeHtml(__('Add to Cart')) ?>" class="action tocart primary">
                                            <span><?php echo /* @escapeNotVerified */ __('Add to Cart') ?></span>
                                        </button>
                                    </form>
                                <?php else: ?>
                                    <?php if ($_product->isAvailable()): ?>
                                        <div class="stock available"><span><?php echo /* @escapeNotVerified */ __('In stock') ?></span></div>
                                    <?php else: ?>
                                        <div class="stock unavailable"><span><?php echo /* @escapeNotVerified */ __('Out of stock') ?></span></div>
                                    <?php endif; ?>
                                <?php endif; ?>
                            </div>
                        <?php endif ?>

                        <?php if (($hideAddWishlist!=1) || ($hideAddCompare!=1)): ?>
                            <div data-role="add-to-links" class="actions-secondary">
                                <?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow() && ($hideAddWishlist!=1)): ?>
                                    <a href="#" class="action towishlist" title="<?php echo $block->escapeHtmlAttr(__('Add to Wish List')) ?>" aria-label="<?php echo $block->escapeHtmlAttr(__('Add to Wish List')) ?>" data-post='<?php echo /* @noEscape */ $block->getAddToWishlistParams($block->getProduct()) ?>' data-action="add-to-wishlist" role="button">
                                        <span><?php echo $block->escapeHtml(__('Add to Wish List')) ?></span>
                                    </a>
                                <?php endif; ?>
                                <?php if ($hideAddCompare!=1): ?>
                                    <?php $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare'); ?>
                                    <a href="#" class="action tocompare" title="<?php echo $block->escapeHtml(__('Add to Compare')) ?>" aria-label="<?php echo $block->escapeHtml(__('Add to Compare')) ?>" data-post='<?php echo /* @escapeNotVerified */ $compareHelper->getPostDataParams($_product) ?>' role="button">
                                        <span><?php echo /* @escapeNotVerified */ __('Add to Compare') ?></span>
                                    </a>
                                <?php endif ?>
                            </div>
                        <?php endif ?>
                    </div>
                </div>
            <?php endif ?>
        </div>
    </div>
<?php endif ?>
<?php endif; ?>
