如何检查订单是否在Magento中有装运?
我需要检查订单是否已经设置了一些装运。我可以使用的唯一数据是订单的增量id。我正在得到一个模型订单的实例,但我看不出有什么方法可以得到一个装运实例 我正在使用以下代码:如何检查订单是否在Magento中有装运?,magento,Magento,我需要检查订单是否已经设置了一些装运。我可以使用的唯一数据是订单的增量id。我正在得到一个模型订单的实例,但我看不出有什么方法可以得到一个装运实例 我正在使用以下代码: $order = Mage::getModel('sales/order') ->loadByIncrementId($order_increment_id); 但是我怎样才能得到一个装运实例呢?我知道我可以调用Mage::getModel('sales/order\u shipping')->loadByInc
$order = Mage::getModel('sales/order')
->loadByIncrementId($order_increment_id);
但是我怎样才能得到一个装运实例呢?我知道我可以调用
Mage::getModel('sales/order\u shipping')->loadByIncrementId($shipping\u increment\u id)
,但是我如何获取装运增量id呢?假设写这篇文章的人可能也需要做你需要做的事情。通常,当Magento对象具有一对多关系时,可以找到一种方法在一个对象上加载多个对象
您有一个类别名sales/order
这对应于Mage\u Sales\u Model\u Order
(在库存安装中)
您可以在app/code/core/Mage/Sales/Model/Order.php
上找到这个类
如果您检查这个类,其中有7个带有单词“ship”的方法
在这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;
}
为了使其完整,Mage\u Sales\u Model\u Order有一个公共方法:
hassipments()
它返回装运数量并在内部使用所提到的
getShipmentsCollection()
非常感谢,Alan!在查看了getShipmentsCollection()和Magento集合之后,我发现使用getShipmentsCollection()->count()正是我所需要的。您的解释一如既往地非常清楚(我想知道您为什么不在核心团队中工作:)。。。然而。。。检查订单状态=‘完成’并不容易。。。所以:$collection=Mage::getResourceModel('sales/order_collection')->addAttributeToFilter('increment_id',$id)->addAttributeToFilter('state','complete'))
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;
}