1

My magento tracking page:

enter image description here

Back-end magento code :

enter image description here

How can i add my PHP script into this tracking page.

Tracking page code - trackorder.phtml [https://i.stack.imgur.com/ySgMA.png]

<?php
    if(Mage::getStoreConfig('trackorder/trackorder_general/enabled')):
    ?>
    <div class="page-title"><h1><?php echo $this->__('Track Your Order ') ?></h1></div>
    <div  class="form-list">
        <form name="track_order" id="track_order" action="" method="post" onsubmit="sendAjax('track_order','<?php  echo Mage::getUrl('*/*/track');?>'); return false;">
        <!--<form name="track_order" method="post" id="track_order" action="<?php echo Mage::getUrl('*/*/view');?>">-->
            <ul class="form-list">
                <li>
                    <label for="order_id" class="required"><em>*</em><?php echo $this->__('Order Id') ?></label>
                    <div class="input-box">
                        <input type="text" name="order_id" id="order_id" value="" title="" class="input-text required-entry" />
                    </div>    
                </li>
                <li>
                    <label for="email_address" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
                    <div class="input-box" >
                        <input type="text" name="email" id="email_address" value="" title="<?php echo $this->__('Email Address') ?>" class="input-text validate-email required-entry" />
                    </div>    
                </li>
            </ul>
            <div class="buttons-set">
               <button type="submit" class="button" title="<?php echo $this->__('Track Order') ?>" name="track" id="track">
                    <span><span><?php echo $this->__('Track Order') ?></span></span>
                </button>
            </div>

        </form>
        <div id="loading-details" class="loading-details" style="display:none">
            <div id="loading-mask" >
                <p class="loader" id="loading_mask_loader"><img src="<?php echo $this->getSkinUrl('trackorder/images/ajax-loader-tr.gif') ?>" alt="<?php echo Mage::helper('adminhtml')->__('Loading...') ?>"/><br/><?php echo $this->__('Please wait...') ?></p>
            </div>
        </div>
    </div> 

    <div id="oderinfo" class="order-info-message"></div>

    <script type="text/javascript">
        var validateForm = new VarienForm('track_order', true);
    </script>           
    <script type="text/javascript">

        function sendAjax(frmId,url){
            if (!validateForm.validator.validate()) {
                return;
            }
            var data = $(frmId).serialize(this);
            $("loading-details").show();


        new Ajax.Updater(
                {
                    success:"oderinfo"
                },

                url,
                {
                    asynchronous:true,
                    evalScripts:false,
                    onComplete:function(request, json){
                        $("loading-details").hide();
                        return false;
                    }, 
                    onLoading:function(request, json){},
                    parameters:data
                }
            ); 
            return false;
        }

    </script>
    <?php else: ?>
    <?php
        $url = Mage::getBaseUrl();
        Mage::app()->getFrontController()->getResponse()->setRedirect($url);
    ?>
    <?php endif; ?>

From above code how can i add my own PHP script :

My PHP script :

<!DOCTYPE HTML>
<html>

<body>

    <form action="#" method="POST">
        Select Courier :
        <select name="courier">
            <option disabled='disabled' selected>-- Choose an option --</option>
            <option value="professional_courier">Professional Courier</option>
            <option value="shree_maruti_courier">Shree Maruti Courier</option>
            <option value="india_post_courier">India Post Courier</option>
            <option value="dhl_courier">DHL Courier</option>
            <option value="fedex_courier">Fedex Courier</option>
            <option value="ups_courier">UPS Courier</option>
        </select>

        Trackingid: <input type="text" name="trackingid">
        <input type="submit">

    </form>

    <?php
    if (isset($_POST['courier'])) {
        // Professional Courier
        if ('professional_courier' === $_POST['courier']) {
            header("Location: https://www.tpcindia.com/Tracking2014.aspx?id=" . $_POST["trackingid"] . "&type=0&service=0");
        }
        // Shree Maruti Courier
        else if ('shree_maruti_courier' === $_POST['courier']) {
            header("Location: https://www.shreemaruticourier.com/track-your-shipment/#track-your", "_blank");
        }

        // india_post_courier
        else if ('india_post_courier' === $_POST['courier']) {
            header("Location: https://www.indiapost.gov.in/vas/Pages/IndiaPostHome.aspx/#main-content", "_blank");
        }

        // DHL Courier
        else if ('dhl_courier' === $_POST['courier']) {
            header("Location: https://www.dhl.com/en/express/tracking.html?AWB=" . $_POST["trackingid"] . "&brand=DHL", "_blank");
        }

        // Fedex Courier
        else if ('fedex_courier' === $_POST['courier']) {
            header("Location: https://www.fedex.com/apps/fedextrack/?action=track&trackingnumber=" . $_POST["trackingid"] . "&cntry_code=in&locale=en_IN", "_blank");
        }

        // ups_courier
        else if ('ups_courier' === $_POST['courier']) {
            header("Location: https://www.ups.com/track?loc=en_US&tracknum=" . $_POST["trackingid"] . "&requester=WT/trackdetails", "_blank");
        }
    }
    ?>
</body>

</html>

My Workout in trackorder.phtml getting error : [start & end header added]

<?php
    if(Mage::getStoreConfig('trackorder/trackorder_general/enabled')):
    ?>
    <div class="page-title"><h1><?php echo $this->__('Track Your Order ') ?></h1></div>
    <div  class="form-list" style="float: left;">
        <form name="track_order" id="track_order" action="" method="post" onsubmit="sendAjax('track_order','<?php  echo Mage::getUrl('*/*/track');?>'); return false;">
        <!--<form name="track_order" method="post" id="track_order" action="<?php echo Mage::getUrl('*/*/view');?>">-->
            <ul class="form-list">
                <li>
                    <label for="order_id" class="required"><em>*</em><?php echo $this->__('Order Id') ?></label>
                    <div class="input-box">
                        <input type="text" name="order_id" id="order_id" value="" title="" class="input-text required-entry" />
                    </div>    
                </li>
                <li>
                    <label for="email_address" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
                    <div class="input-box" >
                        <input type="text" name="email" id="email_address" value="" title="<?php echo $this->__('Email Address') ?>" class="input-text validate-email required-entry" />
                    </div>    
                </li>
            </ul>
            <div class="buttons-set">
               <button type="submit" class="button" title="<?php echo $this->__('Track Order') ?>" name="track" id="track">
                    <span><span><?php echo $this->__('Track Order') ?></span></span>
                </button>
            </div>

        </form>
        <div id="loading-details" class="loading-details" style="display:none">
            <div id="loading-mask" >
                <p class="loader" id="loading_mask_loader"><img src="<?php echo $this->getSkinUrl('trackorder/images/ajax-loader-tr.gif') ?>" alt="<?php echo Mage::helper('adminhtml')->__('Loading...') ?>"/><br/><?php echo $this->__('Please wait...') ?></p>
            </div>
        </div>
    </div> 

    <!-- Start couier tracking -->

      <div style="float: left;">
        <form action="#" method="POST" style="padding: 28px 15px 21px 196px;">
            Select Courier :
            <select name="courier">
            <option disabled='disabled' selected>-- Choose an option --</option>
            <option value="professional_courier">Professional Courier</option>
            <option value="shree_maruti_courier">Shree Maruti Courier</option>
            <option value="india_post_courier">India Post Courier</option>
            <option value="dhl_courier">DHL Courier</option>
            <option value="fedex_courier">Fedex Courier</option>
            <option value="ups_courier">UPS Courier</option>
        </select>

        Trackingid: <input type="text" name="trackingid">
        <input type="submit">

    </form>

    <?php
    if (isset($_POST['courier'])) {
        // Professional Courier
        if ('professional_courier' === $_POST['courier']) {
            header("Location: https://www.tpcindia.com/Tracking2014.aspx?id=" . $_POST["trackingid"] . "&type=0&service=0");
        }
        // Shree Maruti Courier
        else if ('shree_maruti_courier' === $_POST['courier']) {
            header("Location: https://www.shreemaruticourier.com/track-your-shipment/#track-your", "_blank");
        }

        // india_post_courier
        else if ('india_post_courier' === $_POST['courier']) {
            header("Location: https://www.indiapost.gov.in/vas/Pages/IndiaPostHome.aspx/#main-content", "_blank");
        }

        // DHL Courier
        else if ('dhl_courier' === $_POST['courier']) {
            header("Location: https://www.dhl.com/en/express/tracking.html?AWB=" . $_POST["trackingid"] . "&brand=DHL", "_blank");
        }

        // Fedex Courier
        else if ('fedex_courier' === $_POST['courier']) {
            header("Location: https://www.fedex.com/apps/fedextrack/?action=track&trackingnumber=" . $_POST["trackingid"] . "&cntry_code=in&locale=en_IN", "_blank");
        }

        // ups_courier
        else if ('ups_courier' === $_POST['courier']) {
            header("Location: https://www.ups.com/track?loc=en_US&tracknum=" . $_POST["trackingid"] . "&requester=WT/trackdetails", "_blank");
        }
    }
    ?>

    </div>

    <!-- End couier tracking -->

    <div id="oderinfo" class="order-info-message"></div>

    <script type="text/javascript">
        var validateForm = new VarienForm('track_order', true);
    </script>           
    <script type="text/javascript">

        function sendAjax(frmId,url){
            if (!validateForm.validator.validate()) {
                return;
            }
            var data = $(frmId).serialize(this);
            $("loading-details").show();


        new Ajax.Updater(
                {
                    success:"oderinfo"
                },

                url,
                {
                    asynchronous:true,
                    evalScripts:false,
                    onComplete:function(request, json){
                        $("loading-details").hide();
                        return false;
                    }, 
                    onLoading:function(request, json){},
                    parameters:data
                }
            ); 
            return false;
        }

    </script>
    <?php else: ?>
    <?php
        $url = Mage::getBaseUrl();
        Mage::app()->getFrontController()->getResponse()->setRedirect($url);
    ?>
    <?php endif; ?>
  • please more explain with error and log file . – Vishal Baraiya Dec 7 '19 at 6:56
  • @zus, are you using any third party module for track order ? – Pawan Dec 13 '19 at 3:54
  • @Pawan Yes, i am using third party module – zus Dec 13 '19 at 4:45
  • OK, and you want to add a select box after order Id and email ? – Pawan Dec 13 '19 at 4:50
0

Solved :

     <div style="float: right;">
       <!-- <form method="post" action="" > -->
                Select Courier :
                <li>
                <select name="courier" id="courier" >
                    <option disabled='disabled' selected>-- Choose an option --</option>
                    <option value="professional_courier">Professional Courier</option>
                    <option value="shree_maruti_courier">Shree Maruti Courier</option>
                    <option value="india_post_courier">India Post Courier</option>
                    <option value="dhl_courier">DHL Courier</option>
                    <option value="fedex_courier">Fedex Courier</option>
                    <option value="ups_courier">UPS Courier</option>
                </select>
            </li>
            <li>
                Trackingid: <input type="text" name="trackingid" id="trackingid">
            </li>
            <li>
                <button id="buttonpost" >submit</button>
            </li>    
   <!-- </form> -->
    </div>

Jquery :

jQuery(document).ready(function(){
            jQuery("#buttonpost").on("click", function(){      
                var name = jQuery("#courier").val();
                var trackingid=jQuery("#trackingid").val();
                // alert(name);
                if ('professional_courier' == name) {
                     window.location.href="https://www.tpcindia.com/Tracking2014.aspx?id="+ trackingid+"&type=0&service=0";
                }
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.