Skip to main content

Handling Assets

In some cases, assets (e.g., product images or videos) must also be exported and provided in Shopware for further use. Both Pimcore and Shopware offer various options for this.

Pimcore

The AssetHelper is available in Pimcore. It can be accessed in the adapter via the method $this->assetHelper().

Class

Twocream\ShopwareConnectorBundle\Helper\AssetHelper

Method copyAsset

This method generates the specified thumbnail from the given asset. The thumbnail is saved on the filesystem at the configured asset path and under the configured asset domain of the export destination.

Best Practice

It is recommended to consider the asset path and asset domain independently of Pimcore so that the assets remain accessible even when Pimcore is unavailable.

NameValue
Functionpublic function copyAsset($asset = null, array $thumbnailNames = [], string $folder = 'media', string $type = self::ASSET_TYPE_DEFAULT, bool $useReducedAsset = false, string $quality = self::QUALITY_STANDARD): array
(Optional) Argument $assetAsset from Pimcore
(Optional) Argument $thumbnailNamesSpecifies the thumbnails for which the asset should be generated
(Optional) Argument $folderOptional subfolder within the defined asset path where the generated files will be stored
(Optional) Argument $typestandard | original | free | transparent
(Optional) Argument $useReducedAssetAllows a reduced asset
(Optional) Argument $qualitystandard | high
Return valuesee Output

Example

protected function prepare($object): array
{
$productImage = $this->assetHelper()->copyAsset(
$object->getImages(),
[
'shopware_1000x1000',
'shopware_3840x2160',
]
);

return [
// ...,
'custom-fields' => [
'images' => $productImage,
],
// ...,
];
}

Output

[
"1000x1000": "http://pimcore-example-domain.com/media/48/4871/1000x1000/standard/Example.jpg",
"3840x2160": "http://pimcore-example-domain.com/media/48/4871/3840x2160/standard/Example.jpg",
]

Shopware

On the Shopware side, assets can be imported into a previously created custom field (!) . This field can then be used to retrieve the URL for the respective thumbnails.

Example

protected function store(Result $result): ?EntityWrittenContainerEvent
{
// ...

foreach ($result as $entry) {
$records[] = [
// ...,
'customFields' => [
'images' => json_encode($entry['custom-fields']['images'])
],
// ...,
];
}

// ...
}