<?php

/**
 * Shop Category Shortcode
 */


// [progression_shop_cat heading_pro="" menu_description_pro="" etc...]
add_shortcode( 'progression_shop_cat', 'progression_shop_cat_func' );
function progression_shop_cat_func( $atts, $content = null ) { // New function parameter $content is added!
   extract( shortcode_atts( array(
		
	  'progression_studios_shop_layout' => 'progression-shop-default-layout',
	  'progression_studios_shop_columns' => '3',
	  'progression_studios_shop_gap' => '20px',
	  'shop_post_count' => '12',
	  'shop_filter_categories' => '',
	  'shop_heading_size' => '',

		 
   ), $atts ) );
   
    $output_pro = '';
	
	
	STATIC $idpro = 0;
	$idpro++;
	
	ob_start();
	?>
	
	
	<?php
	if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } else if ( get_query_var('page') ) {   $paged = get_query_var('page'); } else {  $paged = 1; }
	
	global $blogloop;
	global $post;
	


	
	?>
	
	<?php	
	$args = array(
		'orderby'    	=> 'name',
		'order'      	=> 'ASC',
		'number'     	=> $shop_post_count,
		'hide_empty' 	=> 0, // Hides Empty Categories
		'include'    => $shop_filter_categories,
	);
	$product_categories = get_terms( 'product_cat', $args );
	?>


<?php if ( $product_categories ): ?>


	
			<div class="woocommerce progression-studios-shop-vc">
				<div class="products">
					<div class="progression-shop-masonry-overflow <?php echo esc_attr($progression_studios_shop_layout) ?>">
						<div class="progression-masonry-margins" style="margin-top:-<?php echo esc_attr($progression_studios_shop_gap) ?>; margin-left:-<?php echo esc_attr($progression_studios_shop_gap) ?>; margin-right:-<?php echo esc_attr($progression_studios_shop_gap) ?>;">
							<div class="progression-shop-cat-masonry-<?php echo esc_attr($idpro) ?>">
								<?php foreach ( $product_categories as $category ) :  $term_link = get_term_link( $category ); ?>
					
									<div class="progression-masonry-item progression-masonry-col-<?php echo esc_attr($progression_studios_shop_columns) ?>">
										<?php include(locate_template('template-parts/visual-composer/content-product_cat.php')); ?>
									</div>

								<?php endforeach; ?>
							
								<div class="clearfix-pro"></div>
							</div>
						</div>
					</div><!-- close .progression-masonry-overflow -->
		
		
					<script type="text/javascript">
					jQuery(document).ready(function($) {
						'use strict';
	
						/* Default Isotope Load Code */
						var $container = $('.progression-shop-cat-masonry-<?php echo esc_attr($idpro) ?>').isotope();
						$container.imagesLoaded( function() {
							$(".progression-masonry-item").addClass('opacity-progression');
							$container.isotope({
								itemSelector: '.progression-masonry-item',
								transitionDuration: '0.4s',

								masonry: {
								    columnWidth: '.progression-masonry-col-<?php echo esc_attr($progression_studios_shop_columns) ?>',
								},hiddenStyle: {
									opacity: 0
								},
								visibleStyle: {
									opacity: 1
								}
					 		});
						});
						/* END Default Isotope Code */
					
					
	
					});
					</script>
	
	
				<div class="clearfix-pro"></div>
				
		
			</div><!-- close .products -->
		</div><!-- close .progression-studios-shop-vc -->
	
				
	
<?php endif ?>
	
	
	
	
	<?php wp_reset_postdata();?>
		
	<?php
	
	return $output_pro. ob_get_clean();
	
}


add_action( 'vc_before_init', 'progression_shop_cat_integrateVC' );
function progression_shop_cat_integrateVC() {
   vc_map( array(
      "name" => __( "Pro Shop Categories", "pro-elements" ),
	  "description" => __( "Shop category list", "pro-elements" ),
      "base" => "progression_shop_cat",
	  "weight" => 100,
      "class" => "",
      "category" => __( "Pro Elements", "pro-elements"),
	  'icon' => 'vc-icon',

      "params" => array(
			
         array(
            "type" => "dropdown",
				"class" => "",
            "heading" => __( "Shop Category Columns", "pro-elements" ),
            "param_name" => "progression_studios_shop_columns",
				"value"       => array(
					'1 Column'   	=> '1',
					'2 Columns'  	=> '2',
					'3 Columns'		=> '3',
					'4 Columns'  	=> '4',
					'5 Colums'  	=> '5',
			),
			"std"         => '3',
         ),
			
			
         array(
            "type" => "textfield",
				"class" => "",
            "heading" => __( "Shop Category Count", "pro-elements" ),
            "param_name" => "shop_post_count",
				"std"         => '12',
         ),
			
         
         array(
            "type" => "dropdown",
				"class" => "",
            "heading" => __( "Shop Category Gap", "pro-elements" ),
            "param_name" => "progression_studios_shop_gap",
				"value"       => array(
					'0px' => '0px',
					'5px' => '5px',
					'10px' => '10px',
					'15px' => '15px',
					'20px' => '20px',
					'25px' => '25px',
					'30px' => '30px',
			),
			"std"         => '20px',
         ),
			
		
			
         array(
            "type" => "dropdown",
				"class" => "",
            "heading" => __( "Shop Category Layout", "pro-elements" ),
            "param_name" => "progression_studios_shop_layout",
				"value"       => array(
				        'Overlay'   				=> 'progression-shop-default-layout',
				        'Underneath'   	=> 'progression-shop-underneath-layout',
				),
				"std"         => 'progression-shop-default-layout',
         ),
			
			
         array(
            "type" => "textfield",
				"class" => "",
            "heading" => __( "Narrow Categories", "pro-elements" ),
				"description" => __( "Enter category slugs to display a specific category. Add-in multiple category slugs seperated by a comma to use multiple categories. (Leave blank to pull in all categories).", "pro-elements" ),
            "param_name" => "shop_filter_categories",
				"std"         => '',
         ),

			




			
      )
   ) );
}