<?php
/*
 * Elementor eCommerce Addon Product Widget
 * Author & Copyright: NicheAddon
*/

namespace Elementor;

if (!isset(get_option( 'naeca_bw_settings' )['naeca_product'])) { // enable & disable
	
if ( class_exists( 'woocommerce' ) ) {

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

class eCommerce_Elementor_Addon_Product extends Widget_Base{

	/**
	 * Retrieve the widget name.
	*/
	public function get_name(){
		return 'naecommerce_basic_product';
	}

	/**
	 * Retrieve the widget title.
	*/
	public function get_title(){
		return esc_html__( 'Woo Products', 'ecommerce-addon' );
	}

	/**
	 * Retrieve the widget icon.
	*/
	public function get_icon() {
		return 'eicon-product-related';
	}

	/**
	 * Retrieve the list of categories the widget belongs to.
	*/
	public function get_categories() {
		return ['naecommerce-basic-category'];
	}

	/**
	 * Register eCommerce Addon Product widget controls.
	 * Adds different input fields to allow the user to change and customize the widget settings.
	*/
	protected function register_controls(){

		$this->start_controls_section(
			'section_product',
			[
				'label' => __( 'Product Item', 'ecommerce-addon' ),
			]
		);
		$this->add_control(
			'product_style',
			[
				'label' => esc_html__( 'Product Style', 'ecommerce-addon' ),
				'type' => Controls_Manager::SELECT,
				'options' => [
					'one' => esc_html__( 'Style One', 'ecommerce-addon' ),
					'two' => esc_html__( 'Style Two', 'ecommerce-addon' ),
				],
				'default' => 'one',
				'description' => esc_html__( 'Select your style.', 'ecommerce-addon' ),
			]
		);
		$this->add_control(
			'pr_limit',
			[
				'label' => esc_html__( 'Products Count', 'ecommerce-addon' ),
				'type' => Controls_Manager::NUMBER,
				'min' => 1,
				'max' => 100,
				'step' => 1,
				'default' => 3,
				'description' => esc_html__( 'Enter the number of items to show.', 'ecommerce-addon' ),
			]
		);
		$this->add_control(
			'pr_column',
			[
				'label' => __( 'Columns', 'ecommerce-addon' ),
				'type' => Controls_Manager::SELECT,
				'frontend_available' => true,
				'options' => [
					'col-2' => esc_html__( 'Two Column', 'ecommerce-addon' ),
					'col-3' => esc_html__( 'Three Column', 'ecommerce-addon' ),
					'col-4' => esc_html__( 'Four Column', 'ecommerce-addon' ),
				],
				'default' => 'col-3',
				'description' => esc_html__( 'Select your blog column.', 'ecommerce-addon' ),
			]
		);
		$this->add_control(
			'need_filter',
			[
				'label' => esc_html__( 'Sorting Filter', 'ecommerce-addon' ),
				'type' => Controls_Manager::SWITCHER,
				'label_on' => esc_html__( 'Show', 'ecommerce-addon' ),
				'label_off' => esc_html__( 'Hide', 'ecommerce-addon' ),
				'return_value' => 'true',
				'default' => 'true',
			]
		);
		$this->add_control(
			'cat_limit',
			[
				'label' => esc_html__( 'Filter Limit', 'ecommerce-addon' ),
				'type' => Controls_Manager::NUMBER,
				'min' => 1,
				'max' => 4,
				'default' => 3,
				'step' => 1,
				'description' => esc_html__( 'Enter the number of categories to show.', 'ecommerce-addon' ),
				'condition' => [
					'need_filter' => 'true',
				],
			]
		);
		$this->add_control(
			'pr_order',
			[
				'label' => __( 'Order', 'ecommerce-addon' ),
				'type' => Controls_Manager::SELECT,
				'options' => [
					'ASC' => esc_html__( 'Asending', 'ecommerce-addon' ),
					'DESC' => esc_html__( 'Desending', 'ecommerce-addon' ),
				],
				'default' => 'DESC',
			]
		);
		$this->add_control(
			'pr_orderby',
			[
				'label' => __( 'Order By', 'ecommerce-addon' ),
				'type' => Controls_Manager::SELECT,
				'options' => [
					'none' => esc_html__( 'None', 'ecommerce-addon' ),
					'ID' => esc_html__( 'ID', 'ecommerce-addon' ),
					'author' => esc_html__( 'Author', 'ecommerce-addon' ),
					'title' => esc_html__( 'Title', 'ecommerce-addon' ),
					'date' => esc_html__( 'Date', 'ecommerce-addon' ),
				],
				'default' => 'date',
			]
		);
		$this->add_control(
			'pr_cats',
			[
				'label' => __( 'Certain Categories?', 'ecommerce-addon' ),
				'type' => Controls_Manager::SELECT2,
				'default' => [],
				'options' => NAeCom_Controls_Helper_Output::get_terms_names( 'product_cat'),
				'multiple' => true,
			]
		);
		$this->add_control(
			'products_pagination',
			[
				'label' => esc_html__( 'Pagination', 'ecommerce-addon' ),
				'type' => Controls_Manager::SWITCHER,
				'label_on' => esc_html__( 'Show', 'ecommerce-addon' ),
				'label_off' => esc_html__( 'Hide', 'ecommerce-addon' ),
				'return_value' => 'true',
				'default' => 'true',
			]
		);
		$this->add_control(
			'btn_text',
			[
				'label' => esc_html__( 'Button Text', 'ecommerce-addon' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Quick View', 'ecommerce-addon' ),
				'placeholder' => esc_html__( 'Type title text here', 'ecommerce-addon' ),
				'label_block' => true,
				'separator' => 'before',
				'condition' => [
					'product_style' => 'two',
				],
			] 
		);
		$this->end_controls_section();// end: Section

		// Section
			$this->start_controls_section(
				'sectn_style',
				[
					'label' => esc_html__( 'Section', 'ecommerce-addon' ),
					'tab' => Controls_Manager::TAB_STYLE,
				]
			);
			$this->add_responsive_control(
				'section_padding',
				[
					'label' => __( 'Padding', 'ecommerce-addon' ),
					'type' => Controls_Manager::DIMENSIONS,
					'size_units' => [ 'px', '%', 'em' ],
					'selectors' => [
						'{{WRAPPER}} .product-items figure' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
					],
				]
			);
			$this->add_responsive_control(
				'section_margin',
				[
					'label' => __( 'Margin', 'ecommerce-addon' ),
					'type' => Controls_Manager::DIMENSIONS,
					'size_units' => [ 'px', '%', 'em' ],
					'selectors' => [
						'{{WRAPPER}} .product-items figure' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
					],
				]
			);
			$this->add_responsive_control(
				'section_in_padding',
				[
					'label' => __( 'Inner Padding', 'ecommerce-addon' ),
					'type' => Controls_Manager::DIMENSIONS,
					'size_units' => [ 'px', '%', 'em' ],
					'selectors' => [
						'{{WRAPPER}} .product-items figcaption' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
					],
				]
			);
			$this->add_group_control(
				Group_Control_Background::get_type(),
				[
					'name' => 'secn_bg_color',
					'label' => __( 'Background Color', 'ecommerce-addon' ),
					'types' => [ 'classic', 'gradient' ],
					'selector' => '{{WRAPPER}} .product-items figcaption',
				]
			);
			$this->add_group_control(
				Group_Control_Border::get_type(),
				[
					'name' => 'secn_border',
					'label' => esc_html__( 'Border', 'ecommerce-addon' ),
					'selector' => '{{WRAPPER}} .product-items figure',
				]
			);
			$this->add_group_control(
				Group_Control_Box_Shadow::get_type(),
				[
					'name' => 'secn_box_shadow',
					'label' => esc_html__( 'Section Box Shadow', 'ecommerce-addon' ),
					'selector' => '{{WRAPPER}} .product-items figure',
				]
			);
			$this->end_controls_section();// end: Section

		// Filter
			$this->start_controls_section(
				'section_filter_style',
				[
					'label' => esc_html__( 'Filter', 'ecommerce-addon' ),
					'tab' => Controls_Manager::TAB_STYLE,
					'condition' => [
						'need_filter' => 'true',
					],
					'frontend_available' => true,
				]
			);
			$this->add_group_control(
				Group_Control_Typography::get_type(),
				[
					'name' => 'filter_typography',
					'selector' => '{{WRAPPER}} .naeca-order-filter ul li a',
				]
			);
			$this->start_controls_tabs( 'filter_style' );
				$this->start_controls_tab(
					'filter_normal',
					[
						'label' => esc_html__( 'Normal', 'ecommerce-addon' ),
					]
				);
				$this->add_control(
					'filter_color',
					[
						'label' => esc_html__( 'Color', 'ecommerce-addon' ),
						'type' => Controls_Manager::COLOR,
						'selectors' => [
							'{{WRAPPER}} .naeca-order-filter ul li a' => 'color: {{VALUE}};',
						],
					]
				);
				$this->add_control(
					'filter_bg_color',
					[
						'label' => esc_html__( 'Color', 'ecommerce-addon' ),
						'type' => Controls_Manager::COLOR,
						'selectors' => [
							'{{WRAPPER}} .naeca-order-filter ul li a' => 'background-color: {{VALUE}};',
						],
					]
				);
				$this->end_controls_tab();  // end:Normal tab
				$this->start_controls_tab(
					'filter_active',
					[
						'label' => esc_html__( 'Active', 'ecommerce-addon' ),
					]
				);
				$this->add_control(
					'filter_active_color',
					[
						'label' => esc_html__( 'Color', 'ecommerce-addon' ),
						'type' => Controls_Manager::COLOR,
						'selectors' => [
							'{{WRAPPER}} .naeca-order-filter ul li.active a, {{WRAPPER}} .naeca-order-filter ul li a:hover' => 'color: {{VALUE}}',
						],
					]
				);
				$this->add_control(
					'filter_active_bg_color',
					[
						'label' => esc_html__( 'Color', 'ecommerce-addon' ),
						'type' => Controls_Manager::COLOR,
						'selectors' => [
							'{{WRAPPER}} .naeca-order-filter ul li.active a' => 'background-color: {{VALUE}};',
						],
					]
				);
				$this->add_control(
					'filter_active_border_color',
					[
						'label' => esc_html__( 'Border Color', 'ecommerce-addon' ),
						'type' => Controls_Manager::COLOR,
						'selectors' => [
							'{{WRAPPER}} .naeca-order-filter ul li.active a' => 'border-color: {{VALUE}};',
						],
					]
				);
				$this->end_controls_tab();  // end:Active tab
			$this->end_controls_tabs(); // end tabs		
			$this->end_controls_section();// end: Section

		// Title
			$this->start_controls_section(
				'section_title_style',
				[
					'label' => esc_html__( 'Title', 'ecommerce-addon' ),
					'tab' => Controls_Manager::TAB_STYLE,
				]
			);
			$this->add_responsive_control(
				'title_margin',
				[
					'label' => __( 'Title Spacing', 'ecommerce-addon' ),
					'type' => Controls_Manager::DIMENSIONS,
					'size_units' => [ 'px' ],
					'selectors' => [
						'{{WRAPPER}} .product-items figure h4' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
					],
				]
			);
			$this->add_group_control(
				Group_Control_Typography::get_type(),
				[
					'label' => esc_html__( 'Typography', 'ecommerce-addon' ),
					'name' => 'sastool_title_typography',
					'selector' => '{{WRAPPER}} .product-items figure h4',
				]
			);
			$this->start_controls_tabs( 'title_style' );
				$this->start_controls_tab(
					'title_normal',
					[
						'label' => esc_html__( 'Normal', 'ecommerce-addon' ),
					]
				);
				$this->add_control(
					'title_color',
					[
						'label' => esc_html__( 'Color', 'ecommerce-addon' ),
						'type' => Controls_Manager::COLOR,
						'selectors' => [
							'{{WRAPPER}} .product-items figure h4, {{WRAPPER}} .product-items figure h4 a' => 'color: {{VALUE}};',
						],
					]
				);
				$this->end_controls_tab();  // end:Normal tab
				$this->start_controls_tab(
					'title_hover',
					[
						'label' => esc_html__( 'Hover', 'ecommerce-addon' ),
					]
				);
				$this->add_control(
					'title_hover_color',
					[
						'label' => esc_html__( 'Color', 'ecommerce-addon' ),
						'type' => Controls_Manager::COLOR,
						'selectors' => [
							'{{WRAPPER}} .product-items figure h4 a:hover' => 'color: {{VALUE}};',
						],
					]
				);
				$this->end_controls_tab();  // end:Hover tab
			$this->end_controls_tabs(); // end tabs
			$this->end_controls_section();// end: Section

		// Content
			$this->start_controls_section(
				'section_content_style',
				[
					'label' => esc_html__( 'Content', 'ecommerce-addon' ),
					'tab' => Controls_Manager::TAB_STYLE,
					'condition' => [
						'product_style' => 'one',
					],
				]
			);
			$this->add_responsive_control(
				'cont_padding',
				[
					'label' => __( 'Content Padding', 'ecommerce-addon' ),
					'type' => Controls_Manager::DIMENSIONS,
					'size_units' => [ 'px', '%', 'em' ],
					'selectors' => [
						'{{WRAPPER}} .side-navigation-style-two .product-items figure p' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
					],
				]
			);
			$this->add_group_control(
				Group_Control_Typography::get_type(),
				[
					'label' => esc_html__( 'Typography', 'ecommerce-addon' ),
					'name' => 'content_typography',
					'selector' => '{{WRAPPER}} .side-navigation-style-two .product-items figure p',
				]
			);
			$this->add_control(
				'content_color',
				[
					'label' => esc_html__( 'Color', 'ecommerce-addon' ),
					'type' => Controls_Manager::COLOR,
					'selectors' => [
						'{{WRAPPER}} .side-navigation-style-two .product-items figure p' => 'color: {{VALUE}};',
					],
				]
			);
			$this->end_controls_section();// end: Section

		// Categories
			$this->start_controls_section(
				'section_cats_style',
				[
					'label' => esc_html__( 'Categories', 'ecommerce-addon' ),
					'tab' => Controls_Manager::TAB_STYLE,
				]
			);
			$this->add_responsive_control(
				'cats_margin',
				[
					'label' => __( 'Categories Spacing', 'ecommerce-addon' ),
					'type' => Controls_Manager::DIMENSIONS,
					'size_units' => [ 'px' ],
					'selectors' => [
						'{{WRAPPER}} .product-items figure h5' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
					],
				]
			);
			$this->add_group_control(
				Group_Control_Typography::get_type(),
				[
					'label' => esc_html__( 'Typography', 'ecommerce-addon' ),
					'name' => 'sastool_cats_typography',
					'selector' => '{{WRAPPER}} .product-items figure h5',
				]
			);
			$this->start_controls_tabs( 'cats_style' );
				$this->start_controls_tab(
					'cats_normal',
					[
						'label' => esc_html__( 'Normal', 'ecommerce-addon' ),
					]
				);
				$this->add_control(
					'cats_color',
					[
						'label' => esc_html__( 'Color', 'ecommerce-addon' ),
						'type' => Controls_Manager::COLOR,
						'selectors' => [
							'{{WRAPPER}} .product-items figure h5, {{WRAPPER}} .product-items figure h5 a' => 'color: {{VALUE}};',
						],
					]
				);
				$this->end_controls_tab();  // end:Normal tab
				$this->start_controls_tab(
					'cats_hover',
					[
						'label' => esc_html__( 'Hover', 'ecommerce-addon' ),
					]
				);
				$this->add_control(
					'cats_hover_color',
					[
						'label' => esc_html__( 'Color', 'ecommerce-addon' ),
						'type' => Controls_Manager::COLOR,
						'selectors' => [
							'{{WRAPPER}} .product-items figure h5 a:hover' => 'color: {{VALUE}};',
						],
					]
				);
				$this->end_controls_tab();  // end:Hover tab
			$this->end_controls_tabs(); // end tabs
			$this->end_controls_section();// end: Section

		// Price
			$this->start_controls_section(
				'section_price_style',
				[
					'label' => esc_html__( 'Price', 'ecommerce-addon' ),
					'tab' => Controls_Manager::TAB_STYLE,
				]
			);
			$this->add_responsive_control(
				'price_margin',
				[
					'label' => __( 'Price Margin', 'ecommerce-addon' ),
					'type' => Controls_Manager::DIMENSIONS,
					'size_units' => [ 'px', '%', 'em' ],
					'selectors' => [
						'{{WRAPPER}} .product-items figure h6' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
					],
				]
			);
			$this->add_responsive_control(
				'price_padding',
				[
					'label' => __( 'Price Padding', 'ecommerce-addon' ),
					'type' => Controls_Manager::DIMENSIONS,
					'size_units' => [ 'px', '%', 'em' ],
					'selectors' => [
						'{{WRAPPER}} .product-items figure h6' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
					],
				]
			);
			$this->add_group_control(
				Group_Control_Typography::get_type(),
				[
					'label' => esc_html__( 'Typography', 'ecommerce-addon' ),
					'name' => 'price_typography',
					'selector' => '{{WRAPPER}} .product-items figure h6',
				]
			);
			$this->add_control(
				'price_color',
				[
					'label' => esc_html__( 'Color', 'ecommerce-addon' ),
					'type' => Controls_Manager::COLOR,
					'selectors' => [
						'{{WRAPPER}} .product-items figure h6' => 'color: {{VALUE}};',
					],
				]
			);
			$this->add_control(
				'price_bg_color',
				[
					'label' => esc_html__( 'Background Color', 'ecommerce-addon' ),
					'type' => Controls_Manager::COLOR,
					'selectors' => [
						'{{WRAPPER}} .product-items figure h6' => 'background: {{VALUE}};',
					],
				]
			);
			$this->end_controls_section();// end: Section

		// Link
			$this->start_controls_section(
				'section_btn_style',
				[
					'label' => esc_html__( 'Link', 'ecommerce-addon' ),
					'tab' => Controls_Manager::TAB_STYLE,
				]
			);
			$this->add_responsive_control(
				'btn_margin',
				[
					'label' => __( 'Margin', 'ecommerce-addon' ),
					'type' => Controls_Manager::DIMENSIONS,
					'size_units' => [ 'px' ],
					'selectors' => [
						'{{WRAPPER}} .product-actions .added_to_cart, {{WRAPPER}} .product-actions .button, {{WRAPPER}} .view-product' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
					],
				]
			);
			$this->add_responsive_control(
				'btn_padding',
				[
					'label' => __( 'Padding', 'ecommerce-addon' ),
					'type' => Controls_Manager::DIMENSIONS,
					'size_units' => [ 'px' ],
					'selectors' => [
						'{{WRAPPER}} .product-actions .added_to_cart, {{WRAPPER}} .product-actions .button, {{WRAPPER}} .view-product' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
					],
				]
			);
			$this->add_group_control(
				Group_Control_Typography::get_type(),
				[
					'label' => esc_html__( 'Typography', 'ecommerce-addon' ),
					'name' => 'btn_typography',
					'selector' => '{{WRAPPER}} .product-actions .added_to_cart, {{WRAPPER}} .product-actions .button, {{WRAPPER}} .view-product',
				]
			);
			$this->start_controls_tabs( 'btn_style' );
				$this->start_controls_tab(
					'btn_normal',
					[
						'label' => esc_html__( 'Normal', 'ecommerce-addon' ),
					]
				);
				$this->add_control(
					'btn_color',
					[
						'label' => esc_html__( 'Color', 'ecommerce-addon' ),
						'type' => Controls_Manager::COLOR,
						'selectors' => [
							'{{WRAPPER}} .product-actions .added_to_cart, {{WRAPPER}} .product-actions .button, {{WRAPPER}} .view-product' => 'color: {{VALUE}};',
						],
					]
				);
				$this->add_group_control(
					Group_Control_Border::get_type(),
					[
						'name' => 'btn_border',
						'label' => esc_html__( 'Border', 'ecommerce-addon' ),
						'selector' => '{{WRAPPER}} .product-actions .added_to_cart, {{WRAPPER}} .product-actions .button, {{WRAPPER}} .view-product',
					]
				);
				$this->end_controls_tab();  // end:Normal tab
				$this->start_controls_tab(
					'btn_hover',
					[
						'label' => esc_html__( 'Hover', 'ecommerce-addon' ),
					]
				);
				$this->add_control(
					'btn_hover_color',
					[
						'label' => esc_html__( 'Color', 'ecommerce-addon' ),
						'type' => Controls_Manager::COLOR,
						'selectors' => [
							'{{WRAPPER}} .product-actions .added_to_cart:hover, {{WRAPPER}} .product-actions .button:hover, {{WRAPPER}} .view-product:hover' => 'color: {{VALUE}};',
						],
					]
				);
				$this->add_group_control(
					Group_Control_Border::get_type(),
					[
						'name' => 'btn_hover_border',
						'label' => esc_html__( 'Border', 'ecommerce-addon' ),
						'selector' => '{{WRAPPER}} .product-actions .added_to_cart:hover, {{WRAPPER}} .product-actions .button:hover, {{WRAPPER}} .view-product:hover',
					]
				);
				$this->end_controls_tab();  // end:Hover tab
			$this->end_controls_tabs(); // end tabs
			$this->end_controls_section();// end: Section

	}

	/**
	 * Render Product widget output on the frontend.
	 * Written in PHP and used to generate the final HTML.
	*/
	protected function render() {
		// Product query
		$settings = $this->get_settings_for_display();
		$product_style = !empty( $settings['product_style'] ) ? $settings['product_style'] : '';
		$need_filter = !empty( $settings['need_filter'] ) ? $settings['need_filter'] : '';
		$pr_limit = !empty( $settings['pr_limit'] ) ? $settings['pr_limit'] : '';
		$pr_order = !empty( $settings['pr_order'] ) ? $settings['pr_order'] : '';
		$pr_orderby = !empty( $settings['pr_orderby'] ) ? $settings['pr_orderby'] : '';
		$pr_column = !empty( $settings['pr_column'] ) ? $settings['pr_column'] : '';
		$pr_cats = !empty( $settings['pr_cats'] ) ? $settings['pr_cats'] : [];
		$products_pagination = !empty( $settings['products_pagination'] ) ? $settings['products_pagination'] : '';
		$btn_text = !empty( $settings['btn_text'] ) ? $settings['btn_text'] : '';

		$cat_limit = !empty( $settings['cat_limit'] ) ? $settings['cat_limit'] : '';
		$cat_limit = $cat_limit ? $cat_limit : '3';

		if ($need_filter) {
			$wrap_cls = ' masonry-wrap';
			$row_cls = ' naeca-masonry';
      $item_class = ' masonry-item';
		} else {
			$wrap_cls = '';
			$row_cls = '';
      $item_class = '';
		}

		if ($product_style === 'two') {
			$style_cls = ' products-style-two';
		} else {
			$style_cls = '';
		}

		$btn_text = $btn_text ? $btn_text : esc_html__( 'Quick View', 'ecommerce-addon' );

		// Columns
		if($pr_column === 'col-2') {
      $col_class = 'nich-col-xl-6 nich-col-lg-6 nich-col-sm-6';
    } elseif($pr_column === 'col-3') {
      $col_class = 'nich-col-xl-4 nich-col-lg-4 nich-col-sm-6';
    } elseif($pr_column === 'col-4') {
      $col_class = 'nich-col-xl-3 nich-col-lg-4 nich-col-sm-6';
    } else {
      $col_class = 'nich-col-md-12';
    }

    global $paged;
	    if( get_query_var( 'paged' ) )
	      $my_page = get_query_var( 'paged' );
	    else {
	      if( get_query_var( 'page' ) )
	        $my_page = get_query_var( 'page' );
	      else
	        $my_page = 1;
	      set_query_var( 'paged', $my_page );
	      $paged = $my_page;
	    }

	    $args = array(
        'paged'          => (int)$my_page,
        'post_type'      => 'product',
	      'posts_per_page' => (int)$pr_limit,
        'order'          => $pr_order,
        'product_cat'    => $pr_cats,
        'orderby'        => $pr_orderby,
        'tax_query'      => array(
                              array(
                                'taxonomy' => 'product_visibility',
                                'field'    => 'name',
                                'terms'    => 'exclude-from-catalog',
                                'operator' => 'NOT IN',
                              )
                            ), 
	    );

	    $naeca_products = new \WP_Query($args);

	    // Turn output buffer on
	    ob_start(); ?>

      <div class="naeca-products<?php echo esc_attr($style_cls.$wrap_cls); ?>">
        <?php if ($need_filter) { ?>  
          <div class="naeca-order-filter normal-filter">
          	<ul class="naeca-order-list">
		          <li class="active"><a href="javascript:void(0);" data-limit="<?php echo esc_attr($pr_limit); ?>" data-filter="*"><?php echo esc_html__( 'All', 'ecommerce-addon' ); ?></a></li>
		          <?php
		            if ($pr_cats) {
		              $terms = $pr_cats;
		              $count = count($terms);
		              if ($count > 0) {
					          $f=0;
		                foreach ($terms as $term) {
		                  echo '<li class="cat-'. preg_replace('/\s+/', "", strtolower($term)) .'"><a href="javascript:void(0);" data-limit="'.$pr_limit.'" data-cat="'. esc_attr($term->slug) .'" data-filter=".cat-'. preg_replace('/\s+/', "", strtolower($term)) .'" title="' . str_replace('-', " ", strtolower($term)) . '">' . str_replace('-', " ", ucwords($term)) . '</a></li>';
					            $f++;
											if($f==$cat_limit) break;
		                 }
		              }
		            } else {
		            	$terms = get_terms('product_cat');
						      $count = count($terms);
						      $i=0;
						      $term_list = '';
						      if ($count > 0) {
					          $f=0;
						        foreach ($terms as $term) {
						          $i++;
						          $term_list .= '<li><a href="javascript:void(0);" data-limit="'.$pr_limit.'" data-cat="'. esc_attr($term->slug) .'" class="filter cat-'. esc_attr($term->slug) .'" data-filter=".cat-'. esc_attr($term->slug) .'" title="' . esc_attr($term->name) . '">' . esc_html($term->name) . '</a></li>';
						          if ($count != $i) {
						            $term_list .= '';
						          } else {
						            $term_list .= '';
						          }
					            $f++;
											if($f==$cat_limit) break;
						        }
						        echo $term_list;
						      }
		            }
		          ?>
		        </ul>
          </div>
        <?php } ?>
        <div class="product-items nich-row<?php echo esc_attr($row_cls); ?>">   
        <?php
          if ($naeca_products->have_posts()) : while ($naeca_products->have_posts()) : $naeca_products->the_post();   
		      	global $post;
            global $product; 
            $large_image =  wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'fullsize', false, '' );
		  			$large_image = $large_image[0];
            $product_thumbnail_id = get_post_thumbnail_id(); 
            $price = $product->get_price_html();

            $naeca_terms = wp_get_post_terms($post->ID,'product_cat');
						foreach ($naeca_terms as $term) {
						  $naeca_cat_class = 'cat-' . $term->slug;
						}
						$naeca_count = count($naeca_terms);
						$i=0;
						$naeca_cat_class = '';
						if ($naeca_count > 0) {
						  foreach ($naeca_terms as $term) {
						    $i++;
						    $naeca_cat_class .= 'cat-'. $term->slug .' ';
						    if ($naeca_count != $i) {
						      $naeca_cat_class .= '';
						    } else {
						      $naeca_cat_class .= '';
						    }
						  }
						}
            ?>
      			<div class="<?php echo esc_attr($col_class.$item_class); ?> <?php echo esc_attr($naeca_cat_class); ?>" data-category="<?php echo esc_attr($naeca_cat_class); ?>">
							<?php if ($product_style === 'two') { ?>
								<figure>
	                <?php if ( defined( 'YITH_WCWL' ) ) {
                    echo do_shortcode('[yith_wcwl_add_to_wishlist icon="fa-heart"]');
                  } ?>
	                <div class="naeca-image">
	                  <a href="<?php echo esc_url( get_permalink() ); ?>"><img src="<?php echo esc_url($large_image); ?>" alt="<?php echo esc_attr(get_the_title()); ?>"></a>
	                  <div class="product-actions naeca-popup">
	                    <?php woocommerce_template_loop_add_to_cart( $naeca_products->post, $product ); ?>
	                    <a href="<?php echo esc_url($large_image); ?>" data-title="<h4><a href='<?php echo get_the_permalink($product->get_id()); ?>''><?php echo get_the_title(); ?></a></h4>" data-price='<h6><?php echo $price; ?></h6>' class="popup view-product"><i class="fa fa-eye"></i> <?php echo $btn_text; ?></a>
	                  </div>
	                </div>
	                <figcaption>
	                  <h4><a href="<?php echo get_the_permalink($product->get_id()); ?>"><?php echo get_the_title(); ?></a></h4>
	                  <h6><?php echo $product->get_price_html(); ?></h6>
	                </figcaption>
	              </figure>
							<?php } else { ?>
	              <figure>
	                <div class="naeca-image">
	                  <a href="<?php echo esc_url( get_permalink() ); ?>"><img src="<?php echo esc_url($large_image); ?>" alt="<?php echo esc_attr(get_the_title()); ?>"></a>
	                </div>
	                <figcaption>
	                  <h4><a href="<?php echo get_the_permalink($product->get_id()); ?>"><?php echo get_the_title(); ?></a></h4>
	                  <h5>
							        <?php
							          $category_list = wp_get_post_terms($product->get_id(), 'product_cat');
							          foreach ($category_list as $term) {
							          	$term_link = get_term_link( $term );
							            echo '<span><a href="'. esc_url($term_link) .'">'. esc_html($term->name) .'</a></span> ';
							          }
							        ?>
							      </h5>
	                  <h6><?php echo $product->get_price_html(); ?></h6>
	                  <div class="product-actions naeca-popup">
	                    <?php woocommerce_template_loop_add_to_cart( $naeca_products->post, $product ); ?>
	                    <a href="<?php echo esc_url($large_image); ?>" data-title="<h4><a href='<?php echo get_the_permalink($product->get_id()); ?>''><?php echo get_the_title(); ?></a></h4>" data-price='<h6><?php echo $price; ?></h6>'  class="popup"><i class="fa fa-search"></i></a>
	                    <?php if ( defined( 'YITH_WCWL' ) ) {
		                    echo do_shortcode('[yith_wcwl_add_to_wishlist icon="fa-heart"]');
		                  } ?>
	                  </div>
	                </figcaption>
	              </figure>
	            <?php } ?>
    				</div>
            <?php
          	endwhile; endif; ?>
          </div>
	    	<?php if ($products_pagination) { 
          echo '<div class="naeca-pagenavi">';
	          echo naecommerce_paging_nav($naeca_products->max_num_pages,"",$paged);
			  	echo '</div>';
        }
		  	wp_reset_postdata(); ?>
    	</div>
		<?php
		// Return outbut buffer
		echo ob_get_clean();

	}

}
Plugin::instance()->widgets_manager->register_widget_type( new eCommerce_Elementor_Addon_Product() );

}
} // enable & disable
