function store($updateNulls = false, $updateRelationships = true) { $result = parent::store($updateNulls, $updateRelationships); $key = $this->getKeyName(); $id = $this->{$key}; // Precalcular precios y disponibilidad if ($result && $this->product_id) { // Determina si el precio desde de la disponibilidad se calcula por las vigencias o // se toma de la configuración del tarifario. Colocar en 1 para usar las vigencias. $calculatePrices = 0; $query = 'CALL GenerateTransfersRateResumeById(' . $this->product_id . ', CURDATE(), ADDDATE(CURDATE(), 365), ' . $calculatePrices . ')'; $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); $result = false; } } return $result; }
function store($updateNulls = false, $updateRelationships = true) { $result = parent::store($updateNulls, $updateRelationships); $key = $this->getKeyName(); $id = $this->{$key}; // Borrar los tarifarios que usan parámetros o suplementos que ya no están asignados al producto if ($result && $id) { // Asociar los impuestos a los suplementos del producto $query = 'DELETE FROM #__cp_hotels_supplement_tax WHERE product_id = ' . $id; $this->_db->setQuery($query); //die($query); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); $result = false; } if ($result && !empty($this->supplement_taxes)) { $insertSupplements = array(); foreach ($this->supplement_taxes as $key => $row) { $insertSupplements[] = "({$id}, {$key}, " . implode("), ({$id}, {$key}, ", $row) . ')'; } $query = 'INSERT INTO #__cp_hotels_supplement_tax (product_id, supplement_id, tax_id) VALUES ' . implode(', ', $insertSupplements); $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); $result = false; } } /* * Verificar el tarifario: * - Eliminar los precios de tarifarios que están con parámetros que se eliminaron del producto * - Eliminar los precios de tarifarios que están con suplementos que se eliminaron del producto * - Eliminar los impuestos de suplementos que están con suplementos que se eliminaron del producto * - Eliminar la precalculada con fechas que no están en las vigencias de los tarifarios del producto * */ if ($result) { $calculatePrices = 0; $query = 'CALL ValidateHotelRates(' . $id . ', ' . $calculatePrices . ')'; $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); $result = false; $query = 'UPDATE #__cp_hotels_info SET published = 0 WHERE product_id = ' . $id; $this->_db->setQuery($query); $this->_db->query(); } } } if (!$result) { if ($id) { $mes = JText::_('CP.ERROR_SAVING_OLD_PRODUCT'); } else { $mes = JText::_('CP.ERROR_SAVING_NEW_PRODUCT'); } $this->setError($mes . '<div class="hiddenerrormessage">' . $this->getError() . '</div>'); } return $result; }
/** * Inserts a new row if id is zero or updates an existing row in the database table * * * @access public * @param boolean If false, null object variables are not updated * @param boolean If false, relationships aren't updated * @return null|string null if successful otherwise returns and error message */ function store($updateNulls = false, $updateRelationships = true) { $key = $this->getKeyName(); $id = $this->{$key}; // Si el proveedor no es nuevo y se está guardando la información completa con estado inactivo, inactivar los productos asociados if ($updateRelationships && $id && $this->published < 1) { $modelProducts =& JModel::getInstance('producttype', 'CatalogoPlanesModel'); $productTypes = $modelProducts->getActiveProductTypesInfo(); if (is_array($productTypes)) { foreach ($productTypes as $type) { $query = 'UPDATE #__cp_' . $type->product_type_code . '_info SET `published` = 0 WHERE `' . $key . '` = ' . $id; $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError(JText::sprintf('CP.SUPPLIER_ERROR_UNPUBLISH_RELATED_PRODUCTS', $this->supplier_name)); return false; } } } } $result = parent::store($updateNulls, $updateRelationships); return $result; }