@@ -3,7 +3,6 @@ | |||
namespace Lc\ShopBundle\Controller\Admin; | |||
use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController; | |||
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; | |||
use FOS\UserBundle\Model\UserManagerInterface; | |||
use Lc\ShopBundle\Context\MerchantInterface; | |||
use Symfony\Component\Security\Core\Security; | |||
@@ -86,9 +85,16 @@ class AdminController extends EasyAdminController | |||
$entity->setCreatedBy($this->security->getUser()); | |||
} | |||
if (method_exists($entity, 'getAddress') | |||
&& method_exists($entity->getAddress(), 'setCreatedBy')) { | |||
if (method_exists($entity, 'getAddress')) { | |||
$entity->getAddress()->setCreatedBy($this->security->getUser()); | |||
$entity->getAddress()->setCreatedAt(new \DateTime()); | |||
} | |||
if (method_exists($entity, 'getAddresses')) { | |||
foreach($entity->getAddresses() as $address) { | |||
$address->setCreatedBy($this->security->getUser()) ; | |||
$address->setCreatedAt(new \DateTime()) ; | |||
} | |||
} | |||
$this->setUpdated($entity); | |||
@@ -110,15 +116,24 @@ class AdminController extends EasyAdminController | |||
$entity->setUpdatedAt(new \DateTime()); | |||
} | |||
if (method_exists($entity, 'setUpdatedAt')) { | |||
if (method_exists($entity, 'setUpdatedBy')) { | |||
$entity->setUpdatedBy($this->security->getUser()); | |||
} | |||
if (method_exists($entity, 'getAddress') | |||
&& method_exists($entity->getAddress(), 'setUpdatedBy')) { | |||
if (method_exists($entity, 'getAddress')) { | |||
$entity->getAddress()->setUpdatedBy($this->security->getUser()); | |||
} | |||
if (method_exists($entity, 'getAddresses')) { | |||
foreach($entity->getAddresses() as $address) { | |||
$address->setUpdatedBy($this->security->getUser()) ; | |||
$address->setUpdatedAt(new \DateTime()) ; | |||
if(!$address->getCreatedBy()) { | |||
$address->setCreatedBy($this->security->getUser()) ; | |||
$address->setCreatedAt(new \DateTime()) ; | |||
} | |||
} | |||
} | |||
} | |||
} |
@@ -97,9 +97,10 @@ abstract class Address extends AbstractEntity | |||
*/ | |||
protected $merchant; | |||
public function __construct() | |||
public function __toString() | |||
{ | |||
$this->shopOrders = new ArrayCollection(); | |||
return $this->getTitle() ; | |||
} | |||
public function getUser(): ?User |
@@ -10,6 +10,7 @@ use Lc\ShopBundle\Context\MerchantInterface; | |||
/** | |||
* @ORM\MappedSuperclass() | |||
* | |||
*/ | |||
abstract class User extends UserModelFOS | |||
{ | |||
@@ -31,23 +32,30 @@ abstract class User extends UserModelFOS | |||
/** | |||
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\CreditHistoryInterface", mappedBy="user", orphanRemoval=true) | |||
*/ | |||
private $creditHistories; | |||
protected $creditHistories; | |||
/** | |||
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\AddressInterface", mappedBy="user") | |||
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\AddressInterface", mappedBy="user", cascade={"persist"}) | |||
*/ | |||
private $addresses; | |||
protected $addresses; | |||
/** | |||
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderShopInterface", mappedBy="user") | |||
*/ | |||
private $orders; | |||
protected $orders; | |||
/** | |||
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\CartInterface", mappedBy="user") | |||
*/ | |||
protected $carts; | |||
public function __construct() | |||
{ | |||
parent::__construct(); | |||
$this->creditHistories = new ArrayCollection(); | |||
$this->addresses = new ArrayCollection(); | |||
$this->orders = new ArrayCollection(); | |||
$this->carts = new ArrayCollection(); | |||
} | |||
public function getPhone(): ?string | |||
@@ -178,4 +186,35 @@ abstract class User extends UserModelFOS | |||
return $this; | |||
} | |||
/** | |||
* @return Collection|Cart[] | |||
*/ | |||
public function getCarts(): Collection | |||
{ | |||
return $this->carts; | |||
} | |||
public function addCart(Cart $cart): self | |||
{ | |||
if (!$this->carts->contains($cart)) { | |||
$this->carts[] = $cart; | |||
$cart->setUser($this); | |||
} | |||
return $this; | |||
} | |||
public function removeCart(Cart $cart): self | |||
{ | |||
if ($this->carts->contains($cart)) { | |||
$this->carts->removeElement($cart); | |||
// set the owning side to null (unless already changed) | |||
if ($cart->getUser() === $this) { | |||
$cart->setUser(null); | |||
} | |||
} | |||
return $this; | |||
} | |||
} |