Initial commit - Dutchie dispensary scraper

This commit is contained in:
Kelly
2025-11-28 19:45:44 -07:00
commit 5757a8e9bd
23375 changed files with 3788799 additions and 0 deletions

View File

@@ -0,0 +1,317 @@
<?php
/**
* Elementor Product Grid Widget
*/
if (!defined('ABSPATH')) {
exit;
}
class Dutchie_Menus_Product_Grid_Widget extends \Elementor\Widget_Base {
public function get_name() {
return 'dutchie_product_grid';
}
public function get_title() {
return __('Dutchie Product Grid', 'dutchie-menus');
}
public function get_icon() {
return 'eicon-products';
}
public function get_categories() {
return ['general'];
}
protected function register_controls() {
// Content Section
$this->start_controls_section(
'content_section',
[
'label' => __('Content', 'dutchie-menus'),
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'store_id',
[
'label' => __('Store ID', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::NUMBER,
'default' => get_option('dutchie_default_store_id', 1),
'min' => 1,
]
);
$this->add_control(
'category_id',
[
'label' => __('Category ID', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::NUMBER,
'default' => '',
'description' => __('Leave empty to show all categories', 'dutchie-menus'),
]
);
$this->add_control(
'limit',
[
'label' => __('Number of Products', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::NUMBER,
'default' => 12,
'min' => 1,
'max' => 100,
]
);
$this->add_control(
'columns',
[
'label' => __('Columns', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => '3',
'options' => [
'2' => __('2 Columns', 'dutchie-menus'),
'3' => __('3 Columns', 'dutchie-menus'),
'4' => __('4 Columns', 'dutchie-menus'),
'6' => __('6 Columns', 'dutchie-menus'),
],
]
);
$this->add_control(
'in_stock_only',
[
'label' => __('In Stock Only', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => __('Yes', 'dutchie-menus'),
'label_off' => __('No', 'dutchie-menus'),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'search',
[
'label' => __('Search Filter', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => '',
'description' => __('Filter products by name', 'dutchie-menus'),
]
);
$this->end_controls_section();
// Display Options Section
$this->start_controls_section(
'display_section',
[
'label' => __('Display Options', 'dutchie-menus'),
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'show_image',
[
'label' => __('Show Image', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => __('Yes', 'dutchie-menus'),
'label_off' => __('No', 'dutchie-menus'),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'show_price',
[
'label' => __('Show Price', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => __('Yes', 'dutchie-menus'),
'label_off' => __('No', 'dutchie-menus'),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'show_thc',
[
'label' => __('Show THC', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => __('Yes', 'dutchie-menus'),
'label_off' => __('No', 'dutchie-menus'),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'show_cbd',
[
'label' => __('Show CBD', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => __('Yes', 'dutchie-menus'),
'label_off' => __('No', 'dutchie-menus'),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'show_description',
[
'label' => __('Show Description', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => __('Yes', 'dutchie-menus'),
'label_off' => __('No', 'dutchie-menus'),
'return_value' => 'yes',
'default' => 'no',
]
);
$this->end_controls_section();
// Style Section
$this->start_controls_section(
'style_section',
[
'label' => __('Style', 'dutchie-menus'),
'tab' => \Elementor\Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'card_background',
[
'label' => __('Card Background', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::COLOR,
'default' => '#ffffff',
'selectors' => [
'{{WRAPPER}} .dutchie-product-card' => 'background-color: {{VALUE}};',
],
]
);
$this->add_control(
'card_border_radius',
[
'label' => __('Border Radius', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::SLIDER,
'size_units' => ['px'],
'range' => [
'px' => [
'min' => 0,
'max' => 50,
],
],
'default' => [
'size' => 8,
],
'selectors' => [
'{{WRAPPER}} .dutchie-product-card' => 'border-radius: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_control(
'text_color',
[
'label' => __('Text Color', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::COLOR,
'default' => '#333333',
'selectors' => [
'{{WRAPPER}} .dutchie-product-card' => 'color: {{VALUE}};',
],
]
);
$this->end_controls_section();
}
protected function render() {
$settings = $this->get_settings_for_display();
$args = [
'store_id' => $settings['store_id'],
'limit' => $settings['limit'],
'in_stock' => $settings['in_stock_only'] === 'yes' ? 'true' : 'false',
];
if (!empty($settings['category_id'])) {
$args['category_id'] = $settings['category_id'];
}
if (!empty($settings['search'])) {
$args['search'] = $settings['search'];
}
$plugin = Dutchie_Menus_Plugin::instance();
$products = $plugin->fetch_products($args);
if (!$products) {
echo '<p>' . __('No products found.', 'dutchie-menus') . '</p>';
return;
}
$columns = $settings['columns'];
?>
<div class="dutchie-product-grid dutchie-grid-cols-<?php echo esc_attr($columns); ?>">
<?php foreach ($products as $product): ?>
<div class="dutchie-product-card">
<?php if ($settings['show_image'] === 'yes' && !empty($product['image_url_full'])): ?>
<div class="dutchie-product-image">
<img src="<?php echo esc_url($product['image_url_full']); ?>"
alt="<?php echo esc_attr($product['name']); ?>"
loading="lazy" />
</div>
<?php endif; ?>
<div class="dutchie-product-content">
<h3 class="dutchie-product-title">
<?php echo esc_html($product['name']); ?>
</h3>
<?php if ($settings['show_description'] === 'yes' && !empty($product['description'])): ?>
<p class="dutchie-product-description">
<?php echo esc_html(wp_trim_words($product['description'], 15)); ?>
</p>
<?php endif; ?>
<div class="dutchie-product-meta">
<?php if ($settings['show_thc'] === 'yes' && !empty($product['metadata']['thc'])): ?>
<span class="dutchie-meta-item dutchie-thc">
<strong>THC:</strong> <?php echo esc_html($product['metadata']['thc']); ?>
</span>
<?php endif; ?>
<?php if ($settings['show_cbd'] === 'yes' && !empty($product['metadata']['cbd'])): ?>
<span class="dutchie-meta-item dutchie-cbd">
<strong>CBD:</strong> <?php echo esc_html($product['metadata']['cbd']); ?>
</span>
<?php endif; ?>
</div>
<?php if ($settings['show_price'] === 'yes' && isset($product['price'])): ?>
<div class="dutchie-product-price">
$<?php echo number_format($product['price'], 2); ?>
</div>
<?php endif; ?>
<?php if (!$product['in_stock']): ?>
<div class="dutchie-out-of-stock">
<?php _e('Out of Stock', 'dutchie-menus'); ?>
</div>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php
}
}

View File

@@ -0,0 +1,325 @@
<?php
/**
* Elementor Single Product Widget
*/
if (!defined('ABSPATH')) {
exit;
}
class Dutchie_Menus_Single_Product_Widget extends \Elementor\Widget_Base {
public function get_name() {
return 'dutchie_single_product';
}
public function get_title() {
return __('Dutchie Single Product', 'dutchie-menus');
}
public function get_icon() {
return 'eicon-single-product';
}
public function get_categories() {
return ['general'];
}
protected function register_controls() {
// Content Section
$this->start_controls_section(
'content_section',
[
'label' => __('Content', 'dutchie-menus'),
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'product_id',
[
'label' => __('Product ID', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::NUMBER,
'default' => '',
'description' => __('Enter the product ID to display', 'dutchie-menus'),
]
);
$this->add_control(
'layout',
[
'label' => __('Layout', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'horizontal',
'options' => [
'horizontal' => __('Horizontal', 'dutchie-menus'),
'vertical' => __('Vertical', 'dutchie-menus'),
],
]
);
$this->end_controls_section();
// Display Options Section
$this->start_controls_section(
'display_section',
[
'label' => __('Display Options', 'dutchie-menus'),
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'show_image',
[
'label' => __('Show Image', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => __('Yes', 'dutchie-menus'),
'label_off' => __('No', 'dutchie-menus'),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'show_price',
[
'label' => __('Show Price', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => __('Yes', 'dutchie-menus'),
'label_off' => __('No', 'dutchie-menus'),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'show_description',
[
'label' => __('Show Description', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => __('Yes', 'dutchie-menus'),
'label_off' => __('No', 'dutchie-menus'),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'show_thc',
[
'label' => __('Show THC', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => __('Yes', 'dutchie-menus'),
'label_off' => __('No', 'dutchie-menus'),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'show_cbd',
[
'label' => __('Show CBD', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => __('Yes', 'dutchie-menus'),
'label_off' => __('No', 'dutchie-menus'),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'show_terpenes',
[
'label' => __('Show Terpenes', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => __('Yes', 'dutchie-menus'),
'label_off' => __('No', 'dutchie-menus'),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'show_effects',
[
'label' => __('Show Effects', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => __('Yes', 'dutchie-menus'),
'label_off' => __('No', 'dutchie-menus'),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'show_brand',
[
'label' => __('Show Brand', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => __('Yes', 'dutchie-menus'),
'label_off' => __('No', 'dutchie-menus'),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->end_controls_section();
// Style Section
$this->start_controls_section(
'style_section',
[
'label' => __('Style', 'dutchie-menus'),
'tab' => \Elementor\Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'background_color',
[
'label' => __('Background Color', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::COLOR,
'default' => '#ffffff',
'selectors' => [
'{{WRAPPER}} .dutchie-single-product' => 'background-color: {{VALUE}};',
],
]
);
$this->add_control(
'border_radius',
[
'label' => __('Border Radius', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::SLIDER,
'size_units' => ['px'],
'range' => [
'px' => [
'min' => 0,
'max' => 50,
],
],
'default' => [
'size' => 8,
],
'selectors' => [
'{{WRAPPER}} .dutchie-single-product' => 'border-radius: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_control(
'text_color',
[
'label' => __('Text Color', 'dutchie-menus'),
'type' => \Elementor\Controls_Manager::COLOR,
'default' => '#333333',
'selectors' => [
'{{WRAPPER}} .dutchie-single-product' => 'color: {{VALUE}};',
],
]
);
$this->end_controls_section();
}
protected function render() {
$settings = $this->get_settings_for_display();
if (empty($settings['product_id'])) {
echo '<p>' . __('Please enter a product ID.', 'dutchie-menus') . '</p>';
return;
}
$plugin = Dutchie_Menus_Plugin::instance();
$product = $plugin->fetch_product($settings['product_id']);
if (!$product) {
echo '<p>' . __('Product not found.', 'dutchie-menus') . '</p>';
return;
}
$layout = $settings['layout'];
?>
<div class="dutchie-single-product dutchie-layout-<?php echo esc_attr($layout); ?>">
<?php if ($settings['show_image'] === 'yes' && !empty($product['image_url_full'])): ?>
<div class="dutchie-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="dutchie-single-product-details">
<h2 class="dutchie-single-product-title">
<?php echo esc_html($product['name']); ?>
</h2>
<?php if ($settings['show_brand'] === 'yes' && !empty($product['brand'])): ?>
<div class="dutchie-single-product-brand">
<strong><?php _e('Brand:', 'dutchie-menus'); ?></strong>
<?php echo esc_html($product['brand']); ?>
</div>
<?php endif; ?>
<?php if ($settings['show_description'] === 'yes' && !empty($product['description'])): ?>
<div class="dutchie-single-product-description">
<?php echo wp_kses_post(nl2br($product['description'])); ?>
</div>
<?php endif; ?>
<div class="dutchie-single-product-info">
<?php if ($settings['show_thc'] === 'yes' && !empty($product['metadata']['thc'])): ?>
<div class="dutchie-info-item">
<strong><?php _e('THC:', 'dutchie-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="dutchie-info-item">
<strong><?php _e('CBD:', 'dutchie-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="dutchie-info-item dutchie-terpenes">
<strong><?php _e('Terpenes:', 'dutchie-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="dutchie-info-item dutchie-effects">
<strong><?php _e('Effects:', 'dutchie-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="dutchie-single-product-price">
$<?php echo number_format($product['price'], 2); ?>
</div>
<?php endif; ?>
<?php if (!$product['in_stock']): ?>
<div class="dutchie-out-of-stock">
<?php _e('Out of Stock', 'dutchie-menus'); ?>
</div>
<?php endif; ?>
</div>
</div>
<?php
}
}