private function getStateFromSession($id) { $state = array(); $session = $this->session->getField(self::CART); if (isset($session[$id])) { $state = $session[$id]; $state['customer'] = $this->customerService->getCurrent(); if (isset($state['items'])) { $productService = $this->productService; $this->wp->addFilter('jigoshop\\internal\\order\\item', function ($value, $data) use($productService) { return $productService->findForState($data); }, 10, 2); $state['items'] = unserialize($state['items']); } if (isset($state['shipping'])) { $shipping = $state['shipping']; if (!empty($shipping['method'])) { $state['shipping'] = array('method' => $this->shippingService->findForState($shipping['method']), 'price' => $shipping['price'], 'rate' => isset($shipping['rate']) ? $shipping['rate'] : null); } } if (isset($state['payment']) && !empty($state['payment'])) { $state['payment'] = $this->paymentService->get($state['payment']); } } return $state; }
/** * Fetches order from database. * * @param $post \WP_Post Post to fetch order for. * * @return \Jigoshop\Entity\Order */ public function fetch($post) { $order = new Entity($this->options->get('tax.classes')); /** @var Entity $order */ $order = $this->wp->applyFilters('jigoshop\\factory\\order\\fetch\\before', $order); $state = array(); if ($post) { $state = array_map(function ($item) { return $item[0]; }, $this->wp->getPostMeta($post->ID)); $order->setId($post->ID); if (isset($state['customer'])) { // Customer must be unserialized twice "thanks" to WordPress second serialization. /** @var CustomerEntity */ $state['customer'] = unserialize(unserialize($state['customer'])); if ($state['customer'] instanceof CustomerEntity && !$state['customer'] instanceof CustomerEntity\Guest && $state['customer_id'] > 0) { $customer = $this->customerService->find($state['customer_id']); $customer->setBillingAddress($state['customer']->getBillingAddress()); $customer->setShippingAddress($state['customer']->getShippingAddress()); $state['customer'] = $customer; } } $state['customer_note'] = $post->post_excerpt; $state['status'] = $post->post_status; $state['created_at'] = strtotime($post->post_date); $state['items'] = $this->getItems($post->ID); if (isset($state['shipping'])) { $shipping = unserialize($state['shipping']); if (!empty($shipping['method'])) { $state['shipping'] = array('method' => $this->shippingService->findForState($shipping['method']), 'price' => $shipping['price'], 'rate' => isset($shipping['rate']) ? $shipping['rate'] : null); } } if (isset($state['payment'])) { $state['payment'] = $this->paymentService->get($state['payment']); } $order = $this->fill($order, $state); } return $this->wp->applyFilters('jigoshop\\find\\order', $order, $state); }