0

在我的本地机器上完成 Magento Community Edition (v. 1.7.0.2) 的全新安装并使用 Magento 提供的示例数据加载后,我可以按预期浏览评论、将商品添加到购物车等。

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

是什么导致了这种行为,我该如何解决?

4

2 回答 2

1

我不确定这是否会帮助你,但它解决了我的问题。我所做的是将 view.phtml 中的 javascript 段从“add-to-cart-wrapper”类下移到它上面。

像这样:

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

我希望这会有所帮助。

于 2014-08-11T08:29:51.633 回答
0

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

  • 缺少 Magento 没有抱怨的 PHP(dom 和 gm)依赖项。
  • PHP 中的低内存限制。我们需要增加 /etc/php.ini 中的 memory_limit 设置(512M 为我们工作)。
于 2012-09-06T23:00:06.320 回答