<?phpnamespace Customize\Service;use Doctrine\ORM\EntityManager;use Eccube\Entity\Order;use Psr\Container\ContainerInterface;use Symfony\Component\HttpFoundation\Session\SessionInterface;class OrderOptionsService{ /** * @var ContainerInterface */ protected $Container; /** * @var SessionInterface */ protected $Session; /** * @var EntityManager */ protected $EntityManager; /** * @var CartService */ protected $CartService; /** * @var OrderHelper */ protected $OrderHelper; public function __construct( ContainerInterface $Container, SessionInterface $Session, CartService $CartService, OrderHelper $OrderHelper ) { $this->Container = $Container; $this->Session = $Session; $this->EntityManager = $this->Container->get('doctrine.orm.entity_manager'); $this->CartService = $CartService; $this->OrderHelper = $OrderHelper; } /** * @return Order|null */ public function getPurchaseProcessingOrder() { if ($preOrderId = $this->CartService->getPreOrderId()) { if ($Order = $this->OrderHelper->getPurchaseProcessingOrder($preOrderId)) { return $Order; } } return null; } public function initializeOrderOptions($key, Order $order = null) { // TODO: } public function addOrderOptions($key, $value, Order $order = null) { if ($order === null && !($order = $this->getPurchaseProcessingOrder())) { return false; } // $options = $order->getOptionsAsArray(); // $options[$key] = $value; // $order->setOptionsAsArray($options); // $this->EntityManager->persist($order); $this->EntityManager->flush(); // return true; } public function getOrderOptions($key = null, Order $order = null) { if ($order === null && !($order = $this->getPurchaseProcessingOrder())) { return null; } // if (!($options = $order->getOptionsAsArray())) { $options = $this->_GetLmOrderOption(); } // if ($key === null) { return $options; } else { return isset($options[$key]) ? $options[$key] : null; } } public function _GetLmOrderOption($Name = null) { $Data = $this->Session->get('Lm_Order_Option_Session'); return is_null($Name) ? $Data : ($Data[$Name] ?? null); }}