0

I've written a module for Magento that works fine on newer versions (tested on 1.8 and 1.9), but of course now I face a customer who is running an ancient 1.5. This causes trouble, since it seems that the table sales_flat_shipment_track does not have a column track_number. I assume the schema was changed at some point, but what is the right way to access this information in older installations of the application?

Not sure how important it is, but the code that is triggering the error is:

<?php
class Foo_Bar_Model_Carrier extends Mage_Shipping_Model_Carrier_Abstract
    implements Mage_Shipping_Model_Carrier_Interface
{
  public function isTrackingAvailable() {
    return true;
  }

  public function getTrackingInfo($tracking) {
    /** @var $trackInfo Mage_Sales_Model_Order_Shipment_Track */
    $trackInfo = Mage::getModel('sales/order_shipment_track')->load($tracking, 'track_number');
    /** @var $track Mage_Shipping_Model_Tracking_Result_Status */
    $track = Mage::getModel('shipping/tracking_result_status');
    $track->setUrl($trackInfo->getTitle())
      ->setTracking($trackInfo->getTrackNumber())
      ->setCarrierTitle($this->getConfigData('name'));
    return $track;
  }

  // snip ...
}
0

OK. It would seem that the column is called number instead of track_number. I have modified my code to this now:

  public function getTrackingInfo($tracking) {
    // Because: http://magento.stackexchange.com/questions/118072/how-do-i-access-sales-flat-shipment-track-track-number-in-older-versions-of-mage
    $mage_version = Mage::getVersionInfo();
    if ($mage_version['major'] == 1 && $mage_version['minor'] < 6) {
      $track_column = 'number';
    } else {
      $track_column = 'track_number';
    }
    /** @var $trackInfo Mage_Sales_Model_Order_Shipment_Track */
    $trackInfo = Mage::getModel('sales/order_shipment_track')->load($tracking, $track_column);
    /** @var $track Mage_Shipping_Model_Tracking_Result_Status */
    $track = Mage::getModel('shipping/tracking_result_status');
    $track->setUrl($trackInfo->getTitle())
      ->setTracking($trackInfo->getTrackNumber())
      ->setCarrierTitle($this->getConfigData('name'));
    return $track;
  }

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.