Get cart contents from my custom module
In my magento, I have added a product to cart - so I see the following on the checkout page:
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
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.
add a comment |
In my magento, I have added a product to cart - so I see the following on the checkout page:
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
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.
add a comment |
In my magento, I have added a product to cart - so I see the following on the checkout page:
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
In my magento, I have added a product to cart - so I see the following on the checkout page:
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
cart quote quoteitem sales-quote
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.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
tested code try it
$cart = Mage::getModel('checkout/cart')->getQuote();
if($cart->getAllItems()):
foreach ($cart->getAllItems() as $item):
echo $item->getProduct()->getName();
endforeach;
endif;
add a comment |
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
Okay, let me try your method also usingMage_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 whatQaisar Satti
suggested. I have tried this method also and it's returning nothing.
– Latheesan
Mar 15 '16 at 15:54
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
tested code try it
$cart = Mage::getModel('checkout/cart')->getQuote();
if($cart->getAllItems()):
foreach ($cart->getAllItems() as $item):
echo $item->getProduct()->getName();
endforeach;
endif;
add a comment |
tested code try it
$cart = Mage::getModel('checkout/cart')->getQuote();
if($cart->getAllItems()):
foreach ($cart->getAllItems() as $item):
echo $item->getProduct()->getName();
endforeach;
endif;
add a comment |
tested code try it
$cart = Mage::getModel('checkout/cart')->getQuote();
if($cart->getAllItems()):
foreach ($cart->getAllItems() as $item):
echo $item->getProduct()->getName();
endforeach;
endif;
tested code try it
$cart = Mage::getModel('checkout/cart')->getQuote();
if($cart->getAllItems()):
foreach ($cart->getAllItems() as $item):
echo $item->getProduct()->getName();
endforeach;
endif;
answered Mar 15 '16 at 13:16
Qaisar SattiQaisar Satti
26.7k1255107
26.7k1255107
add a comment |
add a comment |
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
Okay, let me try your method also usingMage_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 whatQaisar Satti
suggested. I have tried this method also and it's returning nothing.
– Latheesan
Mar 15 '16 at 15:54
add a comment |
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
Okay, let me try your method also usingMage_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 whatQaisar Satti
suggested. I have tried this method also and it's returning nothing.
– Latheesan
Mar 15 '16 at 15:54
add a comment |
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
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
answered Mar 15 '16 at 15:49
MageWorxMageWorx
3,328512
3,328512
Okay, let me try your method also usingMage_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 whatQaisar Satti
suggested. I have tried this method also and it's returning nothing.
– Latheesan
Mar 15 '16 at 15:54
add a comment |
Okay, let me try your method also usingMage_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 whatQaisar 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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