在新的magento商店中,添加到购物车和审核功能适用于localhost,但不能远程

时间:2012-08-30 19:02:15

标签: javascript magento webserver localhost remote-server

在我的本地计算机上彻底安装Magento Community Edition(v.7.7.0.2)并加载Magento提供的示例数据后,我可以按预期浏览评论,将项目添加到购物车等。< / p>

然而,当我在实时服务器上执行相同的步骤时,JS功能在Chrome和Firefox中都不起作用(我没有尝试过其他浏览器)。例如,单击产品页面上的“添加到购物车”只会出现控制台错误(“Uncaught ReferenceError:productAddToCartForm未定义”)。

导致此行为的原因是什么,我该如何解决?

2 个答案:

答案 0 :(得分:1)

我不确定这对你有帮助,但它解决了我的问题。我做的是我在view.phtml中移动了javascript段,从#34; add-to-cart-wrapper&#34;上面的课程。

像这样:

 <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 class="add-to-cart-wrapper">
            <?php echo $this->getChildHtml('product_type_data') ?>
            <?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') ?>
                    <?php echo $this->getChildHtml('sharing') ?>
                </div>
                <?php echo $this->getChildHtml('extra_buttons') ?>
            <?php elseif (!$_product->isSaleable()): ?>
                <div class="add-to-box">
                    <?php echo $this->getChildHtml('addto') ?>
                    <?php echo $this->getChildHtml('sharing') ?>
                </div>
            <?php endif; ?>
        </div>

而不是:

<div class="add-to-cart-wrapper">
            <?php echo $this->getChildHtml('product_type_data') ?>
            <?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') ?>
                    <?php echo $this->getChildHtml('sharing') ?>
                </div>
                <?php echo $this->getChildHtml('extra_buttons') ?>
            <?php elseif (!$_product->isSaleable()): ?>
                <div class="add-to-box">
                    <?php echo $this->getChildHtml('addto') ?>
                    <?php echo $this->getChildHtml('sharing') ?>
                </div>
            <?php endif; ?>
        </div>

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

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

我希望这会有所帮助。

答案 1 :(得分:0)

一位同事解决了这个问题。有两个问题导致magento在实时服务器上失败:

  • 缺少Magento没有抱怨的PHP(dom和gm)依赖项。
  • PHP中的内存限制较低。我们需要增加/etc/php.ini中的memory_limit设置(512M为我们工作)。