{"id":28,"date":"2009-07-03T06:32:00","date_gmt":"2009-07-03T06:32:00","guid":{"rendered":"http:\/\/www.codeboss.in\/web-funda\/?p=28"},"modified":"2009-07-03T06:32:00","modified_gmt":"2009-07-03T06:32:00","slug":"get-cart-quantity-in-magento","status":"publish","type":"post","link":"https:\/\/codeboss.in\/web-funda\/2009\/07\/03\/get-cart-quantity-in-magento\/","title":{"rendered":"Get Cart Quantity in Magento"},"content":{"rendered":"<p>You can get the number of items currently in the cart using the following code.<\/p>\n<pre class=\"brush: php; html-script: true\">\n$cart = Mage::getModel('checkout\/cart')->getQuote()->getData();\necho (int)$cart['items_qty'];\n<\/pre>\n<p>However,if the cart is empty, writing only the above code will show error (Because $cart[&#8216;items_qty&#8217;] is only set when there are items on the cart). For that you need to check if the value is set or not. Hence the total code will be like &#8211; <\/p>\n<pre class=\"brush: php; html-script: true\">\n$cart = Mage::getModel('checkout\/cart')->getQuote()->getData();\nif(isset($cart['items_qty'])){\necho (int)$cart['items_qty'];\n} else {\necho '0';\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You can get the number of items currently in the cart using the following code. $cart = Mage::getModel(&#8216;checkout\/cart&#8217;)->getQuote()->getData(); echo (int)$cart[&#8216;items_qty&#8217;]; However,if the cart is empty, writing only the above code will show error (Because $cart[&#8216;items_qty&#8217;] is only set when there are items on the cart). For that you need to check if the value is&hellip; <a class=\"more-link\" href=\"https:\/\/codeboss.in\/web-funda\/2009\/07\/03\/get-cart-quantity-in-magento\/\">Continue reading <span class=\"screen-reader-text\">Get Cart Quantity in Magento<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[54,57],"class_list":["post-28","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-magento","tag-php","entry"],"_links":{"self":[{"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/posts\/28","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/comments?post=28"}],"version-history":[{"count":0,"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/posts\/28\/revisions"}],"wp:attachment":[{"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/media?parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/categories?post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/tags?post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}