Get cart contents from my custom module












0















In my magento, I have added a product to cart - so I see the following on the checkout page:



enter image description here



I have a custom module with a TestController with a IndexAction where I want to retrieve the current contents of basket for custom processing. This will be used to provide a "get delivery cost estimate" type functionality.



I.e. customer will add bunch of items into basket (as guest), click a button on front end and it takes them to our module where they will enter the destination country and postcode and we will do some custom processing to let the customer know what the estimated delivery cost is going to be.



I tried to retrieve the basket contents like this:



$cart_contents = Mage::helper('checkout')->getQuote();
foreach ($cart_contents->getItemsCollection() as $item) {
var_dump($item->getName());
}
exit;


This does not return anything.



I also tried a different approach:



$quote = Mage::getSingleton('checkout/session')->getQuote();
$cartItems = $quote->getAllVisibleItems();
echo "<pre>";
foreach ($cartItems as $item) {
print_r($item->getData());
}
exit;


This is also returning nothing.



Bear in mind; this is a guest checkout (i.e. customer is not logged in).



To test there is a valid quote; I did the following:



echo "<pre>";
print_r(Mage::helper('checkout')->getQuote()->getData());
echo "<hr>";
print_r(Mage::getSingleton('checkout/session')->getQuote()->getData());
exit;


This is what I get back:



Array
(
[store_id] => 5
[is_checkout_cart] => 1
[remote_ip] => 90.xxx.xxx.xxx
[x_forwarded_for] => 90.xxx.xxx.xxx
)
Array
(
[store_id] => 5
[is_checkout_cart] => 1
[remote_ip] => 90.xxx.xxx.xxx
[x_forwarded_for] => 90.xxx.xxx.xxx
)









share|improve this question














bumped to the homepage by Community 51 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    0















    In my magento, I have added a product to cart - so I see the following on the checkout page:



    enter image description here



    I have a custom module with a TestController with a IndexAction where I want to retrieve the current contents of basket for custom processing. This will be used to provide a "get delivery cost estimate" type functionality.



    I.e. customer will add bunch of items into basket (as guest), click a button on front end and it takes them to our module where they will enter the destination country and postcode and we will do some custom processing to let the customer know what the estimated delivery cost is going to be.



    I tried to retrieve the basket contents like this:



    $cart_contents = Mage::helper('checkout')->getQuote();
    foreach ($cart_contents->getItemsCollection() as $item) {
    var_dump($item->getName());
    }
    exit;


    This does not return anything.



    I also tried a different approach:



    $quote = Mage::getSingleton('checkout/session')->getQuote();
    $cartItems = $quote->getAllVisibleItems();
    echo "<pre>";
    foreach ($cartItems as $item) {
    print_r($item->getData());
    }
    exit;


    This is also returning nothing.



    Bear in mind; this is a guest checkout (i.e. customer is not logged in).



    To test there is a valid quote; I did the following:



    echo "<pre>";
    print_r(Mage::helper('checkout')->getQuote()->getData());
    echo "<hr>";
    print_r(Mage::getSingleton('checkout/session')->getQuote()->getData());
    exit;


    This is what I get back:



    Array
    (
    [store_id] => 5
    [is_checkout_cart] => 1
    [remote_ip] => 90.xxx.xxx.xxx
    [x_forwarded_for] => 90.xxx.xxx.xxx
    )
    Array
    (
    [store_id] => 5
    [is_checkout_cart] => 1
    [remote_ip] => 90.xxx.xxx.xxx
    [x_forwarded_for] => 90.xxx.xxx.xxx
    )









    share|improve this question














    bumped to the homepage by Community 51 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      0












      0








      0








      In my magento, I have added a product to cart - so I see the following on the checkout page:



      enter image description here



      I have a custom module with a TestController with a IndexAction where I want to retrieve the current contents of basket for custom processing. This will be used to provide a "get delivery cost estimate" type functionality.



      I.e. customer will add bunch of items into basket (as guest), click a button on front end and it takes them to our module where they will enter the destination country and postcode and we will do some custom processing to let the customer know what the estimated delivery cost is going to be.



      I tried to retrieve the basket contents like this:



      $cart_contents = Mage::helper('checkout')->getQuote();
      foreach ($cart_contents->getItemsCollection() as $item) {
      var_dump($item->getName());
      }
      exit;


      This does not return anything.



      I also tried a different approach:



      $quote = Mage::getSingleton('checkout/session')->getQuote();
      $cartItems = $quote->getAllVisibleItems();
      echo "<pre>";
      foreach ($cartItems as $item) {
      print_r($item->getData());
      }
      exit;


      This is also returning nothing.



      Bear in mind; this is a guest checkout (i.e. customer is not logged in).



      To test there is a valid quote; I did the following:



      echo "<pre>";
      print_r(Mage::helper('checkout')->getQuote()->getData());
      echo "<hr>";
      print_r(Mage::getSingleton('checkout/session')->getQuote()->getData());
      exit;


      This is what I get back:



      Array
      (
      [store_id] => 5
      [is_checkout_cart] => 1
      [remote_ip] => 90.xxx.xxx.xxx
      [x_forwarded_for] => 90.xxx.xxx.xxx
      )
      Array
      (
      [store_id] => 5
      [is_checkout_cart] => 1
      [remote_ip] => 90.xxx.xxx.xxx
      [x_forwarded_for] => 90.xxx.xxx.xxx
      )









      share|improve this question














      In my magento, I have added a product to cart - so I see the following on the checkout page:



      enter image description here



      I have a custom module with a TestController with a IndexAction where I want to retrieve the current contents of basket for custom processing. This will be used to provide a "get delivery cost estimate" type functionality.



      I.e. customer will add bunch of items into basket (as guest), click a button on front end and it takes them to our module where they will enter the destination country and postcode and we will do some custom processing to let the customer know what the estimated delivery cost is going to be.



      I tried to retrieve the basket contents like this:



      $cart_contents = Mage::helper('checkout')->getQuote();
      foreach ($cart_contents->getItemsCollection() as $item) {
      var_dump($item->getName());
      }
      exit;


      This does not return anything.



      I also tried a different approach:



      $quote = Mage::getSingleton('checkout/session')->getQuote();
      $cartItems = $quote->getAllVisibleItems();
      echo "<pre>";
      foreach ($cartItems as $item) {
      print_r($item->getData());
      }
      exit;


      This is also returning nothing.



      Bear in mind; this is a guest checkout (i.e. customer is not logged in).



      To test there is a valid quote; I did the following:



      echo "<pre>";
      print_r(Mage::helper('checkout')->getQuote()->getData());
      echo "<hr>";
      print_r(Mage::getSingleton('checkout/session')->getQuote()->getData());
      exit;


      This is what I get back:



      Array
      (
      [store_id] => 5
      [is_checkout_cart] => 1
      [remote_ip] => 90.xxx.xxx.xxx
      [x_forwarded_for] => 90.xxx.xxx.xxx
      )
      Array
      (
      [store_id] => 5
      [is_checkout_cart] => 1
      [remote_ip] => 90.xxx.xxx.xxx
      [x_forwarded_for] => 90.xxx.xxx.xxx
      )






      cart quote quoteitem sales-quote






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 15 '16 at 12:54









      LatheesanLatheesan

      6831832




      6831832





      bumped to the homepage by Community 51 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 51 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          2 Answers
          2






          active

          oldest

          votes


















          0














          tested code try it



          $cart = Mage::getModel('checkout/cart')->getQuote();

          if($cart->getAllItems()):

          foreach ($cart->getAllItems() as $item):
          echo $item->getProduct()->getName();
          endforeach;
          endif;





          share|improve this answer































            0














            Use the model of the class called Mage_Sales_Model_Checkout_Cart.



            This is the standard model of the shopping cart that works equally fine both for registered and non-registered users.



            Here is the example of the code:
            https://www.gyazo.com/55a4f2d490e2573af8c25ccba2195ef8



            This is just a shopping cart:
            https://www.gyazo.com/c23cc7d32598f847a785f7689b1f01bf



            And this is the result of the code implementation:
            https://www.gyazo.com/7151712c0af8ff98cf178e6bf94c7a45






            share|improve this answer
























            • Okay, let me try your method also using Mage_Sales_Model_Checkout_Cart

              – Latheesan
              Mar 15 '16 at 15:52






            • 1





              Please don't post screenshots with the code. Post the actual code.

              – Marius
              Mar 15 '16 at 15:53











            • Actually never mind, this method is not any different from what Qaisar Satti suggested. I have tried this method also and it's returning nothing.

              – Latheesan
              Mar 15 '16 at 15:54











            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "479"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f106354%2fget-cart-contents-from-my-custom-module%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            tested code try it



            $cart = Mage::getModel('checkout/cart')->getQuote();

            if($cart->getAllItems()):

            foreach ($cart->getAllItems() as $item):
            echo $item->getProduct()->getName();
            endforeach;
            endif;





            share|improve this answer




























              0














              tested code try it



              $cart = Mage::getModel('checkout/cart')->getQuote();

              if($cart->getAllItems()):

              foreach ($cart->getAllItems() as $item):
              echo $item->getProduct()->getName();
              endforeach;
              endif;





              share|improve this answer


























                0












                0








                0







                tested code try it



                $cart = Mage::getModel('checkout/cart')->getQuote();

                if($cart->getAllItems()):

                foreach ($cart->getAllItems() as $item):
                echo $item->getProduct()->getName();
                endforeach;
                endif;





                share|improve this answer













                tested code try it



                $cart = Mage::getModel('checkout/cart')->getQuote();

                if($cart->getAllItems()):

                foreach ($cart->getAllItems() as $item):
                echo $item->getProduct()->getName();
                endforeach;
                endif;






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 15 '16 at 13:16









                Qaisar SattiQaisar Satti

                26.7k1255107




                26.7k1255107

























                    0














                    Use the model of the class called Mage_Sales_Model_Checkout_Cart.



                    This is the standard model of the shopping cart that works equally fine both for registered and non-registered users.



                    Here is the example of the code:
                    https://www.gyazo.com/55a4f2d490e2573af8c25ccba2195ef8



                    This is just a shopping cart:
                    https://www.gyazo.com/c23cc7d32598f847a785f7689b1f01bf



                    And this is the result of the code implementation:
                    https://www.gyazo.com/7151712c0af8ff98cf178e6bf94c7a45






                    share|improve this answer
























                    • Okay, let me try your method also using Mage_Sales_Model_Checkout_Cart

                      – Latheesan
                      Mar 15 '16 at 15:52






                    • 1





                      Please don't post screenshots with the code. Post the actual code.

                      – Marius
                      Mar 15 '16 at 15:53











                    • Actually never mind, this method is not any different from what Qaisar Satti suggested. I have tried this method also and it's returning nothing.

                      – Latheesan
                      Mar 15 '16 at 15:54
















                    0














                    Use the model of the class called Mage_Sales_Model_Checkout_Cart.



                    This is the standard model of the shopping cart that works equally fine both for registered and non-registered users.



                    Here is the example of the code:
                    https://www.gyazo.com/55a4f2d490e2573af8c25ccba2195ef8



                    This is just a shopping cart:
                    https://www.gyazo.com/c23cc7d32598f847a785f7689b1f01bf



                    And this is the result of the code implementation:
                    https://www.gyazo.com/7151712c0af8ff98cf178e6bf94c7a45






                    share|improve this answer
























                    • Okay, let me try your method also using Mage_Sales_Model_Checkout_Cart

                      – Latheesan
                      Mar 15 '16 at 15:52






                    • 1





                      Please don't post screenshots with the code. Post the actual code.

                      – Marius
                      Mar 15 '16 at 15:53











                    • Actually never mind, this method is not any different from what Qaisar Satti suggested. I have tried this method also and it's returning nothing.

                      – Latheesan
                      Mar 15 '16 at 15:54














                    0












                    0








                    0







                    Use the model of the class called Mage_Sales_Model_Checkout_Cart.



                    This is the standard model of the shopping cart that works equally fine both for registered and non-registered users.



                    Here is the example of the code:
                    https://www.gyazo.com/55a4f2d490e2573af8c25ccba2195ef8



                    This is just a shopping cart:
                    https://www.gyazo.com/c23cc7d32598f847a785f7689b1f01bf



                    And this is the result of the code implementation:
                    https://www.gyazo.com/7151712c0af8ff98cf178e6bf94c7a45






                    share|improve this answer













                    Use the model of the class called Mage_Sales_Model_Checkout_Cart.



                    This is the standard model of the shopping cart that works equally fine both for registered and non-registered users.



                    Here is the example of the code:
                    https://www.gyazo.com/55a4f2d490e2573af8c25ccba2195ef8



                    This is just a shopping cart:
                    https://www.gyazo.com/c23cc7d32598f847a785f7689b1f01bf



                    And this is the result of the code implementation:
                    https://www.gyazo.com/7151712c0af8ff98cf178e6bf94c7a45







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 15 '16 at 15:49









                    MageWorxMageWorx

                    3,328512




                    3,328512













                    • Okay, let me try your method also using Mage_Sales_Model_Checkout_Cart

                      – Latheesan
                      Mar 15 '16 at 15:52






                    • 1





                      Please don't post screenshots with the code. Post the actual code.

                      – Marius
                      Mar 15 '16 at 15:53











                    • Actually never mind, this method is not any different from what Qaisar Satti suggested. I have tried this method also and it's returning nothing.

                      – Latheesan
                      Mar 15 '16 at 15:54



















                    • Okay, let me try your method also using Mage_Sales_Model_Checkout_Cart

                      – Latheesan
                      Mar 15 '16 at 15:52






                    • 1





                      Please don't post screenshots with the code. Post the actual code.

                      – Marius
                      Mar 15 '16 at 15:53











                    • Actually never mind, this method is not any different from what Qaisar Satti suggested. I have tried this method also and it's returning nothing.

                      – Latheesan
                      Mar 15 '16 at 15:54

















                    Okay, let me try your method also using Mage_Sales_Model_Checkout_Cart

                    – Latheesan
                    Mar 15 '16 at 15:52





                    Okay, let me try your method also using Mage_Sales_Model_Checkout_Cart

                    – Latheesan
                    Mar 15 '16 at 15:52




                    1




                    1





                    Please don't post screenshots with the code. Post the actual code.

                    – Marius
                    Mar 15 '16 at 15:53





                    Please don't post screenshots with the code. Post the actual code.

                    – Marius
                    Mar 15 '16 at 15:53













                    Actually never mind, this method is not any different from what Qaisar Satti suggested. I have tried this method also and it's returning nothing.

                    – Latheesan
                    Mar 15 '16 at 15:54





                    Actually never mind, this method is not any different from what Qaisar Satti suggested. I have tried this method also and it's returning nothing.

                    – Latheesan
                    Mar 15 '16 at 15:54


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f106354%2fget-cart-contents-from-my-custom-module%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    What other Star Trek series did the main TNG cast show up in?

                    Berlina muro

                    Berlina aerponto