Skip to content

Commit

Permalink
Don’t use field from ww.merx.cart.fields option if $fieldName is prov…
Browse files Browse the repository at this point in the history
…ided

Fix #77
  • Loading branch information
tobiasfabian committed May 13, 2024
1 parent ec51526 commit 843238e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/ProductList.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,16 @@ public function __set(string $key, $value): void
$value['uid'] = $page->uid();
}
foreach (option('ww.merx.cart.fields', []) as $fieldName) {
$field = $page->{$fieldName}();
if (
$field === null ||
is_scalar($field) ||
is_string($field) ||
(is_object($field) && method_exists($field, '__toString'))
) {
$value[$fieldName] = (string)$field;
if (!array_key_exists($fieldName, $value)) {
$field = $page->{$fieldName}();
if (
$field === null ||
is_scalar($field) ||
is_string($field) ||
(is_object($field) && method_exists($field, '__toString'))
) {
$value[$fieldName] = (string)$field;
}
}
}
}
Expand Down

0 comments on commit 843238e

Please sign in to comment.