/** * 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); }
public function fromCart(\Jigoshop\Entity\Cart $cart) { $order = new \Jigoshop\Entity\Order($this->options->get('tax.classes')); $state = $cart->getStateToSave(); $state['items'] = unserialize($state['items']); $state['customer'] = unserialize($state['customer']); unset($state['shipping'], $state['payment']); $order->setTaxDefinitions($cart->getTaxDefinitions()); $order->restoreState($state); $shipping = $cart->getShippingMethod(); if ($shipping && $shipping instanceof ShippingMethod) { $order->setShippingMethod($shipping); $order->setShippingTax($cart->getShippingTax()); } $payment = $cart->getPaymentMethod(); if ($payment && $payment instanceof PaymentMethod) { $order->setPaymentMethod($payment); } return $order; }