/** * @return $this */ public function getCartFromSession() { //initialise $update_cart_session = false; //get items from the cart /** * If we process the product with "Cart::getItems", then item meta are move to array format. * Raw array format is not suitable for using "$this->meta->meta_key", so product is not yet * processing. */ $cart_items = Cart::getItems(true); foreach ($cart_items as $key => $cartitem) { //let us find the product $product = $cartitem->getProduct(); if ($product && !is_null($product)) { //does the product exists if ($product->getId() && $product->exists() && $cartitem->getQuantity() > 0) { if (!$product->isPurchasable()) { //product is unavailable. Set a flag indicating that the cart session has to be updated. $update_cart_session = true; do_action('sp_remove_cart_item_from_session', $key, $cartitem); } else { $cartitem->put('product', $product); $this->cart_contents[$key] = apply_filters('cartrabbit_get_cart_item_from_session', $cartitem, $key); } } } } // Trigger action do_action('sp_cart_loaded_from_session', $this); if (!$this->subtotal && !$this->isEmpty()) { $this->calculateTotals(); } return $this; }