Skip to content

Commit

Permalink
Removed fieldsPath config setting
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Jun 17, 2020
1 parent 3aa1a50 commit fe7ef8a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
16 changes: 6 additions & 10 deletions src/services/CodesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];
}
}
}
Expand Down
15 changes: 0 additions & 15 deletions src/templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
}) }}

<h3>{{ 'Voucher Code Field Layout' | t('gift-voucher') }}</h3>

{% include '_includes/fieldlayoutdesigner' with {
Expand Down

0 comments on commit fe7ef8a

Please sign in to comment.