ECommerceCart.php 2.08 KB
Newer Older
piccoloprincipe's avatar
piccoloprincipe committed
1 2 3 4
<?php

namespace Doctrine\Tests\Models\ECommerce;

5
use Doctrine\Common\Collections\ArrayCollection;
6

piccoloprincipe's avatar
piccoloprincipe committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/**
 * ECommerceCart
 * Represents a typical cart of a shopping application.
 *
 * @author Giorgio Sironi
 * @Entity
 * @Table(name="ecommerce_carts")
 */
class ECommerceCart
{
    /**
     * @Column(type="integer")
     * @Id
     * @GeneratedValue(strategy="AUTO")
     */
22
    private $id;
piccoloprincipe's avatar
piccoloprincipe committed
23 24

    /**
25
     * @Column(type="string", length=50, nullable=true)
piccoloprincipe's avatar
piccoloprincipe committed
26
     */
27
    private $payment;
piccoloprincipe's avatar
piccoloprincipe committed
28 29 30 31 32

    /**
     * @OneToOne(targetEntity="ECommerceCustomer")
     * @JoinColumn(name="customer_id", referencedColumnName="id")
     */
33
    private $customer;
34 35

    /**
36
     * @ManyToMany(targetEntity="ECommerceProduct", cascade={"persist"})
37
     * @JoinTable(name="ecommerce_carts_products",
38 39
            joinColumns={@JoinColumn(name="cart_id", referencedColumnName="id")},
            inverseJoinColumns={@JoinColumn(name="product_id", referencedColumnName="id")})
40 41
     */
    private $products;
42 43 44

    public function __construct()
    {
45
        $this->products = new ArrayCollection;
46
    }
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
    
    public function getId() {
        return $this->id;
    }
    
    public function getPayment() {
        return $this->payment;
    }
    
    public function setPayment($payment) {
        $this->payment = $payment;
    }
    
    public function setCustomer(ECommerceCustomer $customer) {
        if ($this->customer !== $customer) {
            $this->customer = $customer;
            $customer->setCart($this);
        }
    }
    
    public function removeCustomer() {
        if ($this->customer !== null) {
            $customer = $this->customer;
            $this->customer = null;
romanb's avatar
romanb committed
71
            $customer->removeCart();
72 73 74 75 76 77
        }
    }
    
    public function getCustomer() {
        return $this->customer;
    }
78

79 80 81 82 83 84 85 86
    public function getProducts()
    {
        return $this->products;
    }

    public function addProduct(ECommerceProduct $product) {
        $this->products[] = $product;
    }
87 88 89 90

    public function removeProduct(ECommerceProduct $product) {
        return $this->products->removeElement($product);
    }
piccoloprincipe's avatar
piccoloprincipe committed
91
}