{% comment %} Custom Measurement Block - Updated for Product-Specific Fields & Add-ons File: blocks/custom_measurement_block.liquid {% endcomment %} {%- liquid # ================================ # 1. GET CONFIGURATION FROM METAFIELD # ================================ assign config = shop.metafields.custom_measurements.config # Initialize variables assign show_block = false assign button_text = 'Customize This Item' assign modal_title = 'Custom Measurements' assign instructions = '' assign save_button_text = 'Save & Add to Cart' if config and config.value assign full_config = config.value # Extract values safely assign button_text = full_config.button_text | default: 'Customize This Item' assign modal_title = full_config.modal_title | default: 'Custom Measurements' assign save_button_text = full_config.save_button_text | default: 'Save & Add to Cart' assign instructions = full_config.instructions | default: '' # ========================================== # Check if product is enabled at ALL # ========================================== assign is_enabled = false assign current_product_id = product.id | append: '' # Check 1: Is enabled_for_all TRUE? if full_config.enabled_for_all == true assign is_enabled = true elsif full_config.enabled_for_all == 1 assign is_enabled = true elsif full_config.enabled_for_all == '1' assign is_enabled = true endif # Check 2: If not enabled for all, check specific products unless is_enabled if full_config.enabled_products for enabled_id in full_config.enabled_products assign enabled_id_string = enabled_id | append: '' if enabled_id_string == current_product_id assign is_enabled = true break endif endfor endif endunless # Check 3: If still not enabled, check product types unless is_enabled if full_config.enabled_product_types and product.type != blank assign current_type = product.type | downcase for enabled_type in full_config.enabled_product_types assign enabled_type_lower = enabled_type | downcase if enabled_type_lower == current_type assign is_enabled = true break endif endfor endif endunless # Check 4: If product is enabled at all, we'll show the block # (individual field/product filtering happens in JavaScript) if is_enabled assign show_block = true endif endif # Override with block settings if provided if block.settings.button_text != blank assign button_text = block.settings.button_text endif # Get product price for display assign product_price = product.price | money_without_currency | remove: ',' | plus: 0 -%} {%- if show_block -%} {%- capture modal_id -%}custom-measurements-{{ section.id }}-{{ block.id }}{%- endcapture -%} {%- capture input_id -%}custom-measurements-data-{{ section.id }}-{{ block.id }}{%- endcapture -%}
{%- comment -%} 3. MEASUREMENTS MODAL (HIDDEN) {%- endcomment -%} {%- comment -%} 4. HIDDEN INPUT FOR MEASUREMENTS {%- endcomment -%}
{%- endif -%} {% schema %} { "name": "Custom Measurements", "target": "section", "settings": [ { "type": "header", "content": "Button Appearance" }, { "type": "text", "id": "button_text", "label": "Button Text", "info": "Leave empty to use text from configuration" }, { "type": "color", "id": "button_color", "label": "Button Color", "default": "#5c6ac4" }, { "type": "color", "id": "button_hover_color", "label": "Button Hover Color", "default": "#3f4eae" }, { "type": "color", "id": "button_text_color", "label": "Button Text Color", "default": "#ffffff" }, { "type": "text", "id": "button_padding", "label": "Button Padding", "default": "12px 24px" }, { "type": "text", "id": "button_margin", "label": "Button Margin", "default": "10px 0" }, { "type": "range", "id": "button_radius", "label": "Button Border Radius", "min": 0, "max": 20, "step": 1, "default": 6, "unit": "px" }, { "type": "range", "id": "button_font_size", "label": "Button Font Size", "min": 12, "max": 24, "step": 1, "default": 16, "unit": "px" }, { "type": "select", "id": "button_font_weight", "label": "Button Font Weight", "options": [ {"value": "400", "label": "Normal"}, {"value": "500", "label": "Medium"}, {"value": "600", "label": "Semi Bold"}, {"value": "700", "label": "Bold"} ], "default": "600" } ] } {% endschema %}