Get shopping cart details from checkout cart in Magento
The code snippet below gets the quote from the checkout cart, and loops through each item in the cart to add some basic details of an item to an array. Then prints the cart summary details and item level details.
$cart = Mage::getModel('checkout/cart')->getQuote(); $cartItems = array(); foreach($cart->getItemsCollection() as $item) { //$product = Mage::getModel('catalog/product')->load($item->getProductId()); $row=array(); $row['sku'] = $item->getSku(); $row['original_price'] = $item->getOriginalPrice(); $row['price'] = $item->getPrice(); $row['qty_ordered']= (int)$item->getQtyOrdered(); $row['subtotal']= $item->getSubtotal(); $row['tax_amount']= $item->getTaxAmount(); $row['tax_percent']= $item->getTaxPercent(); $row['discount_amount']= $item->getDiscountAmount(); $row['row_total']= $item->getRowTotal(); $cartItems[]=$row; } echo "cart subtotal: ".$cart->getSubtotal()."<br>"; echo "shipping: ".$cart->getShippingAmount()."<br>"; echo "discount: ".$cart->getDiscountAmount()."<br>"; echo "tax: ".$cart->getTaxAmount()."<br>"; echo "grand total".$cart->getGrandTotal()."<br><br><br>"; echo "All items in the order:<br>".print_r($cartItems,true)."<br><br><br>"; echo "Complete cart info:<br>".print_r($cart->debug(),true)."<br>";
All fields and values of a item in the cart:
Array ( [item_id] => 20 [quote_id] => 8 [created_at] => 2014-03-14 03:17:05 [updated_at] => 2014-03-14 03:17:12 [product_id] => 52 [store_id] => 1 [parent_item_id] => [is_virtual] => 0 [sku] => 1112 [name] => Chair [description] => [applied_rule_ids] => [additional_data] => [free_shipping] => 0 [is_qty_decimal] => 0 [no_discount] => 0 [weight] => 50.0000 [qty] => 1.0000 [price] => 129.9900 [base_price] => 129.9900 [custom_price] => [discount_percent] => 0.0000 [discount_amount] => 0.0000 [base_discount_amount] => 0.0000 [tax_percent] => 8.3750 [tax_amount] => 10.8900 [base_tax_amount] => 10.8900 [row_total] => 129.9900 [base_row_total] => 129.9900 [row_total_with_discount] => 0.0000 [row_weight] => 50.0000 [product_type] => simple [base_tax_before_discount] => [tax_before_discount] => [original_custom_price] => [gift_message_id] => [weee_tax_applied] => a:0:{} [weee_tax_applied_amount] => 0.0000 [weee_tax_applied_row_amount] => 0.0000 [base_weee_tax_applied_amount] => 0.0000 [base_weee_tax_applied_row_amnt] => [weee_tax_disposition] => 0.0000 [weee_tax_row_disposition] => 0.0000 [base_weee_tax_disposition] => 0.0000 [base_weee_tax_row_disposition] => 0.0000 [redirect_url] => [base_cost] => 50.0000 [price_incl_tax] => 140.8800 [base_price_incl_tax] => 140.8800 [row_total_incl_tax] => 140.8800 [base_row_total_incl_tax] => 140.8800 [hidden_tax_amount] => [base_hidden_tax_amount] => )
Search within Codexpedia
Custom Search
Search the entire web
Custom Search
Related Posts