'name', 'tab_index' => true, 'hierarchical' => true, 'show_count' => true, 'class' =>'kb-amz-select-width-100', 'name' => $this->get_field_name('category'), 'selected' => $category, 'show_option_all' => __('Use For All Categories') )); ?>

'name', 'class' =>'kb-amz-select-width-100', 'name' => $this->get_field_name('page'), 'selected' => $page, 'show_option_none' => __('Use For All Pages') )); ?>

id_base.($number ? $number : $this->number).$name); } public static function getWidgets() { return self::$kbWidgets; } public static function getWidgetsFilters() { $where = array(); foreach (self::getWidgets() as $widget) { if (method_exists($widget, 'getWidgetQueryFilter')) { $str = $widget->getWidgetQueryFilter(); if ($str) { $where[] = $str; } } } return $where; } protected function setFilterKeyUsed($key) { self::$kbFilterUsed[$key] = true; } public function getFilterKeyUsed($key) { return isset(self::$kbFilterUsed[$key]) && self::$kbFilterUsed[$key]; } public function isKbAllowedToShow($instance) { if (isset($instance['page']) && !empty($instance['page'])) { if (!is_page($instance['page'])) { return false; } } if (isset($instance['category']) && !empty($instance['category']) && !getKbAmz()->isCurrentCategory($instance['category'])) { return false; } if (isset($instance['categoryAndPageOnly']) && $instance['categoryAndPageOnly']) { return true; } if ((is_single() || is_page())) { if (hasKbPostShortCode('listProduct') && !getKbAmz()->isPostProduct(get_the_ID())) { return true; } return false; } return true; } } class kbAmazonShomProductCategories extends KbAmzWidget { function __construct() { parent::__construct( 'kbAmazonShomProductCategories', 'Kb Product Categories', array() ); getKbAmz()->addWidgetsType('productCategories', array( 'label' => 'Product Categories', 'description' => __('Show Product Categories with products count.') )); } public function widget($args, $instance) { $instance['categoryAndPageOnly'] = true; if (!$this->isKbAllowedToShow($instance)) { return; } $title = apply_filters('widget_title', $instance['title']); echo $args['before_widget']; if (!empty($title)) echo $args['before_title'] . $title . $args['after_title']; $cats = get_categories( array( 'orderby' => isset($instance['orderby']) ? $instance['orderby'] : 'count', 'order' => 'asc', 'number' => isset($instance['number']) ? $instance['number'] : 10, 'child_of' => isset($instance['child_of']) ? $instance['child_of'] : 0, ) ); $categories = array(); echo ''; echo $args['after_widget']; } public function form($instance) { $instance['disableMeta'] = true; parent::form($instance); $childOf = isset($instance['child_of']) ? $instance['child_of'] : ''; $orderBy = isset($instance['orderby']) ? $instance['orderby'] : 'count'; $number = isset($instance['number']) ? $instance['number'] : 10; ?>

'name', 'tab_index' => true, 'hierarchical' => true, 'show_count' => true, 'class' =>'kb-amz-select-width-100', 'name' => $this->get_field_name('child_of'), 'selected' => $childOf, 'show_option_all' => ' - ' )); ?>

__('Creates number slider for given meta key.'),) // Args ); wp_enqueue_style( 'KbAmzVendorSliderCss', getKbPluginUrl() . '/template/vendors/slider/css/slider.css' ); wp_enqueue_script( 'KbAmzStoreJs', getKbPluginUrl() . '/template/vendors/slider/js/bootstrap-slider.js', array('jquery') ); add_action('pre_get_posts', array($this, 'filterQuery')); getKbAmz()->addWidgetsType('slider', array( 'label' => 'Slider', 'description' => __('This widget will get the lowest and hightest prices for all products and create slider.') )); } public function widget($args, $instance) { if (!$this->isKbAllowedToShow($instance)) { return; } $title = apply_filters('widget_title', $instance['title']); echo $args['before_widget']; if (!empty($title)) echo $args['before_title'] . $title . $args['after_title']; $minKey = $this->getKeyParam('min'); $maxKey = $this->getKeyParam('max'); $id = uniqid('kb-slider-'); $url = kbGetUrlWithParams(array($minKey => '__MIN__', $maxKey => '__MAX__')); $min = !isset($_GET[$minKey]) ? '' : (int) $_GET[$minKey]; $max = !isset($_GET[$maxKey]) ? '' : (int) $_GET[$maxKey]; $minMax = getKbAmz()->getMinMaxMetaWidgetMethod( $instance['meta_key'] ); $dbMin = $minMax[0]; $dbMax = $minMax[1]; $min = $dbMin > $min || $min == '' ? $dbMin : $min; $max = $max > $dbMax || $max == '' ? $dbMax : $max; $min = floor($min); $max = ceil($max); ?>
is_main_query() && !kbAmzIsMainQuery()) { return; } if ($query->is_category() || $query->is_front_page() || $query->is_search() || kbAmzIsMainQuery()) { $settings = $this->get_settings(); foreach ($settings as $baseKey => $args) { $minKey = $this->getKeyParam('min', $baseKey); $maxKey = $this->getKeyParam('max', $baseKey); if (isset($_GET[$minKey]) && isset($_GET[$maxKey])) { $key = $args['meta_key']; $min = (int) $_GET[$minKey]; $max = (int) $_GET[$maxKey]; $meta = $query->get('meta_query'); if (empty($meta)) { $meta = array(); } $settings = $this->get_settings(); $meta[] = array( 'key' => $key, 'value' => array($min, $max), 'type' => 'numeric', 'compare' => 'BETWEEN' ); $query->set('meta_query', $meta); } } } } public function getWidgetQueryFilter() { global $wpdb; $settings = $this->get_settings(); $data = array('join' => array(), 'where' => array()); foreach ($settings as $baseKey => $args) { $minKey = $this->getKeyParam('min', $baseKey); $maxKey = $this->getKeyParam('max', $baseKey); if (isset($_GET[$minKey]) && isset($_GET[$maxKey])) { $key = $args['meta_key']; $min = (int) $_GET[$minKey]; $max = (int) $_GET[$maxKey]; $dbkey = uniqid('nm'); $data['join'][] = "JOIN $wpdb->postmeta AS $dbkey ON $dbkey.post_id = t.post_id"; $data['where'][] = "$dbkey.meta_key = '$key' AND $dbkey.meta_value BETWEEN $min AND $max"; } } return $data; } public function form($instance) { parent::form($instance); } public function update($new, $old) { return parent::update($new, $old); } } function kbAmazonShopSliderWidgetLoadWidget() { register_widget('kbAmazonShopSliderWidget'); } add_action('widgets_init', 'kbAmazonShopSliderWidgetLoadWidget'); /* ****************************************************************************** */ class kbAmazonShopAttributeCount extends KbAmzWidget { function __construct() { parent::__construct( 'kbamzattr', // Base ID __('Kb Shop Attribute Count'), // Name array('description' => __('Creates list with attributes.'),) // Args ); add_action('pre_get_posts', array($this, 'filterQuery')); getKbAmz()->addWidgetsType('attributes', array( 'label' => 'Attributes', 'description' => __('This widget will group the selected attribute and create filter link on it.') )); } public function widget($args, $instance) { if (!$this->isKbAllowedToShow($instance)) { return; } $title = apply_filters('widget_title', $instance['title']); $key = $this->getKeyParam(); $items = getKbAmz()->getMetaCountListWidgetMethod( $instance['meta_key'], (isset($instance['number']) ? $instance['number'] : null), (isset($instance['order']) ? $instance['order'] : null) ); if (!empty($items)) { echo $args['before_widget']; if (!empty($title)) echo $args['before_title'] . $title . $args['after_title']; echo ''; echo $args['after_widget']; } } public function getWidgetQueryFilter() { global $wpdb; $base = strtolower($this->id_base); $baseLength = strlen($base); $data = array('join' => array(), 'where' => array()); if (!empty($_GET)) { foreach ($_GET as $name => $metaId) { if (substr($name, 0, $baseLength) == $base) { $row = getKbAmz()->getMetaDataById($metaId); if ($row) { $dbkey = uniqid('nm'); $data['join'][] = "JOIN $wpdb->postmeta AS $dbkey ON $dbkey.post_id = t.post_id"; $data['where'][] = "$dbkey.meta_key = '$row->meta_key' AND $dbkey.meta_value = '$row->meta_value'"; } } } } return $data; } public function filterQuery(WP_Query $query) { // isKbAmzQuery if (!$query->is_main_query() && !kbAmzIsMainQuery()) { return; } if ($query->is_category() || $query->is_front_page() || $query->is_search() || kbAmzIsMainQuery()) { $base = strtolower($this->id_base); $baseLength = strlen($base); if (!empty($_GET)) { foreach ($_GET as $name => $metaId) { if (substr($name, 0, $baseLength) == $base) { $row = getKbAmz()->getMetaDataById($metaId); if ($row) { $meta = $query->get('meta_query'); if (empty($meta)) { $meta = array(); } $meta[] = array( 'key' => $row->meta_key, 'value' => $row->meta_value, 'compare' => '=' ); $query->set('meta_query', $meta); } } } } } } public function form($instance) { parent::form($instance); $number = isset($instance['number']) ? $instance['number'] : 6; $order = isset($instance['order']) ? $instance['order'] : null; ?>