Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $blockId = rand() . time();
- $products = $this->getProductCollection();
- $themeHelper = $this->helper('MGS\Mpanel\Helper\Data');
- $themeSettings = $themeHelper->getThemeSettings();
- $type = 'widget-product-grid';
- $image = 'category_page_grid';
- $imageTwo = 'category_page_two_list';
- ?>
- <?php $quickViewHelper = $this->helper('MGS\QuickView\Helper\Data'); ?>
- <?php if($this->getData('per_row_grid') != null){
- $perRow = $this->getData('per_row_grid');
- }else {
- $perRow = $themeSettings['catalog']['per_row'];
- }
- $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
- ?>
- <div class="block products-grid <?php if($this->getData('custom_class')): ?><?php echo $this->getData('custom_class')?><?php endif;?>">
- <?php if($this->getData('title')): ?>
- <div class="title-block">
- <h2><?php echo $this->getData('title') ?></h2>
- </div>
- <?php endif ?>
- <?php if(count($products)>0): ?>
- <div class="block-content <?php if($this->getData('slider_mode_grid') != 1): ?>row<?php endif;?>">
- <ol class="products-grid <?php if($this->getData('slider_mode_grid') == 1): ?>owl-carousel<?php endif ?>" id="mgs-grid-product-<?php echo $blockId ?>">
- <?php $i = 0; foreach($products as $_product): $i++;?>
- <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
- $productModel = $objectManager->create('Magento\Catalog\Model\Product');
- $_product = $productModel->load($_product->getId()); ?>
- <?php $_itemNameStripped = $block->stripTags($_product->getName(), null, true); ?>
- <?php $_imagehelper = $this->helper('Magento\Catalog\Helper\Image');
- $size = $themeHelper->getImageSize();
- $productImage = $_imagehelper->init($_product, $image)->resize($size['width'], $size['height'])->getUrl();
- $_productType = $_product->getTypeID();
- ?>
- <?php if($this->getData('slider_mode_grid') == 1): ?>
- <li class="product-item item">
- <?php else: ?>
- <li class="item <?php echo $themeHelper->getColClass($perRow) ?> <?php echo $themeHelper->getClearClass($perRow, $i) ?>">
- <?php endif ?>
- <div class="product-item-info product-content">
- <div class="product-top">
- <a href="<?php /* @escapeNotVerified */ echo $block->getProductUrl($_product) ?>" class="product-item-photo">
- <img src="<?php echo $productImage; ?>" alt="<?php echo $_itemNameStripped ?>" class="img-responsive"/>
- </a>
- <div class="button-quickview">
- <?php echo $quickViewHelper->aroundQuickViewHtml($_product); ?>
- </div>
- <?php echo $themeHelper->getProductLabel($_product) ?>
- </div>
- <div class="product-desc">
- <div class="cate-name text-center"><div class="text"><span><?php echo $themeHelper->getCategoryName($_product,$this->getData('title'),'') ?></span></div></div>
- <h4 class="product-name product-item-name">
- <a class="product-item-link" href="<?php /* @escapeNotVerified */ echo $block->getProductUrl($_product) ?>" title="<?php echo $_itemNameStripped ?>"><?php echo $_product->getName() ?></a>
- </h4>
- <div class="rating-price">
- <?php echo $block->getProductPrice($_product) ?>
- <?php if($templateType): ?>
- <?php echo $block->getReviewsSummaryHtml($_product, $templateType, true)?>
- <?php endif;?>
- </div>
- <div class="controls">
- <div class="add-to-cart hover-hidden">
- <?php if ($_product->isSaleable()): ?>
- <?php $url = $this->getAddToCartUrl($_product) ?>
- <form data-role="tocart-form" action="<?php echo $url; ?>" method="post">
- <input type="hidden" name="product" value="<?php echo $_product->getId(); ?>">
- <input type="hidden" name="uenc" value="<?php echo $this->getEncodedUrl($url) ?>">
- <?php echo $block->getBlockHtml('formkey')?>
- <button class="tocart btn-icon btn btn-default" type="submit" title="<?php /* @escapeNotVerified */ echo __('Add to Cart') ?>">
- <?php if($_productType =='simple'):?><?php /* @escapeNotVerified */ echo __('Add to Cart') ?><?php else: ?>
- <?php echo __('Select option')?><?php endif;?>
- </button>
- </form>
- <?php else: ?>
- <?php if ($_product->getIsSalable()): ?>
- <div class="stock available"><span><?php /* @escapeNotVerified */ echo __('In stock') ?></span></div>
- <?php else: ?>
- <div class="stock unavailable"><span><?php /* @escapeNotVerified */ echo __('Out of stock') ?></span></div>
- <?php endif; ?>
- <?php endif; ?>
- </div>
- <div class="controls-hover">
- <?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()): ?>
- <button data-post='<?php /* @escapeNotVerified */ echo $block->getAddToWishlistParams($_product); ?>'
- class="action towishlist btn btn-addlist" data-action="add-to-wishlist"
- title="<?php /* @escapeNotVerified */ echo __('Add to Wish List') ?>">
- <span class="pe-7s-like"></span>
- </button>
- <?php endif;?>
- <?php if ($_product->isSaleable()): ?>
- <?php $url = $this->getAddToCartUrl($_product) ?>
- <form data-role="tocart-form" action="<?php echo $url; ?>" method="post">
- <input type="hidden" name="product" value="<?php echo $_product->getId(); ?>">
- <input type="hidden" name="uenc" value="<?php echo $this->getEncodedUrl($url) ?>">
- <?php echo $block->getBlockHtml('formkey')?>
- <button class="tocart btn-icon btn btn-addlist" type="submit" title="<?php /* @escapeNotVerified */ echo __('Add to Cart') ?>">
- <span class="icon <?php if($_productType =='simple'):?> pe-7s-shopbag<?php else: ?> pe-7s-menu<?php endif;?>"></span>
- </button>
- </form>
- <?php endif; ?>
- <?php if ($block->getAddToCompareUrl()): ?>
- <?php $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');?>
- <button class="action tocompare btn btn-addlist"
- data-post='<?php /* @escapeNotVerified */ echo $compareHelper->getPostDataParams($_product);?>'
- title="<?php /* @escapeNotVerified */ echo __('Add to Compare') ?>">
- <span class="pe-7s-repeat"></span>
- </button>
- <?php endif;?>
- </div>
- </div>
- </div>
- </div>
- </li>
- <?php endforeach ?>
- </ol>
- </div>
- <?php if($this->getData('slider_mode_grid') == 1): ?>
- <script type="text/javascript">
- require([
- 'jquery',
- 'mgs/owlcarousel'
- ], function ($) {
- var owl = $('#mgs-grid-product-<?php echo $blockId ?>');
- owl.owlCarousel({
- items: <?php echo $perRow ?>,
- autoPlay: false,
- stopOnHover: false,
- margin:30,
- nav: true,
- navText: ["<i class='fa fa-angle-left'></i>","<i class='fa fa-angle-right'></i>"],
- dots: false,
- responsive:{ 0 : {items: 1}, 480 : {items: 2}, 768 : {items: 2}, 970 : {items: 3}, 1199 : {items: <?php echo $perRow ?>} }
- });
- });
- </script>
- <?php endif ?>
- <?php else: ?>
- <div class="alert alert-danger"><?php echo __('No product to show'); ?></div>
- <?php endif ?>
- </div>
Add Comment
Please, Sign In to add comment