/** * @param PlentySoapResponse_ObjectItemImage $Image * @param Media $mediaResource * * @return MediaModel */ protected function createMedia(PlentySoapResponse_ObjectItemImage $Image, Media $mediaResource) { // cleanly add the new media from plenty $media = $mediaResource->internalCreateMediaByFileLink($Image->ImageURL); Shopware()->Models()->persist($media); Shopware()->Models()->flush(); $newHash = sha1_file($Image->ImageURL); $attributes = $media->getAttribute(); if (empty($attributes)) { $attributes = new MediaAttributes(); $media->setAttribute($attributes); Shopware()->Models()->persist($attributes); Shopware()->Models()->flush(); } $attributes->setPlentyHash($newHash); Shopware()->Models()->persist($attributes); Shopware()->Models()->flush(); PlentymarketsMappingController::addMedia($media->getId(), $Image->ImageID, true); // Generate the thumbnails if (version_compare('4.2', Shopware::VERSION) == 1) { PlentymarketsImportItemImageThumbnailController::getInstance()->addMediaResource($media); } return $media; }