Exemplo n.º 1
0
 /**
  * Saves cart for current user.
  *
  * @param \Jigoshop\Entity\Cart $cart Cart to save.
  */
 public function save(Cart $cart)
 {
     // TODO: Support for transients?
     $cart->recalculateCoupons();
     if ($cart->getShippingMethod() == null) {
         $method = $this->shippingService->getCheapest($cart);
         if ($method instanceof Method) {
             $cart->setShippingMethod($method);
         }
     } else {
         try {
             $cart->setShippingMethod($cart->getShippingMethod());
         } catch (\Exception $e) {
             $method = $this->shippingService->getCheapest($cart);
             if ($method instanceof Method) {
                 $cart->setShippingMethod($method);
             } else {
                 $cart->removeShippingMethod();
             }
         }
     }
     $session = $this->session->getField(self::CART);
     $session[$cart->getId()] = $cart->getStateToSave();
     $this->session->setField(self::CART, $session);
     do_action('jigoshop\\cart\\save', $cart);
 }