Public Member Functions | |
loadByIncrementId ($incrementId) | |
setOrder (Mage_Sales_Model_Order $order) | |
getOrder () | |
getBillingAddress () | |
getShippingAddress () | |
register () | |
getItemsCollection () | |
getAllItems () | |
getItemById ($itemId) | |
addItem (Mage_Sales_Model_Order_Shipment_Item $item) | |
getTracksCollection () | |
getAllTracks () | |
getTrackById ($trackId) | |
addTrack (Mage_Sales_Model_Order_Shipment_Track $track) | |
addComment ($comment, $notify=false) | |
getCommentsCollection ($reload=false) | |
sendEmail ($notifyCustomer=true, $comment='') | |
sendUpdateEmail ($notifyCustomer=true, $comment='') | |
getStore () | |
Public Attributes | |
const | STATUS_NEW = 1 |
const | XML_PATH_EMAIL_TEMPLATE = 'sales_email/shipment/template' |
const | XML_PATH_EMAIL_GUEST_TEMPLATE = 'sales_email/shipment/guest_template' |
const | XML_PATH_EMAIL_IDENTITY = 'sales_email/shipment/identity' |
const | XML_PATH_EMAIL_COPY_TO = 'sales_email/shipment/copy_to' |
const | XML_PATH_EMAIL_COPY_METHOD = 'sales_email/shipment/copy_method' |
const | XML_PATH_EMAIL_ENABLED = 'sales_email/shipment/enabled' |
const | XML_PATH_UPDATE_EMAIL_TEMPLATE = 'sales_email/shipment_comment/template' |
const | XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE = 'sales_email/shipment_comment/guest_template' |
const | XML_PATH_UPDATE_EMAIL_IDENTITY = 'sales_email/shipment_comment/identity' |
const | XML_PATH_UPDATE_EMAIL_COPY_TO = 'sales_email/shipment_comment/copy_to' |
const | XML_PATH_UPDATE_EMAIL_COPY_METHOD = 'sales_email/shipment_comment/copy_method' |
const | XML_PATH_UPDATE_EMAIL_ENABLED = 'sales_email/shipment_comment/enabled' |
Protected Member Functions | |
_construct () | |
_getEmails ($configPath) | |
_beforeSave () | |
_beforeDelete () | |
Protected Attributes | |
$_items | |
$_tracks | |
$_order | |
$_eventPrefix = 'sales_order_shipment' | |
$_eventObject = 'shipment' |
Definition at line 28 of file Shipment.php.
_beforeDelete | ( | ) | [protected] |
Processing object before delete data
Reimplemented from Mage_Core_Model_Abstract.
Definition at line 476 of file Shipment.php.
00477 { 00478 $this->_protectFromNonAdmin(); 00479 return parent::_beforeDelete(); 00480 }
_beforeSave | ( | ) | [protected] |
Processing object before save data
Reimplemented from Mage_Core_Model_Abstract.
Definition at line 467 of file Shipment.php.
00468 { 00469 if (!count($this->getAllItems())) { 00470 Mage::throwException( 00471 Mage::helper('sales')->__('Cannot create an empty shipment.') 00472 ); 00473 } 00474 }
_construct | ( | ) | [protected] |
Initialize shipment resource model
Reimplemented from Varien_Object.
Definition at line 56 of file Shipment.php.
00057 { 00058 $this->_init('sales/order_shipment'); 00059 }
_getEmails | ( | $ | configPath | ) | [protected] |
Definition at line 458 of file Shipment.php.
00459 { 00460 $data = Mage::getStoreConfig($configPath, $this->getStoreId()); 00461 if (!empty($data)) { 00462 return explode(',', $data); 00463 } 00464 return false; 00465 }
addComment | ( | $ | comment, | |
$ | notify = false | |||
) |
Definition at line 258 of file Shipment.php.
00259 { 00260 if (!($comment instanceof Mage_Sales_Model_Order_Shipment_Comment)) { 00261 $comment = Mage::getModel('sales/order_shipment_comment') 00262 ->setComment($comment) 00263 ->setIsCustomerNotified($notify); 00264 } 00265 $comment->setShipment($this) 00266 ->setParentId($this->getId()) 00267 ->setStoreId($this->getStoreId()); 00268 if (!$comment->getId()) { 00269 $this->getCommentsCollection()->addItem($comment); 00270 } 00271 return $this; 00272 }
addItem | ( | Mage_Sales_Model_Order_Shipment_Item $ | item | ) |
Definition at line 197 of file Shipment.php.
00198 { 00199 $item->setShipment($this) 00200 ->setParentId($this->getId()) 00201 ->setStoreId($this->getStoreId()); 00202 if (!$item->getId()) { 00203 $this->getItemsCollection()->addItem($item); 00204 } 00205 return $this; 00206 }
addTrack | ( | Mage_Sales_Model_Order_Shipment_Track $ | track | ) |
Definition at line 246 of file Shipment.php.
00247 { 00248 $track->setShipment($this) 00249 ->setParentId($this->getId()) 00250 ->setOrderId($this->getOrderId()) 00251 ->setStoreId($this->getStoreId()); 00252 if (!$track->getId()) { 00253 $this->getTracksCollection()->addItem($track); 00254 } 00255 return $this; 00256 }
getAllItems | ( | ) |
Definition at line 176 of file Shipment.php.
00177 { 00178 $items = array(); 00179 foreach ($this->getItemsCollection() as $item) { 00180 if (!$item->isDeleted()) { 00181 $items[] = $item; 00182 } 00183 } 00184 return $items; 00185 }
getAllTracks | ( | ) |
Definition at line 225 of file Shipment.php.
00226 { 00227 $tracks = array(); 00228 foreach ($this->getTracksCollection() as $track) { 00229 if (!$track->isDeleted()) { 00230 $tracks[] = $track; 00231 } 00232 } 00233 return $tracks; 00234 }
getBillingAddress | ( | ) |
Retrieve billing address
Definition at line 113 of file Shipment.php.
00114 { 00115 return $this->getOrder()->getBillingAddress(); 00116 }
getCommentsCollection | ( | $ | reload = false |
) |
Definition at line 274 of file Shipment.php.
00275 { 00276 if (is_null($this->_comments) || $reload) { 00277 $this->_comments = Mage::getResourceModel('sales/order_shipment_comment_collection') 00278 ->addAttributeToSelect('*') 00279 ->setShipmentFilter($this->getId()) 00280 ->setCreatedAtOrder(); 00281 if ($this->getId()) { 00282 foreach ($this->_comments as $comment) { 00283 $comment->setShipment($this); 00284 } 00285 } 00286 } 00287 return $this->_comments; 00288 }
getItemById | ( | $ | itemId | ) |
Definition at line 187 of file Shipment.php.
00188 { 00189 foreach ($this->getItemsCollection() as $item) { 00190 if ($item->getId()==$itemId) { 00191 return $item; 00192 } 00193 } 00194 return false; 00195 }
getItemsCollection | ( | ) |
Definition at line 160 of file Shipment.php.
00161 { 00162 if (empty($this->_items)) { 00163 $this->_items = Mage::getResourceModel('sales/order_shipment_item_collection') 00164 ->addAttributeToSelect('*') 00165 ->setShipmentFilter($this->getId()); 00166 00167 if ($this->getId()) { 00168 foreach ($this->_items as $item) { 00169 $item->setShipment($this); 00170 } 00171 } 00172 } 00173 return $this->_items; 00174 }
getOrder | ( | ) |
Retrieve the order the shipment for created for
Definition at line 100 of file Shipment.php.
00101 { 00102 if (!$this->_order instanceof Mage_Sales_Model_Order) { 00103 $this->_order = Mage::getModel('sales/order')->load($this->getOrderId()); 00104 } 00105 return $this->_order; 00106 }
getShippingAddress | ( | ) |
Retrieve shipping address
Definition at line 123 of file Shipment.php.
00124 { 00125 return $this->getOrder()->getShippingAddress(); 00126 }
getStore | ( | ) |
Retrieve store model instance
Reimplemented from Mage_Sales_Model_Abstract.
Definition at line 487 of file Shipment.php.
00488 { 00489 return $this->getOrder()->getStore(); 00490 }
getTrackById | ( | $ | trackId | ) |
Definition at line 236 of file Shipment.php.
00237 { 00238 foreach ($this->getTracksCollection() as $track) { 00239 if ($track->getId()==$trackId) { 00240 return $track; 00241 } 00242 } 00243 return false; 00244 }
getTracksCollection | ( | ) |
Definition at line 209 of file Shipment.php.
00210 { 00211 if (empty($this->_tracks)) { 00212 $this->_tracks = Mage::getResourceModel('sales/order_shipment_track_collection') 00213 ->addAttributeToSelect('*') 00214 ->setShipmentFilter($this->getId()); 00215 00216 if ($this->getId()) { 00217 foreach ($this->_tracks as $track) { 00218 $track->setShipment($this); 00219 } 00220 } 00221 } 00222 return $this->_tracks; 00223 }
loadByIncrementId | ( | $ | incrementId | ) |
Load shipment by increment id
string | $incrementId |
Definition at line 67 of file Shipment.php.
00068 { 00069 $ids = $this->getCollection() 00070 ->addAttributeToFilter('increment_id', $incrementId) 00071 ->getAllIds(); 00072 00073 if (!empty($ids)) { 00074 reset($ids); 00075 $this->load(current($ids)); 00076 } 00077 return $this; 00078 }
register | ( | ) |
Register shipment
Apply to order, order items etc.
Definition at line 135 of file Shipment.php.
00136 { 00137 if ($this->getId()) { 00138 Mage::throwException( 00139 Mage::helper('sales')->__('Can not register existing shipment') 00140 ); 00141 } 00142 00143 $totalQty = 0; 00144 foreach ($this->getAllItems() as $item) { 00145 if ($item->getQty()>0) { 00146 $item->register(); 00147 if (!$item->getOrderItem()->isDummy(true)) { 00148 $totalQty+= $item->getQty(); 00149 } 00150 } 00151 else { 00152 $item->isDeleted(true); 00153 } 00154 } 00155 $this->setTotalQty($totalQty); 00156 00157 return $this; 00158 }
sendEmail | ( | $ | notifyCustomer = true , |
|
$ | comment = '' | |||
) |
Sending email with Invoice data
Definition at line 295 of file Shipment.php.
00296 { 00297 if (!Mage::helper('sales')->canSendNewShipmentEmail($this->getOrder()->getStore()->getId())) { 00298 return $this; 00299 } 00300 00301 $currentDesign = Mage::getDesign()->setAllGetOld(array( 00302 'package' => Mage::getStoreConfig('design/package/name', $this->getStoreId()), 00303 'store' => $this->getStoreId() 00304 )); 00305 00306 $translate = Mage::getSingleton('core/translate'); 00307 /* @var $translate Mage_Core_Model_Translate */ 00308 $translate->setTranslateInline(false); 00309 00310 $order = $this->getOrder(); 00311 $copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO); 00312 $copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $this->getStoreId()); 00313 00314 if (!$notifyCustomer && !$copyTo) { 00315 return $this; 00316 } 00317 $paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment()) 00318 ->setIsSecureMode(true); 00319 $mailTemplate = Mage::getModel('core/email_template'); 00320 00321 if ($order->getCustomerIsGuest()) { 00322 $template = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $order->getStoreId()); 00323 $customerName = $order->getBillingAddress()->getName(); 00324 } else { 00325 $template = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $order->getStoreId()); 00326 $customerName = $order->getCustomerName(); 00327 } 00328 00329 if ($notifyCustomer) { 00330 $sendTo[] = array( 00331 'name' => $customerName, 00332 'email' => $order->getCustomerEmail() 00333 ); 00334 if ($copyTo && $copyMethod == 'bcc') { 00335 foreach ($copyTo as $email) { 00336 $mailTemplate->addBcc($email); 00337 } 00338 } 00339 00340 } 00341 00342 if ($copyTo && ($copyMethod == 'copy' || !$notifyCustomer)) { 00343 foreach ($copyTo as $email) { 00344 $sendTo[] = array( 00345 'name' => null, 00346 'email' => $email 00347 ); 00348 } 00349 } 00350 00351 foreach ($sendTo as $recipient) { 00352 $mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$order->getStoreId())) 00353 ->sendTransactional( 00354 $template, 00355 Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $order->getStoreId()), 00356 $recipient['email'], 00357 $recipient['name'], 00358 array( 00359 'order' => $order, 00360 'shipment' => $this, 00361 'comment' => $comment, 00362 'billing' => $order->getBillingAddress(), 00363 'payment_html'=> $paymentBlock->toHtml(), 00364 ) 00365 ); 00366 } 00367 00368 $translate->setTranslateInline(true); 00369 00370 Mage::getDesign()->setAllGetOld($currentDesign); 00371 00372 return $this; 00373 }
sendUpdateEmail | ( | $ | notifyCustomer = true , |
|
$ | comment = '' | |||
) |
Sending email with Shipment update information
Definition at line 380 of file Shipment.php.
00381 { 00382 if (!Mage::helper('sales')->canSendShipmentCommentEmail($this->getOrder()->getStore()->getId())) { 00383 return $this; 00384 } 00385 00386 $currentDesign = Mage::getDesign()->setAllGetOld(array( 00387 'package' => Mage::getStoreConfig('design/package/name', $this->getStoreId()), 00388 )); 00389 00390 $translate = Mage::getSingleton('core/translate'); 00391 /* @var $translate Mage_Core_Model_Translate */ 00392 $translate->setTranslateInline(false); 00393 00394 $order = $this->getOrder(); 00395 00396 $copyTo = $this->_getEmails(self::XML_PATH_UPDATE_EMAIL_COPY_TO); 00397 $copyMethod = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_COPY_METHOD, $this->getStoreId()); 00398 00399 if (!$notifyCustomer && !$copyTo) { 00400 return $this; 00401 } 00402 00403 $mailTemplate = Mage::getModel('core/email_template'); 00404 00405 if ($order->getCustomerIsGuest()) { 00406 $template = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE, $order->getStoreId()); 00407 $customerName = $order->getBillingAddress()->getName(); 00408 } else { 00409 $template = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_TEMPLATE, $order->getStoreId()); 00410 $customerName = $order->getCustomerName(); 00411 } 00412 00413 if ($notifyCustomer) { 00414 $sendTo[] = array( 00415 'name' => $customerName, 00416 'email' => $order->getCustomerEmail() 00417 ); 00418 if ($copyTo && $copyMethod == 'bcc') { 00419 foreach ($copyTo as $email) { 00420 $mailTemplate->addBcc($email); 00421 } 00422 } 00423 00424 } 00425 00426 if ($copyTo && ($copyMethod == 'copy' || !$notifyCustomer)) { 00427 foreach ($copyTo as $email) { 00428 $sendTo[] = array( 00429 'name' => null, 00430 'email' => $email 00431 ); 00432 } 00433 } 00434 00435 foreach ($sendTo as $recipient) { 00436 $mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$order->getStoreId())) 00437 ->sendTransactional( 00438 $template, 00439 Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_IDENTITY, $order->getStoreId()), 00440 $recipient['email'], 00441 $recipient['name'], 00442 array( 00443 'order' => $order, 00444 'billing' => $order->getBillingAddress(), 00445 'shipment'=> $this, 00446 'comment' => $comment 00447 ) 00448 ); 00449 } 00450 00451 $translate->setTranslateInline(true); 00452 00453 Mage::getDesign()->setAllGetOld($currentDesign); 00454 00455 return $this; 00456 }
setOrder | ( | Mage_Sales_Model_Order $ | order | ) |
Declare order for shipment
Mage_Sales_Model_Order | $order |
Definition at line 87 of file Shipment.php.
00088 { 00089 $this->_order = $order; 00090 $this->setOrderId($order->getId()) 00091 ->setStoreId($order->getStoreId()); 00092 return $this; 00093 }
$_eventObject = 'shipment' [protected] |
$_eventPrefix = 'sales_order_shipment' [protected] |
$_items [protected] |
Definition at line 46 of file Shipment.php.
$_order [protected] |
Definition at line 48 of file Shipment.php.
$_tracks [protected] |
Definition at line 47 of file Shipment.php.
const STATUS_NEW = 1 |
Definition at line 30 of file Shipment.php.
const XML_PATH_EMAIL_COPY_METHOD = 'sales_email/shipment/copy_method' |
Definition at line 36 of file Shipment.php.
const XML_PATH_EMAIL_COPY_TO = 'sales_email/shipment/copy_to' |
Definition at line 35 of file Shipment.php.
const XML_PATH_EMAIL_ENABLED = 'sales_email/shipment/enabled' |
Definition at line 37 of file Shipment.php.
const XML_PATH_EMAIL_GUEST_TEMPLATE = 'sales_email/shipment/guest_template' |
Definition at line 33 of file Shipment.php.
const XML_PATH_EMAIL_IDENTITY = 'sales_email/shipment/identity' |
Definition at line 34 of file Shipment.php.
const XML_PATH_EMAIL_TEMPLATE = 'sales_email/shipment/template' |
Definition at line 32 of file Shipment.php.
const XML_PATH_UPDATE_EMAIL_COPY_METHOD = 'sales_email/shipment_comment/copy_method' |
Definition at line 43 of file Shipment.php.
const XML_PATH_UPDATE_EMAIL_COPY_TO = 'sales_email/shipment_comment/copy_to' |
Definition at line 42 of file Shipment.php.
const XML_PATH_UPDATE_EMAIL_ENABLED = 'sales_email/shipment_comment/enabled' |
Definition at line 44 of file Shipment.php.
const XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE = 'sales_email/shipment_comment/guest_template' |
Definition at line 40 of file Shipment.php.
const XML_PATH_UPDATE_EMAIL_IDENTITY = 'sales_email/shipment_comment/identity' |
Definition at line 41 of file Shipment.php.
const XML_PATH_UPDATE_EMAIL_TEMPLATE = 'sales_email/shipment_comment/template' |
Definition at line 39 of file Shipment.php.