标签: shopware6

覆盖 Shopware 6 中现有的插件 JS

我目前正在尝试从现有插件覆盖 JavaScript 文件。

我一直在关注文档,但我正在努力解决 JS 类覆盖的路径。

文档中是示例代码:

import CookiePermissionPlugin from 'src/plugin/cookie/cookie-permission.plugin';

export default class MyCookiePermission extends CookiePermissionPlugin {
}
Run Code Online (Sandbox Code Playgroud)

所以我实现了以下代码:

import QuantityField from 'src/plugin/FilterRangeSlider/filter-range-slider.plugin';

export default class ExampleQuantityField extends QuantityField {
Run Code Online (Sandbox Code Playgroud)

该代码对我不起作用,因为原始文件位于供应商目录中,而我的插件位于自定义目录中。当尝试编译(例如bin/build-storefront.sh)时,我收到以下错误消息:

找不到模块:错误:无法解析“<项目根目录>/custom/plugins/ExampleProductFilter/src/Resources/app/storefront/src/filter-”中的“src/plugin/FilterRangeSlider/filter-range-slider.plugin”范围滑块'

知道如何按照文档中的说明导入该类吗?

javascript shopware shopware6

12
推荐指数
1
解决办法
1954
查看次数

shopware 6中如何拆分样式?

我想知道您将如何进行代码分割(例如按页面类型),特别是对于 Shopware 6 店面中的 CSS。现在一切都被捆绑成一个大的all.css. 但我认为用户必须加载样式(例如在第一次访问主页时进行结账)并不明智。
我想象类似不同的入口点,例如product.scsscheckout.scss等等
。有没有内置的方法可以做到这一点?

shopware shopware6

12
推荐指数
0
解决办法
425
查看次数

Font Awesome 的 Webpack 版本在一台机器上添加了 \0 空字节,而在其他机器上则没有

我们通过以下方式提供很棒的字体

\n
$fa-font-path: "#{$asset-path}/../../project/assets/fonts/fontawesome";\n\n@import "fontawesome/fontawesome";\n@import "fontawesome/brands";\n@import "fontawesome/solid";\n
Run Code Online (Sandbox Code Playgroud)\n

在我们的 Shopware 6 SCSS 文件中。

\n

我们注意到在某些机器上(我们正在服务器上构建),生成的 CSS 文件包含“\\0”空字节

\n
.fa-certificate:before {\n   content: "\xef\x8a\xb4\\0";\n}\n
Run Code Online (Sandbox Code Playgroud)\n

这会导致这样的输出:

\n

空字节

\n

Shopware 使用 webpack 从 SCSS 构建 CSS 文件。

\n

造成这种情况的原因是什么\\0

\n

我们看到https://github.com/FortAwesome/Font-Awesome/issues/14660但添加了

\n
@charset "UTF-8";\n
Run Code Online (Sandbox Code Playgroud)\n

CSS 文件开头的内容没有帮助。

\n

当我们将构建的文件从一台机器复制到另一台机器时,它就可以工作了。所以这似乎不是服务器提供CSS的问题,而是在构建过程中的问题。

\n

编辑:深入挖掘:

\n

在 fontawesome SCSS 中有:

\n
$fa-var-certificate: \\f0a3;\n\n...\n\n.#{$fa-css-prefix}-certificate:before { content: fa-content($fa-var-certificate); }\n\n\n// Convenience function used to set content property\n@function fa-content($fa-var) {\n  @return unquote("\\"#{ $fa-var }\\"");\n}\n
Run Code Online (Sandbox Code Playgroud)\n

取消引用是sass_function …

sass font-awesome webpack shopware6

8
推荐指数
1
解决办法
221
查看次数

Shopware 6:无法迁移数据库

我按照以下教程在 shopware 6 中自行创建自定义实体:

https://www.youtube.com/watch?v=mTHTyof4gPk

我通过使用创建了一个迁移

bin/console database:create-migration
Run Code Online (Sandbox Code Playgroud)

并添加了以下代码:

$sql = <<<SQL
CREATE TABLE IF NOT EXISTS  'applicationmanagement' (
    'id' BINARY(26) NOT NULL,
    'name' VARCHAR (255) COLLATE utf8mb4_unicode_ci,
    'created_at' DATETIME(3) NOT NULL,
    'update_at' DATETIME(3),
    PRIMARY KEY ('id')
)
    ENGINE = InnoDB
    DEFAULT CHARSET = utf8mb4
    COLLATE = utf8mb4_unicaode_ci;
SQL;

$connection->executeUpdate($sql);
Run Code Online (Sandbox Code Playgroud)

当我尝试使用执行迁移时

bin/console database:migrate PluginName --all
Run Code Online (Sandbox Code Playgroud)

我收到以下注释

bin/console database:create-migration
Run Code Online (Sandbox Code Playgroud)

我尝试重新安装并刷新插件,但没有任何作用。

有人可以帮我解决这个问题吗?

database-migration shopware shopware6

7
推荐指数
2
解决办法
1991
查看次数

如何在Shopware 6中获取公用文件夹绝对路径?

我试图在 shopware 6 中获取公共文件夹路径,以便使用文件系统在内部创建目录。有人对此有什么想法吗?

shopware shopware6

6
推荐指数
1
解决办法
2491
查看次数

Shopware 6 在自定义主题中使用 fontawesome

我需要在我的自定义主题中使用 fontawesome 。因此我使用yarn安装了它yarn add @fortawesome/fontawesome-free

当我尝试将其导入 ( @import "~@fortawesome") 到主题的 base.scss 中时,出现以下错误:

在 ThemeCompiler.php 第 317 行:
[Shopware\Storefront\Theme\Exception\ThemeCompileException]
无法编译主题“CustomTheme”。~@fortawesome找不到 @import 的文件:第 2 行第 1 列的 custom/plugins/CustomTheme/src/Resources/app/storefront/src/scss/base.scss 调用
堆栈:
#0 import custom/plugins/CustomTheme/src/Resources /app/storefront/src/scss/base.scss(未知文件)第 409 行

有人可以告诉我如何将 fa 正确导入到我的 scss 文件中吗?


编辑: 我通过 npm 在我的插件内的以下路径下安装了 fontawesome plugin/src/Resources/app/storefront

要将其导入到我的 base.scss 中,我不能简单地使用doc./@fortawesome/...中描述的方式。我必须像这样导入文件。../../node_module/@fortawesome/...

另一个问题是系统无法找到/加载fa的网络字体。我知道解决方案是将字体手动复制到我的公共文件夹中,但是有没有办法让商店软件复制它们并在整个编译过程中将它们放入公共文件夹中?

shopware shopware6

6
推荐指数
1
解决办法
742
查看次数

在 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 6 中其他字段的多对多关联

我的数据库模型如下所示:

一个用户可以管理多个公司(USER n:n COMPANY),假设它们在中间表 USER_COMPANY 中连接,并且该表有一个附加字段“active”。

我已经为两个表创建了 EntityDefinitions,并为中间表创建了 MappingDefinition:

公司:

class CompanyDefinition extends EntityDefinition
{
    ...

    protected function defineFields(): FieldCollection
    {
        return new FieldCollection([
            (new IdField('id', 'id'))->addFlags(new PrimaryKey(), new Required()),

            ...

            new ManyToManyAssociationField(
                'users',
                UserDefinition::class,
                CompanyUserDefinition::class,
                'company_id',
                'user_id'
            ),
        ]);
    }
}
Run Code Online (Sandbox Code Playgroud)

用户:

class UserDefinition extends EntityDefinition
{
    ....

    protected function defineFields(): FieldCollection
    {
        return new FieldCollection([
            (new IdField('id', 'id'))->addFlags(new PrimaryKey(), new Required()),
            ...

            new ManyToManyAssociationField(
                'companies',
                CompanyDefinition::class,
                CompanyUserDefinition::class,
                'user_id',
                'company_id'
            ),
        ]);
    }

}
Run Code Online (Sandbox Code Playgroud)

公司_用户:

class CompanyUserDefinition extends EntityDefinition …
Run Code Online (Sandbox Code Playgroud)

php shopware shopware6

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

shopware 6 插件的单元测试未找到自定义服务

我编写了一个插件,现在我想在其中创建测试。我按照官方文档并根据我的开发环境更改了 phpunit.xml.dist 。

测试正在运行,但容器不知道我的自定义定义/存储库。是不是我设置错了什么?

我尝试在标准 Dockware 容器上运行它。

phpunit.xml.dist

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/7.1/phpunit.xsd"
         colors="true"
         bootstrap="../../../vendor/shopware/core/TestBootstrap.php"
         cacheResult="false">

    <php>
        <ini name="error_reporting" value="-1"/>
        <server name="KERNEL_CLASS" value="Shopware\Production\Kernel"/>
        <env name="APP_ENV" value="test"/>
        <env name="APP_DEBUG" value="1"/>
        <env name="APP_SECRET" value="*"/>
        <env name="SHELL_VERBOSITY" value="-1"/>
    </php>

    <testsuites>
        <testsuite name="base">
            <directory>src/Test</directory>
        </testsuite>
        <testsuite name="employee">
            <directory>src/Components/Employee/Test</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory suffix=".php">./</directory>
        </whitelist>
    </filter>
</phpunit>
Run Code Online (Sandbox Code Playgroud)

错误:

$ bash ./bin/phpunit.sh 
PHPUnit 9.5.9 by Sebastian Bergmann and contributors.

Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using …
Run Code Online (Sandbox Code Playgroud)

shopware shopware6

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

我如何知道在 shopware 6 商店 API 端点中可用的关联

我正在将 Shopware 6store-api用于我的无头应用程序。但我无法弄清楚 Shopware 中提供了哪些关联,store-api 例如:

  1. 我打电话store-api/account/customer但也想要例如最后的订单。

  2. 我打电话store-api/login,还想要客户的详细信息(如姓名、电子邮件等)。

  3. 我打电话store-api/seo-urls。如果routeName是的话frontend.detail.page我想获取产品详细信息

这可以在一次 api 调用中实现吗?或者我是否需要使用响应数据发出另一个请求?我将来如何检查这一点?

shopware shopware6

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