Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions core/components/minishop3/src/Model/msProductData.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,19 @@ public function getArraysValues()
*/
public function prepareOptionValues($values = null)
{
if ($values) {
if (!is_array($values)) {
$values = [$values];
}
$values = array_map('trim', $values);
$values = array_keys(array_flip($values));
$values = array_diff($values, ['']);
if ($values === null) {
return null;
}

if (empty($values)) {
$values = null;
}
if (!is_array($values)) {
$values = [$values];
}
$values = array_map('trim', $values);
$values = array_keys(array_flip($values));
$values = array_diff($values, ['']);

if (empty($values)) {
$values = null;
}

return $values;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ public function saveCategories(msProductData $productData): void
* via msProductOption::saveProductOptions() method
*
* @param msProductData $productData
* @param array|null $options If null: built from non-empty JSON fields on $productData only. If array: explicit
* keys/values (e.g. manager POST options-*); then $removeOther is honored.
* @param array|null $options If null: built from JSON fields explicitly present in POST/_fields on
* $productData (including cleared empty values). If array: explicit keys/values
* (e.g. manager POST options-*); then $removeOther is honored.
* @param bool $removeOther When $options is non-null: if true, delete msProductOption rows whose keys are absent
* from $options. When $options is null: ignored — always treated as false so category-only
* options not mirrored in JSON fields are preserved (#153, #158).
Expand All @@ -180,14 +181,24 @@ public function saveOptions(msProductData $productData, ?array $options = null,

if ($options === null) {
$options = [];
foreach ($productData->_fieldMeta as $key => $value) {
if ($value['phptype'] === 'json' && !empty($productData->get($key))) {
if (in_array($key, $repeaterKeys, true)) {
continue;
}
// Use field name as key, not numeric index from array_merge
$options[$key] = $productData->get($key);
$reflection = new \ReflectionClass($productData);
$property = $reflection->getProperty('_fields');
$property->setAccessible(true);
$rawFields = $property->getValue($productData);

foreach ($productData->_fieldMeta as $key => $meta) {
if (($meta['phptype'] ?? '') !== 'json') {
continue;
}
if (in_array($key, $repeaterKeys, true)) {
continue;
}
if (!array_key_exists($key, $rawFields)) {
continue;
}

$fieldValue = $productData->get($key);
$options[$key] = !empty($fieldValue) ? $fieldValue : null;
}
}

Expand Down
7 changes: 7 additions & 0 deletions vueManager/src/components/DynamicField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@
:value="val"
/>
</template>
<!-- Empty array must still POST so ProductDataPayloadTrait clears the field (#324) -->
<input
v-else
type="hidden"
:name="`${fieldConfig.name}[]`"
value=""
/>
</template>

<!-- Dropdown select (ms3-combo-select) -->
Expand Down