diff --git a/src/models/Settings.php b/src/models/Settings.php index 9418ef7..aac1402 100644 --- a/src/models/Settings.php +++ b/src/models/Settings.php @@ -25,10 +25,10 @@ class Settings extends Model public $pdfPaperSize = 'letter'; public $pdfPaperOrientation = 'portrait'; public $fieldLayoutId; - public $fieldsPath = 'fields'; public $codeStorage = Session::class; public $registerAdjuster = 'beforeTax'; // TODO: Remove at next breakpoint private $fieldLayout; + public $fieldsPath = 'fields'; } diff --git a/src/services/CodesService.php b/src/services/CodesService.php index 1ded23c..c28e314 100755 --- a/src/services/CodesService.php +++ b/src/services/CodesService.php @@ -148,18 +148,14 @@ public function codeVoucherByOrder(Voucher $voucher, Order $order, LineItem $lin public function populateCodeByLineItem(Code $code, LineItem $lineItem): array { $settings = GiftVoucher::getInstance()->getSettings(); - $fieldsPath = $settings->fieldsPath; $fieldLayoutId = $settings->fieldLayoutId; $validFields = []; - if (empty($fieldsPath) === false && $settings->fieldLayoutId !== null) { - // set the field layout id + if ($settings->fieldLayoutId !== null) { + // Set the field layout id $code->fieldLayoutId = $fieldLayoutId; - // grab the options from the lineItems, those may contain the field values + // Grab the options from the lineItems, those may contain the field values $options = $lineItem->getOptions(); - // get the correct path specified by users - $customFields = ArrayHelper::getValue($options, $fieldsPath, []); - // okay that might seems a little bit creepy but imagine the case the field layout changes // between storing the line item and creating the code or if the user changes the `fieldsPath` setting @@ -173,9 +169,9 @@ public function populateCodeByLineItem(Code $code, LineItem $lineItem): array foreach ($fields as $field){ $fieldHandle = $field->handle; - if (isset($customFields[$fieldHandle])) { - $code->setFieldValue($fieldHandle, $customFields[$fieldHandle]); - $validFields[$fieldHandle] = $customFields[$fieldHandle]; + if (isset($options[$fieldHandle])) { + $code->setFieldValue($fieldHandle, $options[$fieldHandle]); + $validFields[$fieldHandle] = $options[$fieldHandle]; } } } diff --git a/src/templates/settings.html b/src/templates/settings.html index 5abbe5d..523418f 100644 --- a/src/templates/settings.html +++ b/src/templates/settings.html @@ -89,21 +89,6 @@ warning: macros.configWarning('stopProcessing', 'gift-voucher'), }) }} - {{ forms.textField({ - label: "Voucher Code Fields Path" | t('gift-voucher'), - instructions: 'The fields path for custom fields. For nested arrays separate each key with a dot. For example `nested.array` would require an input like {ex1}' | t('gift-voucher', { - ex1: 'input type="text" name="options[nested][array][fieldHandle]"', - }), - id: 'fieldsPath', - name: 'fieldsPath', - value: settings.fieldsPath, - class: 'code ltr', - placeholder: 'fields', - errors: settings.getErrors('fieldsPath'), - required: true, - warning: macros.configWarning('fieldsPath', 'gift-voucher'), - }) }} -