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
00028
00029
00030
00031
00032
00033
00034 class Mage_Adminhtml_Model_Sales_Order
00035 {
00036
00037
00038
00039
00040
00041 protected function _getSession()
00042 {
00043 return Mage::getSingleton('adminhtml/session');
00044 }
00045
00046 public function checkRelation(Mage_Sales_Model_Order $order)
00047 {
00048
00049
00050
00051 $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
00052 if (!$customer->getId()) {
00053 $this->_getSession()->addNotice(
00054 Mage::helper('adminhtml')->__(' The customer doesn\'t exist in the system anymore')
00055 );
00056 }
00057
00058
00059
00060
00061 $productIds = array();
00062 foreach ($order->getAllItems() as $item) {
00063 $productIds[] = $item->getProductId();
00064 }
00065
00066 $productCollection = Mage::getModel('catalog/product')->getCollection()
00067 ->addIdFilter($productIds)
00068 ->load();
00069
00070 $hasBadItems = false;
00071 foreach ($order->getAllItems() as $item) {
00072 if (!$productCollection->getItemById($item->getProductId())) {
00073 $this->_getSession()->addError(
00074 Mage::helper('adminhtml')->__('The item %s (SKU %s) doesn\'t exist in the catalog anymore',
00075 $item->getName(),
00076 $item->getSku()
00077 ));
00078 $hasBadItems = true;
00079 }
00080 }
00081 if ($hasBadItems) {
00082 $this->_getSession()->addError(
00083 Mage::helper('adminhtml')->__('Some of the ordered items don\'t exist in the catalog anymore and will be removed if you try to edit the order.')
00084 );
00085 }
00086 return $this;
00087 }
00088
00089 }
00090