2009-07-01 13:18:08 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\Models\ECommerce;
|
|
|
|
|
2009-07-29 15:57:27 +04:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
2009-07-03 21:36:41 +04:00
|
|
|
|
2009-07-01 13:18:08 +04:00
|
|
|
/**
|
|
|
|
* ECommerceCart
|
|
|
|
* Represents a typical cart of a shopping application.
|
|
|
|
*
|
|
|
|
* @author Giorgio Sironi
|
|
|
|
* @Entity
|
|
|
|
* @Table(name="ecommerce_carts")
|
|
|
|
*/
|
|
|
|
class ECommerceCart
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @Column(type="integer")
|
|
|
|
* @Id
|
2010-04-10 02:00:36 +04:00
|
|
|
* @GeneratedValue
|
2009-07-01 13:18:08 +04:00
|
|
|
*/
|
2009-07-01 14:04:22 +04:00
|
|
|
private $id;
|
2009-07-01 13:18:08 +04:00
|
|
|
|
|
|
|
/**
|
2010-04-10 02:00:36 +04:00
|
|
|
* @Column(length=50, nullable=true)
|
2009-07-01 13:18:08 +04:00
|
|
|
*/
|
2009-07-01 14:04:22 +04:00
|
|
|
private $payment;
|
2009-07-01 13:18:08 +04:00
|
|
|
|
|
|
|
/**
|
2010-04-10 02:00:36 +04:00
|
|
|
* @OneToOne(targetEntity="ECommerceCustomer", inversedBy="cart")
|
2009-07-01 13:18:08 +04:00
|
|
|
* @JoinColumn(name="customer_id", referencedColumnName="id")
|
|
|
|
*/
|
2009-07-01 14:04:22 +04:00
|
|
|
private $customer;
|
2009-07-01 16:03:41 +04:00
|
|
|
|
|
|
|
/**
|
2009-07-25 20:33:29 +04:00
|
|
|
* @ManyToMany(targetEntity="ECommerceProduct", cascade={"persist"})
|
2009-07-01 16:03:41 +04:00
|
|
|
* @JoinTable(name="ecommerce_carts_products",
|
2009-07-08 19:25:41 +04:00
|
|
|
joinColumns={@JoinColumn(name="cart_id", referencedColumnName="id")},
|
|
|
|
inverseJoinColumns={@JoinColumn(name="product_id", referencedColumnName="id")})
|
2009-07-01 16:03:41 +04:00
|
|
|
*/
|
|
|
|
private $products;
|
2009-07-02 11:47:24 +04:00
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
2009-07-29 15:57:27 +04:00
|
|
|
$this->products = new ArrayCollection;
|
2009-07-02 11:47:24 +04:00
|
|
|
}
|
2009-07-01 14:04:22 +04:00
|
|
|
|
|
|
|
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;
|
2009-07-01 17:08:24 +04:00
|
|
|
$customer->removeCart();
|
2009-07-01 14:04:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCustomer() {
|
|
|
|
return $this->customer;
|
|
|
|
}
|
2009-07-01 16:03:41 +04:00
|
|
|
|
2009-07-02 11:47:24 +04:00
|
|
|
public function getProducts()
|
|
|
|
{
|
|
|
|
return $this->products;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addProduct(ECommerceProduct $product) {
|
|
|
|
$this->products[] = $product;
|
|
|
|
}
|
2009-07-02 13:37:59 +04:00
|
|
|
|
|
|
|
public function removeProduct(ECommerceProduct $product) {
|
|
|
|
return $this->products->removeElement($product);
|
|
|
|
}
|
2009-07-01 13:18:08 +04:00
|
|
|
}
|