setUniqueName('order_number'); $this->setLoggable(); $this->setLockable(); $this->setHashable('o_hash'); $this->setOmittedHashFields(array('order_note','order_pass','order_create_invoice_pass','ip_address','order_status','paid','paid_on','invoice_locked','modified_on','modified_by','locked_on','locked_by')); $this->setTableShortCut('o'); $this->setConvertDecimal(array('paid')); $this->setDateFields(array('paid_on')); } function check(){ if(empty($this->order_number)){ $this->order_number = VirtueMartModelOrders::genStdOrderNumber($this->virtuemart_vendor_id); } if(empty($this->order_pass)){ $this->order_pass = VirtueMartModelOrders::genStdOrderPass(); } if($adminID = vmAccess::getBgManagerId()){ $this->created_by = $adminID; } return parent::check(); } /** * Overloaded delete() to delete records from order_userinfo and order payment as well, * and write a record to the order history (TODO Or should the hist table be cleaned as well?) * * @var integer Order id * @return boolean True on success * @auhtor Max Milbers * @author Kohl Patrick */ function delete( $id=null , $where = 0 ){ $k = $this->_tbl_key; if ($id===null) { $id = $this->{$k}; } $this->_db->setQuery('DELETE from `#__virtuemart_order_userinfos` WHERE `virtuemart_order_id` = ' . (int)$id); if ($this->_db->execute() === false) { vmError($this->_db->getError()); return false; } /*vm_order_payment NOT EXIST have to find the table name*/ $this->_db->setQuery( 'SELECT `payment_element` FROM `#__virtuemart_paymentmethods` , `#__virtuemart_orders` WHERE `#__virtuemart_paymentmethods`.`virtuemart_paymentmethod_id` = `#__virtuemart_orders`.`virtuemart_paymentmethod_id` AND `virtuemart_order_id` = ' . $id ); $payment_element = $this->_db->loadResult(); if(!empty($payment_element)){ $paymentTable = '#__virtuemart_payment_plg_'.$payment_element ; $this->_db->setQuery('DELETE from `'.$paymentTable.'` WHERE `virtuemart_order_id` = ' . $id); if ($this->_db->execute() === false) { vmError($this->_db->getError()); return false; } } /*vm_order_shipment NOT EXIST have to find the table name*/ $this->_db->setQuery( 'SELECT `shipment_element` FROM `#__virtuemart_shipmentmethods` , `#__virtuemart_orders` WHERE `#__virtuemart_shipmentmethods`.`virtuemart_shipmentmethod_id` = `#__virtuemart_orders`.`virtuemart_shipmentmethod_id` AND `virtuemart_order_id` = ' . $id ); $shipmentName = $this->_db->loadResult(); if(!empty($shipmentName)){ $shipmentTable = '#__virtuemart_shipment_plg_'. $shipmentName; $this->_db->setQuery('DELETE from `'.$shipmentTable.'` WHERE `virtuemart_order_id` = ' . $id); if ($this->_db->execute() === false) { vmError('TableOrders delete Order shipmentTable = '.$shipmentTable.' `virtuemart_order_id` = '.$id.' dbErrorMsg '.$this->_db->getError()); return false; } } $_q = 'INSERT INTO `#__virtuemart_order_histories` (' . ' virtuemart_order_history_id' . ',virtuemart_order_id' . ',order_status_code' . ',created_on' . ',customer_notified' . ',comments' .') VALUES (' . ' NULL' . ','.$id . ",'-'" . ',NOW()' . ',0' . ",'Order deleted'" .')'; $this->_db->setQuery($_q); $this->_db->execute(); // Ignore error here return parent::delete($id); } }