我尝试var_dump($order)
,但它给了我:
object(Varien_Object)#290 (7) { ["_data":protected]=> array(0) { } ["_hasDataChanges":protected]=> bool(false) ["_origData":protected]=> NULL ["_idFieldName":protected]=> NULL ["_isDeleted":protected]=> bool(false) ["_oldFieldsMap":protected]=> array(0) { } ["_syncFieldsMap":protected]=> array(0) { } }
我的class PaketId_Shipping_Block_Adminhtml_Sales_Order_Shipment_View_Shipping extends Mage_Sales_Block_Order_Shipment {
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;
}
我的phtml文件:
<?php echo $this->getChildHtml('PaketId_Shipping');?>
<h1>Test custom block</h1>
<?php $order = $this->getOrder()?>
<?php var_dump($order);?>
<?php $shippings = Mage::getModel('paketid_shipping/result')->getCollection()->addOrderFilter($order) ?>
<?php echo "<pre>";?>
<?php var_dump($shippings);?>
<?php echo "</pre>" ;?>
我的phtml文件中的变量$order
在某种程度上没有调用块文件中的$order
,或者我对此有误解?因为,当我在其他phtml中尝试var_dump($order)
时,它会返回object(Mage_Sales_Model_Order)#276...
我尝试将$this-getOrder()
更改为Mage::registry('current_order')
但它给了我NULL
。我做错了什么?
我的收藏:
class PaketId_Shipping_Model_Resource_Result_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
protected function _construct()
{
parent::_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;
}
我的资源:
class PaketId_Shipping_Model_Resource_Result extends Mage_Core_Model_Resource_Db_Abstract
public function _construct()
{
$this->_init('paketid_shipping/result', 'entity_id');
}
我的结果:
class PaketId_Shipping_Model_Result extends Mage_Core_Model_Abstract
const ENTITY = 'paketid_shipping_result';
const CACHE_TAG = 'paketid_shipping_result';
protected $_eventPrefix = 'paketid_shipping_result';
protected $_eventObject = 'paketid_shipping_result';
public function _construct()
{
parent::_construct();
$this->_init('paketid_shipping/result');
}
管理员布局xml:
<layout version="1.0">
<adminhtml_sales_order_shipment_new>
<reference name="content">
<block type="paketid_shipping/adminhtml_sales_order_shipment_view_shipping" name="paketid_shipping.order.view.shipping.block" template="paketid/shipping.phtml"/>
</reference>
</adminhtml_sales_order_shipment_new>
答案 0 :(得分:0)
请从Mage_Sales_Block_Order_Shipment或Mage_Sales_Block_Order_View调用扩展您的模块类,并检查它是否有帮助。