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 MAC安装佳能LBP2900驱动的网盘提取码
  • ¥400 微信停车小程序谁懂的来
  • ¥15 ATAC测序到底用什么peak文件做Diffbind差异分析
  • ¥15 安装ubantu过程中第一个vfat 文件挂载失败
  • ¥20 GZ::CTF如何兼容一些靶机?
  • ¥15 etcd集群部署问题
  • ¥20 谁可以帮我一下问一下各位
  • ¥15 为何重叠加权后love图的SMD与svyCreateTableOne函数绘制基线表的不一致
  • ¥15 QFILHelper怎么恢复全字库,提示进程已完成,只能恢复分区文件
  • ¥150 求 《小魔指》街机游戏机整合模拟软件