Move Items to another cart instance

@param Cart $cart
502372
public function moveItemsTo(Cart $cart){

        \DB::transaction(function () use(&$cart){
            $current_items = $cart->items()->pluck('product_id');
            $items_to_move = $this->items()->whereNotIn('product_id', $current_items->toArray())->get();
            if($items_to_move->count() === 0){
                return;
            }
            $this->items()->whereNotIn('product_id', $current_items->toArray())->update([
                'cart_id' => $cart->id
            ]);
            foreach($items_to_move as $item) {
                $this->item_count -= $item->quantity;
                $this->total_price -= $item->getPrice();
                $cart->item_count += $item->quantity;
                $cart->total_price += $item->getPrice();
            }
            $this->relations = [];
            $cart->relations = [];
            $this->save();
            $cart->save();
        });
        return $cart;
    }
956204
public function setCart(ShoppingCart $cart)
    {
        $curr = $this->getOwner()->getCart();
        $contact = $this->getOwner()->Contact();

        if (isset($curr) && $curr->ID != $cart->ID) {
            $curr->delete();
        }

        $cart->CustomerID = $contact->ID;

        return $this;
    }
313372
protected function cloneCart(array $order, array $cart)
    {
        foreach ($cart['items'] as $item) {
            $cart_id = $item['cart_id'];
            unset($item['cart_id']);
            $item['user_id'] = $order['user_id'];
            $item['order_id'] = $order['order_id'];
            $this->cart->add($item);
            $this->cart->delete($cart_id);
        }
    }
903512
private void moveToNext() {
        if (controller != null) {
            currentItemIndex = controller.nextItem(this, currentItemIndex);
        } else {
            currentItemIndex = defaultController.nextItem(this, currentItemIndex);
        }
    }
454685
public function moveItems( stdClass $params )
	{
		$this->_checkParams( $params, array( 'items', 'oldparentid', 'newparentid', 'refid' ) );

		$manager = $this->_getManager();

		if( $params->newparentid === 'root' ) {
			$params->newparentid = null;
		}

		$refId = ( isset( $params->refid ) ? $params->refid : null );
		$items = ( !is_array( $params->items ) ? array( $params->items ) : $params->items );

		foreach( $items as $entry ) {
			$manager->moveItem( $entry, $params->oldparentid, $params->newparentid, $refId );
		}

		return array(
			'success' => true,
		);
	}
789493
public function storeNewCartData($cartData)
    {
        // Set id of the item to be used for updates later
        foreach ($cartData['items'] as $key => $item) {
            $cartData['items'][$key]['id'] = $key + 1;
        }

        // We use static number 1 as the cart id
        session([
            $this->sessionKey => array_merge($cartData, ['id' => 1]),
        ]);
    }
767029
private function AssignFrom( $src )
	{
		$this->index = $src->index;
		$this->itemSet = $src->itemSet;
		$this->lastNode = $src->lastNode;
		$this->allowSameElementRepeat = $src->allowSameElementRepeat;
	}
819783
public function remove(CartId $cartId)
    {
        if (!$this->exists($cartId)) {
            throw CartNotFoundException::byId($cartId);
        }

        unset($this->carts[(string) $cartId]);
    }
402358
public function set(CartInterface $cart)
    {
        if (!$this->saveInSession) {
            return $this;
        }

        $this
            ->session
            ->set(
                $this->sessionFieldName,
                $cart->getId()
            );

        return $this;
    }
645248
public function validateCartCoupons(CartInterface $cart)
    {
        $cartCoupons = $this
            ->cartCouponManager
            ->getCartCoupons($cart);

        foreach ($cartCoupons as $cartCoupon) {
            $coupon = $cartCoupon->getCoupon();

            try {
                $this
                    ->cartCouponEventDispatcher
                    ->dispatchCartCouponOnCheckEvent(
                        $cart,
                        $coupon
                    );
            } catch (AbstractCouponException $exception) {
                $this
                    ->cartCouponManager
                    ->removeCoupon(
                        $cart,
                        $coupon
                    );

                $this
                    ->cartCouponEventDispatcher
                    ->dispatchCartCouponOnRejectedEvent(
                        $cart,
                        $coupon
                    );
            }
        }
    }
1296246
public function validateCartIntegrity(CartInterface $cart)
    {
        /**
         * Check every CartLine.
         *
         * @var CartLineInterface $cartLine
         */
        foreach ($cart->getCartLines() as $cartLine) {
            $this->validateCartLine($cartLine);
        }
    }
2250
public function handle(RemoveFromCart $command)
    {
        $cart = $this->carts->getById(new CartId($command->cartId()));
        $cart->remove(new SKU($command->sku()));
    }
478966
public function destroyCart()
    {
        $instance = $this->cart->instance;

        $this->session->forget($this->prefix.'.'.$instance);

        $this->events->dispatch('laracart.destroy', $instance);

        $this->cart = new Cart($instance);

        $this->update();
    }
233946
public function onCheckout($cart)
    {
        if (!isset($this->creditCard))
            throw new CheckoutException('Credit Card is not set.', 0);

        if (!in_array($this->creditCard->getType(), $this->validTypes))
            throw new CheckoutException('Credit Card is not supported.', 1);

        if ($this->getPatternType($this->creditCard->getNumber()) != $this->creditCard->getType())
            throw new CheckoutException('Credit Card is invalid.', 2);
    }
654668
public function updateCartObject($cart) {
    if (isset($cart->customer_id)) {
      $cart->customer_id = (string) $cart->customer_id;
    }

    // Some ecommerce backends, like hybris, don't save the billing like they
    // do with shipping. So if a billing was set we don't want it to be
    // overwritten when the API response comes back.
    $current_billing = $this->getBilling();
    if (!empty($current_billing) && empty($cart->billing)) {
      $cart->billing = $current_billing;
    }

    if (isset($cart->carrier)) {
      // We use it as array internally everywhere, even set as array.
      $cart->carrier = (array) $cart->carrier;

      // If carrier is with empty structure, we remove it.
      if (empty($cart->carrier['carrier_code'])) {
        unset($cart->carrier);
      }
    }

    $this->cart = $cart;
    $this->updateCartItemsCount();
  }
259837
public function move($dest)
    {
        $this->copy($dest);
        $this->delete();
        $this->path = $dest;
    }
89598
public function destroy(CartItem $cartitem)
    {
        $this->cartitem->destroy($cartitem);

        return redirect()->route('admin.cart.cartitem.index')
            ->withSuccess(trans('core::core.messages.resource deleted', ['name' => trans('cart::cartitems.title.cartitems')]));
    }