I want to read all the records from one table, but I got Fatal Error in my phtml file.

My paketid_booking_result table structure and it already has some records:

entity_id | order_id | booking_id | created_by_user_id | from_full | from_email | from_name | from_phone | from_address | from_zipcode | from_country_code | to_full | to_name | to_name | to_phone | to_address | to_zipcode | to_country_code | booking_code | booking_date | expiry_date

I tried to select only booking_code (for test) where $order in shipping.phtml :

<?php echo $this->getChildHtml('PaketId_Shipping');?>
<?php $order = $this->getOrder()?>
<?php $shipping = Mage::getModel('paketid_shipping/result')->getConnection()->addOrderFilter($order) ?>
<?php if(count($shipping)):
foreach($shipping as $shipping): ?>
<h1>Test custom block</h1>
<h2><?php echo $shipping->getBookingCode() ?></h2>
<?php endforeach; ?>
<?php endif; ?>

My block :

class PaketId_Shipping_Block_Adminhtml_Sales_Order_Shipment_View_Shipping extends Mage_Core_Block_Template {
protected $order;

public function getOrder() {
    if (is_null($this->order)) {
        if (Mage::registry('current_order')) {
            $order = Mage::registry('current_order');
        elseif (Mage::registry('order')) {
            $order = Mage::registry('order');
        else {
            $order = new Varien_Object();
        $this->order = $order;
    return $this->order;


My config.xml :







    <name>Paket ID Shipping Extension</name>
<title>Paket ID Shipping Extension</title>

My model [...]app/code/community/PaketId/Shipping/Model/Resource/Result.php :

class PaketId_Shipping_Model_Resource_Result extends Mage_EAV_Model_Entity_Abstract {
public function __construct()
    $resource = Mage::getSingleton('core/resource');

My model [...]app/code/community/PaketId/Shipping/Model/Resource/Result/Collection.php :

class PaketId_Shipping_Model_Resource_Result_Collection extends Mage_Eav_Model_Entity_Collection_Abstract{
protected function _construct()

public function addOrderFilter($order)
    if ($order instanceof Mage_Sales_Model_Order) {
        $order = (int) $order->getId();
    if (!is_array($order)) {
        $order = array($order);

    $this->getSelect()->where("main_table.order_id IN (?)", $order);

    return $this;
protected function _toOptionArray($valueField='entity_id', $labelField='booking_code', $additional=array())
    return parent::_toOptionArray($valueField, $labelField, $additional);
protected function _toOptionHash($valueField='entity_id', $labelField='booking_code')
    return parent::_toOptionHash($valueField, $labelField);
public function getSelectCountSql()
    $countSelect = parent::getSelectCountSql();
    return $countSelect;
  • where should i add it? – may Sep 16 '16 at 2:59

In shipping.phtml

File do below changes

<?php $order = $block->getOrder()?> 
<?php $shipping = Mage::getModel('paketid_shipping/result')->getConnection()->‌​ddOrderFilter($orde‌​r) ?> 
  • I don't understand the 'example for block file' part and I replaced my previous code in collection.php as you suggest me but i still got the same fatal error :( – may Sep 16 '16 at 3:06
  • yes, i changed my previous $this->getSelect() function to the one you suggested – may Sep 16 '16 at 3:11
  • yes, the same error :( – may Sep 16 '16 at 3:28
  • echo $shipping->getBookingCode() doesn't echo anything, also it gives me no error. I changed $this into $block like u said – may Sep 16 '16 at 3:39
  • Your Call to a member function addOrderFilter() on null error is solved right? – Ankit Shah Sep 16 '16 at 3:42

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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