/** * Observes grid records update and depends on data updates records in grid too * * @param Varien_Event_Observer $observer * @return Enterprise_SalesArchive_Model_Observer */ public function salesUpdateGridRecords(Varien_Event_Observer $observer) { if (!$this->_config->isArchiveActive()) { return $this; } $proxy = $observer->getEvent()->getProxy(); $archiveEntity = $this->_archive->detectArchiveEntity($proxy->getResource()); if (!$archiveEntity) { return $this; } $ids = $proxy->getIds(); $idsInArchive = $this->_archive->getIdsInArchive($archiveEntity, $ids); // Exclude archive records from default grid rows update $ids = array_diff($ids, $idsInArchive); // Check for newly created shipments, creditmemos, invoices if ($archiveEntity != Enterprise_SalesArchive_Model_Archive::ORDER && !empty($ids)) { $relatedIds = $this->_archive->getRelatedIds($archiveEntity, $ids); $ids = array_diff($ids, $relatedIds); $idsInArchive = array_merge($idsInArchive, $relatedIds); } $proxy->setIds($ids); if (!empty($idsInArchive)) { $this->_archive->updateGridRecords($archiveEntity, $idsInArchive); } return $this; }
/** * Find related to order entity ids for checking of new items in archive * * @param Enterprise_SalesArchive_Model_Archive $archive * @param string $archiveEntity * @param array $ids * @return array */ public function getRelatedIds($archive, $archiveEntity, $ids) { $resourceClass = $archive->getEntityModel($archiveEntity); if (empty($resourceClass) || empty($ids)) { return array(); } /** @var $resource Mage_Sales_Model_Resource_Abstract */ $resource = Mage::getResourceSingleton($resourceClass); $select = $this->_getReadAdapter()->select()->from(array('main_table' => $resource->getMainTable()), 'entity_id')->joinInner(array('order_archive' => $this->getArchiveEntityTable('order')), 'main_table.order_id = order_archive.entity_id', array())->where('main_table.entity_id IN(?)', $ids); return $this->_getReadAdapter()->fetchCol($select); }