Example #1
0
 /**
  * Get loaded object. If object is not loaded yet, then load it and save it
  * locally. Otherwise, just return the pre-loaded object.
  *
  * @return mixed Loaded object
  */
 public function get()
 {
     if ($this->customer instanceof CustomerInterface) {
         return $this->customer;
     }
     $customer = $this->getCustomerFromToken();
     if (null === $customer) {
         $customer = $this->customerFactory->create();
     }
     $this->customer = $customer;
     return $customer;
 }
Example #2
0
 /**
  * Load customer method
  *
  * This method tries to load Customer stored in Session, using specific
  * session field name.
  *
  * If this customer is found, stores it locally and uses it as "official"
  * customer object
  *
  * Otherwise, new Customer is created and stored (not flushed nor persisted)
  *
  * @return CustomerInterface Loaded customer
  */
 public function loadCustomer()
 {
     if ($this->customer instanceof CustomerInterface) {
         return $this->customer;
     }
     $token = $this->securityContext instanceof SecurityContextInterface ? $this->securityContext->getToken() : null;
     if ($token instanceof UsernamePasswordToken) {
         $this->customer = $token->getUser();
     } else {
         $this->customer = $this->customerFactory->create();
     }
     return $this->customer;
 }