添加到购物车magento中的按钮不起作用

时间:2014-05-28 16:29:25

标签: php magento magento-1.8

我的magento商店版社区中的添加到购物车按钮有问题。当您尝试添加文章并单击按钮时,它不起作用。

以下是问题的链接: http://masluz.panamerik.net/ilunimacion-automotriz/gabinete-ice-2x24w-magg.html

我的文件view.phtml

    <div class="product-shop">
        <div class="product-name">
            <h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
        </div>

        <?php if ($this->canEmailToFriend()): ?>
            <p class="email-friend"><a href="<?php echo $this->helper('catalog/product')->getEmailToFriendUrl($_product) ?>"><?php echo $this->__('Email to a Friend') ?></a></p>
        <?php endif; ?>

        <?php echo $this->getReviewsSummaryHtml($_product, false, true)?>
        <?php echo $this->getChildHtml('alert_urls') ?>
        <?php echo $this->getChildHtml('product_type_data') ?>
        <?php echo $this->getTierPriceHtml() ?>
        <?php echo $this->getChildHtml('extrahint') ?>

        <?php if (!$this->hasOptions()):?>
            <div class="add-to-box">
                <?php if($_product->isSaleable()): ?>
                    <?php echo $this->getChildHtml('addtocart') ?>
                    <?php if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
                        <span class="or"><?php echo $this->__('OR') ?></span>
                    <?php endif; ?>
                <?php endif; ?>
                <?php echo $this->getChildHtml('addto') ?>
            </div>
            <?php echo $this->getChildHtml('extra_buttons') ?>
        <?php elseif (!$_product->isSaleable()): ?>
            <div class="add-to-box">
                <?php echo $this->getChildHtml('addto') ?>
            </div>
        <?php endif; ?>

        <?php if ($_product->getShortDescription()):?>
            <div class="short-description">
                <h2><?php echo $this->__('Quick Overview') ?></h2>
                <div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
            </div>
        <?php endif;?>

        <?php echo $this->getChildHtml('other');?>

        <?php if ($_product->isSaleable() && $this->hasOptions()):?>
            <?php echo $this->getChildChildHtml('container1', '', true, true) ?>
        <?php endif;?>

    </div>

    <div class="product-img-box">
        <?php echo $this->getChildHtml('media') ?>
    </div>

    <div class="clearer"></div>
    <?php if ($_product->isSaleable() && $this->hasOptions()):?>
        <?php echo $this->getChildChildHtml('container2', '', true, true) ?>
    <?php endif;?>
</form>
<script type="text/javascript">
//<![CDATA[
    var productAddToCartForm = new VarienForm('product_addtocart_form');
    productAddToCartForm.submit = function(button, url) {
        if (this.validator.validate()) {
            var form = this.form;
            var oldUrl = form.action;

            if (url) {
               form.action = url;
            }
            var e = null;
            try {
                this.form.submit();
            } catch (e) {
            }
            this.form.action = oldUrl;
            if (e) {
                throw e;
            }

            if (button && button != 'undefined') {
                button.disabled = true;
            }
        }
    }.bind(productAddToCartForm);

    productAddToCartForm.submitLight = function(button, url){
        if(this.validator) {
            var nv = Validation.methods;
            delete Validation.methods['required-entry'];
            delete Validation.methods['validate-one-required'];
            delete Validation.methods['validate-one-required-by-name'];
            // Remove custom datetime validators
            for (var methodName in Validation.methods) {
                if (methodName.match(/^validate-datetime-.*/i)) {
                    delete Validation.methods[methodName];
                }
            }

            if (this.validator.validate()) {
                if (url) {
                    this.form.action = url;
                }
                this.form.submit();
            }
            Object.extend(Validation.methods, nv);
        }
    }.bind(productAddToCartForm);
//]]>
</script>
</div>

<div class="product-collateral">

        <?php endif;?>
        <?php echo $html; ?>
    </div>

1 个答案:

答案 0 :(得分:1)

单击它时,控制台会收到以下错误:

TypeError: productAddToCartForm is undefined

您缺少productAddToCartForm函数,它是用于将产品添加到购物车的标准Magento JS函数。这是您的自定义主题的问题。

您的自定义主题很可能会重写产品详细信息页面上使用的文件 view.phtml

  1. 查看: app / design / frontend / base / design / base / default / template / catalog / product / view.phtml

  2. 此phtml文件中定义了productAddToCartForm函数,您将看到如下内容:

    <script type="text/javascript">
    //<![CDATA[
        var productAddToCartForm = new VarienForm('product_addtocart_form');
        productAddToCartForm.submit = function(button, url) {
            if (this.validator.validate()) {
                var form = this.form;
                var oldUrl = form.action;
    
                if (url) {
                   form.action = url;
                }
                var e = null;
                try {
                    this.form.submit();
                } catch (e) {
                }
                this.form.action = oldUrl;
                if (e) {
                    throw e;
                }
    
                if (button && button != 'undefined') {
                    button.disabled = true;
                }
            }
        }.bind(productAddToCartForm);
    
        productAddToCartForm.submitLight = function(button, url){
            if(this.validator) {
                var nv = Validation.methods;
                delete Validation.methods['required-entry'];
                delete Validation.methods['validate-one-required'];
                delete Validation.methods['validate-one-required-by-name'];
                // Remove custom datetime validators
                for (var methodName in Validation.methods) {
                    if (methodName.match(/^validate-datetime-.*/i)) {
                        delete Validation.methods[methodName];
                    }
                }
    
                if (this.validator.validate()) {
                    if (url) {
                        this.form.action = url;
                    }
                    this.form.submit();
                }
                Object.extend(Validation.methods, nv);
            }
        }.bind(productAddToCartForm);
    //]]>
    </script>
    
  3. 现在打开重写 view.ptml 文件的文件,该文件位于自定义主题目录中: app / design / frontend / [theme_scope] / [theme_name] /template/catalog/product/view.phtml (注意: [theme_scope] [theme_name] 应该是您主题的文件夹。

  4. 将包含<script>功能的productAddToCartForm代码粘贴回主题 view.phtml 文件中。

  5. 保存文件,清除&amp;刷新所有Magento缓存。

  6. 如果操作正确,则不应恢复该功能并显示在页面的源标记中。您可以通过查看页面的html源并检查函数是否已定义来验证。