Add to Cart button in Magento 2.1Multiple Add to Cart Button from External php site using product idHow to hide add to cart button from product page of a specific product?Set custom price of product when adding to cart code not workingMagento 2: How to get add to cart url in custom templete file and add product to cartAdd to Cart Button Not Working Magento 2Magento 2: Add a product to the cart programmaticallyMagento 2.2.3 CE, price is zero when adding to cartMagento 2- How to move custom options after cart button?Additional Add to Cart ButtonMagento2 : How to add button in admin custom module page?
Storing voxels for a voxel Engine in C++
Is "vegetable base" a common term in English?
Physical only checkdb is failing, but full one is completed successfully
Fill area of x^2+y^2>1 and x^2+y^2>4 using patterns and tikzpicture
Why did Drogon spare this character?
Is there a simple example that empirical evidence is misleading?
How to remove new line added by readarray when using a delimiter?
Visual Block Mode edit with sequential number
The disk image is 497GB smaller than the target device
What is to the west of Westeros?
How to escape dependency hell?
Why did OJ Simpson's trial take 9 months?
Merge pdfs sequentially
Count all vowels in string
Is this homebrew "Cactus Grenade" cantrip balanced?
Have any humans orbited the Earth in anything other than a prograde orbit?
Is it safe to redirect stdout and stderr to the same file without file descriptor copies?
Status of proof by contradiction and excluded middle throughout the history of mathematics?
Ribbon Cable Cross Talk - Is there a fix after the fact?
How to deceive the MC
Are there guidelines for finding good names for LaTeX 2e packages and control sequences defined in these packages?
What is Orcus doing with Mind Flayers in the art on the last page of Volo's Guide to Monsters?
How to write numbers and percentage?
How to create a `range`-like iterable object of floats?
Add to Cart button in Magento 2.1
Multiple Add to Cart Button from External php site using product idHow to hide add to cart button from product page of a specific product?Set custom price of product when adding to cart code not workingMagento 2: How to get add to cart url in custom templete file and add product to cartAdd to Cart Button Not Working Magento 2Magento 2: Add a product to the cart programmaticallyMagento 2.2.3 CE, price is zero when adding to cartMagento 2- How to move custom options after cart button?Additional Add to Cart ButtonMagento2 : How to add button in admin custom module page?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I tried with button add to cart and it not working,
app/code/Moo/Custom/view/product.phtml
<?php
$product = $this->getData('product');
$postDataHelper = $this->helper('MagentoFrameworkDataHelperPostHelper');
$postData = $postDataHelper->getPostData($block->getAddToCartUrl($product),
['product' => $product->getEntityId()]);
<button class="action description-button" data-post='<?php echo $postData; ?>'
<type="button" title="<?php echo __('Add to cart') ?>">
<span><?php echo __('Add to cart') ?></span>
</button>
data-post
button have action is null ? It look like :
data-post=""action":null,"data":"product":"7","uenc":"aHR0cDovLzUyLjE4My4yNi45OC9hcmR6YW5fc3VwZXJtYXJrZXQvaW5kZXgvbG9hZHByb2R1Y3Qv""
Please help me, why it not work?
magento2 magento-2.1 product cart addtocart
add a comment |
I tried with button add to cart and it not working,
app/code/Moo/Custom/view/product.phtml
<?php
$product = $this->getData('product');
$postDataHelper = $this->helper('MagentoFrameworkDataHelperPostHelper');
$postData = $postDataHelper->getPostData($block->getAddToCartUrl($product),
['product' => $product->getEntityId()]);
<button class="action description-button" data-post='<?php echo $postData; ?>'
<type="button" title="<?php echo __('Add to cart') ?>">
<span><?php echo __('Add to cart') ?></span>
</button>
data-post
button have action is null ? It look like :
data-post=""action":null,"data":"product":"7","uenc":"aHR0cDovLzUyLjE4My4yNi45OC9hcmR6YW5fc3VwZXJtYXJrZXQvaW5kZXgvbG9hZHByb2R1Y3Qv""
Please help me, why it not work?
magento2 magento-2.1 product cart addtocart
please share your block code.
– kunj
Jun 24 '18 at 17:46
add a comment |
I tried with button add to cart and it not working,
app/code/Moo/Custom/view/product.phtml
<?php
$product = $this->getData('product');
$postDataHelper = $this->helper('MagentoFrameworkDataHelperPostHelper');
$postData = $postDataHelper->getPostData($block->getAddToCartUrl($product),
['product' => $product->getEntityId()]);
<button class="action description-button" data-post='<?php echo $postData; ?>'
<type="button" title="<?php echo __('Add to cart') ?>">
<span><?php echo __('Add to cart') ?></span>
</button>
data-post
button have action is null ? It look like :
data-post=""action":null,"data":"product":"7","uenc":"aHR0cDovLzUyLjE4My4yNi45OC9hcmR6YW5fc3VwZXJtYXJrZXQvaW5kZXgvbG9hZHByb2R1Y3Qv""
Please help me, why it not work?
magento2 magento-2.1 product cart addtocart
I tried with button add to cart and it not working,
app/code/Moo/Custom/view/product.phtml
<?php
$product = $this->getData('product');
$postDataHelper = $this->helper('MagentoFrameworkDataHelperPostHelper');
$postData = $postDataHelper->getPostData($block->getAddToCartUrl($product),
['product' => $product->getEntityId()]);
<button class="action description-button" data-post='<?php echo $postData; ?>'
<type="button" title="<?php echo __('Add to cart') ?>">
<span><?php echo __('Add to cart') ?></span>
</button>
data-post
button have action is null ? It look like :
data-post=""action":null,"data":"product":"7","uenc":"aHR0cDovLzUyLjE4My4yNi45OC9hcmR6YW5fc3VwZXJtYXJrZXQvaW5kZXgvbG9hZHByb2R1Y3Qv""
Please help me, why it not work?
magento2 magento-2.1 product cart addtocart
magento2 magento-2.1 product cart addtocart
edited Apr 15 at 12:39
Muhammad Anas
9441323
9441323
asked Feb 3 '17 at 8:21
M.JackM.Jack
163
163
please share your block code.
– kunj
Jun 24 '18 at 17:46
add a comment |
please share your block code.
– kunj
Jun 24 '18 at 17:46
please share your block code.
– kunj
Jun 24 '18 at 17:46
please share your block code.
– kunj
Jun 24 '18 at 17:46
add a comment |
2 Answers
2
active
oldest
votes
Create form in your template file and pass action for the same .Also you need to pass formkey .
Try below code :
<form data-role="tocart-form" action="<?php echo $block->getAddToCartUrl($_item); ?>" method="post">
<?php echo $block->getBlockHtml('formkey'); ?>
<button type="submit" title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>" class="action tocart primary" style="float:right;margin-left: 10px;">
<span><?php /* @escapeNotVerified */echo __('Add to Cart'); ?></span>
</button>
</form>
thank, but it not work, action form not have url.
– M.Jack
Feb 3 '17 at 8:42
@M.Jack so what you want to achieve ? you want add to cart button in your template file ?
– Manthan Dave
Feb 3 '17 at 8:44
my issue is product not add to cart. It not work when click add to cart button.Can you hepl me ?
– M.Jack
Feb 3 '17 at 8:51
Yes put my code when you need this button and it will add product to the cart .ultimately you need to take form with the action so paste my code when you need it
– Manthan Dave
Feb 3 '17 at 9:06
Yes, I use code of you but it not show in minicart and check cart page is empty.
– M.Jack
Feb 3 '17 at 9:27
add a comment |
all data-post attributes has to be with simple quotation marks
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%2f157850%2fadd-to-cart-button-in-magento-2-1%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
Create form in your template file and pass action for the same .Also you need to pass formkey .
Try below code :
<form data-role="tocart-form" action="<?php echo $block->getAddToCartUrl($_item); ?>" method="post">
<?php echo $block->getBlockHtml('formkey'); ?>
<button type="submit" title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>" class="action tocart primary" style="float:right;margin-left: 10px;">
<span><?php /* @escapeNotVerified */echo __('Add to Cart'); ?></span>
</button>
</form>
thank, but it not work, action form not have url.
– M.Jack
Feb 3 '17 at 8:42
@M.Jack so what you want to achieve ? you want add to cart button in your template file ?
– Manthan Dave
Feb 3 '17 at 8:44
my issue is product not add to cart. It not work when click add to cart button.Can you hepl me ?
– M.Jack
Feb 3 '17 at 8:51
Yes put my code when you need this button and it will add product to the cart .ultimately you need to take form with the action so paste my code when you need it
– Manthan Dave
Feb 3 '17 at 9:06
Yes, I use code of you but it not show in minicart and check cart page is empty.
– M.Jack
Feb 3 '17 at 9:27
add a comment |
Create form in your template file and pass action for the same .Also you need to pass formkey .
Try below code :
<form data-role="tocart-form" action="<?php echo $block->getAddToCartUrl($_item); ?>" method="post">
<?php echo $block->getBlockHtml('formkey'); ?>
<button type="submit" title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>" class="action tocart primary" style="float:right;margin-left: 10px;">
<span><?php /* @escapeNotVerified */echo __('Add to Cart'); ?></span>
</button>
</form>
thank, but it not work, action form not have url.
– M.Jack
Feb 3 '17 at 8:42
@M.Jack so what you want to achieve ? you want add to cart button in your template file ?
– Manthan Dave
Feb 3 '17 at 8:44
my issue is product not add to cart. It not work when click add to cart button.Can you hepl me ?
– M.Jack
Feb 3 '17 at 8:51
Yes put my code when you need this button and it will add product to the cart .ultimately you need to take form with the action so paste my code when you need it
– Manthan Dave
Feb 3 '17 at 9:06
Yes, I use code of you but it not show in minicart and check cart page is empty.
– M.Jack
Feb 3 '17 at 9:27
add a comment |
Create form in your template file and pass action for the same .Also you need to pass formkey .
Try below code :
<form data-role="tocart-form" action="<?php echo $block->getAddToCartUrl($_item); ?>" method="post">
<?php echo $block->getBlockHtml('formkey'); ?>
<button type="submit" title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>" class="action tocart primary" style="float:right;margin-left: 10px;">
<span><?php /* @escapeNotVerified */echo __('Add to Cart'); ?></span>
</button>
</form>
Create form in your template file and pass action for the same .Also you need to pass formkey .
Try below code :
<form data-role="tocart-form" action="<?php echo $block->getAddToCartUrl($_item); ?>" method="post">
<?php echo $block->getBlockHtml('formkey'); ?>
<button type="submit" title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>" class="action tocart primary" style="float:right;margin-left: 10px;">
<span><?php /* @escapeNotVerified */echo __('Add to Cart'); ?></span>
</button>
</form>
answered Feb 3 '17 at 8:34
Manthan DaveManthan Dave
8,08421640
8,08421640
thank, but it not work, action form not have url.
– M.Jack
Feb 3 '17 at 8:42
@M.Jack so what you want to achieve ? you want add to cart button in your template file ?
– Manthan Dave
Feb 3 '17 at 8:44
my issue is product not add to cart. It not work when click add to cart button.Can you hepl me ?
– M.Jack
Feb 3 '17 at 8:51
Yes put my code when you need this button and it will add product to the cart .ultimately you need to take form with the action so paste my code when you need it
– Manthan Dave
Feb 3 '17 at 9:06
Yes, I use code of you but it not show in minicart and check cart page is empty.
– M.Jack
Feb 3 '17 at 9:27
add a comment |
thank, but it not work, action form not have url.
– M.Jack
Feb 3 '17 at 8:42
@M.Jack so what you want to achieve ? you want add to cart button in your template file ?
– Manthan Dave
Feb 3 '17 at 8:44
my issue is product not add to cart. It not work when click add to cart button.Can you hepl me ?
– M.Jack
Feb 3 '17 at 8:51
Yes put my code when you need this button and it will add product to the cart .ultimately you need to take form with the action so paste my code when you need it
– Manthan Dave
Feb 3 '17 at 9:06
Yes, I use code of you but it not show in minicart and check cart page is empty.
– M.Jack
Feb 3 '17 at 9:27
thank, but it not work, action form not have url.
– M.Jack
Feb 3 '17 at 8:42
thank, but it not work, action form not have url.
– M.Jack
Feb 3 '17 at 8:42
@M.Jack so what you want to achieve ? you want add to cart button in your template file ?
– Manthan Dave
Feb 3 '17 at 8:44
@M.Jack so what you want to achieve ? you want add to cart button in your template file ?
– Manthan Dave
Feb 3 '17 at 8:44
my issue is product not add to cart. It not work when click add to cart button.Can you hepl me ?
– M.Jack
Feb 3 '17 at 8:51
my issue is product not add to cart. It not work when click add to cart button.Can you hepl me ?
– M.Jack
Feb 3 '17 at 8:51
Yes put my code when you need this button and it will add product to the cart .ultimately you need to take form with the action so paste my code when you need it
– Manthan Dave
Feb 3 '17 at 9:06
Yes put my code when you need this button and it will add product to the cart .ultimately you need to take form with the action so paste my code when you need it
– Manthan Dave
Feb 3 '17 at 9:06
Yes, I use code of you but it not show in minicart and check cart page is empty.
– M.Jack
Feb 3 '17 at 9:27
Yes, I use code of you but it not show in minicart and check cart page is empty.
– M.Jack
Feb 3 '17 at 9:27
add a comment |
all data-post attributes has to be with simple quotation marks
add a comment |
all data-post attributes has to be with simple quotation marks
add a comment |
all data-post attributes has to be with simple quotation marks
all data-post attributes has to be with simple quotation marks
answered Jul 21 '17 at 9:02
MekkonMekkon
1
1
add a comment |
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%2f157850%2fadd-to-cart-button-in-magento-2-1%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
please share your block code.
– kunj
Jun 24 '18 at 17:46