namespace Lc\ShopBundle\Controller\Admin; | namespace Lc\ShopBundle\Controller\Admin; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController; | use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; | |||||
use FOS\UserBundle\Model\UserManagerInterface; | use FOS\UserBundle\Model\UserManagerInterface; | ||||
use Lc\ShopBundle\Context\MerchantInterface; | use Lc\ShopBundle\Context\MerchantInterface; | ||||
use Symfony\Component\Security\Core\Security; | use Symfony\Component\Security\Core\Security; | ||||
$entity->setCreatedBy($this->security->getUser()); | $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()->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); | $this->setUpdated($entity); | ||||
$entity->setUpdatedAt(new \DateTime()); | $entity->setUpdatedAt(new \DateTime()); | ||||
} | } | ||||
if (method_exists($entity, 'setUpdatedAt')) { | |||||
if (method_exists($entity, 'setUpdatedBy')) { | |||||
$entity->setUpdatedBy($this->security->getUser()); | $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()); | $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()) ; | |||||
} | |||||
} | |||||
} | |||||
} | } | ||||
} | } |
*/ | */ | ||||
protected $merchant; | protected $merchant; | ||||
public function __construct() | |||||
public function __toString() | |||||
{ | { | ||||
$this->shopOrders = new ArrayCollection(); | |||||
return $this->getTitle() ; | |||||
} | } | ||||
public function getUser(): ?User | public function getUser(): ?User |
/** | /** | ||||
* @ORM\MappedSuperclass() | * @ORM\MappedSuperclass() | ||||
* | |||||
*/ | */ | ||||
abstract class User extends UserModelFOS | abstract class User extends UserModelFOS | ||||
{ | { | ||||
/** | /** | ||||
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\CreditHistoryInterface", mappedBy="user", orphanRemoval=true) | * @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") | * @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() | public function __construct() | ||||
{ | { | ||||
parent::__construct(); | |||||
$this->creditHistories = new ArrayCollection(); | $this->creditHistories = new ArrayCollection(); | ||||
$this->addresses = new ArrayCollection(); | $this->addresses = new ArrayCollection(); | ||||
$this->orders = new ArrayCollection(); | $this->orders = new ArrayCollection(); | ||||
$this->carts = new ArrayCollection(); | |||||
} | } | ||||
public function getPhone(): ?string | public function getPhone(): ?string | ||||
return $this; | 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; | |||||
} | |||||
} | } |