Skip to content

Commit

Permalink
Merge branch '5.x' into 6.x
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	src/fields/Matrix.php
  • Loading branch information
angrybrad committed Oct 9, 2024
2 parents 948b93c + 08f5c31 commit 28b4c57
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Fixed a PHP error that would occur when importing Products that had new Variants. ([#1528](https://github.com/craftcms/feed-me/pull/1528))
- Fixed a bug where Lightswitch fields would not import correctly when nested in a Matrix or Super Table field. ([#1529](https://github.com/craftcms/feed-me/pull/1529))

## 6.4.0 - 2024-09-25

Expand Down
26 changes: 13 additions & 13 deletions src/fields/Matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function parseField(): mixed
$node = Hash::get($fieldInfo, 'node');
if ($node === 'usedefault') {
$key = $this->_getBlockKey($nodePathSegments, $blockHandle, $fieldHandle);

$parsedValue = DataHelper::fetchSimpleValue($this->feedData, $fieldInfo);
$attributeData[$key] = $parsedValue;
}
Expand Down Expand Up @@ -226,18 +226,18 @@ public function parseField(): mixed
$index = 1;
$resultBlocks = [];
foreach ($expanded as $blockData) {
// all the fields are empty and setEmptyValues is off, ignore the block
if (isset($blockData['fields'])) {
if (
!empty(array_filter(
$blockData['fields'],
fn($value) => (is_string($value) && !empty($value)) || (is_array($value) && !empty(array_filter($value)))
))
) {
$resultBlocks['new' . $index++] = $blockData;
}
} else {
// if there are no fields in the block data, we can still have just the attributes, e.g. just the title
// if all the fields are empty and setEmptyValues is off, ignore the block
if (
!empty(array_filter(
$blockData['fields'],
fn($value) => (
(is_string($value) && !empty($value)) ||
(is_array($value) && !empty(array_filter($value))) ||
is_bool($value) ||
is_numeric($value)
)
))
) {
$resultBlocks['new' . $index++] = $blockData;
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/fields/SuperTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,13 @@ public function parseField(): mixed
$preppedData[$blockIndex . '.enabled'] = true;
$preppedData[$blockIndex . '.fields.' . $subFieldHandle] = $value;

if ((is_string($value) && !empty($value)) || (is_array($value) && !empty(array_filter($value)))) {
// if all the fields are empty and setEmptyValues is off, ignore the block
if (
(is_string($value) && !empty($value)) ||
(is_array($value) && !empty(array_filter($value))) ||
is_bool($value) ||
is_numeric($value)
) {
$allEmpty = false;
}

Expand Down

0 comments on commit 28b4c57

Please sign in to comment.