Supported events: sales_order_load_after sales_order_save_before sales_order_save_after sales_order_delete_before sales_order_delete_after
Definition at line 39 of file Order.php.
_beforeDelete | ( | ) | [protected] |
Processing object before delete data
Reimplemented from Mage_Core_Model_Abstract.
Definition at line 1611 of file Order.php.
01612 { 01613 $this->_protectFromNonAdmin(); 01614 return parent::_beforeDelete(); 01615 }
_beforeSave | ( | ) | [protected] |
Processing object before save data
Process items dependency for new order
Reimplemented from Mage_Core_Model_Abstract.
Definition at line 1400 of file Order.php.
01401 { 01402 parent::_beforeSave(); 01403 $this->_checkState(); 01404 if (!$this->getId()) { 01405 $store = $this->getStore(); 01406 $name = array($store->getWebsite()->getName(),$store->getGroup()->getName(),$store->getName()); 01407 $this->setStoreName(implode("\n", $name)); 01408 } 01409 01410 /** 01411 * Process items dependency for new order 01412 */ 01413 if (!$this->getId()) { 01414 foreach ($this->getAllItems() as $item) { 01415 if ($parent = $item->getQuoteParentItemId() && !$item->getParentItem()) { 01416 $item->setParentItem($this->getItemByQuoteItemId($parent)); 01417 } 01418 } 01419 } 01420 01421 return $this; 01422 }
_checkState | ( | ) | [protected] |
Order can be closed just in case when we have refunded amount
Definition at line 1424 of file Order.php.
01425 { 01426 if (!$this->getId()) { 01427 return $this; 01428 } 01429 01430 if ($this->getState() !== self::STATE_CANCELED 01431 && !$this->canUnhold() 01432 && !$this->canInvoice() 01433 && !$this->canShip()) { 01434 if ($this->canCreditmemo()) { 01435 if ($this->getState() !== self::STATE_COMPLETE) { 01436 $this->setState(self::STATE_COMPLETE, true); 01437 } 01438 } 01439 /** 01440 * Order can be closed just in case when we have refunded amount 01441 */ 01442 elseif(floatval($this->getTotalRefunded())) { 01443 if ($this->getState() !== self::STATE_CLOSED) { 01444 $this->setState(self::STATE_CLOSED, true); 01445 } 01446 } 01447 } 01448 01449 if ($this->getState() == self::STATE_NEW && $this->getIsInProcess()) { 01450 $this->setState(self::STATE_PROCESSING, true); 01451 } 01452 return $this; 01453 }
_construct | ( | ) | [protected] |
Initialize resource model
Reimplemented from Varien_Object.
Definition at line 108 of file Order.php.
00109 { 00110 $this->_init('sales/order'); 00111 }
_getEmails | ( | $ | configPath | ) | [protected] |
_needToAddDummy | ( | $ | item, | |
$ | qtys = array() | |||
) | [protected] |
Decides if we need to create dummy invoice item or not for eaxample we don't need create dummy parent if all children are not in process
Mage_Sales_Model_Order_Item | $item | |
array | $qtys |
Definition at line 1583 of file Order.php.
01583 { 01584 if ($item->getHasChildren()) { 01585 foreach ($item->getChildrenItems() as $child) { 01586 if (empty($qtys)) { 01587 if ($child->getQtyToInvoice() > 0) { 01588 return true; 01589 } 01590 } else { 01591 if (isset($qtys[$child->getId()]) && $qtys[$child->getId()] > 0) { 01592 return true; 01593 } 01594 } 01595 } 01596 return false; 01597 } else if($item->getParentItem()) { 01598 if (empty($qtys)) { 01599 if ($item->getParentItem()->getQtyToInvoice() > 0) { 01600 return true; 01601 } 01602 } else { 01603 if (isset($qtys[$child->getId()]) && $qtys[$child->getId()] > 0) { 01604 return true; 01605 } 01606 } 01607 return false; 01608 } 01609 }
_placePayment | ( | ) | [protected] |
Place order payments
Definition at line 432 of file Order.php.
00433 { 00434 $this->getPayment()->place(); 00435 return $this; 00436 }
addAddress | ( | Mage_Sales_Model_Order_Address $ | address | ) |
Definition at line 865 of file Order.php.
00866 { 00867 $address->setOrder($this)->setParentId($this->getId()); 00868 if (!$address->getId()) { 00869 $this->getAddressesCollection()->addItem($address); 00870 } 00871 return $this; 00872 }
addItem | ( | Mage_Sales_Model_Order_Item $ | item | ) |
Definition at line 956 of file Order.php.
00957 { 00958 $item->setOrder($this); 00959 if (!$item->getId()) { 00960 $this->getItemsCollection()->addItem($item); 00961 } 00962 return $this; 00963 }
addPayment | ( | Mage_Sales_Model_Order_Payment $ | payment | ) |
Definition at line 1005 of file Order.php.
01006 { 01007 $payment->setOrder($this) 01008 ->setParentId($this->getId()); 01009 if (!$payment->getId()) { 01010 $this->getPaymentsCollection()->addItem($payment); 01011 } 01012 return $this; 01013 }
addRelatedObject | ( | Mage_Core_Model_Abstract $ | object | ) |
Add New object to related array
Mage_Core_Model_Abstract | $object |
Definition at line 1370 of file Order.php.
addStatusHistory | ( | Mage_Sales_Model_Order_Status_History $ | status | ) |
Definition at line 1091 of file Order.php.
01092 { 01093 $status->setOrder($this) 01094 ->setParentId($this->getId()) 01095 ->setStoreId($this->getStoreId()); 01096 $this->setStatus($status->getStatus()); 01097 if (!$status->getId()) { 01098 $this->getStatusHistoryCollection()->addItem($status); 01099 } 01100 return $this; 01101 }
addStatusToHistory | ( | $ | status, | |
$ | comment = '' , |
|||
$ | isCustomerNotified = false | |||
) |
Add status change information to history
string | $status | |
string | $comments | |
boolean | $is_customer_notified |
Definition at line 554 of file Order.php.
00555 { 00556 $status = Mage::getModel('sales/order_status_history') 00557 ->setStatus($status) 00558 ->setComment($comment) 00559 ->setIsCustomerNotified($isCustomerNotified); 00560 $this->addStatusHistory($status); 00561 return $this; 00562 }
canCancel | ( | ) |
Retrieve order cancel availability
Use only state for availability detect
Definition at line 188 of file Order.php.
00189 { 00190 if ($this->canUnhold()) { 00191 return false; 00192 } 00193 00194 if ($this->getState() === self::STATE_CANCELED || 00195 $this->getState() === self::STATE_COMPLETE || 00196 $this->getState() === self::STATE_CLOSED) { 00197 return false; 00198 } 00199 00200 if ($this->getActionFlag(self::ACTION_FLAG_CANCEL) === false) { 00201 return false; 00202 } 00203 00204 /** 00205 * Use only state for availability detect 00206 */ 00207 /*foreach ($this->getAllItems() as $item) { 00208 if ($item->getQtyToCancel()>0) { 00209 return true; 00210 } 00211 } 00212 return false;*/ 00213 return true; 00214 }
cancel | ( | ) |
Cancel order
Definition at line 602 of file Order.php.
00603 { 00604 if ($this->canCancel()) { 00605 $this->getPayment()->cancel(); 00606 $cancelState = self::STATE_CANCELED; 00607 foreach ($this->getAllItems() as $item) { 00608 if ($item->getQtyInvoiced()>$item->getQtyRefunded()) { 00609 $cancelState = self::STATE_COMPLETE; 00610 } 00611 $item->cancel(); 00612 } 00613 00614 $this->setSubtotalCanceled($this->getSubtotal() - $this->getSubtotalInvoiced()); 00615 $this->setBaseSubtotalCanceled($this->getBaseSubtotal() - $this->getBaseSubtotalInvoiced()); 00616 00617 $this->setTaxCanceled($this->getTaxAmount() - $this->getTaxInvoiced()); 00618 $this->setBaseTaxCanceled($this->getBaseTaxAmount() - $this->getBaseTaxInvoiced()); 00619 00620 $this->setShippingCanceled($this->getShippingAmount() - $this->getShippingInvoiced()); 00621 $this->setBaseShippingCanceled($this->getBaseShippingAmount() - $this->getBaseShippingInvoiced()); 00622 00623 $this->setDiscountCanceled( 00624 $this->getDiscountAmount() - $this->getDiscountInvoiced() 00625 ); 00626 $this->setBaseDiscountCanceled( 00627 $this->getBaseDiscountAmount() - $this->getBaseDiscountInvoiced() 00628 ); 00629 00630 $this->setState($cancelState, true); 00631 } 00632 return $this; 00633 }
canComment | ( | ) |
Definition at line 315 of file Order.php.
00316 { 00317 if ($this->getActionFlag(self::ACTION_FLAG_COMMENT) === false) { 00318 return false; 00319 } 00320 00321 return true; 00322 }
canCreditmemo | ( | ) |
Retrieve order credit memo (refund) availability
We can have problem with float in php (on some server $a=762.73;$b=762.73; $a-$b!=0) for this we have additional diapason for 0
Definition at line 249 of file Order.php.
00250 { 00251 if ($this->hasForcedCanCreditmemo()) { 00252 return $this->getForcedCanCreditmemo(); 00253 } 00254 00255 if ($this->canUnhold()) { 00256 return false; 00257 } 00258 00259 if ($this->getState() === self::STATE_CANCELED || 00260 $this->getState() === self::STATE_CLOSED ) { 00261 return false; 00262 } 00263 00264 /** 00265 * We can have problem with float in php (on some server $a=762.73;$b=762.73; $a-$b!=0) 00266 * for this we have additional diapason for 0 00267 */ 00268 if (abs($this->getTotalPaid()-$this->getTotalRefunded())<.0001) { 00269 return false; 00270 } 00271 00272 if ($this->getActionFlag(self::ACTION_FLAG_EDIT) === false) { 00273 return false; 00274 } 00275 00276 00277 return true; 00278 }
canEdit | ( | ) |
Retrieve order edit availability
Definition at line 358 of file Order.php.
00359 { 00360 if ($this->canUnhold()) { 00361 return false; 00362 } 00363 00364 if ($this->getState() === self::STATE_CANCELED || 00365 $this->getState() === self::STATE_COMPLETE || 00366 $this->getState() === self::STATE_CLOSED) { 00367 return false; 00368 } 00369 00370 if (!$this->getPayment()->getMethodInstance()->canEdit()) { 00371 return false; 00372 } 00373 00374 if ($this->getActionFlag(self::ACTION_FLAG_EDIT) === false) { 00375 return false; 00376 } 00377 00378 return true; 00379 }
canHold | ( | ) |
Retrieve order hold availability
Definition at line 285 of file Order.php.
00286 { 00287 if ($this->getState() === self::STATE_CANCELED || 00288 $this->getState() === self::STATE_COMPLETE || 00289 $this->getState() === self::STATE_CLOSED || 00290 $this->getState() === self::STATE_HOLDED) { 00291 return false; 00292 } 00293 00294 if ($this->getActionFlag(self::ACTION_FLAG_HOLD) === false) { 00295 return false; 00296 } 00297 00298 return true; 00299 }
canInvoice | ( | ) |
Retrieve order invoice availability
Definition at line 221 of file Order.php.
00222 { 00223 if ($this->canUnhold()) { 00224 return false; 00225 } 00226 if ($this->getState() === self::STATE_CANCELED || 00227 $this->getState() === self::STATE_COMPLETE || 00228 $this->getState() === self::STATE_CLOSED ) { 00229 return false; 00230 } 00231 00232 if ($this->getActionFlag(self::ACTION_FLAG_INVOICE) === false) { 00233 return false; 00234 } 00235 00236 foreach ($this->getAllItems() as $item) { 00237 if ($item->getQtyToInvoice()>0 && !$item->getLockedDoInvoice()) { 00238 return true; 00239 } 00240 } 00241 return false; 00242 }
canReorder | ( | ) |
Retrieve order reorder availability
Definition at line 386 of file Order.php.
00387 { 00388 if ($this->canUnhold() || !$this->getCustomerId()) { 00389 return false; 00390 } 00391 00392 $products = array(); 00393 foreach ($this->getItemsCollection() as $item) { 00394 $products[] = $item->getProductId(); 00395 } 00396 $productsCollection = Mage::getModel('catalog/product')->getCollection() 00397 ->setStoreId($this->getStoreId()); 00398 00399 if (!empty($products)) { 00400 $productsCollection->addIdFilter($products) 00401 ->addAttributeToSelect('status') 00402 ->load(); 00403 foreach ($productsCollection as $product) { 00404 if (!$product->isSalable()) { 00405 return false; 00406 } 00407 } 00408 } 00409 00410 if ($this->getActionFlag(self::ACTION_FLAG_REORDER) === false) { 00411 return false; 00412 } 00413 00414 return true; 00415 }
canShip | ( | ) |
Retrieve order shipment availability
Definition at line 329 of file Order.php.
00330 { 00331 if ($this->canUnhold()) { 00332 return false; 00333 } 00334 00335 if ($this->getIsVirtual()) { 00336 return false; 00337 } 00338 00339 if ($this->getActionFlag(self::ACTION_FLAG_SHIP) === false) { 00340 return false; 00341 } 00342 00343 foreach ($this->getAllItems() as $item) { 00344 if ($item->getQtyToShip()>0 && !$item->getIsVirtual() 00345 && !$item->getLockedDoShip()) 00346 { 00347 return true; 00348 } 00349 } 00350 return false; 00351 }
canUnhold | ( | ) |
Retrieve order unhold availability
Definition at line 306 of file Order.php.
00307 { 00308 if ($this->getActionFlag(self::ACTION_FLAG_UNHOLD) === false) { 00309 return false; 00310 } 00311 00312 return $this->getState() === self::STATE_HOLDED; 00313 }
formatBasePrice | ( | $ | price | ) |
Definition at line 1178 of file Order.php.
01179 { 01180 return $this->getBaseCurrency()->format($price); 01181 }
formatPrice | ( | $ | price, | |
$ | addBrackets = false | |||
) |
Retrieve formated price value includeing order rate
float | $price | |
bool | $addBrackets |
Definition at line 1138 of file Order.php.
01139 { 01140 return $this->getOrderCurrency()->format($price, array(), true, $addBrackets); 01141 }
formatPriceTxt | ( | $ | price | ) |
Retrieve text formated price value includeing order rate
float | $price |
Definition at line 1149 of file Order.php.
01150 { 01151 return $this->getOrderCurrency()->formatTxt($price); 01152 }
getActionFlag | ( | $ | action | ) |
getAddressById | ( | $ | addressId | ) |
Definition at line 855 of file Order.php.
00856 { 00857 foreach ($this->getAddressesCollection() as $address) { 00858 if ($address->getId()==$addressId) { 00859 return $address; 00860 } 00861 } 00862 return false; 00863 }
getAddressesCollection | ( | ) |
Definition at line 838 of file Order.php.
00839 { 00840 if (is_null($this->_addresses)) { 00841 $this->_addresses = Mage::getResourceModel('sales/order_address_collection') 00842 ->addAttributeToSelect('*') 00843 ->setOrderFilter($this->getId()); 00844 00845 if ($this->getId()) { 00846 foreach ($this->_addresses as $address) { 00847 $address->setOrder($this); 00848 } 00849 } 00850 } 00851 00852 return $this->_addresses; 00853 }
getAllItems | ( | ) |
getAllPayments | ( | ) |
Definition at line 983 of file Order.php.
00984 { 00985 $payments = array(); 00986 foreach ($this->getPaymentsCollection() as $payment) { 00987 if (!$payment->isDeleted()) { 00988 $payments[] = $payment; 00989 } 00990 } 00991 return $payments; 00992 }
getAllStatusHistory | ( | ) |
Enter description here...
Definition at line 1054 of file Order.php.
01055 { 01056 $history = array(); 01057 foreach ($this->getStatusHistoryCollection() as $status) { 01058 if (!$status->isDeleted()) { 01059 $history[] = $status; 01060 } 01061 } 01062 return $history; 01063 }
getAllVisibleItems | ( | ) |
getBaseCurrency | ( | ) |
Retrieve order website currency for working with base prices
Definition at line 1159 of file Order.php.
01160 { 01161 if (is_null($this->_baseCurrency)) { 01162 $this->_baseCurrency = Mage::getModel('directory/currency')->load($this->getBaseCurrencyCode()); 01163 } 01164 return $this->_baseCurrency; 01165 }
getBaseTotalDue | ( | ) |
getBillingAddress | ( | ) |
Retrieve order billing address
Definition at line 490 of file Order.php.
00491 { 00492 foreach ($this->getAddressesCollection() as $address) { 00493 if ($address->getAddressType()=='billing' && !$address->isDeleted()) { 00494 return $address; 00495 } 00496 } 00497 return false; 00498 }
getConfig | ( | ) |
Retrieve order configuration model
Definition at line 422 of file Order.php.
00423 { 00424 return Mage::getSingleton('sales/order_config'); 00425 }
getCreatedAtFormated | ( | $ | format | ) |
Get formated order created date in store timezone
string | $format date format type (short|medium|long|full) |
Definition at line 1382 of file Order.php.
01383 { 01384 return Mage::helper('core')->formatDate($this->getCreatedAtStoreDate(), $format); 01385 }
getCreditmemosCollection | ( | ) |
Retrieve order creditmemos collection
Definition at line 1276 of file Order.php.
01277 { 01278 if (empty($this->_creditmemos)) { 01279 if ($this->getId()) { 01280 $this->_creditmemos = Mage::getResourceModel('sales/order_Creditmemo_collection') 01281 ->addAttributeToSelect('*') 01282 ->setOrderFilter($this->getId()) 01283 ->load(); 01284 } else { 01285 return false; 01286 } 01287 } 01288 return $this->_creditmemos; 01289 }
getCustomerName | ( | ) |
Definition at line 1353 of file Order.php.
01354 { 01355 if ($this->getCustomerFirstname()) { 01356 $customerName = $this->getCustomerFirstname() . ' ' . $this->getCustomerLastname(); 01357 } 01358 else { 01359 $customerName = Mage::helper('sales')->__('Guest'); 01360 } 01361 return $customerName; 01362 }
getData | ( | $ | key = '' , |
|
$ | index = null | |||
) |
Retrieves data from the object
If $key is empty will return all the data as an array Otherwise it will return value of the attribute specified by $key
If $index is specified it will assume that attribute data is an array and retrieve corresponding member.
string | $key | |
string|int | $index | |
mixed | $default |
If we have any data, even if it empty - we should use it, anyway
Reimplemented from Varien_Object.
Definition at line 1212 of file Order.php.
01213 { 01214 if ($key == 'total_due') { 01215 return $this->getTotalDue(); 01216 } 01217 if ($key == 'base_total_due') { 01218 return $this->getBaseTotalDue(); 01219 } 01220 return parent::getData($key, $index); 01221 }
getEmailCustomerNote | ( | ) |
getFullTaxInfo | ( | ) |
Definition at line 1493 of file Order.php.
01494 { 01495 $rates = Mage::getModel('sales/order_tax')->getCollection()->loadByOrder($this)->toArray(); 01496 return Mage::getSingleton('tax/calculation')->reproduceProcess($rates['items']); 01497 }
getInvoiceCollection | ( | ) |
Retrieve order invoices collection
Definition at line 1228 of file Order.php.
01229 { 01230 if (is_null($this->_invoices)) { 01231 $this->_invoices = Mage::getResourceModel('sales/order_invoice_collection') 01232 ->addAttributeToSelect('*') 01233 ->setOrderFilter($this->getId()); 01234 01235 if ($this->getId()) { 01236 foreach ($this->_invoices as $invoice) { 01237 $invoice->setOrder($this); 01238 } 01239 } 01240 } 01241 return $this->_invoices; 01242 }
getIsNotVirtual | ( | ) |
getItemById | ( | $ | itemId | ) |
Definition at line 941 of file Order.php.
00942 { 00943 return $this->getItemsCollection()->getItemById($itemId); 00944 }
getItemByQuoteItemId | ( | $ | quoteItemId | ) |
Definition at line 946 of file Order.php.
00947 { 00948 foreach ($this->getItemsCollection() as $item) { 00949 if ($item->getQuoteItemId()==$quoteItemId) { 00950 return $item; 00951 } 00952 } 00953 return null; 00954 }
getItemsCollection | ( | $ | filterByTypes = array() , |
|
$ | nonChildrenOnly = false | |||
) |
Definition at line 874 of file Order.php.
00875 { 00876 if (is_null($this->_items)) { 00877 $this->_items = Mage::getResourceModel('sales/order_item_collection') 00878 ->setOrderFilter($this->getId()); 00879 if ($filterByTypes) { 00880 $this->_items->filterByTypes($filterByTypes); 00881 } 00882 if ($nonChildrenOnly) { 00883 $this->_items->filterByParent(); 00884 } 00885 00886 if ($this->getId()) { 00887 foreach ($this->_items as $item) { 00888 $item->setOrder($this); 00889 } 00890 } 00891 } 00892 return $this->_items; 00893 }
getItemsRandomCollection | ( | $ | limit = 1 |
) |
Definition at line 895 of file Order.php.
00896 { 00897 $collection = Mage::getModel('sales/order_item')->getCollection() 00898 ->setOrderFilter($this->getId()) 00899 ->setRandomOrder() 00900 ->setPageSize($limit); 00901 00902 $products = array(); 00903 foreach ($collection as $item) { 00904 $products[] = $item->getProductId(); 00905 } 00906 00907 $productsCollection = Mage::getModel('catalog/product') 00908 ->getCollection() 00909 ->addIdFilter($products) 00910 ->load(); 00911 Mage::getSingleton('catalog/product_visibility') 00912 ->addVisibleInSiteFilterToCollection($productsCollection); 00913 foreach ($collection as $item) { 00914 $item->setProduct($productsCollection->getItemById($item->getProductId())); 00915 } 00916 return $collection; 00917 }
getOrderCurrency | ( | ) |
Retrieve order currency model instance
Definition at line 1123 of file Order.php.
01124 { 01125 if (is_null($this->_orderCurrency)) { 01126 $this->_orderCurrency = Mage::getModel('directory/currency')->load($this->getOrderCurrencyCode()); 01127 } 01128 return $this->_orderCurrency; 01129 }
getPayment | ( | ) |
Retrieve order payment model object
Definition at line 443 of file Order.php.
00444 { 00445 foreach ($this->getPaymentsCollection() as $payment) { 00446 if (!$payment->isDeleted()) { 00447 return $payment; 00448 } 00449 } 00450 return false; 00451 }
getPaymentById | ( | $ | paymentId | ) |
Definition at line 995 of file Order.php.
00996 { 00997 foreach ($this->getPaymentsCollection() as $payment) { 00998 if ($payment->getId()==$paymentId) { 00999 return $payment; 01000 } 01001 } 01002 return false; 01003 }
getPaymentsCollection | ( | ) |
Definition at line 967 of file Order.php.
00968 { 00969 if (is_null($this->_payments)) { 00970 $this->_payments = Mage::getResourceModel('sales/order_payment_collection') 00971 ->addAttributeToSelect('*') 00972 ->setOrderFilter($this->getId()); 00973 00974 if ($this->getId()) { 00975 foreach ($this->_payments as $payment) { 00976 $payment->setOrder($this); 00977 } 00978 } 00979 } 00980 return $this->_payments; 00981 }
getRealOrderId | ( | ) |
getRelatedObjects | ( | ) |
getShipmentsCollection | ( | ) |
Retrieve order shipments collection
Definition at line 1249 of file Order.php.
01250 { 01251 if (empty($this->_shipments)) { 01252 if ($this->getId()) { 01253 //TODO: add full name logic 01254 $this->_shipments = Mage::getResourceModel('sales/order_shipment_collection') 01255 ->addAttributeToSelect('increment_id') 01256 ->addAttributeToSelect('created_at') 01257 ->addAttributeToSelect('total_qty') 01258 ->addAttributeToSelect('email_sent') 01259 ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left') 01260 ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left') 01261 ->setOrderFilter($this->getId()) 01262 ->load() 01263 ; 01264 } else { 01265 return false; 01266 } 01267 } 01268 return $this->_shipments; 01269 }
getShippingAddress | ( | ) |
Retrieve order shipping address
Definition at line 505 of file Order.php.
00506 { 00507 foreach ($this->getAddressesCollection() as $address) { 00508 if ($address->getAddressType()=='shipping' && !$address->isDeleted()) { 00509 return $address; 00510 } 00511 } 00512 return false; 00513 }
getShippingCarrier | ( | ) |
$method - carrier_method
Definition at line 648 of file Order.php.
00649 { 00650 $carrierModel = $this->getData('shipping_carrier'); 00651 if (is_null($carrierModel)) { 00652 $carrierModel = false; 00653 /** 00654 * $method - carrier_method 00655 */ 00656 if ($method = $this->getShippingMethod()) { 00657 $data = explode('_', $method); 00658 $carrierCode = $data[0]; 00659 $className = Mage::getStoreConfig('carriers/'.$carrierCode.'/model'); 00660 if ($className) { 00661 $carrierModel = Mage::getModel($className); 00662 } 00663 } 00664 $this->setData('shipping_carrier', $carrierModel); 00665 } 00666 return $carrierModel; 00667 }
getStatusHistoryById | ( | $ | statusId | ) |
Definition at line 1081 of file Order.php.
01082 { 01083 foreach ($this->getStatusHistoryCollection() as $status) { 01084 if ($status->getId()==$statusId) { 01085 return $status; 01086 } 01087 } 01088 return false; 01089 }
getStatusHistoryCollection | ( | $ | reload = false |
) |
Enter description here...
Definition at line 1031 of file Order.php.
01032 { 01033 if (is_null($this->_statusHistory) || $reload) { 01034 $this->_statusHistory = Mage::getResourceModel('sales/order_status_history_collection') 01035 ->addAttributeToSelect('*') 01036 ->setOrderFilter($this->getId()) 01037 ->setOrder('created_at', 'desc') 01038 ->setOrder('entity_id', 'desc'); 01039 01040 if ($this->getId()) { 01041 foreach ($this->_statusHistory as $status) { 01042 $status->setOrder($this); 01043 } 01044 } 01045 } 01046 return $this->_statusHistory; 01047 }
getStatusLabel | ( | ) |
getStore | ( | ) |
Retrieve store model instance
Reimplemented from Mage_Sales_Model_Abstract.
Definition at line 175 of file Order.php.
00176 { 00177 if ($storeId = $this->getStoreId()) { 00178 return Mage::app()->getStore($storeId); 00179 } 00180 return Mage::app()->getStore(); 00181 }
getStoreCurrency | ( | ) |
Retrieve order website currency for working with base prices Deprecated method, please use getBaseCurrency instead.
Definition at line 1173 of file Order.php.
01174 { 01175 return $this->getStoreCurrency(); 01176 }
getStoreGroupName | ( | ) |
getTotalDue | ( | ) |
getTrackingNumbers | ( | ) |
getTracksCollection | ( | ) |
Retrieve order tracking numbers collection
Definition at line 1296 of file Order.php.
01297 { 01298 if (empty($this->_tracks)) { 01299 $this->_tracks = Mage::getResourceModel('sales/order_shipment_track_collection') 01300 ->addAttributeToSelect('*') 01301 ->setOrderFilter($this->getId()); 01302 01303 if ($this->getId()) { 01304 $this->_tracks->load(); 01305 } 01306 } 01307 return $this->_tracks; 01308 }
getVisibleStatusHistory | ( | ) |
Enter description here...
Definition at line 1070 of file Order.php.
01071 { 01072 $history = array(); 01073 foreach ($this->getStatusHistoryCollection() as $status) { 01074 if (!$status->isDeleted() && $status->getComment() && $status->getIsCustomerNotified()) { 01075 $history[] = $status; 01076 } 01077 } 01078 return $history; 01079 }
hasCreditmemos | ( | ) |
Check order creditmemos availability
Definition at line 1335 of file Order.php.
01336 { 01337 return $this->getCreditmemosCollection()->count(); 01338 }
hasInvoices | ( | ) |
Check order invoices availability
Definition at line 1315 of file Order.php.
01316 { 01317 return $this->getInvoiceCollection()->count(); 01318 }
hasShipments | ( | ) |
Check order shipments availability
Definition at line 1325 of file Order.php.
01326 { 01327 return $this->getShipmentsCollection()->count(); 01328 }
hold | ( | ) |
Definition at line 578 of file Order.php.
00579 { 00580 if (!$this->canHold()) { 00581 Mage::throwException(Mage::helper('sales')->__('Hold action is not available')); 00582 } 00583 $this->setHoldBeforeState($this->getState()); 00584 $this->setHoldBeforeStatus($this->getStatus()); 00585 $this->setState(self::STATE_HOLDED, true); 00586 return $this; 00587 }
isCurrencyDifferent | ( | ) |
loadByAttribute | ( | $ | attribute, | |
$ | value | |||
) |
Definition at line 155 of file Order.php.
00156 { 00157 $collection = $this->getCollection() 00158 ->addAttributeToSelect('*') 00159 ->addAttributeToFilter($attribute, $value) 00160 ->load() 00161 ->getItems(); 00162 if (sizeof($collection)) { 00163 reset($collection); 00164 $order = current($collection); 00165 $this->setData($order->getData()); 00166 } 00167 return $this; 00168 }
loadByIncrementId | ( | $ | incrementId | ) |
Definition at line 150 of file Order.php.
00151 { 00152 return $this->loadByAttribute('increment_id', $incrementId); 00153 }
place | ( | ) |
Place order
Definition at line 570 of file Order.php.
00571 { 00572 Mage::dispatchEvent('sales_order_place_before', array('order'=>$this)); 00573 $this->_placePayment(); 00574 Mage::dispatchEvent('sales_order_place_after', array('order'=>$this)); 00575 return $this; 00576 }
prepareInvoice | ( | $ | qtys = array() |
) |
Create new invoice with maximum qty for invoice for each item
Definition at line 1504 of file Order.php.
01505 { 01506 $convertor = Mage::getModel('sales/convert_order'); 01507 $invoice = $convertor->toInvoice($this); 01508 foreach ($this->getAllItems() as $orderItem) { 01509 if (!$orderItem->isDummy() && !$orderItem->getQtyToInvoice()) { 01510 continue; 01511 } 01512 if ($orderItem->isDummy() && !$this->_needToAddDummy($orderItem, $qtys)) { 01513 continue; 01514 } 01515 $item = $convertor->itemToInvoiceItem($orderItem); 01516 if ($orderItem->isDummy()) { 01517 $qty = 1; 01518 } else { 01519 if (isset($qtys[$orderItem->getId()])) { 01520 $qty = $qtys[$orderItem->getId()]; 01521 } else { 01522 $qty = $orderItem->getQtyToInvoice(); 01523 } 01524 } 01525 01526 $item->setQty($qty); 01527 $invoice->addItem($item); 01528 } 01529 $invoice->collectTotals(); 01530 01531 return $invoice; 01532 }
prepareShipment | ( | $ | qtys = array() |
) |
Create new shipment with maximum qty for shipping for each item
Definition at line 1539 of file Order.php.
01540 { 01541 $totalToShip = 0; 01542 $convertor = Mage::getModel('sales/convert_order'); 01543 $shipment = $convertor->toShipment($this); 01544 foreach ($this->getAllItems() as $orderItem) { 01545 if (!$orderItem->isDummy() && !$orderItem->getQtyToShip()) { 01546 continue; 01547 } 01548 if ($orderItem->isDummy() && !$this->_needToAddDummy($orderItem, $qtys)) { 01549 continue; 01550 } 01551 $item = $convertor->itemToShipmentItem($orderItem); 01552 if ($orderItem->isDummy()) { 01553 $qty = 1; 01554 } else { 01555 if (isset($qtys[$orderItem->getId()])) { 01556 $qty = $qtys[$orderItem->getId()]; 01557 } else { 01558 $qty = $orderItem->getQtyToShip(); 01559 } 01560 } 01561 01562 $totalToShip += $qty; 01563 $item->setQty($qty); 01564 $shipment->addItem($item); 01565 } 01566 01567 if ($totalToShip) { 01568 return $shipment; 01569 } else { 01570 return null; 01571 } 01572 }
reset | ( | ) |
Resets all data in object so after another load it will be complete new object
Definition at line 1470 of file Order.php.
01471 { 01472 $this->unsetData(); 01473 $this->_addresses = null; 01474 $this->_items = null; 01475 $this->_payments = null; 01476 $this->_statusHistory = null; 01477 $this->_invoices = null; 01478 $this->_tracks = null; 01479 $this->_shipments = null; 01480 $this->_creditmemos = null; 01481 $this->_relatedObjects = array(); 01482 $this->_orderCurrency = null; 01483 $this->_baseCurrency = null; 01484 01485 return $this; 01486 }
sendNewOrderEmail | ( | ) |
Sending email with order data
Definition at line 674 of file Order.php.
00675 { 00676 if (!Mage::helper('sales')->canSendNewOrderEmail($this->getStore()->getId())) { 00677 return $this; 00678 } 00679 00680 $translate = Mage::getSingleton('core/translate'); 00681 /* @var $translate Mage_Core_Model_Translate */ 00682 $translate->setTranslateInline(false); 00683 00684 $paymentBlock = Mage::helper('payment')->getInfoBlock($this->getPayment()) 00685 ->setIsSecureMode(true); 00686 00687 $paymentBlock->getMethod()->setStore($this->getStore()->getId()); 00688 00689 $mailTemplate = Mage::getModel('core/email_template'); 00690 /* @var $mailTemplate Mage_Core_Model_Email_Template */ 00691 $copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO); 00692 $copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $this->getStoreId()); 00693 if ($copyTo && $copyMethod == 'bcc') { 00694 foreach ($copyTo as $email) { 00695 $mailTemplate->addBcc($email); 00696 } 00697 } 00698 00699 if ($this->getCustomerIsGuest()) { 00700 $template = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $this->getStoreId()); 00701 $customerName = $this->getBillingAddress()->getName(); 00702 } else { 00703 $template = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $this->getStoreId()); 00704 $customerName = $this->getCustomerName(); 00705 } 00706 00707 $sendTo = array( 00708 array( 00709 'email' => $this->getCustomerEmail(), 00710 'name' => $customerName 00711 ) 00712 ); 00713 if ($copyTo && $copyMethod == 'copy') { 00714 foreach ($copyTo as $email) { 00715 $sendTo[] = array( 00716 'email' => $email, 00717 'name' => null 00718 ); 00719 } 00720 } 00721 00722 foreach ($sendTo as $recipient) { 00723 $mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$this->getStoreId())) 00724 ->sendTransactional( 00725 $template, 00726 Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $this->getStoreId()), 00727 $recipient['email'], 00728 $recipient['name'], 00729 array( 00730 'order' => $this, 00731 'billing' => $this->getBillingAddress(), 00732 'payment_html' => $paymentBlock->toHtml(), 00733 ) 00734 ); 00735 } 00736 00737 $translate->setTranslateInline(true); 00738 00739 return $this; 00740 }
sendOrderUpdateEmail | ( | $ | notifyCustomer = true , |
|
$ | comment = '' | |||
) |
Sending email with order update information
Definition at line 747 of file Order.php.
00748 { 00749 if (!Mage::helper('sales')->canSendOrderCommentEmail($this->getStore()->getId())) { 00750 return $this; 00751 } 00752 00753 $copyTo = $this->_getEmails(self::XML_PATH_UPDATE_EMAIL_COPY_TO); 00754 $copyMethod = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_COPY_METHOD, $this->getStoreId()); 00755 if (!$notifyCustomer && !$copyTo) { 00756 return $this; 00757 } 00758 00759 // set design parameters, required for email (remember current) 00760 $currentDesign = Mage::getDesign()->setAllGetOld(array( 00761 'store' => $this->getStoreId(), 00762 'area' => 'frontend', 00763 'package' => Mage::getStoreConfig('design/package/name', $this->getStoreId()), 00764 )); 00765 00766 $translate = Mage::getSingleton('core/translate'); 00767 /* @var $translate Mage_Core_Model_Translate */ 00768 $translate->setTranslateInline(false); 00769 00770 $sendTo = array(); 00771 00772 $mailTemplate = Mage::getModel('core/email_template'); 00773 00774 if ($this->getCustomerIsGuest()) { 00775 $template = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE, $this->getStoreId()); 00776 $customerName = $this->getBillingAddress()->getName(); 00777 } else { 00778 $template = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_TEMPLATE, $this->getStoreId()); 00779 $customerName = $this->getCustomerName(); 00780 } 00781 00782 if ($notifyCustomer) { 00783 $sendTo[] = array( 00784 'name' => $customerName, 00785 'email' => $this->getCustomerEmail() 00786 ); 00787 if ($copyTo && $copyMethod == 'bcc') { 00788 foreach ($copyTo as $email) { 00789 $mailTemplate->addBcc($email); 00790 } 00791 } 00792 00793 } 00794 00795 if ($copyTo && ($copyMethod == 'copy' || !$notifyCustomer)) { 00796 foreach ($copyTo as $email) { 00797 $sendTo[] = array( 00798 'name' => null, 00799 'email' => $email 00800 ); 00801 } 00802 } 00803 00804 foreach ($sendTo as $recipient) { 00805 $mailTemplate->setDesignConfig(array('area'=>'frontend', 'store' => $this->getStoreId())) 00806 ->sendTransactional( 00807 $template, 00808 Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_IDENTITY, $this->getStoreId()), 00809 $recipient['email'], 00810 $recipient['name'], 00811 array( 00812 'order' => $this, 00813 'billing' => $this->getBillingAddress(), 00814 'comment' => $comment 00815 ) 00816 ); 00817 } 00818 00819 $translate->setTranslateInline(true); 00820 00821 // revert current design 00822 Mage::getDesign()->setAllGetOld($currentDesign); 00823 00824 return $this; 00825 }
setActionFlag | ( | $ | action, | |
$ | flag | |||
) |
Set can flag value for action (edit, unhold, etc...)
string | $action | |
boolean | $flag |
Definition at line 144 of file Order.php.
setBillingAddress | ( | Mage_Sales_Model_Order_Address $ | address | ) |
Declare order billing address
Mage_Sales_Model_Order_Address | $address |
Definition at line 459 of file Order.php.
00460 { 00461 $old = $this->getBillingAddress(); 00462 if (!empty($old)) { 00463 $address->setId($old->getId()); 00464 } 00465 $this->addAddress($address->setAddressType('billing')); 00466 return $this; 00467 }
setPayment | ( | Mage_Sales_Model_Order_Payment $ | payment | ) |
Definition at line 1015 of file Order.php.
01016 { 01017 if (!$this->getIsMultiPayment() && ($old = $this->getPayment())) { 01018 $payment->setId($old->getId()); 01019 } 01020 $this->addPayment($payment); 01021 return $payment; 01022 }
setShippingAddress | ( | Mage_Sales_Model_Order_Address $ | address | ) |
Declare order shipping address
Mage_Sales_Model_Order_Address | $address |
Definition at line 475 of file Order.php.
00476 { 00477 $old = $this->getShippingAddress(); 00478 if (!empty($old)) { 00479 $address->setId($old->getId()); 00480 } 00481 $this->addAddress($address->setAddressType('shipping')); 00482 return $this; 00483 }
setState | ( | $ | state, | |
$ | status = false , |
|||
$ | comment = '' , |
|||
$ | isCustomerNotified = false | |||
) |
Declare order state
string | $state | |
string | $status | |
string | $comment | |
bool | $isCustomerNotified |
Definition at line 524 of file Order.php.
00525 { 00526 $this->setData('state', $state); 00527 if ($status) { 00528 if ($status === true) { 00529 $status = $this->getConfig()->getStateDefaultStatus($state); 00530 } 00531 $this->addStatusToHistory($status, $comment, $isCustomerNotified); 00532 } 00533 return $this; 00534 }
unhold | ( | ) |
unsetData | ( | $ | key = null |
) |
Unset data from the object.
$key can be a string only. Array will be ignored.
$isChanged will specify if the object needs to be saved after an update.
string | $key | |
boolean | $isChanged |
Reimplemented from Varien_Object.
Definition at line 113 of file Order.php.
00114 { 00115 parent::unsetData($key); 00116 if (is_null($key)) { 00117 $this->_items = null; 00118 } 00119 return $this; 00120 }
$_eventObject = 'order' [protected] |
$_eventPrefix = 'sales_order' [protected] |
const ACTION_FLAG_CANCEL = 'cancel' |
const ACTION_FLAG_COMMENT = 'comment' |
const ACTION_FLAG_CREDITMEMO = 'creditmemo' |
const ACTION_FLAG_EDIT = 'edit' |
const ACTION_FLAG_HOLD = 'hold' |
const ACTION_FLAG_INVOICE = 'invoice' |
const ACTION_FLAG_REORDER = 'reorder' |
const ACTION_FLAG_SHIP = 'ship' |
const ACTION_FLAG_UNHOLD = 'unhold' |
const STATE_CANCELED = 'canceled' |
const STATE_CLOSED = 'closed' |
const STATE_COMPLETE = 'complete' |
const STATE_HOLDED = 'holded' |
const STATE_PENDING_PAYMENT = 'pending_payment' |
const STATE_PROCESSING = 'processing' |
const XML_PATH_EMAIL_COPY_METHOD = 'sales_email/order/copy_method' |
const XML_PATH_EMAIL_COPY_TO = 'sales_email/order/copy_to' |
const XML_PATH_EMAIL_ENABLED = 'sales_email/order/enabled' |
const XML_PATH_EMAIL_GUEST_TEMPLATE = 'sales_email/order/guest_template' |
const XML_PATH_EMAIL_IDENTITY = 'sales_email/order/identity' |
const XML_PATH_EMAIL_TEMPLATE = 'sales_email/order/template' |
const XML_PATH_UPDATE_EMAIL_COPY_METHOD = 'sales_email/order_comment/copy_method' |
const XML_PATH_UPDATE_EMAIL_COPY_TO = 'sales_email/order_comment/copy_to' |
const XML_PATH_UPDATE_EMAIL_ENABLED = 'sales_email/order_comment/enabled' |
const XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE = 'sales_email/order_comment/guest_template' |
const XML_PATH_UPDATE_EMAIL_IDENTITY = 'sales_email/order_comment/identity' |
const XML_PATH_UPDATE_EMAIL_TEMPLATE = 'sales_email/order_comment/template' |