Skip to content
This repository was archived by the owner on Apr 30, 2023. It is now read-only.

Message Success on Product Page times out too quickly when adding to cart. #59

Open
Draginto opened this issue Jun 18, 2021 · 4 comments

Comments

@Draginto
Copy link

We encountered this problem yesterday on our site. We ruled it out to this extension being the culprit. What happens is, that when a user clicks a product and goes to its details page, if they click "add to cart", the "success" message that usually appears at the bottom (for us) of the page, flickers then disappears essentially not letting the customer know that the product was added.

We also would like to note, this "flicker" does not occur anywhere else except for when we add to cart from the product details page. We would also like to point out, that if we do not run the setup to hook up our facebook page and pixel. The messages appear as they should.

Here are our steps:

  1. Install Facebook extension for Magento
  2. Run the setup for facebook in the admin, connecting our facebook page and pixel.
  3. See the frontend and try adding product to cart from product details page.
@KostasMel
Copy link

I Have the same problem too. when you press the "add to cart" button, it shows the success messages and it disappears almost immediately!

@visahardik
Copy link

I have the same problem not only success messages all messages quickly disappear.

@aterjung
Copy link

We have the same problem, all messages are removed right after they are displayed. As far as i could see. After disabling the module the messages are displayed as normal again. How to solve this issue? I have allready tried the latest version from main branch.

@haelbichalex
Copy link

I couldn't yet find out why, but if you use GET instead of POST in the ajax call for ProductInfoForAddToCart, this issue is gone.

https://github.com/facebookincubator/facebook-for-magento2/blob/0da8145b893f7fa7f43e4851bf75b6c304d97317/view/frontend/templates/pixel/add_to_cart.phtml#L37


This call is done here: view/frontend/templates/pixel/add_to_cart.phtml

<?php /** @var \Facebook\BusinessExtension\Block\Pixel\AddToCart $block */ ?>
<?php if ($block->getFacebookPixelID()) { ?>
    <script>
        require([
            'jquery'
        ], function ($) {

            function trackAddToCart(content_ids, content_name, content_category, value, eventId) {
                fbq('set', 'agent', '<?= $block->getFacebookAgentVersion() ?>', '<?= $block->getFacebookPixelID() ?>');
                fbq('track', 'AddToCart', {
                        source: "<?= $block->getSource() ?>",
                        pluginVersion: "<?= $block->getPluginVersion() ?>",
                        content_type: "<?= $block->getContentType() ?>",
                        currency: "<?= $block->getCurrency() ?>",
                        content_ids: content_ids,
                        content_name: content_name,
                        content_category: content_category,
                        value: value
                    },
                    {
                        eventID: eventId
                    }
                );
            }

            var product_info_url = '<?= $block->getProductInfoUrl() ?>';

            $(document).on('ajax:addToCart', function (event, data) {
                var product_sku = data.sku;
                var form_key = jQuery("[name='form_key']").val();
                $.ajax({
                    url: product_info_url,
                    data: {
                        product_sku: product_sku,
                        form_key: form_key
                    },
-                  type: 'post',
+                  type: 'get',
                    dataType: 'json',
                    success: function (res) {
                        trackAddToCart(
                            [res.id],
                            res.name,
                            res.content_category,
                            res.value,
                            res.event_id
                        );
                    }
                });
            });
        });
    </script>
    <?php $block->logEvent($block->getFacebookPixelID(), 'AddToCart') ?>
<?php } ?>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants