3

製品ファミリの動作を「シミュレート」するために、いくつかの固定属性を使用して Akeneo で新しいバリアント グループを作成したいと考えています。ProductTemplate残念ながら、空の値を持ついくつかの属性でを取得する方法がわかりません。

以下のコードを試したところ、作成したバリアント グループを Akeneo GUI で開いた後にエラーが発生しました。

Error: Option "attributes" must only contains instances of "Pim\Bundle\CatalogBundle\Entity\Attribute", got "Pim\Bundle\EnrichBundle\Form\Type\AvailableAttributesType"

私のコードは次のようになります。

    $groupType = $this->groupManager
        ->getGroupTypeRepository()
        ->findOneBy(['code' => 'VARIANT']);
    $group = $this->groupFactory->createGroup($groupType);
    $group->setCode('MY_VARIANT_GROUP');

    $attributes = array($this->attributeRepository->findOneByIdentifier('AXIS_ATTRIBUTE'));
    $group->setAxisAttributes($attributes);

    // ??? How can I create a new product value?
    $productValue1 = new ProductValue();
    $productValue1->setId('PREDEFINED_ATTRIBUTE1');
    $productValue1->setAttribute($this->attributeRepository->findOneByIdentifier('PREDEFINED_ATTRIBUTE1'));

    $productTemplate = new ProductTemplate();
    $productTemplate->setValuesData(array($productValue1));

    $group->setProductTemplate($productTemplate);
    $this->groupSaver->save($group);
4

1 に答える 1