load() public method

public load ( Sonata\Component\Customer\CustomerInterface $customer )
$customer Sonata\Component\Customer\CustomerInterface
 /**
  * {@inheritdoc}
  */
 public function load(CustomerInterface $customer)
 {
     $sessionBasket = parent::load($customer);
     if ($customer->getId()) {
         $basket = $this->basketManager->loadBasketPerCustomer($customer);
         if (!$basket) {
             return $sessionBasket;
         }
         $this->basketBuilder->build($basket);
         if ($sessionBasket && !$sessionBasket->isEmpty()) {
             // Retrieve elements put in session before user logged in and replace db elements with it
             $basket->setBasketElements($sessionBasket->getBasketElements());
         }
         // Clear session to avoid retaking elements from session afterwards
         $this->clearSession($customer);
         // We need to ensure that both customer & customer id are set
         $basket->setCustomer($customer);
         return $basket;
     }
     return $sessionBasket;
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function load(CustomerInterface $customer)
 {
     // always clone the basket so it can be only saved by calling
     // the save method
     return clone parent::load($customer);
 }