0

The form action on the add to cart button is showing the wrong product id - but when you echo out $submitUrl it shows the correct product ID. I've disabled javascript and re-loaded the page but that doesn't seem to be where the problem is. Is this is a Magento 2 bug?

Here is the product: PRODUCT PAGE

When you add the product to the basket it's showing the incorrect product.

Magento ver. 2.1.7

Template path: /Magento_Catalog/templates/product/view

Template code:

<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/**
 * Product view template
 *
 * @var $block \Magento\Catalog\Block\Product\View
 */
?>
<?php $_helper = $this->helper('Magento\Catalog\Helper\Output'); ?>
<?php $_product = $block->getProduct(); ?>

<?php
    $submitUrl = $block->getSubmitUrl($_product);
    #echo basename($submitUrl);
    $submitUrl = str_replace('/' . basename($submitUrl) . '/', '/' . $_product->getId() . '/', $submitUrl);
    #echo $submitUrl;
?>

<div class="product-add-form">
    <form action="<?php /* @escapeNotVerified */ echo $submitUrl ?>" method="post" id="product_addtocart_form"<?php if ($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
        <input type="hidden" name="product" value="<?php /* @escapeNotVerified */ echo $_product->getId() ?>" />
        <input type="hidden" name="selected_configurable_option" value="" />
        <input type="hidden" name="related_product" id="related-products-field" value="" />
        <?php echo $block->getBlockHtml('formkey')?>
        <?php echo $block->getChildHtml('form_top'); ?>
        <?php if (!$block->hasOptions()):?>
            <?php echo $block->getChildHtml('product_info_form_content'); ?>
        <?php else:?>
            <?php if ($_product->isSaleable() && $block->getOptionsContainer() == 'container1'):?>
                <?php echo $block->getChildChildHtml('options_container') ?>
            <?php endif;?>
        <?php endif; ?>

        <?php if ($_product->isSaleable() && $block->hasOptions() && $block->getOptionsContainer() == 'container2'):?>
            <?php echo $block->getChildChildHtml('options_container') ?>
        <?php endif;?>
        <?php echo $block->getChildHtml('form_bottom'); ?>
        <?php echo $block->getChildHtml('extrahint'); ?>
        <div class="addit">
             <div class="alo-social-links clearfix">
                <span class="share-this">SHARE THIS:</span>
                <div class="pw-server-widget" data-id="wid-4ae3vrrm"></div>
                <!--<div class="so-facebook so-social-share">
                    <div id="fb-root"></div>
                    <div class="fb-like" data-href="<?php echo $_product->getProductUrl();?>" data-send="false" data-layout="button_count" data-width="20" data-show-faces="false"></div>
                </div>
                <div class="so-twitter so-social-share">
                    <a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-dnt="true">Tweet</a>
                </div>
                <div class="so-plusone so-social-share">
                    <div class="g-plusone" data-size="medium"></div>
                    <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
                </div>
                <div class="so-linkedin so-social-share">
                    <script src="//platform.linkedin.com/in.js" type="text/javascript"></script>
                    <script type="IN/Share" data-counter="right"></script>
                </div>
                <?php
                    $imageUrl = $this->helper('Magento\Catalog\Helper\Image')
                        ->init($block->getProduct(), 'product_page_image_large')
                        ->setImageFile($block->getImageFile())
                        ->getUrl();
                ?>
                <div class="so-pinterest so-social-share">
                    <a href="//pinterest.com/pin/create/button/?url=<?php echo urlencode($_product->getProductUrl());?>&media=<?php /* @escapeNotVerified */ echo urlencode($imageUrl); ?>&description=<?php echo $_product->getName();?>" data-pin-do="buttonPin" data-pin-config="beside">
                        <img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" />
                    </a>
                    <script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script>
                </div>-->
            </div>
        </div>
    </form>
</div>
<script>
    require([
        'jquery',
        'priceBox'
    ], function($){
        var dataPriceBoxSelector = '[data-role=priceBox]',
            dataProductIdSelector = '[data-product-id=<?php echo $block->escapeHtml($_product->getId())?>]',
            priceBoxes = $(dataPriceBoxSelector + dataProductIdSelector);

        priceBoxes = priceBoxes.filter(function(index, elem){
            return !$(elem).find('.price-from').length;
        });

        priceBoxes.priceBox({'priceConfig': <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>});
    });

    (function(d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) return;
            js = d.createElement(s);
            js.id = id;
            js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=115245961994281";
            fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));
        !function(d,s,id){
            var js,fjs=d.getElementsByTagName(s)[0];
            if(!d.getElementById(id)){
                js=d.createElement(s);
                js.id=id;
                js.src="//platform.twitter.com/widgets.js";
                fjs.parentNode.insertBefore(js,fjs);
            }
        }(document,"script","twitter-wjs");
</script>
<script type="text/javascript">
    (function () {
        var s = document.createElement('script');
        s.type = 'text/javascript';
        s.async = true;
        s.src = ('https:' == document.location.protocol ? 'https://s' : 'http://i')
          + '.po.st/static/v4/post-widget.js#publisherKey=3seo3r17duh8iq2tt9fh';
        var x = document.getElementsByTagName('script')[0];
        x.parentNode.insertBefore(s, x);
     })();
</script>

Can anyone see where the problem could be?

7
  • Is that any third party extension install in shop? Jan 22, 2018 at 13:13
  • The only 3rd party extensions are Fishpig, IWD One Page Checkout, Crafty Clicks & Wyomind (Google Shopping) @DhirenVasoya
    – mjcoder
    Jan 22, 2018 at 15:57
  • try to disabling that extesion and then check. Jan 23, 2018 at 3:16
  • Do you want me to disable all the mentioned extensions above or do you want me to disable a specific extension? @DhirenVasoya ?
    – mjcoder
    Jan 23, 2018 at 9:32
  • You need to try disabling extension one by one and then check. Jan 23, 2018 at 9:34

1 Answer 1

0

Right, it seems like the issue is the theme. I've disabled the 3rd party modules and checked the form and it was still referencing the incorrect product ID.

I've changed the theme (Magento Blank), flushed the cache and then reloaded the page - voila - the form on the add to cart button is referencing the correct product ID.

The theme is Alothemes Milano for Magento. Need to see if I have a support license with them in order to get this resolved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.