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 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用