Merge pull request #389 from shreesh-webkul/gli-854

Prevent admin or employee from adding rooms in order other than rooms of current hotel in order
This commit is contained in:
Rohit Jain
2022-09-23 14:51:15 +05:30
committed by GitHub
3 changed files with 78 additions and 62 deletions

View File

@@ -3750,7 +3750,7 @@ class ProductCore extends ObjectModel
* @param string $query Search query
* @return array Matching products
*/
public static function searchByName($id_lang, $query, Context $context = null)
public static function searchByName($id_lang, $query, Context $context = null, $id_hotel = false)
{
if (!$context) {
$context = Context::getContext();
@@ -3765,6 +3765,14 @@ class ProductCore extends ObjectModel
AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl')
);
$sql->leftJoin('manufacturer', 'm', 'm.`id_manufacturer` = p.`id_manufacturer`');
if ($id_hotel) {
$sql->innerJoin(
'htl_room_type',
'hrt',
'p.`id_product` = hrt.`id_product` AND hrt.`id_hotel` = '.(int)$id_hotel
);
}
$where = 'pl.`name` LIKE \'%'.pSQL($query).'%\'
OR p.`ean13` LIKE \'%'.pSQL($query).'%\'

View File

@@ -159,7 +159,7 @@ class AdminOrdersControllerCore extends AdminController
'remove_onclick' => true
)
));
$this->shopLinkType = 'shop';
$this->shopShareDatas = Shop::SHARE_ORDER;
@@ -321,7 +321,7 @@ class AdminOrdersControllerCore extends AdminController
$this->addJqueryUI('ui.datepicker');
$this->addJS(_PS_JS_DIR_.'vendor/d3.v3.min.js');
if ($this->tabAccess['edit'] == 1 && $this->display == 'view') {
$this->addJS(_PS_JS_DIR_.'admin/orders.js');
$this->addJS(_PS_JS_DIR_.'tools.js');
@@ -1607,78 +1607,85 @@ class AdminOrdersControllerCore extends AdminController
{
Context::getContext()->customer = new Customer((int)Tools::getValue('id_customer'));
$currency = new Currency((int)Tools::getValue('id_currency'));
if ($products = Product::searchByName((int)$this->context->language->id, pSQL(Tools::getValue('product_search')))) {
foreach ($products as &$product) {
// Formatted price
$product['formatted_price'] = Tools::displayPrice(Tools::convertPrice($product['price_tax_incl'], $currency), $currency);
// Concret price
$product['price_tax_incl'] = Tools::ps_round(Tools::convertPrice($product['price_tax_incl'], $currency), 2);
$product['price_tax_excl'] = Tools::ps_round(Tools::convertPrice($product['price_tax_excl'], $currency), 2);
$productObj = new Product((int)$product['id_product'], false, (int)$this->context->language->id);
$combinations = array();
$attributes = $productObj->getAttributesGroups((int)$this->context->language->id);
$to_return = array('found' => false);
if (Validate::isLoadedObject($order = new Order(Tools::getValue('id_order')))) {
$objBookingDetail = new HotelBookingDetail();
$hotelBookingDetail = $objBookingDetail->getOrderCurrentDataByOrderId($order->id);
if (count($hotelBookingDetail)) {
$idHotel = reset($hotelBookingDetail)['id_hotel'];
} else {
$idHotel = false;
}
// Tax rate for this customer
if (Tools::isSubmit('id_address')) {
$product['tax_rate'] = $productObj->getTaxesRate(new Address(Tools::getValue('id_address')));
}
if ($products = Product::searchByName((int)$this->context->language->id, pSQL(Tools::getValue('product_search')), null, $idHotel)) {
foreach ($products as &$product) {
// Formatted price
$product['formatted_price'] = Tools::displayPrice(Tools::convertPrice($product['price_tax_incl'], $currency), $currency);
// Concret price
$product['price_tax_incl'] = Tools::ps_round(Tools::convertPrice($product['price_tax_incl'], $currency), 2);
$product['price_tax_excl'] = Tools::ps_round(Tools::convertPrice($product['price_tax_excl'], $currency), 2);
$productObj = new Product((int)$product['id_product'], false, (int)$this->context->language->id);
$combinations = array();
$attributes = $productObj->getAttributesGroups((int)$this->context->language->id);
$product['warehouse_list'] = array();
foreach ($attributes as $attribute) {
if (!isset($combinations[$attribute['id_product_attribute']]['attributes'])) {
$combinations[$attribute['id_product_attribute']]['attributes'] = '';
// Tax rate for this customer
if (Tools::isSubmit('id_address')) {
$product['tax_rate'] = $productObj->getTaxesRate(new Address(Tools::getValue('id_address')));
}
$combinations[$attribute['id_product_attribute']]['attributes'] .= $attribute['attribute_name'].' - ';
$combinations[$attribute['id_product_attribute']]['id_product_attribute'] = $attribute['id_product_attribute'];
$combinations[$attribute['id_product_attribute']]['default_on'] = $attribute['default_on'];
if (!isset($combinations[$attribute['id_product_attribute']]['price'])) {
$price_tax_incl = Product::getPriceStatic((int)$product['id_product'], true, $attribute['id_product_attribute']);
$price_tax_excl = Product::getPriceStatic((int)$product['id_product'], false, $attribute['id_product_attribute']);
$combinations[$attribute['id_product_attribute']]['price_tax_incl'] = Tools::ps_round(Tools::convertPrice($price_tax_incl, $currency), 2);
$combinations[$attribute['id_product_attribute']]['price_tax_excl'] = Tools::ps_round(Tools::convertPrice($price_tax_excl, $currency), 2);
$combinations[$attribute['id_product_attribute']]['formatted_price'] = Tools::displayPrice(Tools::convertPrice($price_tax_excl, $currency), $currency);
}
if (!isset($combinations[$attribute['id_product_attribute']]['qty_in_stock'])) {
$combinations[$attribute['id_product_attribute']]['qty_in_stock'] = StockAvailable::getQuantityAvailableByProduct((int)$product['id_product'], $attribute['id_product_attribute'], (int)$this->context->shop->id);
$product['warehouse_list'] = array();
foreach ($attributes as $attribute) {
if (!isset($combinations[$attribute['id_product_attribute']]['attributes'])) {
$combinations[$attribute['id_product_attribute']]['attributes'] = '';
}
$combinations[$attribute['id_product_attribute']]['attributes'] .= $attribute['attribute_name'].' - ';
$combinations[$attribute['id_product_attribute']]['id_product_attribute'] = $attribute['id_product_attribute'];
$combinations[$attribute['id_product_attribute']]['default_on'] = $attribute['default_on'];
if (!isset($combinations[$attribute['id_product_attribute']]['price'])) {
$price_tax_incl = Product::getPriceStatic((int)$product['id_product'], true, $attribute['id_product_attribute']);
$price_tax_excl = Product::getPriceStatic((int)$product['id_product'], false, $attribute['id_product_attribute']);
$combinations[$attribute['id_product_attribute']]['price_tax_incl'] = Tools::ps_round(Tools::convertPrice($price_tax_incl, $currency), 2);
$combinations[$attribute['id_product_attribute']]['price_tax_excl'] = Tools::ps_round(Tools::convertPrice($price_tax_excl, $currency), 2);
$combinations[$attribute['id_product_attribute']]['formatted_price'] = Tools::displayPrice(Tools::convertPrice($price_tax_excl, $currency), $currency);
}
if (!isset($combinations[$attribute['id_product_attribute']]['qty_in_stock'])) {
$combinations[$attribute['id_product_attribute']]['qty_in_stock'] = StockAvailable::getQuantityAvailableByProduct((int)$product['id_product'], $attribute['id_product_attribute'], (int)$this->context->shop->id);
}
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int)$product['advanced_stock_management'] == 1) {
$product['warehouse_list'][$attribute['id_product_attribute']] = Warehouse::getProductWarehouseList($product['id_product'], $attribute['id_product_attribute']);
} else {
$product['warehouse_list'][$attribute['id_product_attribute']] = array();
}
$product['stock'][$attribute['id_product_attribute']] = Product::getRealQuantity($product['id_product'], $attribute['id_product_attribute']);
}
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int)$product['advanced_stock_management'] == 1) {
$product['warehouse_list'][$attribute['id_product_attribute']] = Warehouse::getProductWarehouseList($product['id_product'], $attribute['id_product_attribute']);
$product['warehouse_list'][0] = Warehouse::getProductWarehouseList($product['id_product']);
} else {
$product['warehouse_list'][$attribute['id_product_attribute']] = array();
$product['warehouse_list'][0] = array();
}
$product['stock'][$attribute['id_product_attribute']] = Product::getRealQuantity($product['id_product'], $attribute['id_product_attribute']);
}
$product['stock'][0] = StockAvailable::getQuantityAvailableByProduct((int)$product['id_product'], 0, (int)$this->context->shop->id);
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int)$product['advanced_stock_management'] == 1) {
$product['warehouse_list'][0] = Warehouse::getProductWarehouseList($product['id_product']);
} else {
$product['warehouse_list'][0] = array();
}
foreach ($combinations as &$combination) {
$combination['attributes'] = rtrim($combination['attributes'], ' - ');
}
$product['combinations'] = $combinations;
$product['stock'][0] = StockAvailable::getQuantityAvailableByProduct((int)$product['id_product'], 0, (int)$this->context->shop->id);
foreach ($combinations as &$combination) {
$combination['attributes'] = rtrim($combination['attributes'], ' - ');
}
$product['combinations'] = $combinations;
if ($product['customizable']) {
$product_instance = new Product((int)$product['id_product']);
$product['customization_fields'] = $product_instance->getCustomizationFields($this->context->language->id);
if ($product['customizable']) {
$product_instance = new Product((int)$product['id_product']);
$product['customization_fields'] = $product_instance->getCustomizationFields($this->context->language->id);
}
}
$to_return = array(
'products' => $products,
'found' => true
);
}
$to_return = array(
'products' => $products,
'found' => true
);
} else {
$to_return = array('found' => false);
}
$this->content = json_encode($to_return);
}

View File

@@ -366,6 +366,7 @@ function init()
id_currency: id_currency,
id_address: id_address,
id_customer: id_customer,
id_order: id_order,
product_search: function() { return $('#add_product_product_name').val(); }
}
}
@@ -539,7 +540,7 @@ function init()
error : function(XMLHttpRequest, textStatus, errorThrown) {
jAlert("Impossible to add the room to the cart.\n\ntextStatus: '" + textStatus + "'\nerrorThrown: '" + errorThrown + "'\nresponseText:\n" + XMLHttpRequest.responseText);
},
complete: function() {
complete: function() {
$('#submitAddProduct').removeAttr('disabled');
}
});