doudui5753 2014-03-21 09:59
浏览 42
已采纳

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

if u see javascript don't edit because its related with magento. thank you!

i have called a phtml script under price box in product view page with a validation function this is the phtml :

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

this script hide the span that displays the price then it draw a input box with the price so that the client enter his price that should be greater than the mean price; if it s less then it draw an error.

when clicked in add to cart button the damn function doesn't execute and nothing is done !

if this method is wrong then how can i hide the span and add the input in product view using magento (php/...)

  • 写回答

1条回答 默认 最新

  • donglun4682 2014-03-30 01:55
    关注

    I'm not sure your issue is the function not running or addtocart fail. First, add to cart button is irrelevant to the price showing block. Second, you didn't bind the event on add to cart, so even you click button that will not execute. Last, maybe I miss something but I found the price that customer changed will not affect the price in your Magento. after these process the price might show different to user on product page, but it still show original price in cart.

    you need to modified the price before product add to cart from php.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办