<?php
/**
 * Copyright © 2015 PlazaThemes.com. All rights reserved.

 * @author PlazaThemes Team <contact@plazathemes.com>
 */
if($this->getConfig('enable_frontend')):
	$_imagehelper = $this->helper('Magento\Catalog\Helper\Image');
	$image = 'category_page_grid';
	$_productHelper = $this->helper('Magento\Catalog\Helper\Product');
	$block = $this->getBlockProduct();
 
	$auto = $this->getConfig('auto');
	if($auto)
		$auto = 'true';
	else
		$auto = 'false';
	$rows = $this->getConfig('rows');
	$show_next_back = $this->getConfig('show_next_back');
	$pagination = $this->getConfig('pagination');
	if($this->getConfig('speed'))
		$speed = $this->getConfig('speed');
	else
		$speed = '3000';
	if($show_next_back)
		$show_next_back = 'true';
	else
		$show_next_back = 'false';
	$show_navigation_control = $this->getConfig('show_navigation_control');
	if($show_navigation_control)
		$show_navigation_control = 'true';
	else
		$show_navigation_control = 'false';
?>
<div class="pt-randomproduct-container">
	<!--<div class="title"><h2><?php //echo $this->getConfig('title') ?></h2></div>-->
	<ul class="ptowl">
	<?php
	$i = 0;
	 foreach($this->getProducts() as $_product)
	{
	if($i%$rows == 0):
	?>
		<li class="item">
	<?php
	endif;
			$productImage = $_imagehelper->init($_product, $image)->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(400)->getUrl();
		?>
		
		<div class="product-item-inner">
			<div class="pull-left">
				<a href="<?php echo $_product->getProductUrl() ?>" class="product-item-photo"><img src="<?php echo $productImage; ?>" alt=""/></a>
			</div>
			
			<div class="media-body">
				<strong class="product-item-name">
					<a href="<?php echo $_product->getProductUrl() ?>" class="product-item-link"><?php echo $_product->getName() ?></a>
				</strong>				
				<?php echo $block->getProductPrice($_product) ?>

				<?php if ($_product->isSaleable()): ?>
					<?php $postParams = $block->getAddToCartPostParams($_product); ?>
					<form data-role="tocart-form" action="<?php /* @escapeNotVerified */ echo $postParams['action']; ?>" method="post">
						<input type="hidden" name="product" value="<?php /* @escapeNotVerified */ echo $postParams['data']['product']; ?>">
						<input type="hidden" name="<?php /* @escapeNotVerified */ //echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php /* @escapeNotVerified */ //echo $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 /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
						</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>
	<?php if($i%$rows == $rows - 1): ?>
		</li>
	<?php
	endif;
	$i++;
	}
	?>
	</ul>
</div>
<script type="text/javascript">
require([
  "jquery",
  "owlcarousel/minjs"
 ], function($,owlCarousel){
		$(document).ready(function(){
			$(".pt-randomproduct-container .ptowl").owlCarousel({
				<?php
					if(($auto== 'true') && $speed):
				?>
				autoPlay : <?php echo $speed; ?>,
				<?php
					endif;
				?>
				items : 2,
				itemsDesktop : [1199,2],
				itemsDesktopSmall : [992,3],
				itemsTablet: [767,2],
				itemsMobile : [479,1],
				slideSpeed : <?php echo $pagination; ?>,
				paginationSpeed : <?php echo $pagination; ?>,
				rewindSpeed : <?php echo $pagination; ?>,
				addClassActive: true,
				navigation : <?php echo $show_next_back; ?>,
				stopOnHover : true,
				pagination : <?php echo $show_navigation_control; ?>,
				scrollPerPage:true,
			});
		});
	});
</script>
<?php
endif;
?>