Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cart Instance
<?php
namespace FrontEnd\CartBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* CartItem
*
* @ORM\Table()
* @ORM\Entity
*/
class CartItem
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
public $id;
/**
* @var Cart
*
* @ORM\ManyToOne(targetEntity="FrontEnd\CartBundle\Entity\Cart", inversedBy="items")
*/
public $cart;
/**
* @var int
*
* @ORM\Column(name="quantity", type="integer")
*/
public $quantity;
/**
* @var decimal
*
* @ORM\Column(name="amount", type="decimal")
*/
public $amount;
/**
* @var decimal
*
* @ORM\Column(name="item", type="string")
*/
public $item;
/**
* @var decimal
*
* @ORM\Column(name="checkbox", type="boolean")
*/
public $checkbox;
}
<?php
namespace FrontEnd\CartBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Cart
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="FrontEnd\CartBundle\Entity\CartRepository")
*/
class Cart
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
public $id;
/**
* @var CartItem[] $items
*
* @ORM\OneToMany(targetEntity="FrontEnd\CartBundle\Entity\CartItem", mappedBy="cart", cascade={"all"})
*/
public $items;
public function __construct()
{
$this->items = new ArrayCollection();
}
}
//Controller Method
/**
* Checkout
*
*/
public function checkoutAction()
{
$entity = $this->session->get('cart');
$om = $this->getDoctrine()->getManager();
//Load old data HERE
$form = $this->createCreateForm($entity, $om);
return array(
'entity' => $entity,
'form' => $form->createView(),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment