This topic contains 2 replies, has 1 voice, and was last updated by mlozynskyy 6 years, 9 months ago.
- Topic
Hello,
How can I create product attribute programmatically. Below is my template of code:12345678910111213141516171819202122232425262728293031$fieldConfigModel = $configManager->createConfigFieldModel(Product::class,$this->prepareAttributeCode($attributeName),$attributeType);...$entityManager->persist($fieldConfigModel);$entityManager->flush();...$entityProcessor->updateDatabase(true, true, true)...$attributeRelation = new AttributeGroupRelation();$attributeRelation->setEntityConfigFieldId($fieldConfigModel->getId());$attributeGroup->addAttributeRelation($attributeRelation);...$attributeFamily->addAttributeGroup($attributeGroup);$this->manager->persist($attributeFamily);$this->manager->flush();$queryBuilder = $this->manager->getRepository(Product::class)->createQueryBuilder('product');$queryBuilder->update(Product::class, 'product')->set('product.attributeFamily', ':attributeFamily')->setParameter('attributeFamily', $attributeFamily)->getQuery()->execute();That code add attribute to Products->Product Attribute, but when I created my new Product based on new Family, I’ve got an error:
1234567[2017-06-02 07:03:21] request.CRITICAL: Uncaught PHP Exception Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException: "Neither the property "ldfFSila"nor one of the methods "getLdfFSila()", "ldfFSila()", "isLdfFSila()","hasLdfFSila()", "__get()" exist and have public access in class"Oro\Bundle\ProductBundle\Entity\Product"."at /var/www/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php line 486 {"exception":"[object] (Symfony\\Component\\PropertyAccess\\Exception\\NoSuchPropertyException(code: 0):Neither the property \"ldfFSila\" nor one of the methods \"getLdfFSila()\", \"ldfFSila()\", \"isLdfFSila()\", \"hasLdfFSila()\", \"__get()\" exist and have public access in class \"Oro\\Bundle\\ProductBundle\\Entity\\Product\".at /var/www/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php:486)"} []Maybe I forgot to add something?! Could You help me?
Thanks.
The forum ‘OroCommerce’ is closed to new topics and replies.