3 namespace Doctrine\Tests\Models\ECommerce;
5 use Doctrine\Common\Collections\ArrayCollection;
9 * Represents a typical cart of a shopping application.
11 * @author Giorgio Sironi
13 * @Table(name="ecommerce_carts")
18 * @Column(type="integer")
25 * @Column(length=50, nullable=true)
30 * @OneToOne(targetEntity="ECommerceCustomer", inversedBy="cart")
31 * @JoinColumn(name="customer_id", referencedColumnName="id")
36 * @ManyToMany(targetEntity="ECommerceProduct", cascade={"persist"})
37 * @JoinTable(name="ecommerce_carts_products",
38 joinColumns={@JoinColumn(name="cart_id", referencedColumnName="id")},
39 inverseJoinColumns={@JoinColumn(name="product_id", referencedColumnName="id")})
43 public function __construct()
45 $this->products = new ArrayCollection;
48 public function getId() {
52 public function getPayment() {
53 return $this->payment;
56 public function setPayment($payment) {
57 $this->payment = $payment;
60 public function setCustomer(ECommerceCustomer $customer) {
61 if ($this->customer !== $customer) {
62 $this->customer = $customer;
63 $customer->setCart($this);
67 public function removeCustomer() {
68 if ($this->customer !== null) {
69 $customer = $this->customer;
70 $this->customer = null;
71 $customer->removeCart();
75 public function getCustomer() {
76 return $this->customer;
79 public function getProducts()
81 return $this->products;
84 public function addProduct(ECommerceProduct $product) {
85 $this->products[] = $product;
88 public function removeProduct(ECommerceProduct $product) {
89 return $this->products->removeElement($product);