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;








3















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?










share|improve this question
























  • please share your block code.

    – kunj
    Jun 24 '18 at 17:46

















3















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?










share|improve this question
























  • please share your block code.

    – kunj
    Jun 24 '18 at 17:46













3












3








3








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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










2 Answers
2






active

oldest

votes


















0














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>





share|improve this answer























  • 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


















0














all data-post attributes has to be with simple quotation marks






share|improve this answer























    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%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









    0














    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>





    share|improve this answer























    • 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















    0














    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>





    share|improve this answer























    • 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













    0












    0








    0







    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>





    share|improve this answer













    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>






    share|improve this answer












    share|improve this answer



    share|improve this answer










    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

















    • 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













    0














    all data-post attributes has to be with simple quotation marks






    share|improve this answer



























      0














      all data-post attributes has to be with simple quotation marks






      share|improve this answer

























        0












        0








        0







        all data-post attributes has to be with simple quotation marks






        share|improve this answer













        all data-post attributes has to be with simple quotation marks







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jul 21 '17 at 9:02









        MekkonMekkon

        1




        1



























            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%2f157850%2fadd-to-cart-button-in-magento-2-1%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

            Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form