假設寫這個的人可能也需要做你需要做的事情。一般來說,當Magento對象有一對多的關係時,你可以找到一種方法來加載一個。
你有一個班別名sales/order
。
這對應於Mage_Sales_Model_Order
(在股票安裝中)。
你可以在app/code/core/Mage/Sales/Model/Order.php
找到該課程。
如果您檢查這個類中,有7種方法,與單詞「船」在他們
function canShip
function setShippingAddress
function getShippingAddress
function getShip
function getShipmentsCollection
function hasShip
function prepareShip
那些7中,只有getShipmentsCollection
語義指示搶奪訂單的出貨量的方法。因此,嘗試
foreach($order->getShipmentsCollection() as $shipment)
{
var_dump(get_class($shipment));
//var_dump($shipment->getData());
}
還是先看看源getShipmentsCollection
public function getShipmentsCollection()
{
if (empty($this->_shipments)) {
if ($this->getId()) {
$this->_shipments = Mage::getResourceModel('sales/order_shipment_collection')
->setOrderFilter($this)
->load();
} else {
return false;
}
}
return $this->_shipments;
}
非常感謝,Alan!在看了getShipmentsCollection()和Magento Collections後,我發現使用getShipmentsCollection() - > count()就是我所需要的。 –
您的解釋與往常一樣非常清晰(我想知道您爲什麼不在覈心團隊中工作:) ...但是... 檢查訂單狀態=「完成」不會更容易嗎? ...所以:$ collection = Mage :: getResourceModel('sales/order_collection') - > addAttributeToFilter('increment_id',$ id) - > addAttributeToFilter('state','complete') – WonderLand