0

我正在关注高级开发人员教程(https://docs.shopware.com/en/shopware-platform-dev-en/how-to/indepth-guide-bundle)。

目前我在第 7 步,根据教程,我到目前为止所做的应该可以工作。

但事实并非如此。

在数据库中它显示了关联,但我无法从存储库中检索它们。

4

2 回答 2

3

您必须将关联添加到标准。

$criteria->addAssociation("name_of_association")
没有它,关联就无效了。

于 2020-08-19T09:30:06.060 回答
1

好吧,原来我无意中切换了两个参数。当我正确设置它们时,它可以正常工作。

<?php declare(strict_types=1);

namespace Swag\BundleExample\Core\Content\Product;

use Shopware\Core\Content\Product\ProductDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityExtension;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Inherited;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToManyAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
use Swag\BundleExample\Core\Content\Bundle\Aggregate\BundleProduct\BundleProductDefinition;
use Swag\BundleExample\Core\Content\Bundle\BundleDefinition;

class ProductExtension extends EntityExtension
{
    public function extendFields(FieldCollection $collection): void
    {
        $collection->add(
            (new ManyToManyAssociationField(
                'bundles', 
                BundleDefinition::class,
                BundleProductDefinition::class, 
                'product_id', 
                'bundle_id'
            ))->addFlags(new Inherited())
        );
    }

    public function getDefinitionClass(): string
    {
        return ProductDefinition::class;
    }
}

我说的是“product_id”和“bundle_id”。就我而言,我将“product_id”作为最后一个参数。

于 2020-08-19T10:29:55.673 回答