app/Plugin/PiaAdminLog/Event.php line 45

Open in your IDE?
  1. <?php
  2. namespace Plugin\PiaAdminLog;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Eccube\Event\EccubeEvents;
  5. use Eccube\Event\EventArgs;
  6. use Plugin\PiaAdminLog\Entity\PiaAdminLog;
  7. use Plugin\PiaAdminLog\Repository\PiaAdminLogRepository;
  8. use Plugin\CustomerRank42\Repository\CustomerPriceRepository;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. class Event implements EventSubscriberInterface {
  11.   /**
  12.    * @var EntityManagerInterface
  13.    */
  14.   protected $entityManager;
  15.   protected $PiaAdminLogRepository;
  16.   protected $CustomerPriceRepository;
  17.   
  18.   public function __construct(
  19.     EntityManagerInterface $entityManager
  20.     PiaAdminLogRepository $PiaAdminLogRepository,
  21.     CustomerPriceRepository $CustomerPriceRepository) {
  22.     $this->entityManager $entityManager;
  23.     $this->PiaAdminLogRepository $PiaAdminLogRepository;
  24.     $this->CustomerPriceRepository $CustomerPriceRepository;
  25.   }
  26.   /**
  27.    * @return array
  28.    */
  29.   public static function getSubscribedEvents() {
  30.     return [
  31.       EccubeEvents::ADMIN_PRODUCT_EDIT_COMPLETE => 'onAdminProductEditComplete',
  32.     ];
  33.   }
  34.   /**
  35.    * 商品更新ログの登録
  36.    * @param EventArgs $event
  37.    */
  38.   public function onAdminProductEditComplete(EventArgs $event) {
  39.    
  40.     $htPrice $this->CustomerPriceRepository->getHashPrice();
  41.     
  42.     $datetime = new \DateTime();
  43.     $Product $event->getArgument('Product');
  44.     $product_id $Product->getId();
  45.     $product_name $Product->getName();
  46.     $product_price $Product->getPrice02IncTaxMax();
  47.     $product_price_member = empty($htPrice[$product_id]) ? "" $htPrice[$product_id];
  48.     $product_stock $Product->getStockMax();
  49.     $product_status $Product->getStatus()->getName();
  50.     $type "編集";
  51.     if(empty($product_id)){
  52.       $type "登録";
  53.     }elseif($product_status == "廃止"){
  54.       $type "廃止";
  55.     }
  56.     $Creator $Product->getCreator();
  57.     $member_id $Creator->getId();
  58.     $member_name $Creator->getName();
  59.     $repository $this->PiaAdminLogRepository;    
  60.     $row = new PiaAdminLog();
  61.     $row->setProductId($product_id);
  62.     $row->setProductName($product_name);
  63.     $row->setProductPrice($product_price);
  64.     $row->setProductPriceMenber($product_price_member);
  65.     $row->setProductStock($product_stock);
  66.     $row->setProductStatus($product_status);
  67.     $row->setType($type);
  68.     $row->setMemberId($member_id);
  69.     $row->setMemberName($member_name);
  70.     $row->setRegistDate($datetime);
  71.     $row->setCreateDate($datetime);
  72.     $repository->save($row);
  73.   }
  74. }