How to check whether a product is in the cart? The 2019 Stack Overflow Developer Survey Results Are InGetting the product SKU in the header mini-cartMagento 2 : Check Static Block with same identifier in InstallData ScriptMagento 2 : How to Check Cart Items Satisfying Cart Price Rule Condition?How can I check if the module output is enabled on the Magento 2?Magento 2 check which catalog rule is applied to cart productMagento 2 not passing minimum QTY when adding related products to cartCheck bundle product magento 2Magento 2 : How to change the quantity of items in the checkout?How to get the product category id in the cart? Magento 2How to show the client pop-up when adding a product to the cart?
How to display lines in a file like ls displays files in a directory?
Can a rogue use sneak attack with weapons that have the thrown property even if they are not thrown?
What information about me do stores get via my credit card?
Worn-tile Scrabble
How do you keep chess fun when your opponent constantly defeats?
Why can't devices on different VLANs, but on the same subnet, communicate?
Is it safe to harvest rainwater that fell on solar panels?
What is this business jet?
Did any laptop computers have a built-in 5 1/4 inch floppy drive?
If I can cast sorceries at instant speed, can I use sorcery-speed activated abilities at instant speed?
Output the Arecibo Message
Button changing its text & action. Good or terrible?
What does Linus Torvalds mean when he says that Git "never ever" tracks a file?
APIPA and LAN Broadcast Domain
Flight paths in orbit around Ceres?
If a sorcerer casts the Banishment spell on a PC while in Avernus, does the PC return to their home plane?
Compute the product of 3 dictionaries and concatenate keys and values
Keeping a retro style to sci-fi spaceships?
How do PCB vias affect signal quality?
$EDITOR environment variable won't set
Computing the expectation of the number of balls in a box
Star Trek - X-shaped Item on Regula/Orbital Office Starbases
If I score a critical hit on an 18 or higher, what are my chances of getting a critical hit if I roll 3d20?
Old scifi movie from the 50s or 60s with men in solid red uniforms who interrogate a spy from the past
How to check whether a product is in the cart?
The 2019 Stack Overflow Developer Survey Results Are InGetting the product SKU in the header mini-cartMagento 2 : Check Static Block with same identifier in InstallData ScriptMagento 2 : How to Check Cart Items Satisfying Cart Price Rule Condition?How can I check if the module output is enabled on the Magento 2?Magento 2 check which catalog rule is applied to cart productMagento 2 not passing minimum QTY when adding related products to cartCheck bundle product magento 2Magento 2 : How to change the quantity of items in the checkout?How to get the product category id in the cart? Magento 2How to show the client pop-up when adding a product to the cart?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
How to create a module that will check if there is an item in the basket?
Verification is needed on the product page.
magento2
add a comment |
How to create a module that will check if there is an item in the basket?
Verification is needed on the product page.
magento2
add a comment |
How to create a module that will check if there is an item in the basket?
Verification is needed on the product page.
magento2
How to create a module that will check if there is an item in the basket?
Verification is needed on the product page.
magento2
magento2
edited Apr 8 at 10:39
Рома Лытарь
asked Apr 8 at 10:02
Рома ЛытарьРома Лытарь
1789
1789
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Try to use this below code :
public function __construct(
MagentoCheckoutModelCart $cart
)
$this->_cart = $cart;
public function getProductData()
$productInfo = $this->_cart->getQuote()->getItemsCollection();
foreach ($productInfo as $item)
$item->getProductId();
if($item->getProductId() == 'your_product_id')
echo "Item available in cart";
else
echo "Item not available in cart";
Where should I put this code?
– Рома Лытарь
Apr 8 at 10:14
you can add in your block or controller.
– Rohan Hapani
Apr 8 at 10:15
What structure should be? I just do not understand what should be in the model and what should be in the block, etc.
– Рома Лытарь
Apr 8 at 10:23
Wherer you want to access this value?
– Rohan Hapani
Apr 8 at 10:30
On the product page
– Рома Лытарь
Apr 8 at 10:31
|
show 3 more comments
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%2f269130%2fhow-to-check-whether-a-product-is-in-the-cart%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try to use this below code :
public function __construct(
MagentoCheckoutModelCart $cart
)
$this->_cart = $cart;
public function getProductData()
$productInfo = $this->_cart->getQuote()->getItemsCollection();
foreach ($productInfo as $item)
$item->getProductId();
if($item->getProductId() == 'your_product_id')
echo "Item available in cart";
else
echo "Item not available in cart";
Where should I put this code?
– Рома Лытарь
Apr 8 at 10:14
you can add in your block or controller.
– Rohan Hapani
Apr 8 at 10:15
What structure should be? I just do not understand what should be in the model and what should be in the block, etc.
– Рома Лытарь
Apr 8 at 10:23
Wherer you want to access this value?
– Rohan Hapani
Apr 8 at 10:30
On the product page
– Рома Лытарь
Apr 8 at 10:31
|
show 3 more comments
Try to use this below code :
public function __construct(
MagentoCheckoutModelCart $cart
)
$this->_cart = $cart;
public function getProductData()
$productInfo = $this->_cart->getQuote()->getItemsCollection();
foreach ($productInfo as $item)
$item->getProductId();
if($item->getProductId() == 'your_product_id')
echo "Item available in cart";
else
echo "Item not available in cart";
Where should I put this code?
– Рома Лытарь
Apr 8 at 10:14
you can add in your block or controller.
– Rohan Hapani
Apr 8 at 10:15
What structure should be? I just do not understand what should be in the model and what should be in the block, etc.
– Рома Лытарь
Apr 8 at 10:23
Wherer you want to access this value?
– Rohan Hapani
Apr 8 at 10:30
On the product page
– Рома Лытарь
Apr 8 at 10:31
|
show 3 more comments
Try to use this below code :
public function __construct(
MagentoCheckoutModelCart $cart
)
$this->_cart = $cart;
public function getProductData()
$productInfo = $this->_cart->getQuote()->getItemsCollection();
foreach ($productInfo as $item)
$item->getProductId();
if($item->getProductId() == 'your_product_id')
echo "Item available in cart";
else
echo "Item not available in cart";
Try to use this below code :
public function __construct(
MagentoCheckoutModelCart $cart
)
$this->_cart = $cart;
public function getProductData()
$productInfo = $this->_cart->getQuote()->getItemsCollection();
foreach ($productInfo as $item)
$item->getProductId();
if($item->getProductId() == 'your_product_id')
echo "Item available in cart";
else
echo "Item not available in cart";
answered Apr 8 at 10:11
Rohan HapaniRohan Hapani
6,90431865
6,90431865
Where should I put this code?
– Рома Лытарь
Apr 8 at 10:14
you can add in your block or controller.
– Rohan Hapani
Apr 8 at 10:15
What structure should be? I just do not understand what should be in the model and what should be in the block, etc.
– Рома Лытарь
Apr 8 at 10:23
Wherer you want to access this value?
– Rohan Hapani
Apr 8 at 10:30
On the product page
– Рома Лытарь
Apr 8 at 10:31
|
show 3 more comments
Where should I put this code?
– Рома Лытарь
Apr 8 at 10:14
you can add in your block or controller.
– Rohan Hapani
Apr 8 at 10:15
What structure should be? I just do not understand what should be in the model and what should be in the block, etc.
– Рома Лытарь
Apr 8 at 10:23
Wherer you want to access this value?
– Rohan Hapani
Apr 8 at 10:30
On the product page
– Рома Лытарь
Apr 8 at 10:31
Where should I put this code?
– Рома Лытарь
Apr 8 at 10:14
Where should I put this code?
– Рома Лытарь
Apr 8 at 10:14
you can add in your block or controller.
– Rohan Hapani
Apr 8 at 10:15
you can add in your block or controller.
– Rohan Hapani
Apr 8 at 10:15
What structure should be? I just do not understand what should be in the model and what should be in the block, etc.
– Рома Лытарь
Apr 8 at 10:23
What structure should be? I just do not understand what should be in the model and what should be in the block, etc.
– Рома Лытарь
Apr 8 at 10:23
Wherer you want to access this value?
– Rohan Hapani
Apr 8 at 10:30
Wherer you want to access this value?
– Rohan Hapani
Apr 8 at 10:30
On the product page
– Рома Лытарь
Apr 8 at 10:31
On the product page
– Рома Лытарь
Apr 8 at 10:31
|
show 3 more comments
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%2f269130%2fhow-to-check-whether-a-product-is-in-the-cart%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