{#
Custom override for nothing field
File: views-view-field--offer_details--page_1--nothing.html.twig
#}
{% set discount = row._entity.field_discount_per_unit.value|default(0) %}
{% set thirty_percent_off = discount * 0.70 %}
{# Entity reference fields: get label instead of target_id #}
{% set field_offer_advertiser = row._entity.field_offer_advertiser.entity.label()|default('N/A') %}
{% set field_upc_sku_producer_no = row._entity.field_upc_sku_producer_no.entity.label()|default('N/A') %}
{# Dates and text fields #}
{% set field_offer_start_date = row._entity.field_offer_start_date.value|date("M j, Y") %}
{% set field_offer_end_date = row._entity.field_offer_end_date.value|date("M j, Y") %}
{% set field_offer_description = row._entity.field_offer_description.value|default('N/A') %}
{% set audience_restriction_entity = row._entity.field_audience_restriction.entity %}
{# 1. Get the RENDERED string value ("On" or "Off") for the conditional logic #}
{% set by_quantity_string = audience_restriction_entity.field_by_quantity.value|render|striptags|trim|default('Off') %}
{# 2. Get the max quantity value. Default to 0 for a cleaner output if "No Max" isn't needed. #}
{% set max_qty = audience_restriction_entity.field_offer_valid_upto.value|default(0) %}
{# NOTE: Removed the 'related_entity' variable as it was redundant and confusing the access #}
Producer Name: {{ field_offer_advertiser }}
Product Name: {{ field_upc_sku_producer_no }}
Duration: {{ field_offer_start_date }} - {{ field_offer_end_date }}
Offer Per Unit: {{ thirty_percent_off|number_format(2, '.', ',') }}
{# 3. Use the RENDERED STRING for the conditional check against "1" #}
{% if by_quantity_string == 1 %}
Max Qty: {{ max_qty }}
{% else %}
Max Qty: {{ "No Limit" }}
{% endif %}
Description: {{ field_offer_description }}