/** * 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(); }
function setquantities() { $this->set('suffix', 'productquantities'); $model = $this->getModel($this->get('suffix')); $model->setState('filter_productid', $model->getId()); $model->setState('filter_vendorid', '0'); $items = $model->getAll(); $row = JTable::getInstance('Products', 'TiendaTable'); $row->load($model->getId()); Tienda::load("TiendaHelperProduct", 'helpers.product'); // $csvs = TiendaHelperProduct::getProductAttributeCSVs( $row->product_id ); // $items = TiendaHelperProduct::reconcileProductAttributeCSVs( $row->product_id, '0', $items, $csvs ); TiendaHelperProduct::doProductQuantitiesReconciliation($row->product_id); $state = parent::_setModelState(); $app = JFactory::getApplication(); $ns = $this->getNamespace(); foreach (@$state as $key => $value) { $model->setState($key, $value); } $view = $this->getView('products', 'html'); $view->set('_controller', 'products'); $view->set('_view', 'products'); $view->set('_action', "index.php?option=com_tienda&view=products&task=setquantities&id={$model->getId()}&tmpl=component"); $view->setModel($model, true); $view->assign('state', $model->getState()); $view->assign('row', $row); $view->assign('items', $model->getList()); $view->setLayout('setquantities'); $view->setTask(true); $view->display(); }