The job_run_logs table tracks scheduled job orchestration, not individual worker jobs. Worker info (worker_id, worker_hostname) belongs on dispensary_crawl_jobs, not job_run_logs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
374 lines
13 KiB
PHP
374 lines
13 KiB
PHP
<?php
|
|
/**
|
|
* Elementor Single Product Widget
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class Crawlsy_Menus_Single_Product_Widget extends \Elementor\Widget_Base {
|
|
|
|
public function get_name() {
|
|
return 'crawlsy_single_product';
|
|
}
|
|
|
|
public function get_title() {
|
|
return __('Crawlsy Single Product', 'crawlsy-menus');
|
|
}
|
|
|
|
public function get_icon() {
|
|
return 'eicon-single-product';
|
|
}
|
|
|
|
public function get_categories() {
|
|
return ['general'];
|
|
}
|
|
|
|
/**
|
|
* Get products for the SELECT2 dropdown
|
|
*
|
|
* @return array Associative array of product_id => product_name
|
|
*/
|
|
protected function get_products_for_select() {
|
|
$options = ['' => __('-- Select a Product --', 'crawlsy-menus')];
|
|
|
|
$plugin = Crawlsy_Menus_Plugin::instance();
|
|
$products = $plugin->fetch_products(['limit' => 500]);
|
|
|
|
if ($products && is_array($products)) {
|
|
foreach ($products as $product) {
|
|
$label = $product['name'];
|
|
if (!empty($product['brand'])) {
|
|
$label = $product['brand'] . ' - ' . $label;
|
|
}
|
|
if (!empty($product['category'])) {
|
|
$label .= ' (' . $product['category'] . ')';
|
|
}
|
|
$options[$product['id']] = $label;
|
|
}
|
|
}
|
|
|
|
return $options;
|
|
}
|
|
|
|
protected function register_controls() {
|
|
|
|
// Content Section
|
|
$this->start_controls_section(
|
|
'content_section',
|
|
[
|
|
'label' => __('Content', 'crawlsy-menus'),
|
|
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
|
|
]
|
|
);
|
|
|
|
// Get products for the select dropdown
|
|
$products_options = $this->get_products_for_select();
|
|
|
|
$this->add_control(
|
|
'product_id',
|
|
[
|
|
'label' => __('Select Product', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SELECT2,
|
|
'options' => $products_options,
|
|
'default' => '',
|
|
'label_block' => true,
|
|
'description' => __('Search and select a product to display', 'crawlsy-menus'),
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'product_id_manual',
|
|
[
|
|
'label' => __('Or Enter Product ID', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::NUMBER,
|
|
'default' => '',
|
|
'description' => __('Manually enter a product ID if not found in dropdown', 'crawlsy-menus'),
|
|
'condition' => [
|
|
'product_id' => '',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'layout',
|
|
[
|
|
'label' => __('Layout', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SELECT,
|
|
'default' => 'horizontal',
|
|
'options' => [
|
|
'horizontal' => __('Horizontal', 'crawlsy-menus'),
|
|
'vertical' => __('Vertical', 'crawlsy-menus'),
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->end_controls_section();
|
|
|
|
// Display Options Section
|
|
$this->start_controls_section(
|
|
'display_section',
|
|
[
|
|
'label' => __('Display Options', 'crawlsy-menus'),
|
|
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_image',
|
|
[
|
|
'label' => __('Show Image', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'crawlsy-menus'),
|
|
'label_off' => __('No', 'crawlsy-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_price',
|
|
[
|
|
'label' => __('Show Price', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'crawlsy-menus'),
|
|
'label_off' => __('No', 'crawlsy-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_description',
|
|
[
|
|
'label' => __('Show Description', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'crawlsy-menus'),
|
|
'label_off' => __('No', 'crawlsy-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_thc',
|
|
[
|
|
'label' => __('Show THC', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'crawlsy-menus'),
|
|
'label_off' => __('No', 'crawlsy-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_cbd',
|
|
[
|
|
'label' => __('Show CBD', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'crawlsy-menus'),
|
|
'label_off' => __('No', 'crawlsy-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_terpenes',
|
|
[
|
|
'label' => __('Show Terpenes', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'crawlsy-menus'),
|
|
'label_off' => __('No', 'crawlsy-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_effects',
|
|
[
|
|
'label' => __('Show Effects', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'crawlsy-menus'),
|
|
'label_off' => __('No', 'crawlsy-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_brand',
|
|
[
|
|
'label' => __('Show Brand', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'crawlsy-menus'),
|
|
'label_off' => __('No', 'crawlsy-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
|
|
$this->end_controls_section();
|
|
|
|
// Style Section
|
|
$this->start_controls_section(
|
|
'style_section',
|
|
[
|
|
'label' => __('Style', 'crawlsy-menus'),
|
|
'tab' => \Elementor\Controls_Manager::TAB_STYLE,
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'background_color',
|
|
[
|
|
'label' => __('Background Color', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#ffffff',
|
|
'selectors' => [
|
|
'{{WRAPPER}} .crawlsy-single-product' => 'background-color: {{VALUE}};',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'border_radius',
|
|
[
|
|
'label' => __('Border Radius', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SLIDER,
|
|
'size_units' => ['px'],
|
|
'range' => [
|
|
'px' => [
|
|
'min' => 0,
|
|
'max' => 50,
|
|
],
|
|
],
|
|
'default' => [
|
|
'size' => 8,
|
|
],
|
|
'selectors' => [
|
|
'{{WRAPPER}} .crawlsy-single-product' => 'border-radius: {{SIZE}}{{UNIT}};',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'text_color',
|
|
[
|
|
'label' => __('Text Color', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#333333',
|
|
'selectors' => [
|
|
'{{WRAPPER}} .crawlsy-single-product' => 'color: {{VALUE}};',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->end_controls_section();
|
|
}
|
|
|
|
protected function render() {
|
|
$settings = $this->get_settings_for_display();
|
|
|
|
// Use dropdown selection, or fall back to manual ID
|
|
$product_id = !empty($settings['product_id']) ? $settings['product_id'] : $settings['product_id_manual'];
|
|
|
|
if (empty($product_id)) {
|
|
echo '<p>' . __('Please select or enter a product ID.', 'crawlsy-menus') . '</p>';
|
|
return;
|
|
}
|
|
|
|
$plugin = Crawlsy_Menus_Plugin::instance();
|
|
$product = $plugin->fetch_product($product_id);
|
|
|
|
if (!$product) {
|
|
echo '<p>' . __('Product not found.', 'crawlsy-menus') . '</p>';
|
|
return;
|
|
}
|
|
|
|
$layout = $settings['layout'];
|
|
?>
|
|
<div class="crawlsy-single-product crawlsy-layout-<?php echo esc_attr($layout); ?>">
|
|
<?php if ($settings['show_image'] === 'yes' && !empty($product['image_url_full'])): ?>
|
|
<div class="crawlsy-single-product-image">
|
|
<img src="<?php echo esc_url($product['image_url_full']); ?>"
|
|
alt="<?php echo esc_attr($product['name']); ?>" />
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="crawlsy-single-product-details">
|
|
<h2 class="crawlsy-single-product-title">
|
|
<?php echo esc_html($product['name']); ?>
|
|
</h2>
|
|
|
|
<?php if ($settings['show_brand'] === 'yes' && !empty($product['brand'])): ?>
|
|
<div class="crawlsy-single-product-brand">
|
|
<strong><?php _e('Brand:', 'crawlsy-menus'); ?></strong>
|
|
<?php echo esc_html($product['brand']); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($settings['show_description'] === 'yes' && !empty($product['description'])): ?>
|
|
<div class="crawlsy-single-product-description">
|
|
<?php echo wp_kses_post(nl2br($product['description'])); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="crawlsy-single-product-info">
|
|
<?php if ($settings['show_thc'] === 'yes' && !empty($product['metadata']['thc'])): ?>
|
|
<div class="crawlsy-info-item">
|
|
<strong><?php _e('THC:', 'crawlsy-menus'); ?></strong>
|
|
<span><?php echo esc_html($product['metadata']['thc']); ?></span>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($settings['show_cbd'] === 'yes' && !empty($product['metadata']['cbd'])): ?>
|
|
<div class="crawlsy-info-item">
|
|
<strong><?php _e('CBD:', 'crawlsy-menus'); ?></strong>
|
|
<span><?php echo esc_html($product['metadata']['cbd']); ?></span>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($settings['show_terpenes'] === 'yes' && !empty($product['metadata']['terpenes'])): ?>
|
|
<div class="crawlsy-info-item crawlsy-terpenes">
|
|
<strong><?php _e('Terpenes:', 'crawlsy-menus'); ?></strong>
|
|
<?php if (is_array($product['metadata']['terpenes'])): ?>
|
|
<span><?php echo esc_html(implode(', ', $product['metadata']['terpenes'])); ?></span>
|
|
<?php else: ?>
|
|
<span><?php echo esc_html($product['metadata']['terpenes']); ?></span>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($settings['show_effects'] === 'yes' && !empty($product['metadata']['effects'])): ?>
|
|
<div class="crawlsy-info-item crawlsy-effects">
|
|
<strong><?php _e('Effects:', 'crawlsy-menus'); ?></strong>
|
|
<?php if (is_array($product['metadata']['effects'])): ?>
|
|
<span><?php echo esc_html(implode(', ', $product['metadata']['effects'])); ?></span>
|
|
<?php else: ?>
|
|
<span><?php echo esc_html($product['metadata']['effects']); ?></span>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php if ($settings['show_price'] === 'yes' && isset($product['price'])): ?>
|
|
<div class="crawlsy-single-product-price">
|
|
$<?php echo number_format($product['price'], 2); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!$product['in_stock']): ?>
|
|
<div class="crawlsy-out-of-stock">
|
|
<?php _e('Out of Stock', 'crawlsy-menus'); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|