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 :

<config>
<modules>
<PaketId_Shipping>
  <version>1.0</version>
</PaketId_Shipping>
</modules>
<global>

<blocks>
  <paketid_shipping>
    <class>PaketId_Shipping_Block</class>
  </paketid_shipping>
</blocks>
<resources>
<shipping_write>
  <connection>
    <use>core_write</use>
  </connection>
</shipping_write>
<shipping_read>
  <connection>
    <use>core_read</use>
  </connection>
</shipping_read>
</resources>

<models>

  <paketid_shipping>
    <class>PaketId_Shipping_Model</class>
    <resourceModel>paketid_shipping_result</resourceModel>
  </paketid_shipping>

  <paketid_shipping_resource>
    <class>PaketId_Shipping_Model_Resource</class>
  </paketid_shipping_resource>

  <paketid_shipping_resource>
    <class>PaketId_Shipping_Model_Resource</class>
      <entities>
        <result>
          <table>paketid_shipping_result</table>
        </result>
      </entities>
  </paketid_shipping_resource>

</models>
<helpers>
  <paketid_shipping>
    <class>PaketId_Shipping_Helper</class>
  </paketid_shipping>
</helpers>
</global>
<adminhtml>
<layout>
  <updates>
    <paketid_shipping>
      <file>paketid_shipping.xml</file>
    </paketid_shipping>
  </updates>
</layout>
</adminhtml>
<default>
<carriers>
  <paketid_shipping>
    <active>1</active>
    <sallowspecific>1</sallowspecific>
<model>paketid_shipping/carrier</model>
    <name>Paket ID Shipping Extension</name>
    <price>10.00</price>
<title>Paket ID Shipping Extension</title>
  </paketid_shipping>
</carriers>
</default>
</config>

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');
    $this->setType('paketid_shipping_result');
    $this->setConnection(
        $resource->getConnection('shipping_read'),
        $resource->getConnection('shipping_write')
    );
}}

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()
{
    $this->_init('paketid_shipping/result');
}

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();
    $countSelect->reset(Zend_Db_Select::GROUP);
    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

 
discard

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.