Merge branch 'develop' into gli-2961
This commit is contained in:
@@ -2024,6 +2024,16 @@ class AdminProductsControllerCore extends AdminController
|
||||
$this->errors[] = $error;
|
||||
}
|
||||
|
||||
if (!count($this->errors)) {
|
||||
$objHotelRoomType = new HotelRoomType();
|
||||
if ($roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($this->object->id)) {
|
||||
$objHotelBranchInformation = new HotelBranchInformation((int)$roomTypeInfo['id_hotel']);
|
||||
if (!$objHotelBranchInformation->active && !$this->object->active) {
|
||||
$this->errors[] = $this->l('Room type can not be active as long as hotel is disabled.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($this->errors)) {
|
||||
return false;
|
||||
}
|
||||
@@ -2041,6 +2051,61 @@ class AdminProductsControllerCore extends AdminController
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function processBulkStatusSelection($status)
|
||||
{
|
||||
if (!is_array($this->boxes) || empty($this->boxes)) {
|
||||
return parent::processBulkStatusSelection($status);
|
||||
}
|
||||
|
||||
$disabledHotelRoomTypes = array();
|
||||
$objHotelRoomType = new HotelRoomType();
|
||||
$result = true;
|
||||
$hasSuccessfulUpdate = false;
|
||||
|
||||
foreach ($this->boxes as $id) {
|
||||
$id = (int) $id;
|
||||
$object = new $this->className($id);
|
||||
if (!Validate::isLoadedObject($object)) {
|
||||
$this->errors[] = sprintf($this->l('Invalid room type ID %d.'), $id);
|
||||
$result = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($status && ($roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($id))) {
|
||||
$objHotelBranchInformation = new HotelBranchInformation((int) $roomTypeInfo['id_hotel']);
|
||||
if (!$objHotelBranchInformation->active) {
|
||||
$disabledHotelRoomTypes[] = Product::getProductName($id, null, (int)$this->context->language->id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$object->setFieldsToUpdate(array('active' => true));
|
||||
$object->active = (int) $status;
|
||||
$isUpdated = (bool) $object->update();
|
||||
$result = $result && $isUpdated;
|
||||
$hasSuccessfulUpdate = $hasSuccessfulUpdate || $isUpdated;
|
||||
|
||||
if (!$isUpdated) {
|
||||
$this->errors[] = sprintf($this->l('Can\'t update #%d status.'), $id);
|
||||
}
|
||||
}
|
||||
|
||||
if ($disabledHotelRoomTypes) {
|
||||
$this->errors[] =
|
||||
$this->l('Room types linked to inactive hotels cannot be enabled.');
|
||||
}
|
||||
|
||||
if ($result && $hasSuccessfulUpdate && !$disabledHotelRoomTypes) {
|
||||
$this->redirect_after = self::$currentIndex.'&conf=5&token='.$this->token;
|
||||
} elseif ($result && $hasSuccessfulUpdate) {
|
||||
$this->confirmations[] = $this->l('The status has been updated for the room types linked to active hotels.');
|
||||
} elseif (!$result) {
|
||||
$this->errors[] = $this->l('An error occurred while updating the status.');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function processToggleShowAtFront()
|
||||
{
|
||||
if (!$this->loadObject()) {
|
||||
@@ -2366,6 +2431,10 @@ class AdminProductsControllerCore extends AdminController
|
||||
} else if (!Validate::isLoadedObject($objHotel = new HotelBranchInformation($id_hotel))) {
|
||||
$this->errors[] = Tools::displayError('Selected Hotel not found');
|
||||
} else {
|
||||
// Prevent enabling a room type when its hotel is disabled
|
||||
if ((int)Tools::getValue('active') === 1 && isset($objHotel) && !$objHotel->active) {
|
||||
$this->errors[] = Tools::displayError('Room type can not be active as long as hotel is disabled.');
|
||||
}
|
||||
$hotelIdCategory = $objHotel->id_category;
|
||||
if (Validate::isLoadedObject($objCategory = new Category($hotelIdCategory))) {
|
||||
foreach($objCategory->getParentsCategories() as $category) {
|
||||
|
||||
Reference in New Issue
Block a user