{% macro titleField(product) %} {%- import "_includes/forms" as forms -%} {{ forms.textField({ label: "Title"|t('commerce'), site: product.site, id: 'title', name: 'title', value: product.title, placeholder: 'Enter title'|t('commerce'), errors: product.getErrors('title'), first: true, autofocus: true, required: true, maxlength: 255 }) }} {% endmacro %} {% macro generalMetaFields(product) %} {%- import "_includes/forms" as forms -%} {{ forms.textField({ label: "Slug"|t('commerce'), site: product.site, id: 'slug', name: 'slug', value: product.slug, placeholder: 'Enter slug'|t('commerce'), errors: product.getErrors('slug')|merge(product.getErrors('uri')) }) }} {{ forms.dateTimeField({ label: 'Post Date'|t('commerce'), id: 'postDate', name: 'postDate', value: product.postDate, errors: product.getErrors('postDate') }) }} {{ forms.dateTimeField({ label: 'Expiry Date'|t('commerce'), id: 'expiryDate', name: 'expiryDate', value: product.expiryDate, errors: product.getErrors('expiryDate') }) }} {% endmacro %} {% macro behavioralMetaFields(product) %} {%- import "_includes/forms" as forms -%} {% if product.getType().taxCategories|length > 1 %} {% set taxCategories = [] %} {% for taxCategory in product.getType().taxCategories %} {% set taxCategories = taxCategories|merge([{'value': taxCategory.id, 'label': taxCategory.name}]) %} {% endfor %} {{ forms.selectField({ label: 'Tax Category'|t('commerce'), name: 'taxCategoryId', value: product.taxCategoryId, required: true, options: taxCategories }) }} {% else %} {{ forms.hidden({ name: "taxCategoryId", value: product.taxCategoryId }) }} {% endif %} {% if product.getType().shippingCategories|length > 1 %} {% set shippingCategories = [] %} {% for shippingCategory in product.getType().shippingCategories %} {% set shippingCategories = shippingCategories|merge([{'value': shippingCategory.id, 'label': shippingCategory.name}]) %} {% endfor %} {{ forms.selectField({ label: 'Shipping Category'|t('commerce'), name: 'shippingCategoryId', value: product.shippingCategoryId, required: true, options: shippingCategories }) }} {% else %} {{ forms.hidden({ name: "shippingCategoryId", value: product.shippingCategoryId }) }} {% endif %} {{ forms.checkboxField({ id: 'available-for-purchase', fieldLabel: 'Available for purchase'|t('commerce'), name: 'availableForPurchase', checked: product.availableForPurchase, }) }} {{ forms.checkboxField({ id: 'free-shipping', fieldLabel: 'Free Shipping'|t('commerce'), name: 'freeShipping', checked: product.freeShipping, }) }} {{ forms.checkboxField({ id: 'promotable', fieldLabel: 'Promotable'|t('commerce'), name: 'promotable', checked: product.promotable, }) }} {% endmacro %} {% macro generalVariantFields(variant) %} {%- import "_includes/forms" as forms -%} {%- import "commerce/_includes/forms/commerceForms" as commerceForms -%} {% if variant.product.getType().hasVariantTitleField and variant.product.getType().hasVariants %} {{ forms.textField({ label: "Title"|t('commerce'), site: variant.site, id: 'title', name: 'title', value: variant.title, placeholder: 'Enter title'|t('commerce'), errors: variant.getErrors('title'), first: true, required: true, maxlength: 255 }) }} {% endif %} {{ forms.textField({ id: 'sku', label: 'SKU'|t('commerce'), required: true, name: 'sku', value: variant.sku, placeholder: 'Enter SKU'|t('commerce'), class: 'code', errors: variant.getErrors('sku') }) }} {{ forms.textField({ id: 'price', label: 'Price'|t('commerce')~' ('~craft.commerce.paymentCurrencies.primaryPaymentCurrency.iso|upper~')', name: 'price', value: (variant.price == '0' ? '0'|number : (variant.price ? variant.price|number ?: '')), placeholder: 'Enter price'|t('commerce'), required: true, errors: variant.getErrors('price') }) }} {% set stockInput %}
{{ forms.text({ id: 'stock', name: 'stock', value: (variant.hasUnlimitedStock ? '' : (variant.stock == '0' ? '0': (variant.stock ? variant.stock : ''))), placeholder: 'Enter stock'|t('commerce'), disabled: variant.hasUnlimitedStock }) }}
{{ forms.checkbox({ id: 'unlimited-stock', class: 'unlimited-stock', label: 'Unlimited'|t('commerce'), name: 'hasUnlimitedStock', checked: variant.hasUnlimitedStock, }) }}
{% endset %} {{ forms.field({ id: 'stock', label: 'Stock'|t('commerce'), required: true, errors: variant.getErrors('hasUnlimitedStock')|merge(variant.getErrors('stock')), }, stockInput) }} {% set quantityRangeInput %}
{{ forms.text({ id: 'minQty', name: 'minQty', value: variant.minQty, placeholder: 'Any'|t('commerce'), title: 'Minimum allowed quantity'|t }) }}
{{ 'to'|t('commerce') }}
{{ forms.text({ id: 'maxQty', name: 'maxQty', value: variant.maxQty, placeholder: 'Any'|t('commerce'), title: 'Maximum allowed quantity'|t }) }}
{% endset %} {{ forms.field({ id: 'minQty', label: 'Allowed Qty'|t('commerce'), errors: variant.getErrors('minQty')|merge(variant.getErrors('maxQty')) }, quantityRangeInput) }} {% endmacro %} {% macro dimensionVariantFields(variant) %} {%- import "_includes/forms" as forms -%} {% set dimensionsInput %}
{{ forms.text({ id: 'length', name: 'length', value: (variant.length ? variant.length|number : ''), placeholder: 'Length'|t|upper[0:1], title: 'Length'|t('commerce'), unit: craft.commerce.settings.dimensionUnits, errors: variant.getErrors('length') }) }}
/
{{ forms.text({ id: 'width', name: 'width', value: (variant.width ? variant.width|number : ''), placeholder: 'Width'|t|upper[0:1], title: 'Width'|t('commerce'), unit: craft.commerce.settings.dimensionUnits, errors: variant.getErrors('width') }) }}
/
{{ forms.text({ id: 'height', name: 'height', value: (variant.height ? variant.height|number : ''), placeholder: 'Height'|t|upper[0:1], title: 'Height'|t('commerce'), unit: craft.commerce.settings.dimensionUnits, errors: variant.getErrors('height') }) }}
{{ craft.commerce.settings.dimensionUnits }}
{% endset %} {{ forms.field({ label: 'Dimensions'|t('commerce'), id: 'width' }, dimensionsInput) }} {{ forms.textField({ id: 'weight', label: 'Weight'|t('commerce'), name: 'weight', value: (variant.weight ? variant.weight|number : ''), placeholder: 'Enter weight'|t('commerce'), unit: craft.commerce.settings.weightUnits, errors: variant.getErrors('weight') }) }} {% endmacro %}