{% extends "commerce/_layouts/cp" %} {% set crumbs = [ { label: "Commerce Settings"|t('commerce'), url: url('commerce/settings') }, { label: "Shipping Methods"|t('commerce'), url: url('commerce/shipping/shippingmethods') }, { label: shippingMethod.getName()|t('commerce'), url: url('commerce/shipping/shippingmethods/'~methodId) }, ] %} {% set selectedSubnavItem = 'shipping' %} {% set fullPageForm = true %} {% macro lazyCreateSelect(selectParams, newOptionLabel, modalHeading, html, js, action, successText) %} {% from "_includes/forms" import selectField %} {{ selectField(selectParams) }} {% js %} (function () { var $select = $('#{{ selectParams.id }}').selectize({ dropdownParent: 'body' }); var selectize = $select.get(0).selectize; selectize.addOption({ value: 'new', text: '{{ newOptionLabel|e("js") }}' }); selectize.on('item_add', function (value, $item) { if (value == 'new') { // Not a real option selectize.clear(); var $form = $( '
' ); var modal = new Garnish.Modal($form, { onHide: function () { modal.destroy(); delete modal; } }); eval('{{ js|e("js") }}'); setTimeout(function () { $form.find('.text:first').focus(); modal.updateSizeAndPosition(); $form.find('.body:first').on('resize', function () { modal.updateSizeAndPosition(); }); }, 100); $form.on('submit', function (ev) { ev.preventDefault(); $form.find('.spinner').removeClass('hidden'); var namespacedData = Garnish.getPostData($form), data = {}; for (var name in namespacedData) { data[name.replace(/^new\[([^\]]+)\]/, '$1')] = namespacedData[name]; } Craft.postActionRequest('{{ action|e("js") }}', data, function (response, textStatus) { $form.find('.spinner').addClass('hidden'); if (textStatus == 'success') { if (response.success) { Craft.cp.displayNotice('{{ successText|e("js") }}'); selectize.addOption({ value: response.id, text: response.name, $order: selectize.order - 1 }); selectize.setValue(response.id); modal.hide(); } else { Craft.ui.clearErrorsFromField($form.find('.field')); for (var attribute in response.errors) { Craft.ui.addErrorsToField($('#new-' + attribute + '-field'), response.errors[attribute]); } modal.updateSizeAndPosition(); Garnish.shake($form); } } }); }); $form.find('.cancel-btn').on('click', function () { modal.hide(); }); } }); })(); {% endjs %} {% endmacro %} {% from _self import lazyCreateSelect %} {% import "_includes/forms" as forms %} {% import "commerce/_includes/forms/commerceForms" as commerceForms %} {% set tabs = { 0: {'label':'Rule'|t('commerce'),'url':'#rule-tab'}, 1: {'label':'Conditions'|t('commerce'),'url':'#conditions-tab'}, 2: {'label':'Costs'|t('commerce'),'url':'#costs-tab'} } %} {% block content %} {{ redirectInput('commerce/shipping/shippingmethods/{methodId}#rules') }} {% if shippingRule.id %}{% endif %}{{ "Filtering conditions which describe to which orders this rule is applicable to. Write 0 to skip a condition."|t('commerce') }}
{% set shippingZoneSelectParams = { label: "Shipping Zone"|t('commerce'), instructions: "Select a shipping zone."|t('commerce'), id: 'shippingZoneId', name: 'shippingZoneId', value: shippingRule.shippingZoneId, errors: shippingRule.getErrors('shippingZoneId'), required: false, options: shippingZones, class: 'selectize fullwidth', } %} {{ lazyCreateSelect( shippingZoneSelectParams, 'New shipping zone'|t('commerce'), 'Create a new shipping zone'|t('commerce'), newShippingZoneFields, newShippingZoneJs, 'commerce/shippingZones/save', 'Shipping zone saved.'|t ) }} {{ commerceForms.numberField({ label: "Minimum Order Quantity"|t('commerce'), name: 'minQty', instructions: "The minimum number of items in the cart to match this rule. Zero matches all carts."|t('commerce'), value: shippingRule.minQty + 0, type: 'number', min: 0, errors: shippingRule.getErrors('minQty'), required: true, }) }} {{ commerceForms.numberField({ label: "Maximum Order Quantity"|t('commerce'), name: 'maxQty', instructions: "The maximum number of items in the cart to match this rule. Zero matches all carts."|t('commerce'), value: shippingRule.maxQty + 0, type: 'number', min: 0, errors: shippingRule.getErrors('maxQty'), required: true, }) }} {{ commerceForms.numberField({ label: "Minimum Order Total Value"|t('commerce'), name: 'minTotal', instructions: "The minimum total value of items in the cart (before any adjustments) to match this rule. Zero matches all carts."|t('commerce'), value: shippingRule.minTotal + 0, type: 'number', min: 0, step: 'any', errors: shippingRule.getErrors('minTotal'), required: true, }) }} {{ commerceForms.numberField({ label: "Maximum Order Total Value"|t('commerce'), name: 'maxTotal', instructions: "The maximum total value of items in the cart (before any adjustments) to match this rule. Zero matches all carts."|t('commerce'), value: shippingRule.maxTotal + 0, type: 'number', min: 0, step: 'any', errors: shippingRule.getErrors('maxTotal'), required: true, }) }} {{ commerceForms.numberField({ label: "Minimum Order Total Weight"|t('commerce'), name: 'minWeight', instructions: "The minimum weight of the cart to match this rule. Zero matches all carts."|t('commerce'), value: shippingRule.minWeight + 0, type: 'number', min: 0, step: 'any', errors: shippingRule.getErrors('minWeight'), required: true, }) }} {{ commerceForms.numberField({ label: "Maximum Order Total Weight"|t('commerce'), name: 'maxWeight', instructions: "The maximum weight of the cart to match this rule. Zero matches all carts."|t('commerce'), value: shippingRule.maxWeight + 0, type: 'number', min: 0, step: 'any', errors: shippingRule.getErrors('maxWeight'), required: true, }) }}{{ 'Name'|t('commerce') }} | {{ 'Condition'|t('commerce') }} |
---|---|
{{ shippingCategory.name }} | {{ forms.selectField({ name: 'ruleCategories['~shippingCategory.id~'][condition]', value: shippingRule.getShippingRuleCategories[shippingCategory.id].condition ?? 'allow', options: categoryShippingOptions }) }} |
{{ 'Name'|t('commerce') }} | {{ 'Per Item Rate'|t('commerce') }} | {{ 'Weight Rate'|t('commerce') }} | {{ 'Percentage Rate'|t('commerce') }} |
---|---|---|---|
{{ commerceForms.numberField({ name: 'perItemRate', value: shippingRule.perItemRate + 0, type: 'number', min: 0, step: 'any', errors: shippingRule.getErrors('perItemRate'), required: true, }) }} | {{ commerceForms.numberField({ name: 'weightRate', value: shippingRule.weightRate + 0, type: 'number', min: 0, step: 'any', errors: shippingRule.getErrors('weightRate'), required: true, }) }} | {{ commerceForms.numberField({ name: 'percentageRate', value: shippingRule.percentageRate + 0, type: 'number', min: 0, step: 'any', errors: shippingRule.getErrors('percentageRate'), required: true, }) }} | |
{{ "Category Rate Overrides"|t('commerce') }} | |||
{{ shippingCategory.name }} | {{ commerceForms.numberField({ name: 'ruleCategories['~shippingCategory.id~'][perItemRate]', placeholder: shippingRule.perItemRate + 0, class: 'categoryPerItemRate', value: perItemRate ? perItemRate + 0 : '', type: 'number', step: 'any' }) }} | {{ commerceForms.numberField({ name: 'ruleCategories['~shippingCategory.id~'][weightRate]', class: 'categoryWeightRate', placeholder: shippingRule.weightRate + 0, value: weightRate ? weightRate + 0 : '', type: 'number', step: 'any' }) }} | {{ commerceForms.numberField({ name: 'ruleCategories['~shippingCategory.id~'][percentageRate]', class: 'categoryPercentageRate', placeholder: shippingRule.percentageRate + 0, value: percentageRate ? percentageRate + 0 : '', type: 'number', step: 'any' }) }} |