예제 #1
0
 /**
  * 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);
     }
 }
예제 #2
0
 /**
  * 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'];
     })));
 }
예제 #3
0
 /**
  * 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);
 }
예제 #4
0
 /**
  * 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);
     }
 }
예제 #5
0
 /**
  * @param Session $session
  */
 public function addSessionToSave(Session $session)
 {
     $this->sessionsToSave[$session->getKey()] = $session;
 }
예제 #6
0
 /**
  * @param Session $session
  */
 public function save(Session $session)
 {
     set_transient('jigoshop_session_' . $session->getKey(), $session->getFields(), 2592000);
     //30 DAYS
 }
예제 #7
0
파일: Php.php 프로젝트: jigoshop/Jigoshop2
 /**
  * @param Session $session
  */
 public function save(Session $session)
 {
     $_SESSION[$session->getKey()] = $session->getFields();
 }