{% extends "commerce/_layouts/cp" %} {% set title = productType.id ? productType.name : 'Create a new product type'|t('commerce') %} {% set crumbs = [ { label: "Commerce Settings"|t('commerce'), url: url('commerce/settings') }, { label: "Product Types"|t('commerce'), url: url('commerce/settings/producttypes') }, ] %} {% set selectedSubnavItem = 'settings' %} {% set fullPageForm = true %} {% import "_includes/forms" as forms %} {% block content %} {{ redirectInput('commerce/settings/producttypes') }} {% if productType.id %} {% endif %}
{{ forms.textField({ first: true, label: "Name"|t('commerce'), instructions: "What this product type will be called in the CP."|t('commerce'), id: 'name', name: 'name', value: productType.name, errors: productType.getErrors('name'), autofocus: true, required: true, translatable: true }) }} {{ forms.textField({ label: "Handle"|t('commerce'), instructions: "How you’ll refer to this product type in the templates."|t('commerce'), id: 'handle', class: 'code', name: 'handle', value: productType.handle, errors: productType.getErrors('handle'), required: true }) }} {{ forms.textField({ label: "Automatic SKU Format"|t('commerce'), instructions: "What the unique auto-generated SKUs should look like, when a SKU field is submitted without a value. You can include tags that output properties, such as {ex1} or {ex2}"|t('commerce', { ex1: '{product.slug}', ex2: '{myVariantCustomField}' }), id: 'skuFormat', class: 'code ltr', name: 'skuFormat', value: productType.skuFormat, errors: productType.getErrors('skuFormat') }) }} {{ forms.textField({ label: "Order Description Format"|t('commerce'), instructions: "How this product will be described on a line item in an order. You can include tags that output properties, such as {ex1} or {ex2}"|t('commerce', { ex1: '{product.title}', ex2: '{myVariantCustomField}' }), id: 'descriptionFormat', class: 'code ltr', name: 'descriptionFormat', value: productType.descriptionFormat, errors: productType.getErrors('descriptionFormat') }) }} {{ forms.checkboxField({ label: "Show the Dimensions and Weight fields for products of this type"|t('commerce'), id: 'hasDimensions', name: 'hasDimensions', checked: productType.hasDimensions, }) }} {% macro hasVariantsField(productType) %} {% from "_includes/forms" import checkboxField %} {% set hasVariantsInstructions %} {%- spaceless %} {% if productType.id and productType.hasVariants %} {{ "Careful—your existing variant data will be deleted if you change this." }} {% endif %} {% endspaceless -%} {% endset %} {{ checkboxField({ label: "Products of this type have multiple variants"|t('commerce'), instructions: hasVariantsInstructions, id: 'hasVariants', name: 'hasVariants', checked: productType.hasVariants, toggle: '#variant-settings' }) }} {% endmacro %} {% macro templateField(productType) %} {% from "_includes/forms" import textField %} {{ textField({ label: "Product Template"|t('commerce'), instructions: "The template to use when a product’s URL is requested."|t('commerce'), id: 'template', class: 'ltr', name: 'template', value: productType.template, errors: productType.getErrors('template') }) }} {% endmacro %} {% macro titleFormatField(productType) %} {% from "_includes/forms" import textField, checkboxField %} {% endmacro %} {% from _self import hasVariantsField, titleFormatField, uriFormatText %}
{{ hasVariantsField(productType) }} {{ titleFormatField(productType) }}
{% set siteRows = [] %} {% set siteErrors = productType.getErrors('siteSettings') %} {% for site in craft.app.sites.getAllSites() %} {% set siteSettings = productType.siteSettings[site.id] ?? null %} {% if siteSettings %} {% for attribute, errors in siteSettings.getErrors() %} {% set siteErrors = siteErrors|merge(errors) %} {% endfor %} {% endif %} {% set siteRows = siteRows|merge({ (site.handle): { heading: site.name|t('site'), uriFormat: { value: siteSettings.uriFormat ?? null, hasErrors: siteSettings.hasErrors('uriFormat') ?? false }, template: { value: siteSettings.template ?? null, hasErrors: siteSettings.hasErrors('template') ?? false, } } }) %} {% endfor %} {{ forms.editableTableField({ label: "Site Settings"|t('app'), instructions: "Configure the product types’s site-specific settings."|t('app'), id: 'sites', name: 'sites', cols: { heading: { type: 'heading', heading: "Site"|t('app'), class: 'thin' }, uriFormat: { type: 'singleline', heading: "Category URI Format"|t('app'), info: "What category URIs should look like for the site."|t('app'), placeholder: "Leave blank if categories don’t have URLs"|t('app'), code: true }, template: { type: 'singleline', heading: "Template"|t('app'), info: "Which template should be loaded when an entry’s URL is requested."|t('app'), code: true }, }, rows: siteRows, staticRows: true, errors: siteErrors|unique }) }}
{% endblock %} {% if brandNewProductType %} {% js %} new Craft.HandleGenerator('#name', '#handle'); {% for site in craft.app.sites.getAllSites() %} new Craft.UriFormatGenerator('#name', '#sites tr[data-id="{{ site.handle }}"] textarea[name$="[uriFormat]"]', { suffix: '/{slug}' }); new Craft.UriFormatGenerator('#name', '#sites tr[data-id="{{ site.handle }}"] textarea[name$="[template]"]', { suffix: '/_product' }); {% endfor %} {% endjs %} {% endif %} {% js %} if (!document.getElementById('hasVariants').checked){ $('#tab-variantFields').parent().addClass('hidden'); } $('#hasVariants').on('change', function() { $('#tab-variantFields').parent().toggleClass('hidden'); }); {% endjs %}