I am following the process described here :
http://docs.sylius.org/en/latest/bundles/SyliusCartBundle/installation.html#creating-your-entities
I've been trying to implement the CartBundle
for days without success, any help is appreciate !
I am just trying to implement my own Product Entity, as described in the doc.
Here is my YAML :
Pharmacie\FrontBundle\Entity\CartItem:
type: entity
table: cart_item
manyToOne:
product:
targetEntity: Product
joinColumn:
name: product_id
referencedColumnName: id
The database automatically created looks good, with a ID auto increment, a product_id
and all the fields from sylius_cart_item
But When I try to access :
/cart/add?productId=3
I get
No identifier/primary key specified for Entity "Pharmacie\FrontBundle\Entity\CartItem" sub class of "Sylius\Bundle\CartBundle\Model\CartItem". Every Entity must have an identifier/primary key.
Even that in the database the primary key has been set.
- Attributes
$id
and$product
are protected in the EntityCartItem
. - if I have try to specify an id in the YAML i get errors saying that it's duplicate. Plus in the doc it's specify to not map id again
UPDATE : Maybe i went in the wrong direction.
The first error showing was :
A new entity was found through the relationship 'Pharmacie\FrontBundle\Entity\CartItem#produit' that was not configured to cascade persist operations for entity: Pharmacie\FrontBundle\Entity\Product@000000007ba4ab6a0000000010e955d1. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem implement 'Pharmacie\FrontBundle\Entity\Product#__toString()' to get a clue. 500 Internal Server Error - ORMInvalidArgumentException
So I added
$this->entityManager->persist($item);
And this gave me the error. But maybe i should do something different