I need a tutorial to read an existing custom table. I have been searching many tutorial but it looks like we have to create setup / install file first. I just want to read all records from my table, like:
SELECT * FROM mytable
The most confusing part for me is in Magento we have 3 models:
- the model
- the collection model
- the resource model
My table name is paketid_booking_result
I want to show it in adminhtml_sales_order_shipment_view
My table has already some records in it.
I have tried to create :
class PaketId_Shipping_Model_Resource_Result_Collection extends Mage_Eav_Model_Entity_Collection_Abstract
protected function _construct() { $this->_init('paketid_shipping/result'); }
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') ); }
class PaketId_Shipping_Model_Result extends Mage_Core_Model_Abstract
protected function _construct() { $this->_init('paketid_shipping/result'); //initialized resource model }
Config file config.xml
:
<config>
<modules>
<PaketId_Shipping>
<version>1.0</version>
</PaketId_Shipping>
</modules>
<global>
<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_booking_result</table>
</result>
</entities>
</paketid_shipping_resource>
</models>
<helpers>
<paketid_shipping>
<class>PaketId_Shipping_Helper</class>
</paketid_shipping>
</helpers>
<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>
</global>
<adminhtml>
<layout>
<updates>
<paketid_booking>
<file>shipping.xml</file>
</paketid_booking>
</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>
The layout shipping.xml
:
<layout version="1.0">
<adminhtml_sales_order_shipment_view>
<reference name="content">
<block type="paketid_booking/adminhtml_sales_order_view_info_booking" name="paketid_booking.order.info.booking.block" template="paketid/shipping.phtml" after="order_history" />
</reference>
</adminhtml_sales_order_shipment_view>
</layout>
The template shipping.phtml
:
<?php echo $this->getChildHtml('PaketId_Shipping');?>
<?php $booking = Mage::getModel('paketid_shipping/result')->getCollection();
<?php foreach($bookings as $booking): ?>
<h1><?php echo $booking->getBookingCode() ?></h1>
Those script above produce nothing, I mean my query didn't return anything, and my shipping.phtml
not showing. The existing table paketid_booking_result
is coming from another extension, I want to show it in admin page for a reason.
I am new in Magento, I really need advice and best practice for my case. Any help would be appreciated. Thanks in advanced.
shipping.xml
in yourconfig.xml
layout
afterglobal
tag