首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Magento添加到购物车不工作

Magento添加到购物车不工作
EN

Stack Overflow用户
提问于 2012-12-18 13:12:39
回答 2查看 7.7K关注 0票数 1

“添加到购物车”在我的Magento移动版本中不起作用。它是Jquery-Mobile的构建。

Javascript控制台说

未捕获的TypeError:无法调用未定义的方法“”submit“”

我找了很长时间的代码,但没有找到错误。我对magento和Jquery- mobile版本有点陌生。请帮帮忙。我将在下面分享我的代码。

app/design/frontend/mobile/template/catalog/product/view.phtml

代码语言:javascript
运行
复制
helper('catalog/output'); ?>
getProduct(); ?>

    var optionsPrice = new Product.OptionsPrice(getJsonConfig() ?>);

getMessagesBlock()->getGroupedHtml() ?>

    
    getOptions()): ?> enctype="multipart/form-data">
        
            
            
        

        
            
                productAttribute($_product, $_product->getName(), 'name') ?>
            

            canEmailToFriend()): ?>
                __('Email to a Friend') ?>
            

            getReviewsSummaryHtml($_product, false, true)?>
            getChildHtml('alert_urls') ?>
             */ ?>
            getChildHtml('product_type_data') ?>
            getTierPriceHtml() ?>
            getChildHtml('extrahint') ?>


            hasOptions()):?>
                
                    isSaleable()): ?>
                        getChildHtml('addtocart') ?>
                        helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
                            __('OR') ?>
                        
                    
                    getChildHtml('addto') ?>
                
                getChildHtml('extra_buttons') ?>
            

            getShortDescription()):?>
                
                    __('Quick Overview') ?>
                    productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?>
                
            

            getChildHtml('other');?>

            isSaleable() && $this->hasOptions()):?>
                getChildChildHtml('container1', '', true, true) ?>
            

        

        
            getChildHtml('media') ?>
        

        
        isSaleable() && $this->hasOptions()):?>
            getChildChildHtml('container2', '', true, true) ?>
        
    //<![CDATA[
        var productAddToCartForm = new VarienForm('product_addtocart_form');
        productAddToCartForm.submit = function(button, url) {
            alert("hiii");
            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'];
                if (this.validator.validate()) {
                    if (url) {
                        this.form.action = url;
                    }
                    this.form.submit();
                }
                Object.extend(Validation.methods, nv);
            }
        }.bind(productAddToCartForm);
    //]]>
    
    

    
getChildGroup('detailed_info', 'getChildHtml') as $alias => $html):?>
        ">
            getChildData($alias, 'title')):?>
            escapeHtml($title); ?>
            
            
        

    getChildHtml('upsell_products') ?>
        getChildHtml('product_additional_data') ?>
     */ ?>

app/design/frontend/mobile/template/catalog/product/view/addtocart.phtml

代码语言:javascript
运行
复制
getProduct(); ?>
__('Add to Cart'); ?>
isSaleable()): ?>
    
        isGrouped()): ?>
        __('Qty:') ?>
        
        
        
        getChildHtml('', true, true) ?>

如您所见,我在javascript提交函数中给出了一个警告。但它并没有出现。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-12-18 14:30:58

在下面这一行后面尝试console.log(productAddToCartForm):

代码语言:javascript
运行
复制
var productAddToCartForm = new VarienForm('product_addtocart_form');

输出是什么?确保页面中实际加载了包含这些VarienForm js类的文件。基本上,检查控制台是否有任何可能丢失的JS库,如果您没有修改任何内容,这可能是原因……

票数 1
EN

Stack Overflow用户

发布于 2013-09-03 17:07:41

我注意到,在Internet Explorer中出现该问题是由于合并了JavaScript文件(这是管理中System -> Configuration -> Developer下的一个设置)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13926697

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档