Magento 2: Add to cart button in category page with pre-selected attributes of configurable childadd to cart button is not workingGet javascript value without html or script tagsProblem inserting template below add to cart with rwd themeMagento 2 Grouped Product Add Product with Custom Options to CartAdd to Cart Button Not Working Magento 2I want to add parent product to cart using child product id, it's configurable options in magento 2.1Add to cart button added the same product issueAdditional Add to Cart Buttonhow to pass product page selected value to cart in magento2How to create custom form in Magento 2.2.3
Why did moving the mouse cursor cause Windows 95 to run more quickly?
What is the highest level of accuracy in motion control a Victorian society could achieve?
What happens if the limit of 4 billion files was exceeded in an ext4 partition?
How do I check that users don't write down their passwords?
Convert integer to full text string duration
What can a novel do that film and TV cannot?
In the Seventh Seal why does Death let the chess game happen?
What is the maximum amount of diamond in one Minecraft game?
Taking my Ph.D. advisor out for dinner after graduation
Does 5e have an equivalent of the Psychic Paper from Doctor Who?
n-level Ouroboros Quine
Why would "dead languages" be the only languages that spells could be written in?
Why is there paternal, for fatherly, fraternal, for brotherly, but no similar word for sons?
Way to see all encrypted fields in Salesforce?
Has there ever been a cold war other than between the U.S. and the U.S.S.R.?
The Purpose of "Natu"
Taking advantage when the HR forgets to communicate the rules
How to play a D major chord lower than the open E major chord on guitar?
What is exact meaning of “ich wäre gern”?
What do you call the angle of the direction of an airplane?
Is it possible to spoof an IP address to an exact number?
Shipped package arrived - didn't order, possible scam?
Will Jimmy fall off his platform?
How come a desk dictionary be abridged?
Magento 2: Add to cart button in category page with pre-selected attributes of configurable child
add to cart button is not workingGet javascript value without html or script tagsProblem inserting template below add to cart with rwd themeMagento 2 Grouped Product Add Product with Custom Options to CartAdd to Cart Button Not Working Magento 2I want to add parent product to cart using child product id, it's configurable options in magento 2.1Add to cart button added the same product issueAdditional Add to Cart Buttonhow to pass product page selected value to cart in magento2How to create custom form in Magento 2.2.3
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to create an add to cart button for a child of a configurable product in the category page.
I'm trying with this code where I add the super_attribute hidden fields with the values of the attribute.
<?php $postParams = $block->getAddToCartPostParams($_product); ?>
<form data-role="tocart-form" action="<?php echo $postParams['action']; ?>" method="post">
<input type="hidden" name="product" value="<?php echo $_product->getId(); ?>">
<input type="hidden" name="<?php echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
<?php foreach ($attributeOptions as $attr) ?>
<input type="hidden" name="super_attribute[<?php echo $_child->getResource()->getAttribute($attr)->getData("attribute_id")?>]" value="<?php echo $super_attr[$attr] ?>">
<?php ?>
<?php echo $block->getBlockHtml('formkey')?>
<div class="fieldset">
<div class="actions">
<button type="submit" title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>" class="action tocart primary">
<span><?php echo __('Add to Cart') ?></span>
</button>
</div>
</div>
</form>
The result is (for example)
<form data-role="tocart-form" action="baseurl/product-name?options=cart" method="post">
<input type="hidden" name="product" value="5858">
<input type="hidden" name="uenc" value="abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd">
<input type="hidden" name="super_attribute[185]" value="10">
<input type="hidden" name="super_attribute[186]" value="12">
<input name="form_key" type="hidden" value="DDAAkjkkkkkkj">
<div class="fieldset">
<div class="actions">
<button type="submit" title="Add to Cart" class="action tocart primary">
<span>Add to Cart</span>
</button>
</div>
</div>
</form>
But when I try to add to cart, I'm redirected to the product page with the error "You need to choose options for your item."
I'm working on the v2.3.1.
Do you have suggestions on how to specify the options for the add to cart in the add to cart button? Thanks!
magento2 php addtocart
add a comment |
I want to create an add to cart button for a child of a configurable product in the category page.
I'm trying with this code where I add the super_attribute hidden fields with the values of the attribute.
<?php $postParams = $block->getAddToCartPostParams($_product); ?>
<form data-role="tocart-form" action="<?php echo $postParams['action']; ?>" method="post">
<input type="hidden" name="product" value="<?php echo $_product->getId(); ?>">
<input type="hidden" name="<?php echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
<?php foreach ($attributeOptions as $attr) ?>
<input type="hidden" name="super_attribute[<?php echo $_child->getResource()->getAttribute($attr)->getData("attribute_id")?>]" value="<?php echo $super_attr[$attr] ?>">
<?php ?>
<?php echo $block->getBlockHtml('formkey')?>
<div class="fieldset">
<div class="actions">
<button type="submit" title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>" class="action tocart primary">
<span><?php echo __('Add to Cart') ?></span>
</button>
</div>
</div>
</form>
The result is (for example)
<form data-role="tocart-form" action="baseurl/product-name?options=cart" method="post">
<input type="hidden" name="product" value="5858">
<input type="hidden" name="uenc" value="abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd">
<input type="hidden" name="super_attribute[185]" value="10">
<input type="hidden" name="super_attribute[186]" value="12">
<input name="form_key" type="hidden" value="DDAAkjkkkkkkj">
<div class="fieldset">
<div class="actions">
<button type="submit" title="Add to Cart" class="action tocart primary">
<span>Add to Cart</span>
</button>
</div>
</div>
</form>
But when I try to add to cart, I'm redirected to the product page with the error "You need to choose options for your item."
I'm working on the v2.3.1.
Do you have suggestions on how to specify the options for the add to cart in the add to cart button? Thanks!
magento2 php addtocart
add a comment |
I want to create an add to cart button for a child of a configurable product in the category page.
I'm trying with this code where I add the super_attribute hidden fields with the values of the attribute.
<?php $postParams = $block->getAddToCartPostParams($_product); ?>
<form data-role="tocart-form" action="<?php echo $postParams['action']; ?>" method="post">
<input type="hidden" name="product" value="<?php echo $_product->getId(); ?>">
<input type="hidden" name="<?php echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
<?php foreach ($attributeOptions as $attr) ?>
<input type="hidden" name="super_attribute[<?php echo $_child->getResource()->getAttribute($attr)->getData("attribute_id")?>]" value="<?php echo $super_attr[$attr] ?>">
<?php ?>
<?php echo $block->getBlockHtml('formkey')?>
<div class="fieldset">
<div class="actions">
<button type="submit" title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>" class="action tocart primary">
<span><?php echo __('Add to Cart') ?></span>
</button>
</div>
</div>
</form>
The result is (for example)
<form data-role="tocart-form" action="baseurl/product-name?options=cart" method="post">
<input type="hidden" name="product" value="5858">
<input type="hidden" name="uenc" value="abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd">
<input type="hidden" name="super_attribute[185]" value="10">
<input type="hidden" name="super_attribute[186]" value="12">
<input name="form_key" type="hidden" value="DDAAkjkkkkkkj">
<div class="fieldset">
<div class="actions">
<button type="submit" title="Add to Cart" class="action tocart primary">
<span>Add to Cart</span>
</button>
</div>
</div>
</form>
But when I try to add to cart, I'm redirected to the product page with the error "You need to choose options for your item."
I'm working on the v2.3.1.
Do you have suggestions on how to specify the options for the add to cart in the add to cart button? Thanks!
magento2 php addtocart
I want to create an add to cart button for a child of a configurable product in the category page.
I'm trying with this code where I add the super_attribute hidden fields with the values of the attribute.
<?php $postParams = $block->getAddToCartPostParams($_product); ?>
<form data-role="tocart-form" action="<?php echo $postParams['action']; ?>" method="post">
<input type="hidden" name="product" value="<?php echo $_product->getId(); ?>">
<input type="hidden" name="<?php echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
<?php foreach ($attributeOptions as $attr) ?>
<input type="hidden" name="super_attribute[<?php echo $_child->getResource()->getAttribute($attr)->getData("attribute_id")?>]" value="<?php echo $super_attr[$attr] ?>">
<?php ?>
<?php echo $block->getBlockHtml('formkey')?>
<div class="fieldset">
<div class="actions">
<button type="submit" title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>" class="action tocart primary">
<span><?php echo __('Add to Cart') ?></span>
</button>
</div>
</div>
</form>
The result is (for example)
<form data-role="tocart-form" action="baseurl/product-name?options=cart" method="post">
<input type="hidden" name="product" value="5858">
<input type="hidden" name="uenc" value="abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd">
<input type="hidden" name="super_attribute[185]" value="10">
<input type="hidden" name="super_attribute[186]" value="12">
<input name="form_key" type="hidden" value="DDAAkjkkkkkkj">
<div class="fieldset">
<div class="actions">
<button type="submit" title="Add to Cart" class="action tocart primary">
<span>Add to Cart</span>
</button>
</div>
</div>
</form>
But when I try to add to cart, I'm redirected to the product page with the error "You need to choose options for your item."
I'm working on the v2.3.1.
Do you have suggestions on how to specify the options for the add to cart in the add to cart button? Thanks!
magento2 php addtocart
magento2 php addtocart
edited Jun 26 at 15:37
Gianni
asked Jun 26 at 15:33
GianniGianni
63 bronze badges
63 bronze badges
add a comment |
add a comment |
0
active
oldest
votes
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%2f279755%2fmagento-2-add-to-cart-button-in-category-page-with-pre-selected-attributes-of-c%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f279755%2fmagento-2-add-to-cart-button-in-category-page-with-pre-selected-attributes-of-c%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