use Doctrine\Common\Collections\ArrayCollection; | use Doctrine\Common\Collections\ArrayCollection; | ||||
use Doctrine\Common\Collections\Collection; | use Doctrine\Common\Collections\Collection; | ||||
use Gedmo\Mapping\Annotation as Gedmo; | |||||
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
use Lc\ShopBundle\Context\DocumentInterface; | use Lc\ShopBundle\Context\DocumentInterface; | ||||
use Lc\ShopBundle\Context\FilterMerchantInterface; | use Lc\ShopBundle\Context\FilterMerchantInterface; | ||||
*/ | */ | ||||
protected $documents; | protected $documents; | ||||
/** | |||||
* @Gedmo\Blameable(on="create") | |||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface") | |||||
* @ORM\JoinColumn(nullable=true) | |||||
*/ | |||||
protected $createdBy; | |||||
/** | |||||
* @Gedmo\Blameable(on="update") | |||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface") | |||||
* @ORM\JoinColumn(nullable=true) | |||||
*/ | |||||
protected $updatedBy; | |||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
$this->orderStatusHistories = new ArrayCollection(); | $this->orderStatusHistories = new ArrayCollection(); |
namespace Lc\ShopBundle\Model; | namespace Lc\ShopBundle\Model; | ||||
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
use Gedmo\Mapping\Annotation as Gedmo; | |||||
/** | /** | ||||
* @ORM\MappedSuperclass() | * @ORM\MappedSuperclass() | ||||
*/ | */ | ||||
protected $origin; | protected $origin; | ||||
/** | |||||
* @Gedmo\Blameable(on="create") | |||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface") | |||||
* @ORM\JoinColumn(nullable=true) | |||||
*/ | |||||
protected $createdBy; | |||||
/** | |||||
* @Gedmo\Blameable(on="update") | |||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface") | |||||
* @ORM\JoinColumn(nullable=true) | |||||
*/ | |||||
protected $updatedBy; | |||||
public function getOrderShop(): ?OrderShop | public function getOrderShop(): ?OrderShop | ||||
{ | { | ||||
return $this->orderShop; | return $this->orderShop; |
$orderShop = $this->setOrderStatus('cart', $orderShop); | $orderShop = $this->setOrderStatus('cart', $orderShop); | ||||
if ($this->security->getUser()) { | |||||
$orderShop->setCreatedBy($this->security->getUser()); | |||||
$orderShop->setUpdatedBy($this->security->getUser()); | |||||
} else { | |||||
// createdBy doit pouvoir être NULL pour OrderShop, en attendant qu'on en discute, j'assigne ça au premier de la base | |||||
$userRepository = $this->em->getRepository($this->em->getClassMetadata(UserInterface::class)->getName()); | |||||
$user = $userRepository->find(1); | |||||
$orderShop->setCreatedBy($user); | |||||
$orderShop->setUpdatedBy($user); | |||||
} | |||||
$this->em->persist($orderShop); | $this->em->persist($orderShop); | ||||
$this->em->flush(); | $this->em->flush(); | ||||