Files
cannaiq/wordpress-plugin/widgets/card-template-horizontal.php
Kelly 0b4ed48d2f
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
feat: Add premade card templates and click analytics
WordPress Plugin v2.0.0:
- Add Promo Banner widget (dark banner with deal text)
- Add Horizontal Product Row widget (wide list format)
- Add Category Card widget (image-based categories)
- Add Compact Card widget (dense grid layout)
- Add CannaiQAnalytics click tracking (tracks add_to_cart,
  product_view, promo_click, category_click events)
- Register cannaiq-templates Elementor category
- Fix branding: CannaiQAnalytics (not CannaIQAnalytics)

Backend:
- Add POST /api/analytics/click endpoint for WordPress plugin
- Accepts API token auth, records to product_click_events table
- Stores metadata: product_name, price, category, url, referrer

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-17 02:03:28 -07:00

369 lines
13 KiB
PHP

<?php
/**
* Elementor Horizontal Product Row Widget
* Wide format product display for lists
*/
if (!defined('ABSPATH')) {
exit;
}
class CannaIQ_Card_Horizontal_Widget extends \Elementor\Widget_Base {
public function get_name() {
return 'cannaiq_card_horizontal';
}
public function get_title() {
return __('CannaiQ Horizontal Product Row', 'cannaiq-menus');
}
public function get_icon() {
return 'eicon-post-list';
}
public function get_categories() {
return ['cannaiq-templates'];
}
public function get_keywords() {
return ['cannaiq', 'product', 'horizontal', 'row', 'list'];
}
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' => 10,
'min' => 1,
'max' => 50,
]
);
$this->add_control(
'category',
[
'label' => __('Category', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => '',
'options' => CannaIQ_Menus_Plugin::instance()->get_category_options(),
]
);
$this->add_control(
'specials_only',
[
'label' => __('Specials Only', '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();
// Display Options
$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,
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'show_brand',
[
'label' => __('Show Brand', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'show_thc',
[
'label' => __('Show THC', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'show_weight',
[
'label' => __('Show Weight', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'show_special_tag',
[
'label' => __('Show Special Tag', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'show_discount_badge',
[
'label' => __('Show Discount Badge', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'show_add_button',
[
'label' => __('Show Add Button', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'return_value' => 'yes',
'default' => 'yes',
]
);
$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(
'row_background',
[
'label' => __('Row Background', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::COLOR,
'default' => '#ffffff',
]
);
$this->add_control(
'border_color',
[
'label' => __('Border Color', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::COLOR,
'default' => '#e5e7eb',
]
);
$this->add_control(
'special_tag_color',
[
'label' => __('Special Tag Color', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::COLOR,
'default' => '#22c55e',
]
);
$this->add_control(
'discount_badge_color',
[
'label' => __('Discount Badge Color', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::COLOR,
'default' => '#f97316',
]
);
$this->add_control(
'add_button_color',
[
'label' => __('Add Button Color', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::COLOR,
'default' => '#22c55e',
]
);
$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();
if ($settings['specials_only'] === 'yes') {
$products = $plugin->fetch_specials($args);
} else {
$products = $plugin->fetch_products($args);
}
if (!$products) {
echo '<p>' . __('No products found.', 'cannaiq-menus') . '</p>';
return;
}
$row_bg = $settings['row_background'];
$border_color = $settings['border_color'];
$special_color = $settings['special_tag_color'];
$discount_color = $settings['discount_badge_color'];
$btn_color = $settings['add_button_color'];
?>
<div class="cannaiq-horizontal-list">
<?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'] ?? $product['price_rec'] ?? 0;
$sale_price = $product['sale_price'] ?? $product['price_rec_special'] ?? $regular_price;
$has_discount = $regular_price > 0 && $sale_price < $regular_price;
$discount_percent = $has_discount ? round((($regular_price - $sale_price) / $regular_price) * 100) : 0;
$brand = $product['brand'] ?? '';
$thc = $product['thc_percentage'] ?? '';
$weight = $product['weight'] ?? $product['subcategory'] ?? '';
$special_name = $product['special_name'] ?? '';
?>
<div class="cannaiq-horizontal-row" style="
background: <?php echo esc_attr($row_bg); ?>;
border: 1px solid <?php echo esc_attr($border_color); ?>;
border-radius: 8px;
padding: 16px;
margin-bottom: 12px;
display: flex;
align-items: center;
gap: 16px;
">
<?php if ($settings['show_image'] === 'yes' && !empty($image_url)): ?>
<div class="cannaiq-hr-image" style="flex-shrink: 0; width: 60px; height: 60px;">
<img src="<?php echo esc_url($image_url); ?>"
alt="<?php echo esc_attr($product['name']); ?>"
style="width: 100%; height: 100%; object-fit: contain; border-radius: 4px;" />
</div>
<?php endif; ?>
<div class="cannaiq-hr-info" style="flex: 1; min-width: 0;">
<div class="cannaiq-hr-name" style="font-weight: 600; font-size: 15px; margin-bottom: 4px;">
<?php echo esc_html($product['name']); ?>
</div>
<?php if ($settings['show_brand'] === 'yes' && !empty($brand)): ?>
<div class="cannaiq-hr-brand" style="color: #6b7280; font-size: 13px; margin-bottom: 4px;">
<?php echo esc_html($brand); ?>
</div>
<?php endif; ?>
<div class="cannaiq-hr-meta" style="display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px;">
<?php if ($settings['show_thc'] === 'yes' && !empty($thc)): ?>
<span style="color: #6b7280;">THC: <?php echo esc_html($thc); ?>%</span>
<?php endif; ?>
<?php if ($settings['show_special_tag'] === 'yes' && !empty($special_name)): ?>
<span style="color: <?php echo esc_attr($special_color); ?>; font-weight: 500;">
● <?php echo esc_html($special_name); ?>
</span>
<?php endif; ?>
</div>
</div>
<div class="cannaiq-hr-price" style="text-align: right; flex-shrink: 0;">
<?php if ($settings['show_weight'] === 'yes' && !empty($weight)): ?>
<div style="font-size: 12px; color: #6b7280; margin-bottom: 4px;">
<?php echo esc_html($weight); ?>
</div>
<?php endif; ?>
<div style="font-size: 18px; font-weight: 700;">
$<?php echo esc_html(number_format($sale_price, 2)); ?>
</div>
<?php if ($has_discount): ?>
<div style="display: flex; align-items: center; gap: 6px; justify-content: flex-end;">
<span style="text-decoration: line-through; color: #9ca3af; font-size: 13px;">
$<?php echo esc_html(number_format($regular_price, 2)); ?>
</span>
<?php if ($settings['show_discount_badge'] === 'yes'): ?>
<span style="
background: <?php echo esc_attr($discount_color); ?>;
color: white;
font-size: 11px;
padding: 2px 6px;
border-radius: 4px;
font-weight: 600;
"><?php echo esc_html($discount_percent); ?>% off</span>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<?php if ($settings['show_add_button'] === 'yes'): ?>
<a href="<?php echo esc_url($product_url); ?>"
target="_blank"
class="cannaiq-hr-add-btn"
style="
flex-shrink: 0;
width: 36px;
height: 36px;
background: <?php echo esc_attr($btn_color); ?>;
color: white;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
text-decoration: none;
font-size: 20px;
font-weight: bold;
transition: opacity 0.2s;
">+</a>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php
}
}