New Widgets: - Brand Grid: Display brands in a grid with product counts - Category List: Show categories in grid/list/pills layouts - Specials Grid: Display products on sale with discount badges Enhanced Product Grid Widget: - Dynamic category dropdown (fetches from API) - Dynamic brand dropdown (fetches from API) - "On Special Only" toggle filter New Plugin Methods: - fetch_categories() - Get categories from API - fetch_brands() - Get brands from API - fetch_specials() - Get products on sale - get_category_options() - Cached options for Elementor - get_brand_options() - Cached options for Elementor 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
289 lines
9.8 KiB
PHP
289 lines
9.8 KiB
PHP
<?php
|
|
/**
|
|
* Elementor Specials/Deals Grid Widget
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class CannaIQ_Menus_Specials_Grid_Widget extends \Elementor\Widget_Base {
|
|
|
|
public function get_name() {
|
|
return 'cannaiq_specials_grid';
|
|
}
|
|
|
|
public function get_title() {
|
|
return __('CannaIQ Specials/Deals', 'cannaiq-menus');
|
|
}
|
|
|
|
public function get_icon() {
|
|
return 'eicon-price-table';
|
|
}
|
|
|
|
public function get_categories() {
|
|
return ['general'];
|
|
}
|
|
|
|
protected function register_controls() {
|
|
|
|
// Content Section
|
|
$this->start_controls_section(
|
|
'content_section',
|
|
[
|
|
'label' => __('Content', 'cannaiq-menus'),
|
|
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'store_id',
|
|
[
|
|
'label' => __('Store ID', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::NUMBER,
|
|
'default' => get_option('cannaiq_default_store_id', 1),
|
|
'min' => 1,
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'limit',
|
|
[
|
|
'label' => __('Number of Products', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::NUMBER,
|
|
'default' => 8,
|
|
'min' => 1,
|
|
'max' => 50,
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'columns',
|
|
[
|
|
'label' => __('Columns', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::SELECT,
|
|
'default' => '4',
|
|
'options' => [
|
|
'2' => __('2 Columns', 'cannaiq-menus'),
|
|
'3' => __('3 Columns', 'cannaiq-menus'),
|
|
'4' => __('4 Columns', 'cannaiq-menus'),
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'category',
|
|
[
|
|
'label' => __('Category', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::SELECT,
|
|
'default' => '',
|
|
'options' => CannaIQ_Menus_Plugin::instance()->get_category_options(),
|
|
'description' => __('Filter specials by category', 'cannaiq-menus'),
|
|
]
|
|
);
|
|
|
|
$this->end_controls_section();
|
|
|
|
// Display Options Section
|
|
$this->start_controls_section(
|
|
'display_section',
|
|
[
|
|
'label' => __('Display Options', 'cannaiq-menus'),
|
|
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_image',
|
|
[
|
|
'label' => __('Show Image', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'cannaiq-menus'),
|
|
'label_off' => __('No', 'cannaiq-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_discount_badge',
|
|
[
|
|
'label' => __('Show Discount Badge', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'cannaiq-menus'),
|
|
'label_off' => __('No', 'cannaiq-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_original_price',
|
|
[
|
|
'label' => __('Show Original Price', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'cannaiq-menus'),
|
|
'label_off' => __('No', 'cannaiq-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_thc',
|
|
[
|
|
'label' => __('Show THC', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'cannaiq-menus'),
|
|
'label_off' => __('No', 'cannaiq-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'no',
|
|
]
|
|
);
|
|
|
|
$this->end_controls_section();
|
|
|
|
// Style Section
|
|
$this->start_controls_section(
|
|
'style_section',
|
|
[
|
|
'label' => __('Style', 'cannaiq-menus'),
|
|
'tab' => \Elementor\Controls_Manager::TAB_STYLE,
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'card_background',
|
|
[
|
|
'label' => __('Card Background', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#ffffff',
|
|
'selectors' => [
|
|
'{{WRAPPER}} .cannaiq-special-card' => 'background-color: {{VALUE}};',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'badge_background',
|
|
[
|
|
'label' => __('Badge Background', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#ef4444',
|
|
'selectors' => [
|
|
'{{WRAPPER}} .cannaiq-discount-badge' => 'background-color: {{VALUE}};',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'sale_price_color',
|
|
[
|
|
'label' => __('Sale Price Color', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#16a34a',
|
|
'selectors' => [
|
|
'{{WRAPPER}} .cannaiq-price-sale' => 'color: {{VALUE}};',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'card_border_radius',
|
|
[
|
|
'label' => __('Border Radius', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::SLIDER,
|
|
'size_units' => ['px'],
|
|
'range' => [
|
|
'px' => [
|
|
'min' => 0,
|
|
'max' => 50,
|
|
],
|
|
],
|
|
'default' => [
|
|
'size' => 8,
|
|
],
|
|
'selectors' => [
|
|
'{{WRAPPER}} .cannaiq-special-card' => 'border-radius: {{SIZE}}{{UNIT}};',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->end_controls_section();
|
|
}
|
|
|
|
protected function render() {
|
|
$settings = $this->get_settings_for_display();
|
|
|
|
$args = [
|
|
'store_id' => $settings['store_id'],
|
|
'limit' => $settings['limit'],
|
|
];
|
|
|
|
if (!empty($settings['category'])) {
|
|
$args['type'] = $settings['category'];
|
|
}
|
|
|
|
$plugin = CannaIQ_Menus_Plugin::instance();
|
|
$products = $plugin->fetch_specials($args);
|
|
|
|
if (!$products) {
|
|
echo '<p>' . __('No specials found.', 'cannaiq-menus') . '</p>';
|
|
return;
|
|
}
|
|
|
|
$columns = $settings['columns'];
|
|
?>
|
|
<div class="cannaiq-specials-grid cannaiq-grid-cols-<?php echo esc_attr($columns); ?>">
|
|
<?php foreach ($products as $product):
|
|
$image_url = $product['image_url'] ?? $product['primary_image_url'] ?? '';
|
|
$product_url = !empty($product['menu_url']) ? $product['menu_url'] : '#';
|
|
$regular_price = $product['regular_price'] ?? 0;
|
|
$sale_price = $product['sale_price'] ?? $regular_price;
|
|
$discount = ($regular_price > 0 && $sale_price < $regular_price)
|
|
? round((($regular_price - $sale_price) / $regular_price) * 100)
|
|
: 0;
|
|
?>
|
|
<div class="cannaiq-special-card"
|
|
<?php if ($product_url !== '#'): ?>onclick="window.open('<?php echo esc_url($product_url); ?>', '_blank')"<?php endif; ?>
|
|
style="cursor: <?php echo ($product_url !== '#') ? 'pointer' : 'default'; ?>;">
|
|
|
|
<?php if ($settings['show_discount_badge'] === 'yes' && $discount > 0): ?>
|
|
<div class="cannaiq-discount-badge">
|
|
-<?php echo esc_html($discount); ?>%
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($settings['show_image'] === 'yes' && !empty($image_url)): ?>
|
|
<div class="cannaiq-special-image">
|
|
<img src="<?php echo esc_url($image_url); ?>"
|
|
alt="<?php echo esc_attr($product['name']); ?>"
|
|
loading="lazy" />
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="cannaiq-special-content">
|
|
<h3 class="cannaiq-special-title">
|
|
<?php echo esc_html($product['name']); ?>
|
|
</h3>
|
|
|
|
<?php if ($settings['show_thc'] === 'yes' && !empty($product['thc_percentage'])): ?>
|
|
<span class="cannaiq-meta-item cannaiq-thc">
|
|
THC: <?php echo esc_html($product['thc_percentage']); ?>%
|
|
</span>
|
|
<?php endif; ?>
|
|
|
|
<div class="cannaiq-special-price">
|
|
<span class="cannaiq-price-sale">$<?php echo esc_html($sale_price); ?></span>
|
|
<?php if ($settings['show_original_price'] === 'yes' && $regular_price > $sale_price): ?>
|
|
<span class="cannaiq-price-regular cannaiq-strikethrough">$<?php echo esc_html($regular_price); ?></span>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|