Files
cannaiq/wordpress-plugin/widgets/product-grid.php
Kelly 511629b4e6 Rename WordPress plugin from Dutchie Menus to Crawlsy Menus v1.3.0
- Renamed plugin to avoid WordPress.org naming conflict causing false update notifications
- Added /downloads static route to serve plugin zip file
- Updated all CSS classes from dutchie- to crawlsy- prefix
- Added plugin zip to backend/public/downloads for hosting
- Plugin available at: https://dispos.crawlsy.com/downloads/crawlsy-menus-1.3.0.zip

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-01 16:29:21 -07:00

318 lines
11 KiB
PHP

<?php
/**
* Elementor Product Grid Widget
*/
if (!defined('ABSPATH')) {
exit;
}
class Crawlsy_Menus_Product_Grid_Widget extends \Elementor\Widget_Base {
public function get_name() {
return 'crawlsy_product_grid';
}
public function get_title() {
return __('Crawlsy Product Grid', 'crawlsy-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', 'crawlsy-menus'),
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'store_id',
[
'label' => __('Store ID', 'crawlsy-menus'),
'type' => \Elementor\Controls_Manager::NUMBER,
'default' => get_option('crawlsy_default_store_id', 1),
'min' => 1,
]
);
$this->add_control(
'category_id',
[
'label' => __('Category ID', 'crawlsy-menus'),
'type' => \Elementor\Controls_Manager::NUMBER,
'default' => '',
'description' => __('Leave empty to show all categories', 'crawlsy-menus'),
]
);
$this->add_control(
'limit',
[
'label' => __('Number of Products', 'crawlsy-menus'),
'type' => \Elementor\Controls_Manager::NUMBER,
'default' => 12,
'min' => 1,
'max' => 100,
]
);
$this->add_control(
'columns',
[
'label' => __('Columns', 'crawlsy-menus'),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => '3',
'options' => [
'2' => __('2 Columns', 'crawlsy-menus'),
'3' => __('3 Columns', 'crawlsy-menus'),
'4' => __('4 Columns', 'crawlsy-menus'),
'6' => __('6 Columns', 'crawlsy-menus'),
],
]
);
$this->add_control(
'in_stock_only',
[
'label' => __('In Stock Only', '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(
'search',
[
'label' => __('Search Filter', 'crawlsy-menus'),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => '',
'description' => __('Filter products by name', '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_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_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' => 'no',
]
);
$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(
'card_background',
[
'label' => __('Card Background', 'crawlsy-menus'),
'type' => \Elementor\Controls_Manager::COLOR,
'default' => '#ffffff',
'selectors' => [
'{{WRAPPER}} .crawlsy-product-card' => 'background-color: {{VALUE}};',
],
]
);
$this->add_control(
'card_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-product-card' => 'border-radius: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_control(
'text_color',
[
'label' => __('Text Color', 'crawlsy-menus'),
'type' => \Elementor\Controls_Manager::COLOR,
'default' => '#333333',
'selectors' => [
'{{WRAPPER}} .crawlsy-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 = Crawlsy_Menus_Plugin::instance();
$products = $plugin->fetch_products($args);
if (!$products) {
echo '<p>' . __('No products found.', 'crawlsy-menus') . '</p>';
return;
}
$columns = $settings['columns'];
?>
<div class="crawlsy-product-grid crawlsy-grid-cols-<?php echo esc_attr($columns); ?>">
<?php foreach ($products as $product): ?>
<div class="crawlsy-product-card">
<?php if ($settings['show_image'] === 'yes' && !empty($product['image_url_full'])): ?>
<div class="crawlsy-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="crawlsy-product-content">
<h3 class="crawlsy-product-title">
<?php echo esc_html($product['name']); ?>
</h3>
<?php if ($settings['show_description'] === 'yes' && !empty($product['description'])): ?>
<p class="crawlsy-product-description">
<?php echo esc_html(wp_trim_words($product['description'], 15)); ?>
</p>
<?php endif; ?>
<div class="crawlsy-product-meta">
<?php if ($settings['show_thc'] === 'yes' && !empty($product['metadata']['thc'])): ?>
<span class="crawlsy-meta-item crawlsy-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="crawlsy-meta-item crawlsy-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="crawlsy-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 endforeach; ?>
</div>
<?php
}
}