Skip to content
Open
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
26 changes: 21 additions & 5 deletions src/Export/Adapters/AttributeAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Vin\ShopwareSdk\Data\Entity\Product\ProductEntity;
use Vin\ShopwareSdk\Data\Entity\PropertyGroupOption\PropertyGroupOptionCollection;
use Vin\ShopwareSdk\Data\Entity\PropertyGroupOption\PropertyGroupOptionEntity;
use Shopware\Core\Framework\DataAbstractionLayer\Pricing\PriceCollection;

class AttributeAdapter
{
Expand Down Expand Up @@ -223,11 +224,26 @@ protected function getCustomFieldAttributes(ProductEntity $product): array
}

// Filter null, false and empty strings, but not "0". See: https://stackoverflow.com/a/27501297/6281648
$customFieldAttribute = new Attribute(
$key,
$this->decodeHtmlEntities(array_filter((array) $cleanedValue, 'strlen')),
);
$attributes[] = $customFieldAttribute;
if ($cleanedValue instanceof PriceCollection) {
$price = current($cleanedValue->getElements());
$attributes[] = new Attribute(
$key . '_net',
array_filter((array) $price->getNet(), 'strlen'),
);
$attributes[] = new Attribute(
$key . '_gross',
array_filter((array) $price->getGross(), 'strlen'),
);
$attributes[] = new Attribute(
$key . '_curency_id',
array_filter((array) $price->getCurrencyId(), 'strlen'),
);
} else {
$attributes[] = new Attribute(
$key,
$this->decodeHtmlEntities(array_filter((array) $cleanedValue, 'strlen')),
);
}
}
}

Expand Down