订单一旦置于magento中,订单商品的商品状态为' Ordered'。我能够获取此状态。但我需要修改此状态,例如'创建'。
尝试使用以下代码但未反映更改
$order = Mage::getModel("sales/order")->loadByIncrementId($orderId);
$ordered_items = $order->getAllVisibleItems();
foreach($ordered_items as $item){
$item->getStatus();
$item->setStatus('Creating');
$order->save();
}
即使尝试使用此处Howto update order item's custom option in Magento?建议的选项也无效。 请在此处添加您的建议。提前致谢
答案 0 :(得分:5)
订单商品没有单独的字段 - 状态。要了解如何确定状态,您可以看到方法Mage_Sales_Model_Order_Item :: getStatusId
/**
* Retrieve item status identifier
*
* @return int
*/
public function getStatusId()
{
$backordered = (float)$this->getQtyBackordered();
if (!$backordered && $this->getHasChildren()) {
$backordered = (float)$this->_getQtyChildrenBackordered();
}
$canceled = (float)$this->getQtyCanceled();
$invoiced = (float)$this->getQtyInvoiced();
$ordered = (float)$this->getQtyOrdered();
$refunded = (float)$this->getQtyRefunded();
$shipped = (float)$this->getQtyShipped();
$actuallyOrdered = $ordered - $canceled - $refunded;
if (!$invoiced && !$shipped && !$refunded && !$canceled && !$backordered) {
return self::STATUS_PENDING;
}
if ($shipped && $invoiced && ($actuallyOrdered == $shipped)) {
return self::STATUS_SHIPPED;
}
if ($invoiced && !$shipped && ($actuallyOrdered == $invoiced)) {
return self::STATUS_INVOICED;
}
if ($backordered && ($actuallyOrdered == $backordered) ) {
return self::STATUS_BACKORDERED;
}
if ($refunded && $ordered == $refunded) {
return self::STATUS_REFUNDED;
}
if ($canceled && $ordered == $canceled) {
return self::STATUS_CANCELED;
}
if (max($shipped, $invoiced) < $actuallyOrdered) {
return self::STATUS_PARTIAL;
}
return self::STATUS_MIXED;
}
和可用状态:
/**
* Retrieve order item statuses array
*
* @return array
*/
public static function getStatuses()
{
if (is_null(self::$_statuses)) {
self::$_statuses = array(
//self::STATUS_PENDING => Mage::helper('sales')->__('Pending'),
self::STATUS_PENDING => Mage::helper('sales')->__('Ordered'),
self::STATUS_SHIPPED => Mage::helper('sales')->__('Shipped'),
self::STATUS_INVOICED => Mage::helper('sales')->__('Invoiced'),
self::STATUS_BACKORDERED => Mage::helper('sales')->__('Backordered'),
self::STATUS_RETURNED => Mage::helper('sales')->__('Returned'),
self::STATUS_REFUNDED => Mage::helper('sales')->__('Refunded'),
self::STATUS_CANCELED => Mage::helper('sales')->__('Canceled'),
self::STATUS_PARTIAL => Mage::helper('sales')->__('Partial'),
self::STATUS_MIXED => Mage::helper('sales')->__('Mixed'),
);
}
return self::$_statuses;
}