00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 class Mage_Sales_Model_Order_Shipment_Item extends Mage_Core_Model_Abstract
00028 {
00029 protected $_eventPrefix = 'sales_shipment_item';
00030 protected $_eventObject = 'shipment_item';
00031
00032 protected $_shipment = null;
00033 protected $_orderItem = null;
00034
00035
00036
00037
00038 function _construct()
00039 {
00040 $this->_init('sales/order_shipment_item');
00041 }
00042
00043
00044
00045
00046
00047
00048
00049 public function setShipment(Mage_Sales_Model_Order_Shipment $shipment)
00050 {
00051 $this->_shipment = $shipment;
00052 return $this;
00053 }
00054
00055
00056
00057
00058
00059
00060 public function getShipment()
00061 {
00062 return $this->_shipment;
00063 }
00064
00065
00066
00067
00068
00069
00070
00071 public function setOrderItem(Mage_Sales_Model_Order_Item $item)
00072 {
00073 $this->_orderItem = $item;
00074 $this->setOrderItemId($item->getId());
00075 return $this;
00076 }
00077
00078
00079
00080
00081
00082
00083 public function getOrderItem()
00084 {
00085 if (is_null($this->_orderItem)) {
00086 if ($this->getShipment()) {
00087 $this->_orderItem = $this->getShipment()->getOrder()->getItemById($this->getOrderItemId());
00088 }
00089 else {
00090 $this->_orderItem = Mage::getModel('sales/order_item')
00091 ->load($this->getOrderItemId());
00092 }
00093 }
00094 return $this->_orderItem;
00095 }
00096
00097
00098
00099
00100
00101
00102
00103 public function setQty($qty)
00104 {
00105 if ($this->getOrderItem()->getIsQtyDecimal()) {
00106 $qty = (float) $qty;
00107 }
00108 else {
00109 $qty = (int) $qty;
00110 }
00111 $qty = $qty > 0 ? $qty : 0;
00112
00113
00114
00115 if ($qty <= $this->getOrderItem()->getQtyToShip() || $this->getOrderItem()->isDummy(true)) {
00116 $this->setData('qty', $qty);
00117 }
00118 else {
00119 Mage::throwException(
00120 Mage::helper('sales')->__('Invalid qty to ship for item "%s"', $this->getName())
00121 );
00122 }
00123 return $this;
00124 }
00125
00126
00127
00128
00129
00130
00131 public function register()
00132 {
00133 $this->getOrderItem()->setQtyShipped(
00134 $this->getOrderItem()->getQtyShipped()+$this->getQty()
00135 );
00136 return $this;
00137 }
00138
00139 }