Exemplo n.º 1
0
 /**
  * Creates cart from order - useful for cancelling orders.
  *
  * @param $cartId string Cart ID to use.
  * @param $order  Order Order to base cart on.
  *
  * @return \Jigoshop\Entity\Cart The cart.
  */
 public function createFromOrder($cartId, $order)
 {
     $cart = new \Jigoshop\Entity\Cart($this->options->get('tax.classes'));
     $cart->setId($cartId);
     $cart->setCustomer($order->getCustomer());
     $cart->setCustomerNote($order->getCustomerNote());
     $cart->setTaxDefinitions($order->getTaxDefinitions());
     foreach ($order->getItems() as $item) {
         /** @var $item Order\Item */
         $item = clone $item;
         $item->setId(false);
         $item->setKey(false);
         $cart->addItem($item);
     }
     //		foreach ($order->getCoupons() as $coupon) {
     //			$cart->addCoupon()
     //		}
     $shipping = $order->getShippingMethod();
     if ($shipping !== null) {
         $cart->setShippingMethod($shipping);
         $cart->setShippingTax($order->getShippingTax());
     }
     $payment = $order->getPaymentMethod();
     if ($payment !== null) {
         $cart->setPaymentMethod($payment);
     }
     return $cart;
 }
Exemplo n.º 2
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);
     }
 }
Exemplo n.º 3
0
 private function updateQuantities(\Jigoshop\Entity\Cart $cart)
 {
     if (isset($_POST['cart']) && is_array($_POST['cart'])) {
         foreach ($_POST['cart'] as $item => $quantity) {
             $cart->updateQuantity($item, (int) $quantity);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Checks whether user is allowed to see checkout page.
  *
  * @param CartEntity $cart The cart.
  *
  * @return bool Is user allowed to enter checkout page?
  */
 private function isAllowedToCheckout(CartEntity $cart)
 {
     return $this->options->get('shopping.guest_purchases') || $this->wp->isUserLoggedIn() || $this->options->get('shopping.allow_registration') && $cart->getCustomer()->getId() > 0;
 }
Exemplo n.º 5
0
 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;
 }
Exemplo n.º 6
0
 /**
  * Removes cart.
  *
  * @param Cart $cart Cart to remove.
  */
 public function remove(Cart $cart)
 {
     unset($this->objects[$cart->getId()]);
     $this->service->remove($cart);
 }