Magento:跟踪和调试其PHP代码

Magento:跟踪和调试其PHP代码,php,Php,所以,我开始尝试一些Magento代码。我试图在购物车页面上找到计算运费的代码。我正在查看/your\u theme/template/checkout/cart/中名为shipping.phtml的文件 Zipcode输入框: <li> <label for="postcode"<?php if ($this->isZipCodeRequired()) echo ' class="required"' ?&g

所以,我开始尝试一些Magento代码。我试图在购物车页面上找到计算运费的代码。我正在查看
/your\u theme/template/checkout/cart/
中名为
shipping.phtml的文件

Zipcode输入框:

            <li>
                <label for="postcode"<?php if ($this->isZipCodeRequired()) echo ' class="required"' ?>><?php if ($this->isZipCodeRequired()) echo '<em>*</em>' ?><?php echo $this->__('Zip/Postal Code') ?></label>
                <input class="input-text validate-postcode<?php if ($this->isZipCodeRequired()):?> required-entry<?php endif;?>" type="text" id="postcode" name="estimate_postcode" value="<?php echo $this->htmlEscape($this->getEstimatePostcode()) ?>" />
            </li>
  • >
    这不是计算发货的代码,而是提交请求的表单。从那里开始,最简单的方法可能是在嗅探HTTP请求的同时提交表单(即通过浏览器开发工具的“网络”选项卡),查看请求的去向,然后找到在该URL处处理请求的控制器


    如果您想知道$this在该文件中引用了哪个类,那么最可靠的方法可能是从模板中回显
    get_class($this)
    。然而,这可能不是找到你要找的东西的最直接的方法。

    [magento]/app/code/
    目录中的某个地方,但是你想要实现什么呢?你到底想从我们这里得到什么有用的答案,你在这个问题上的回答相当含糊。安装xdebug(在开发服务器上),将调试器指向它,将它设置为在开始时中断,并愉快地单击“下一步”,直到找到坏男孩。如果你最终得到了一个类名,并且想知道如何继续,请参阅
    [magento]中的自动加载功能/app/code/core/Mage/core/functions.php
    用于将类名转换为文件名的代码。
            <div class="buttons-set">
                <button type="button" onclick="coShippingMethodForm.submit()" class="button"><span><span><?php echo $this->__('Get a Quote') ?></span></span></button>
            </div>
    
    <script type="text/javascript">
    //<![CDATA[
        var coShippingMethodForm = new VarienForm('shipping-zip-form');
        var countriesWithOptionalZip = <?php echo $this->helper('directory')->getCountriesWithOptionalZip(true) ?>;
    
        coShippingMethodForm.submit = function () {
            var country = $F('country');
            var optionalZip = false;
    
            for (i=0; i < countriesWithOptionalZip.length; i++) {
                if (countriesWithOptionalZip[i] == country) {
                    optionalZip = true;
                }
            }
            if (optionalZip) {
                $('postcode').removeClassName('required-entry');
            }
            else {
                $('postcode').addClassName('required-entry');
            }
            return VarienForm.prototype.submit.bind(coShippingMethodForm)();
        }
    //]]>
    </script>