小编Phi*_*hil的帖子

在 Shopware 6 中通过 php 创建媒体

我正在努力通过 PHP 导入媒体以使 Shopware 6 正常工作。

这是我的服务:

<?php declare(strict_types=1);

namespace My\Namespace\Service;

use Shopware\Core\Content\Media\File\MediaFile;
use Shopware\Core\Content\Media\MediaService;
use Shopware\Core\Framework\Context;

class ImageImport
{
    /**
     * @var MediaService
     */
    protected $mediaService;

    /**
     * ImageImport constructor.
     * @param MediaService $mediaService
     */
    public function __construct(MediaService $mediaService)
    {
        $this->mediaService = $mediaService;
    }


    public function addImageToProductMedia($imageUrl, Context $context)
    {
        $mediaId = NULL;
        $context->disableCache(function (Context $context) use ($imageUrl, &$mediaId): void {
            $filePathParts = explode('/', $imageUrl);
            $fileName = array_pop($filePathParts);
            $fileNameParts = explode('.', $fileName);

            $actualFileName = $fileNameParts[0];
            $fileExtension = $fileNameParts[1];


            if …
Run Code Online (Sandbox Code Playgroud)

shopware shopware6

5
推荐指数
1
解决办法
3034
查看次数

标签 统计

shopware ×1

shopware6 ×1