/** * Removes cart. * * @param \Jigoshop\Entity\Cart $cart Cart to remove. */ public function remove(Cart $cart) { $session = $this->session->getField(self::CART); if (isset($session[$cart->getId()])) { unset($session[$cart->getId()]); $this->session->setField(self::CART, $session); } }
/** * Preserves messages storing them to PHP session. */ public function preserveMessages() { $this->session->setField(self::NOTICES, array_values(array_filter($this->notices, function ($item) { return $item['persistent']; }))); $this->session->setField(self::WARNINGS, array_values(array_filter($this->warnings, function ($item) { return $item['persistent']; }))); $this->session->setField(self::ERRORS, array_values(array_filter($this->errors, function ($item) { return $item['persistent']; }))); }
/** * Fetches customer from database. * * @param $user \WP_User User object to fetch customer for. * * @return \Jigoshop\Entity\Customer */ public function fetch($user) { $state = array(); if ($user->ID == 0) { $customer = new Entity\Guest(); if ($this->session->getField(self::CUSTOMER)) { $customer->restoreState($this->session->getField(self::CUSTOMER)); } } else { $customer = new Entity(); $meta = $this->wp->getUserMeta($user->ID); if (is_array($meta)) { $state = array_map(function ($item) { return $item[0]; }, $meta); } $state['id'] = $user->ID; $state['login'] = $user->get('login'); $state['email'] = $user->get('user_email'); $state['name'] = $user->get('display_name'); $customer->restoreState($state); } return $this->wp->applyFilters('jigoshop\\find\\customer', $customer, $state); }
/** * Saves product to database. * * @param EntityInterface $object Customer to save. * * @throws Exception */ public function save(EntityInterface $object) { if (!$object instanceof Entity) { throw new Exception('Trying to save not a customer!'); } $fields = $object->getStateToSave(); if (isset($fields['id']) || isset($fields['name']) || isset($fields['email']) || isset($fields['login'])) { // TODO: Do we want to update user data like this? // $this->wp->wpUpdateUser(array( // 'ID' => $fields['id'], // 'display_name' => $fields['name'], // 'user_email' => $fields['email'], // )); unset($fields['id'], $fields['name'], $fields['email'], $fields['login']); } if ($object instanceof Entity\Guest) { $this->session->setField(Factory::CUSTOMER, $fields); return; } foreach ($fields as $field => $value) { $this->wp->updateUserMeta($object->getId(), $field, $value); } }
/** * @param Session $session */ public function addSessionToSave(Session $session) { $this->sessionsToSave[$session->getKey()] = $session; }
/** * @param Session $session */ public function save(Session $session) { set_transient('jigoshop_session_' . $session->getKey(), $session->getFields(), 2592000); //30 DAYS }
/** * @param Session $session */ public function save(Session $session) { $_SESSION[$session->getKey()] = $session->getFields(); }