From b4c4f67157ee6d2da1a03ac16a6a523476bcafc1 Mon Sep 17 00:00:00 2001 From: Josh Crawford Date: Sat, 15 Jul 2023 23:54:24 +1000 Subject: [PATCH] =?UTF-8?q?Fix=20Variants=20fields=20not=20persisting=20th?= =?UTF-8?q?eir=20=E2=80=9CSource=E2=80=9D=20setting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fields/formfields/Variants.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/fields/formfields/Variants.php b/src/fields/formfields/Variants.php index bc73cf911..8824a7e21 100644 --- a/src/fields/formfields/Variants.php +++ b/src/fields/formfields/Variants.php @@ -78,6 +78,7 @@ public static function getSvgIconPath(): string // ========================================================================= public bool $searchable = true; + public bool $allowMultipleSources = false; protected string $inputTemplate = 'formie/_includes/element-select-input'; @@ -112,8 +113,15 @@ public function getExtraBaseFieldConfig(): array */ public function getFieldDefaults(): array { + $productType = null; + $productTypes = Commerce::getInstance()->getProductTypes()->getAllProductTypes(); + + if (!empty($productTypes)) { + $productType = 'productType:' . ArrayHelper::firstValue($productTypes)->uid; + } + return [ - 'source' => '*', + 'source' => $productType, 'placeholder' => Craft::t('formie', 'Select a variant'), 'labelSource' => 'title', 'orderBy' => 'title ASC',