EC-CUBE4で受注を受けた際、受注した顧客IDと商品IDを新規テーブル(
dtb_ticket)に追加する為、以下の構文を記入しました。
Ticket.php(エンティティ)
php
1<?php 2 3namespace Customize\Entity; 4 5use Doctrine\ORM\Mapping as ORM; 6use Eccube\Entity\AbstractEntity; 7 8/** 9 * Ticket 10 * 11 * // 12 * @ORM\Table(name="dtb_ticket") 13 * // 14 * @ORM\Entity(repositoryClass="Customize\Repository\TicketRepository") 15 */ 16class Ticket extends AbstractEntity 17{ 18 /** 19 * @var int 20 * 21 * // 22 * @ORM\Column(name="id", type="integer", options={"unsigned":true}) 23 * @ORM\Id 24 * @ORM\GeneratedValue(strategy="AUTO") 25 */ 26 private $id; 27 28 /** 29 * @ORM\Column(name="ticket_id", type="integer", options={"unsigned":true}) 30 */ 31 private $ticketId; 32 33 /** 34 * @ORM\Column(name="customer_id", type="integer", options={"unsigned":true}) 35 */ 36 private $customerId; 37 38 /** 39 * Get id 40 * 41 * @return int 42 */ 43 public function getId() 44 { 45 return $this->id; 46 } 47 48 /** 49 * Set ticketId. 50 * 51 * @param int $ticketId 52 * 53 * @return Ticket 54 */ 55 public function setTicketId($ticketId) 56 { 57 $this->ticketId = $ticketId; 58 59 return $this; 60 } 61 62 /** 63 * Get ticketId. 64 * 65 * @return int 66 */ 67 public function getTicketId() 68 { 69 return $this->ticketId; 70 } 71 72 /** 73 * Set customerId. 74 * 75 * @param int $customerId 76 * 77 * @return Ticket 78 */ 79 public function setCustomerId($customerId) 80 { 81 $this->customerId = $customerId; 82 83 return $this; 84 } 85 86 /** 87 * Get customerId. 88 * 89 * @return int 90 */ 91 public function getCustomerId() 92 { 93 return $this->customerId; 94 } 95} 96
TicketRepository.php
php
1<?php 2 3/* 4 * This file is part of EC-CUBE 5 * 6 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved. 7 * 8 * http://www.lockon.co.jp/ 9 * 10 * For the full copyright and license information, please view the LICENSE 11 * file that was distributed with this source code. 12 */ 13 14namespace Customize\Repository; 15 16use Customize\Entity\Ticket; 17use Eccube\Entity\OrderItem; 18use Eccube\Repository\AbstractRepository; 19use Symfony\Bridge\Doctrine\RegistryInterface; 20use Doctrine\ORM\EntityManagerInterface; 21use Eccube\Service\OrderHelper; 22use Eccube\Repository\OrderRepository; 23use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; 24 25/** 26 * TicketRepository 27 * 28 * This class was generated by the Doctrine ORM. Add your own custom 29 * repository methods below. 30 */ 31class TicketRepository extends AbstractRepository 32{ 33 /** 34 * @var TokenStorageInterface 35 */ 36 protected $tokenStorage; 37 38 /** 39 * @var OrderRepository 40 */ 41 protected $orderRepository; 42 43 public function __construct( 44 RegistryInterface $registry, 45 EntityManagerInterface $entityManager, 46 TokenStorageInterface $tokenStorage, 47 OrderRepository $orderRepository 48 ) 49 { 50 parent::__construct($registry, Ticket::class); 51 $this->entityManager = $entityManager; 52 $this->tokenStorage = $tokenStorage; 53 $this->orderRepository = $orderRepository; 54 } 55 56 public function addElectronicTicket(OrderItem $OrderItem) 57 { 58 $orderId = $this->session->get(OrderHelper::SESSION_ORDER_ID); 59 $Order = $this->orderRepository->find($orderId); 60 61 $em = $this->getDoctrine()->getManager(); 62 63 if(!is_null($Order)) { 64 if(null !== $token = $this->tokenStorage->getToken()) { 65 $Ticket = new Ticket(); 66 $Ticket 67 ->setCustomerId($token->getUser()->getId()) 68 ->setProductId($OrderItem->getProduct()); 69 70 $em->persist($Ticket); 71 $em->flush(); 72 } 73 } 74 } 75}
実行してもエラーは表示されないのですが、構文が呼び出せていないのかデータの追加ができません。何処を改善すればデータが追加されるでしょうか。
回答1件
あなたの回答
tips
プレビュー