问题Magento =插入元素和调用函数javascript


Issue Magento = insert elements and call function javascript

如果你看到javascript,不要编辑,因为它与magento相关。谢谢你!

我已经调用了一个php脚本下的价格框在产品视图页面与验证函数这是php:

<script type="text/javascript">
//<![CDATA[
    $$('#product-price-<?php echo Mage::registry('current_product')->getId(); ?>').each (function(elem){
        $(elem).hide();
    });
    $('product-price-<?php echo Mage::registry('current_product')->getId(); ?>').show();
    var Cp = document.getElementById('product-price-<?php echo Mage::registry('current_product')->getId(); ?>');
    Cp.innerHTML = '$&nbsp;<input type="text" class="input-text price" name="custom_price" style="width:auto;" value="<?php echo Mage::registry('current_product')->getPrice(); ?>" onchange="onChangeCP(this);"/></span><input type="hidden" id="custom_price_total" name="custom_price_total" value="<?php echo Mage::registry('current_product')->getPrice(); ?>">';
    <?php 
        $product = Mage::getModel('catalog/product')->load(Mage::registry('current_product')->getId()); 
        $allowCustomPrice = $product->getAttributeText('allow_customprice');
        $minPrice = $product->getMinPrice(); //getAttributeText('min_price');
    ?>
    function changeCustomPrice(el){
        adviceBlock=$(el).up('span').down('.validation-advice');
        if(el.value.replace(',','.')>=<?php echo $minPrice; ?>){
            if(adviceBlock){
                adviceBlock.remove();
                el.removeClassName('validation-failed');
            }
        }else{
            if(!adviceBlock){
                el.insert({after:'<div class="validation-advice">The price should be equal or greater than <?php echo $minPrice; ?>.</div>'});
                el.addClassName('validation-failed');
            }
        }
        optionsPrice.productPrice=el.value;
        optionsPrice.reload();
    }
    optionsPrice.formatPrice=function(price){
        $('custom_price_total').value=price;
        return formatCurrency(price,optionsPrice.priceFormat);
    };
//]]>
</script>

这个脚本隐藏了显示价格的跨度,然后它绘制了一个价格输入框,以便客户端输入他的价格,应该大于平均价格;

当点击添加到购物车按钮时,这个该死的函数没有执行,什么也没做!

如果这个方法是错误的,那么我如何隐藏span和添加输入在产品视图使用magento (php/…)

我不确定你的问题是功能不运行或addtocart失败。首先,添加到购物车按钮与价格显示块无关。其次,您没有绑定添加到购物车的事件,因此即使您单击按钮也不会执行。最后,也许我遗漏了什么,但我发现客户更改的价格不会影响您Magento中的价格。经过这些过程后,价格可能会在产品页面上显示不同的用户,但它仍然显示原始价格在购物车中。

您需要在产品添加到购物车之前从php修改价格。