Exemple #1
0
 function delete($oid = null, $doReconciliation = true)
 {
     $k = $this->_tbl_key;
     if ($oid) {
         $this->{$k} = intval($oid);
     }
     $id = $this->{$k};
     if ($return = parent::delete($oid)) {
         if ($id) {
             $query = "UPDATE #__tienda_wishlistitems SET wishlist_id = '0' WHERE wishlist_id = '" . $id . "'";
             $db = $this->getDBO();
             $db->setQuery($query);
             $db->query();
         }
     }
     return parent::check();
 }
 /**
  * Run function after deleteing
  */
 function delete($oid = null, $doReconciliation = true)
 {
     $k = $this->_tbl_key;
     if ($oid) {
         $this->{$k} = intval($oid);
     }
     if ($doReconciliation) {
         if ($oid) {
             $row = JTable::getInstance('ProductAttributes', 'TiendaTable');
             $row->load($oid);
             $product_id = $row->product_id;
         } else {
             $product_id = $this->product_id;
         }
     }
     $db = $this->getDBO();
     $db->setQuery('SET foreign_key_checks = 0;');
     $db->query();
     if ($return = parent::delete($oid)) {
         DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models');
         $model = DSCModel::getInstance('ProductAttributeOptions', 'TiendaModel');
         $model->setState('filter_attribute', $this->{$k});
         if ($items = $model->getList()) {
             $table = $model->getTable();
             foreach ($items as $item) {
                 if (!$table->delete($item->productattributeoption_id)) {
                     $this->setError($table->getError());
                 }
             }
         }
         if ($doReconciliation) {
             Tienda::load("TiendaHelperProduct", 'helpers.product');
             TiendaHelperProduct::doProductQuantitiesReconciliation($product_id);
         }
     }
     $db->setQuery('SET foreign_key_checks = 1;');
     $db->query();
     return parent::check();
 }
Exemple #3
0
 /**
  * Delete also the prices linked to this group
  */
 function delete($oid = null)
 {
     $k = $this->_tbl_key;
     $default_user_group = Tienda::getInstance()->get('default_user_group', '1');
     if ($oid) {
         $key = $oid;
     } else {
         $key = $this->{$k};
     }
     if ($key != $default_user_group) {
         $return = parent::delete($oid);
         if ($return) {
             // Delete user group relationships
             $model = JModel::getInstance('UserGroups', 'TiendaModel');
             $model->setState('filter_group', $this->{$k});
             $links = $model->getList();
             if ($links) {
                 $table = JTable::getInstance('UserGroups', 'TiendaTable');
                 foreach ($links as $link) {
                     $table->delete($link->user_id);
                 }
             }
             // Delete prices
             $model = JModel::getInstance('ProductPrices', 'TiendaModel');
             $model->setState('filter_user_group', $this->{$k});
             $prices = $model->getList();
             if ($prices) {
                 $table = JTable::getInstance('ProductPrices', 'TiendaTable');
                 foreach ($prices as $price) {
                     $table->delete($price->user_id);
                 }
             }
         }
     } else {
         $this->setError(JText::_('COM_TIENDA_COM_TIENDA_YOU_CANT_DELETE_THE_DEFAULT_USER_GROUP'));
         return false;
     }
     return $return;
 }
Exemple #4
0
 /**
  * 
  * @param $oid
  * @return unknown_type
  */
 function delete($oid = null, $doReconciliation = true)
 {
     $k = $this->_tbl_key;
     if ($oid) {
         $this->{$k} = intval($oid);
     }
     if ($doReconciliation) {
         if ($oid) {
             $row = JTable::getInstance('ProductComments', 'TiendaTable');
             $row->load($oid);
             $product_id = $row->product_id;
         } else {
             $product_id = $this->product_id;
         }
     }
     if (parent::delete($oid)) {
         DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models');
         $model = DSCModel::getInstance('ProductCommentsHelpfulness', 'TiendaModel');
         $model->setState('filter_comment', $this->{$k});
         if ($items = $model->getList()) {
             $table = $model->getTable();
             foreach ($items as $item) {
                 if (!$table->delete($item->productcommentshelpfulness_id)) {
                     $this->setError($table->getError());
                 }
             }
         }
         if ($doReconciliation) {
             $product = JTable::getInstance('Products', 'TiendaTable');
             $product->load($product_id);
             $product->updateOverallRating();
             if (!$product->save()) {
                 $this->setError($product->getError());
             }
         }
     }
     return parent::check();
 }
Exemple #5
0
 public function delete($oid = null)
 {
     $delete = array();
     $k = $this->_tbl_key;
     if ($oid) {
         $this->{$k} = intval($oid);
     }
     // this should all be a transaction...
     // Delete all the orderitems, orderpayments, ordershipping, etc
     $delete['items'] = $this->deleteItems('items', $oid);
     $delete['payments'] = $this->deleteItems('payments', $oid);
     $delete['info'] = $this->deleteItems('info', $oid);
     $delete['shippings'] = $this->deleteItems('shippings', $oid);
     $delete['history'] = $this->deleteItems('history', $oid);
     $delete['taxclasses'] = $this->deleteItems('taxclasses', $oid);
     $delete['taxrates'] = $this->deleteItems('taxrates', $oid);
     $delete['coupons'] = $this->deleteItems('coupons', $oid);
     $delete['order'] = parent::delete($oid);
     $this->deleteResults = $delete;
     return parent::check();
 }
Exemple #6
0
 function delete($oid = null)
 {
     $k = $this->_tbl_key;
     if ($oid) {
         $this->{$k} = intval($oid);
     }
     if ($return = parent::delete($oid)) {
         $query = new TiendaQuery();
         $query->delete();
         $query->from('#__tienda_productdownloads');
         $query->where('productfile_id = ' . $this->{$k});
         $this->_db->setQuery((string) $query);
         $this->_db->query();
         $query = new TiendaQuery();
         $query->delete();
         $query->from('#__tienda_productdownloadlogs');
         $query->where('productfile_id = ' . $this->{$k});
         $this->_db->setQuery((string) $query);
         $this->_db->query();
     }
     return parent::check();
 }
Exemple #7
0
 /**
  * 
  * @param $oid
  * @return unknown_type
  */
 function delete($oid = null)
 {
     // if this record changed the user credits, then change them back
     $this->load($oid);
     if (!empty($this->credits_updated)) {
         // this record cause a credit change for the user
         // so deduct their value from the users total
         $userdata = JTable::getInstance('Userdata', 'TiendaTable');
         $userdata->load(array('user_id' => $this->user_id));
         $userdata->user_id = $this->user_id;
         $userdata->credits_total = $userdata->credits_total - $this->credit_amount;
         if ($this->credit_withdrawable) {
             $userdata->credits_withdrawable_total = $userdata->credits_withdrawable_total - $this->credit_amount;
         }
         if (!$userdata->save()) {
             $this->setError($userdata->getError());
         }
     }
     return parent::delete($oid);
 }
Exemple #8
0
 /**
  * (non-PHPdoc)
  * @see tienda/admin/tables/TiendaTable#delete($oid)
  */
 function delete($oid = '')
 {
     $dispatcher = JDispatcher::getInstance();
     $before = $dispatcher->trigger('onBeforeDelete' . $this->get('_suffix'), array($this, $oid));
     if (in_array(false, $before, true)) {
         return false;
     }
     if ($return = parent::delete($oid)) {
         // Delete also the values for that product in EAV tables
         $key = $this->_tbl_key;
         $id = $this->{$key};
         // Get the custom fields for this entities
         Tienda::load('TiendaHelperEav', 'helpers.eav');
         $eavs = TiendaHelperEav::getAttributes($this->get('_suffix'), $id, false, '-1');
         $error = false;
         $msg = '';
         foreach (@$eavs as $eav) {
             // get the value table
             $table = JTable::getInstance('EavValues', 'TiendaTable');
             // set the type based on the attribute
             $table->setType($eav->eavattribute_type);
             // load the value based on the entity id
             $keynames = array();
             $keynames['eavattribute_id'] = $eav->eavattribute_id;
             $keynames['eaventity_id'] = $id;
             // If the value exists for this entity
             if ($table->load($keynames)) {
                 // delete the value
                 $result = $table->delete();
                 if (!$result) {
                     $error = true;
                     $msg = $table->getError();
                 }
             }
         }
         // log eav errors
         if ($error) {
             $this->setError(JText::_('COM_TIENDA_EAV_DELETE_FAILED') . $msg);
             return false;
         }
         $dispatcher = JDispatcher::getInstance();
         $dispatcher->trigger('onAfterDelete' . $this->get('_suffix'), array($this, $oid));
     }
     return $return;
 }
Exemple #9
0
 public function delete($oid = null)
 {
     // Check the table activation status first
     if (!$this->active) {
         // Activate it with a default value
         $this->setType('');
     }
     return parent::delete($oid);
 }