<?php
/**
 * @package J2Store
 * @copyright Copyright (c)2014-17 Ramesh Elamathi / J2Store.org
 * @license GNU GPL v3 or later
 *
 * Bootstrap 2 layout of product detail
 */
// No direct access
defined('_JEXEC') or die;
$columns = $this->params->get('item_related_product_columns', 3);
$total = count($this->up_sells); $counter = 0;
?>

<div class="row product-upsells-container">
	<div class="col-sm-12">
		<h3 class="j2store-upcross-title"><?php echo JText::_('J2STORE_RELATED_PRODUCTS_UPSELLS'); ?></h3>
				<?php foreach($this->up_sells as $upsell_product):?>
					<?php
						if(!empty($upsell_product->addtocart_text)) {
							$cart_text = JText::_($upsell_product->addtocart_text);
						} else {
							$cart_text = JText::_('J2STORE_ADD_TO_CART');
						}
					
					?>
					
					<?php $rowcount = ((int) $counter % (int) $columns) + 1; ?>
					<?php if ($rowcount == 1) : ?>
						<?php $row = $counter / $columns; ?>
					
					<div class="upsell-product-row <?php echo 'row-'.$row; ?> row">
					<?php endif;?>
					<div class="col-sm-<?php echo round((12 / $columns));?> upsell-product">
							<div class="j2store-productlist-img-wrap">
								<div class="j2store-product-images">
									<div class="mod_pic">
										<a href="<?php echo $upsell_product->product_link;?>" class="j2store-plist-img">
											<i class="fa fa-link"></i>
										</a>
									</div>

									<div class="j2store-thumbnail-image upsell-product-image">
										<?php
											$thumb_image = '';
											if(isset($upsell_product->thumb_image) && $upsell_product->thumb_image){
					      					$thumb_image = $upsell_product->thumb_image;
					      					}
				
					      				?>
						   				<?php if(isset($thumb_image) &&  JFile::exists(JPATH::clean(JPATH_SITE.'/'.$thumb_image))):?>
						   					<a href="<?php echo $upsell_product->product_link;?>">
						   						<img alt="<?php echo $upsell_product->product_name ;?>" class="j2store-product-thumb-image-<?php echo $upsell_product->j2store_product_id; ?>"  src="<?php echo JUri::root().JPath::clean($thumb_image);?>" />
						   					</a>
									   	<?php endif; ?>
			
									</div> <!-- /.j2store-thumbnail-image -->

									<div class="product-icons add-to-cart">
										<?php echo J2Store::plugin()->eventWithHtml('AfterAddToCartButton', array($this->product, J2Store::utilities()->getContext('default_cart'))); ?>
										<?php if(count($upsell_product->options) || $upsell_product->product_type == 'variable'): ?>
											<a class="j2store-cart-button j2store-cart-button-cls"
												href="<?php echo $upsell_product->product_link; ?>">
												<?php //echo JText::_('J2STORE_CART_CHOOSE_OPTIONS'); ?><i class="fa fa-eye"></i>
											</a>
										<?php else: ?>
										<?php
											$this->singleton_product = $upsell_product;
											$this->singleton_params = $this->params;
											$this->singleton_cartext = $cart_text;
											echo $this->loadAnyTemplate('site:com_j2store/products/cart');
										?>
										<?php endif; ?>

									</div> <!-- /.add-to-cart -->

								</div> <!-- /.j2store-product-images -->
							</div> <!-- /.j2store-productlist-img-wrap -->

							<div class="j2store-content upsell-content">
								<div class="j2store-title-wrap">
									<h3 class="product-title upsell-product-title">
										<a href="<?php echo $upsell_product->product_link; ?>">
											<?php echo $upsell_product->product_name; ?>
										</a>
									</h3>
			
									<?php
										$this->singleton_product = $upsell_product;
										$this->singleton_params = $this->params;
										echo $this->loadAnyTemplate('site:com_j2store/products/price');
									?>
								</div>
							</div>				
					</div>
				<?php $counter++; ?>
				<?php if (($rowcount == $columns) or ($counter == $total)) : ?>
					</div>
				<?php endif; ?>
			<?php endforeach;?>
	</div>
</div>
