laketuna
laketuna

Reputation: 4090

Magento: tracking and debugging its PHP code

So, I'm starting to take a crack at some Magento code. I'm trying to track down the code that calculate shipping on a shopping cart page. I'm looking at a file called shipping.phtml in /your_theme/template/checkout/cart/.

Zipcode input box:

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

Calculate shipping button:

        <div class="buttons-set">
            <button type="button" onclick="coShippingMethodForm.submit()" class="button"><span><span><?php echo $this->__('Get a Quote') ?></span></span></button>
        </div>

Javascript:

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

Now, I have no idea where it goes from here. Could somebody provide me some hints as to where this goes from here?

EDIT:

I should add that I'm looking for the code that takes in the weight of the item and calculates the USPS shipping cost. I've read that a file named Usps.php is what calculate this rate, but I wasn't able to change how the cost is displayed on the site even with core file modifications, so I wanted to find out myself that is indeed the code that calculate the shipping rate.

Upvotes: 0

Views: 1045

Answers (1)

Brilliand
Brilliand

Reputation: 13714

That isn't the code that calculates shipping - it's just the form that submits the request. Probably the simplest way to proceed from there would be to submit the form while sniffing HTTP requests (i.e. via the network tab of your browser's developer tools), and see where the request goes - then find the controller that handles requests at that URL.

If you want to know which class is referred to by $this in that file, then probably the most reliable way would be to echo get_class($this) from within the template. However, that's probably not the most direct way to find what you're looking for.

Upvotes: 1

Related Questions