Procházet zdrojové kódy

Ajustements structure Product / ProductOrder

master
Guillaume před 4 roky
rodič
revize
916f4bd48e
2 změnil soubory, kde provedl 46 přidání a 1 odebrání
  1. +1
    -1
      ShopBundle/Model/OrderProduct.php
  2. +45
    -0
      ShopBundle/Model/Product.php

+ 1
- 1
ShopBundle/Model/OrderProduct.php Zobrazit soubor

@@ -19,7 +19,7 @@ abstract class OrderProduct implements PriceInterface
protected $orderShop;

/**
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\ProductInterface")
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\ProductInterface", inversedBy="orderProducts"))
*/
protected $product;


+ 45
- 0
ShopBundle/Model/Product.php Zobrazit soubor

@@ -2,8 +2,12 @@

namespace Lc\ShopBundle\Model;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\PriceInterface;
use Lc\ShopBundle\Context\ProductInterface;
use Lc\ShopBundle\Context\ProductPropertyInterface;
use Lc\ShopBundle\Context\SortableInterface;
use Lc\ShopBundle\Services\Price;
@@ -27,6 +31,16 @@ abstract class Product extends AbstractEntity implements SortableInterface, Prod
*/
protected $title;

/**
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderProductInterface", mappedBy="product", orphanRemoval=true, cascade={"remove"})
*/
protected $orderProducts ;

public function __construct()
{
$this->orderProducts = new ArrayCollection() ;
}

public function getPriceInherited()
{
if($this->price) {
@@ -117,4 +131,35 @@ abstract class Product extends AbstractEntity implements SortableInterface, Prod

return $this;
}

/**
* @return Collection|OrderProductInterface[]
*/
public function getOrderProducts(): Collection
{
return $this->orderProducts;
}

public function addOrderProduct(OrderProductInterface $orderProduct): self
{
if (!$this->orderProducts->contains($orderProduct)) {
$this->orderProducts[] = $orderProduct;
$orderProduct->setProduct($this);
}

return $this;
}

public function removeOrderProduct(OrderProductInterface $orderProduct): self
{
if ($this->orderProducts->contains($orderProduct)) {
$this->orderProducts->removeElement($orderProduct);
// set the owning side to null (unless already changed)
if ($orderProduct->getProduct() === $this) {
$orderProduct->setProduct(null);
}
}

return $this;
}
}

Načítá se…
Zrušit
Uložit