<?php 

if ( ! defined( 'ABSPATH' ) ) {
  die( '-1' );
}

/**
 * Shortcode attributes
 * @var $atts
 * @var $order
 * @var $cat
 * @var $content - shortcode content
 * Shortcode class
 * @var $this WPBakeryShortCode_qk_products_carousel
 */
$order =  $cat = '';
$output = $after_output = '';
$atts = vc_map_get_attributes( $this->getShortcode(), $atts );
extract( $atts );

wp_enqueue_script("mousewheel", get_template_directory_uri()."/js/jquery.mousewheel.js",array('jquery'),false,true);
?>
<!-- shop section -->
<div class="shop-section">
	<div class="shop-box">
		<div class="scroller-posts-line">
			<div class="inner-scroller">

				<?php 
				$query_args = array(
					'posts_per_page' => $order,
					'post_status' 	 => 'publish',
						'post_type' 	 => 'product',
						'no_found_rows'  => 1,
						'order'          => $order == 'asc' ? 'asc' : 'desc'
					);
					
					if($cat!='all'){ 
					$query_args['tax_query'] = array(  array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => $cat  ));
					}
				?>
				<?php 
					
					$r = new WP_Query( $query_args );
					if ( $r->have_posts() ) : while( $r->have_posts() ) : $r->the_post(); 
					
				?>

				<?php $new_product = new WC_Product( get_the_ID() ); ?>
				<div class="shop-post item">
					<div class="shop-gal">
						<?php do_action( 'woocommerce_before_shop_loop_item_title' ); ?>
						<div class="hover-box">
							<div class="inner-hover">
								<?php
									$handler = apply_filters( 'woocommerce_add_to_cart_handler', $new_product->product_type, $new_product );
									switch ( $handler ) {
									case "variable" :
										$add_cart = get_permalink();
									break;
									case "grouped" :
										$add_cart = get_permalink();
									break;
									case "external" :
										 $add_cart = get_permalink();
									break;
									default :
										if ( $new_product->is_purchasable() ) {
											 $add_cart = esc_url( $new_product->add_to_cart_url() );
										} else {
											 $add_cart = get_permalink();
										}
									break;
								}
								?>
								<a rel="nofollow" href="<?php echo esc_url($add_cart); ?>" data-quantity="1" data-product_id="<?php the_ID(); ?>" data-product_sku="<?php echo esc_attr($new_product->get_sku()); ?>" class="product_type_<?php echo esc_attr($new_product->product_type); ?> add_to_cart_button ajax_add_to_cart"><?php esc_html_e('Add to Cart','photofolio'); ?></a><br>
								
							</div>
						</div>
					</div>
					<div class="post-content">
						<span><?php echo $new_product->get_categories( ', ', '' . _n( '', '', sizeof( get_the_terms( get_the_ID(), 'product_cat' ) ), 'woocommerce' ) . ' ', '' ); ?></span>
						<h2><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h2>
						<?php do_action( 'woocommerce_after_shop_loop_item_title' ); ?>
					</div>
				</div>

				<?php endwhile; endif; ?>
				<?php wp_reset_postdata(); ?>

			</div>
		</div>
	</div>
</div>
<!-- End shop section -->