Added feature for adding standard product in cart

This commit is contained in:
Shreesh Arora
2025-02-26 11:07:31 +05:30
parent 950b37ed1c
commit ec23dbd4f3
98 changed files with 8153 additions and 3882 deletions

View File

@@ -1061,6 +1061,20 @@ class AdminCartsControllerCore extends AdminController
}
}
public function ajaxProcessUpdateProductQuantity()
{
$params = Tools::getValue('params');
$idProduct = (int) $params['id_product'];
$idCart = (int) $params['id_cart'];
$this->context->cart = new Cart($idCart);
if ($this->tabAccess['edit'] === '1') {
$id_hotel_service_product_cart_detail = (int) $params['id_hotel_service_product_cart_detail'];
$product = new Product($idProduct, true, $this->context->language->id);
}
}
// Process to get extra demands of any room while order creation process form.tpl
public function ajaxProcessGetRoomTypeCartDemands()
{

View File

@@ -102,6 +102,7 @@ class AdminNormalProductsControllerCore extends AdminController
// 'Seo' => $this->l('SEO'),
'Images' => $this->l('Images'),
'Associations' => $this->l('Associations'),
// 'Quantities' => $this->l('Quantities'),
);
if ($this->context->shop->getContext() != Shop::CONTEXT_GROUP) {
@@ -111,6 +112,7 @@ class AdminNormalProductsControllerCore extends AdminController
// 'Seo' => 2,
'Associations' => 3,
'Images' => 4,
// 'Quantities' => 5,
));
}
@@ -207,6 +209,7 @@ class AdminNormalProductsControllerCore extends AdminController
// show the list of the product according to the booking or service products
$this->_where .= ' AND a.`booking_product` = 0';
$this->_where .= ' AND a.`service_product_type` = '.(int)ProductCore::SERVICE_PRODUCT_WITH_ROOMTYPE;
$this->_group = 'GROUP BY a.`id_product`';
@@ -291,7 +294,7 @@ class AdminNormalProductsControllerCore extends AdminController
);
// $serviceProductType = array(
// Product::SERVICE_PRODUCT_WITH_ROOMTYPE => $this->l('Bought with room type'),
// Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE => $this->l('Bought without room type')
// Product::SERVICE_PRODUCT_STANDALONE => $this->l('Bought without room type')
// );
// $this->fields_list['service_product_type'] = array(
// 'type' => 'select',
@@ -358,7 +361,7 @@ class AdminNormalProductsControllerCore extends AdminController
{
if ($service_product_type == Product::SERVICE_PRODUCT_WITH_ROOMTYPE) {
return $this->l('With room type');
} else if ($service_product_type == Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE) {
} else if ($service_product_type == Product::SERVICE_PRODUCT_STANDALONE) {
return $this->l('Without room type');
}
@@ -1822,8 +1825,8 @@ class AdminNormalProductsControllerCore extends AdminController
$_POST['allow_multiple_quantity'] = 0;
}
$_POST['service_product_type'] = Product::SERVICE_PRODUCT_WITH_ROOMTYPE;
$this->copyFromPost($this->object, $this->table);
$this->object->service_product_type = Product::SERVICE_PRODUCT_WITH_ROOMTYPE;
// set product visibility to none for current flow.
@@ -1967,6 +1970,7 @@ class AdminNormalProductsControllerCore extends AdminController
if (Validate::isLoadedObject($object)) {
$this->_removeTaxFromEcotax();
$product_type_before = $object->getType();
$_POST['service_product_type'] = Product::SERVICE_PRODUCT_WITH_ROOMTYPE;
$this->copyFromPost($object, $this->table);
$object->indexed = 0;
@@ -2878,8 +2882,9 @@ class AdminNormalProductsControllerCore extends AdminController
{
if (Validate::isLoadedObject($product)) {
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
$associatedRoomTypes = $objRoomTypeServiceProduct->getAssociatedHotelsAndRoomType($product->id)['room_type'];
$allAssociations = $objRoomTypeServiceProduct->getAssociatedHotelsAndRoomType($product->id);
if (Product::SERVICE_PRODUCT_WITH_ROOMTYPE == $product->service_product_type) {
$associatedRoomTypes = $allAssociations['room_type'];
$selectedRoomTypes = Tools::getValue('room_type_box');
// Generate list of new associations
@@ -2915,15 +2920,55 @@ class AdminNormalProductsControllerCore extends AdminController
RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE
);
}
} else {
RoomTypeServiceProduct::deleteRoomProductLink(
$product->id,
RoomTypeServiceProduct::WK_ELEMENT_TYPE_HOTEL
);
} elseif (Product::SERVICE_PRODUCT_lINKED_WITH_HOTEL == $product->service_product_type) {
$associatedHotels = $allAssociations['hotel'];
$selectedHotel = Tools::getValue('hotel_box');
// Generate list of new associations
$newHotels = array();
foreach ($selectedHotel as $selectedRoomType) {
if (!in_array($selectedRoomType, $associatedHotels)) {
$newHotels[] = $selectedRoomType;
}
}
// Generate list of associations to remove
$removedHotels = array();
foreach ($associatedHotels as $associatedRoomType) {
if (!in_array($associatedRoomType, $selectedHotel)) {
$removedHotels[] = $associatedRoomType;
}
}
// Remove associations
foreach ($associatedRoomTypes as $associatedRoomType) {
foreach ($removedHotels as $removedHotel) {
RoomTypeServiceProduct::deleteRoomProductLink(
$product->id,
RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE,
$associatedRoomType
RoomTypeServiceProduct::WK_ELEMENT_TYPE_HOTEL,
$removedHotel
);
}
// Save new associations
if ($newHotels) {
$objRoomTypeServiceProduct->addRoomProductLink(
$product->id,
$newHotels,
RoomTypeServiceProduct::WK_ELEMENT_TYPE_HOTEL
);
}
RoomTypeServiceProduct::deleteRoomProductLink(
$product->id,
RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE
);
} else {
// Remove associations
RoomTypeServiceProduct::deleteRoomProductLink(
$product->id
);
}
}
}
@@ -3190,6 +3235,160 @@ class AdminNormalProductsControllerCore extends AdminController
$this->tpl_form_vars['custom_form'] = $data->fetch();
}
/**
* @param Product $obj
* @throws Exception
* @throws SmartyException
*/
public function initFormQuantities($obj)
{
if (!$this->default_form_language) {
$this->getLanguages();
}
$data = $this->createTemplate($this->tpl_form);
$data->assign('default_form_language', $this->default_form_language);
if ($obj->id) {
if ($this->product_exists_in_shop) {
// Get all id_product_attribute
$attributes = $obj->getAttributesResume($this->context->language->id);
if (empty($attributes)) {
$attributes[] = array(
'id_product_attribute' => 0,
'attribute_designation' => ''
);
}
// Get available quantities
$available_quantity = array();
$product_designation = array();
foreach ($attributes as $attribute) {
// Get available quantity for the current product attribute in the current shop
$available_quantity[$attribute['id_product_attribute']] = isset($attribute['id_product_attribute']) && $attribute['id_product_attribute'] ? (int)$attribute['quantity'] : (int)$obj->quantity;
// Get all product designation
$product_designation[$attribute['id_product_attribute']] = rtrim(
$obj->name[$this->context->language->id].' - '.$attribute['attribute_designation'],
' - '
);
}
$show_quantities = true;
$shop_context = Shop::getContext();
$shop_group = new ShopGroup((int)Shop::getContextShopGroupID());
// if we are in all shops context, it's not possible to manage quantities at this level
if (Shop::isFeatureActive() && $shop_context == Shop::CONTEXT_ALL) {
$show_quantities = false;
}
// if we are in group shop context
elseif (Shop::isFeatureActive() && $shop_context == Shop::CONTEXT_GROUP) {
// if quantities are not shared between shops of the group, it's not possible to manage them at group level
if (!$shop_group->share_stock) {
$show_quantities = false;
}
}
// if we are in shop context
elseif (Shop::isFeatureActive()) {
// if quantities are shared between shops of the group, it's not possible to manage them for a given shop
if ($shop_group->share_stock) {
$show_quantities = false;
}
}
$data->assign('ps_stock_management', Configuration::get('PS_STOCK_MANAGEMENT'));
$data->assign('has_attribute', $obj->hasAttributes());
// Check if product has combination, to display the available date only for the product or for each combination
if (Combination::isFeatureActive()) {
$data->assign('countAttributes', (int)Db::getInstance()->getValue('SELECT COUNT(id_product) FROM '._DB_PREFIX_.'product_attribute WHERE id_product = '.(int)$obj->id));
} else {
$data->assign('countAttributes', false);
}
// if advanced stock management is active, checks associations
$advanced_stock_management_warning = false;
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $obj->advanced_stock_management) {
$p_attributes = Product::getProductAttributesIds($obj->id);
$warehouses = array();
if (!$p_attributes) {
$warehouses[] = Warehouse::getProductWarehouseList($obj->id, 0);
}
foreach ($p_attributes as $p_attribute) {
$ws = Warehouse::getProductWarehouseList($obj->id, $p_attribute['id_product_attribute']);
if ($ws) {
$warehouses[] = $ws;
}
}
$warehouses = Tools::arrayUnique($warehouses);
if (empty($warehouses)) {
$advanced_stock_management_warning = true;
}
}
if ($advanced_stock_management_warning) {
$this->displayWarning($this->l('If you wish to use the advanced stock management, you must:'));
$this->displayWarning('- '.$this->l('associate your room types with warehouses.'));
$this->displayWarning('- '.$this->l('associate your warehouses with carriers.'));
$this->displayWarning('- '.$this->l('associate your warehouses with the appropriate shops.'));
}
$pack_quantity = null;
// if product is a pack
if (Pack::isPack($obj->id)) {
$items = Pack::getItems((int)$obj->id, Configuration::get('PS_LANG_DEFAULT'));
// gets an array of quantities (quantity for the product / quantity in pack)
$pack_quantities = array();
foreach ($items as $item) {
/** @var Product $item */
if (!$item->isAvailableWhenOutOfStock((int)$item->out_of_stock)) {
$pack_id_product_attribute = Product::getDefaultAttribute($item->id, 1);
$pack_quantities[] = Product::getQuantity($item->id, $pack_id_product_attribute) / ($item->pack_quantity !== 0 ? $item->pack_quantity : 1);
}
}
// gets the minimum
if (count($pack_quantities)) {
$pack_quantity = $pack_quantities[0];
foreach ($pack_quantities as $value) {
if ($pack_quantity > $value) {
$pack_quantity = $value;
}
}
}
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && !Warehouse::getPackWarehouses((int)$obj->id)) {
$this->displayWarning($this->l('You must have a common warehouse between this pack and its room type.'));
}
}
$data->assign(array(
'attributes' => $attributes,
'available_quantity' => $available_quantity,
'pack_quantity' => $pack_quantity,
'stock_management_active' => Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'),
'product_designation' => $product_designation,
'product' => $obj,
'show_quantities' => $show_quantities,
'order_out_of_stock' => Configuration::get('PS_ORDER_OUT_OF_STOCK'),
'pack_stock_type' => Configuration::get('PS_PACK_STOCK_TYPE'),
'token_preferences' => Tools::getAdminTokenLite('AdminPPreferences'),
'token' => $this->token,
'languages' => $this->_languages,
'id_lang' => $this->context->language->id
));
} else {
$this->displayWarning($this->l('You must save the room type in this shop before managing quantities.'));
}
} else {
$this->displayWarning($this->l('You must save this room type before managing quantities.'));
}
$this->tpl_form_vars['custom_form'] = $data->fetch();
}
protected function _getFinalPrice($specific_price, $product_price, $tax_rate)
{
return $this->object->getPrice(false, $specific_price['id_product_attribute'], 2);
@@ -3503,7 +3702,7 @@ class AdminNormalProductsControllerCore extends AdminController
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
$selectedElements = $objRoomTypeServiceProduct->getAssociatedHotelsAndRoomType($product->id);
$tree = new HelperTree('hotels-tree');
$tree = new HelperTree('hotels-room-tree');
$tree->setData(HotelHelper::generateTreeData([
'rootNode' => HotelHelper::NODE_HOTEL,
'leafNode' => HotelHelper::NODE_ROOM_TYPE,
@@ -3513,6 +3712,18 @@ class AdminNormalProductsControllerCore extends AdminController
->setAutoSelectChildren(true)
->setUseBulkActions(true)
->setUseSearch(true);
$data->assign('hotel_room_tree', $tree->render());
$tree = new HelperTree('hotels-tree');
$tree->setData(HotelHelper::generateTreeData([
'rootNode' => HotelHelper::NODE_HOTEL,
'leafNode' => HotelHelper::NODE_HOTEL,
'selectedElements' => $selectedElements
]))
->setUseCheckBox(true)
->setAutoSelectChildren(true)
->setUseBulkActions(true)
->setUseSearch(true);
$data->assign('hotel_tree', $tree->render());
// TinyMCE

File diff suppressed because it is too large Load Diff

View File

@@ -340,80 +340,80 @@ class AdminPPreferencesControllerCore extends AdminController
),
'submit' => array('title' => $this->l('Save'))
),
// 'stock' => array(
// 'title' => $this->l('Products stock'),
// 'fields' => array(
// 'PS_ORDER_OUT_OF_STOCK' => array(
// 'title' => $this->l('Allow ordering of out-of-stock products'),
// 'hint' => $this->l('By default, the Add to Cart button is hidden when a product is unavailable. You can choose to have it displayed in all cases.'),
// 'validation' => 'isBool',
// 'cast' => 'intval',
// 'required' => false,
// 'type' => 'bool'
// ),
// 'PS_STOCK_MANAGEMENT' => array(
// 'title' => $this->l('Enable stock management'),
// 'validation' => 'isBool',
// 'cast' => 'intval',
// 'required' => false,
// 'type' => 'bool',
// 'js' => array(
// 'on' => 'onchange="stockManagementActivationAuthorization()"',
// 'off' => 'onchange="stockManagementActivationAuthorization()"'
// )
// ),
// 'PS_ADVANCED_STOCK_MANAGEMENT' => array(
// 'title' => $this->l('Enable advanced stock management'),
// 'hint' => $this->l('Allows you to manage physical stock, warehouses and supply orders in a new Stock menu.'),
// 'validation' => 'isBool',
// 'cast' => 'intval',
// 'required' => false,
// 'type' => 'bool',
// 'visibility' => Shop::CONTEXT_ALL,
// 'js' => array(
// 'on' => 'onchange="advancedStockManagementActivationAuthorization()"',
// 'off' => 'onchange="advancedStockManagementActivationAuthorization()"'
// )
// ),
// 'PS_FORCE_ASM_NEW_PRODUCT' => array(
// 'title' => $this->l('New products use advanced stock management'),
// 'hint' => $this->l('New products will automatically use advanced stock management and depends on stock, but no warehouse will be selected'),
// 'validation' => 'isBool',
// 'cast' => 'intval',
// 'required' => false,
// 'type' => 'bool',
// 'visibility' => Shop::CONTEXT_ALL,
// ),
// 'PS_DEFAULT_WAREHOUSE_NEW_PRODUCT' => array(
// 'title' => $this->l('Default warehouse on new products'),
// 'hint' => $this->l('Automatically set a default warehouse when new product is created'),
// 'type' => 'select',
// 'list' => $warehouse_list,
// 'identifier' => 'id_warehouse'
// ),
// 'PS_PACK_STOCK_TYPE' => array(
// 'title' => $this->l('Default pack stock management'),
// 'type' => 'select',
// 'list' =>array(
// array(
// 'pack_stock' => 0,
// 'name' => $this->l('Decrement pack only.')
// ),
// array(
// 'pack_stock' => 1,
// 'name' => $this->l('Decrement products in pack only.')
// ),
// array(
// 'pack_stock' => 2,
// 'name' => $this->l('Decrement both.')
// ),
// ),
// 'identifier' => 'pack_stock',
// ),
// ),
// 'bottom' => '<script type="text/javascript">stockManagementActivationAuthorization();advancedStockManagementActivationAuthorization();</script>',
// 'submit' => array('title' => $this->l('Save'))
// ),
'stock' => array(
'title' => $this->l('Products stock'),
'fields' => array(
'PS_ORDER_OUT_OF_STOCK' => array(
'title' => $this->l('Allow ordering of out-of-stock products'),
'hint' => $this->l('By default, the Add to Cart button is hidden when a product is unavailable. You can choose to have it displayed in all cases.'),
'validation' => 'isBool',
'cast' => 'intval',
'required' => false,
'type' => 'bool'
),
'PS_STOCK_MANAGEMENT' => array(
'title' => $this->l('Enable stock management'),
'validation' => 'isBool',
'cast' => 'intval',
'required' => false,
'type' => 'bool',
'js' => array(
'on' => 'onchange="stockManagementActivationAuthorization()"',
'off' => 'onchange="stockManagementActivationAuthorization()"'
)
),
// 'PS_ADVANCED_STOCK_MANAGEMENT' => array(
// 'title' => $this->l('Enable advanced stock management'),
// 'hint' => $this->l('Allows you to manage physical stock, warehouses and supply orders in a new Stock menu.'),
// 'validation' => 'isBool',
// 'cast' => 'intval',
// 'required' => false,
// 'type' => 'bool',
// 'visibility' => Shop::CONTEXT_ALL,
// 'js' => array(
// 'on' => 'onchange="advancedStockManagementActivationAuthorization()"',
// 'off' => 'onchange="advancedStockManagementActivationAuthorization()"'
// )
// ),
// 'PS_FORCE_ASM_NEW_PRODUCT' => array(
// 'title' => $this->l('New products use advanced stock management'),
// 'hint' => $this->l('New products will automatically use advanced stock management and depends on stock, but no warehouse will be selected'),
// 'validation' => 'isBool',
// 'cast' => 'intval',
// 'required' => false,
// 'type' => 'bool',
// 'visibility' => Shop::CONTEXT_ALL,
// ),
// 'PS_DEFAULT_WAREHOUSE_NEW_PRODUCT' => array(
// 'title' => $this->l('Default warehouse on new products'),
// 'hint' => $this->l('Automatically set a default warehouse when new product is created'),
// 'type' => 'select',
// 'list' => $warehouse_list,
// 'identifier' => 'id_warehouse'
// ),
// 'PS_PACK_STOCK_TYPE' => array(
// 'title' => $this->l('Default pack stock management'),
// 'type' => 'select',
// 'list' =>array(
// array(
// 'pack_stock' => 0,
// 'name' => $this->l('Decrement pack only.')
// ),
// array(
// 'pack_stock' => 1,
// 'name' => $this->l('Decrement products in pack only.')
// ),
// array(
// 'pack_stock' => 2,
// 'name' => $this->l('Decrement both.')
// ),
// ),
// 'identifier' => 'pack_stock',
// ),
),
// 'bottom' => '<script type="text/javascript">stockManagementActivationAuthorization();advancedStockManagementActivationAuthorization();</script>',
'submit' => array('title' => $this->l('Save'))
),
);
}

View File

@@ -62,6 +62,7 @@ class CartControllerCore extends FrontController
$this->id_product_attribute = (int)Tools::getValue('id_product_attribute', Tools::getValue('ipa'));
$this->customization_id = (int)Tools::getValue('id_customization');
$this->qty = abs(Tools::getValue('qty', 1));
$this->id_hotel = abs(Tools::getValue('id_hotel', null));
$this->id_address_delivery = (int)Tools::getValue('id_address_delivery');
}
@@ -178,7 +179,29 @@ class CartControllerCore extends FrontController
$this->context->cookie->avail_rooms = $total_available_rooms;
}
} else {
$result = $this->context->cart->deleteProduct($this->id_product, $this->id_product_attribute, $this->customization_id, $this->id_address_delivery);
$idServiceProductOption = Tools::getValue('id_service_product_option', null);
if ($product->service_product_type == Product::SERVICE_PRODUCT_STANDALONE) {
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
$result = $objRoomTypeServiceProductCartDetail->removeCartServiceProduct(
$this->context->cart->id,
$this->id_product,
false,
false,
false,
$idServiceProductOption
);
} elseif ($product->service_product_type == Product::SERVICE_PRODUCT_lINKED_WITH_HOTEL) {
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
$result = $objRoomTypeServiceProductCartDetail->removeCartServiceProduct(
$this->context->cart->id,
$this->id_product,
false,
$this->id_hotel,
false,
$idServiceProductOption
);
}
}
if ($result) {
@@ -432,19 +455,82 @@ class CartControllerCore extends FrontController
}
}
} else {
$obj_htl_cart_booking_data = new HotelCartBookingData();
if ($product->service_product_type == Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE) {
$objHotelCartBookingData = new HotelCartBookingData();
if ($product->service_product_type == Product::SERVICE_PRODUCT_STANDALONE) {
// if can be added without room type then we can directly add product in cart.
if (!$product->allow_multiple_quantity) {
// check if product already exists in cart.
if ($id_cart) {
if (cart::getProductQtyInCart($id_cart, $product->id)) {
$this->errors[] = Tools::displayError('You can only order one quantity for this product.');
if ($operator == 'up') {
if ($product->allow_multiple_quantity) {
if ($id_cart) {
$quantityInCart = Cart::getProductQtyInCart(
$id_cart,
$this->id_product
);
}
$finalQuantity = $this->qty;
if (isset($quantityInCart)) {
$finalQuantity += $quantityInCart;
}
if ($product->max_quantity && $finalQuantity > $product->max_quantity) {
$this->errors[] = Tools::displayError(sprintf('cannot add more than %d quantity.', $product->max_quantity));
}
} else {
if ($id_cart) {
if (cart::getProductQtyInCart($id_cart, $product->id)) {
$this->errors[] = Tools::displayError('You can only order one quantity for this product.');
}
}
}
if (ServiceProductOption::productHasOptions($this->id_product)) {
if (!$idServiceProductOption = Tools::getValue('id_service_product_option')) {
$this->errors[] = Tools::displayError('Cannot add service without a option.');
} else {
if (!ServiceProductOption::productHasOptions($this->id_product, $idServiceProductOption)) {
$this->errors[] = Tools::displayError('The selected option is not available.');
}
}
}
}
} elseif ($product->service_product_type == Product::SERVICE_PRODUCT_lINKED_WITH_HOTEL) {
$id_hotel = Tools::getValue('id_hotel');
if ($operator == 'up') {
if ($id_hotel) {
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
if ($cartDetail = $objRoomTypeServiceProductCartDetail->getProducts(
$id_cart,
$this->id_product,
ProductCore::SERVICE_PRODUCT_lINKED_WITH_HOTEL,
$id_hotel
)) {
$productCartDetail = array_shift($cartDetail);
}
if ($product->allow_multiple_quantity) {
$finalQuantity = $this->qty;
if (isset($productCartDetail)) {
$finalQuantity += $productCartDetail['quantity'];
}
if ($product->max_quantity && $finalQuantity > $product->max_quantity) {
$this->errors[] = Tools::displayError(sprintf('cannot add more than %d quantity.', $product->max_quantity));
}
} else {
if ($productCartDetail) {
$this->errors[] = Tools::displayError('You can only order one quantity for this product.');
}
}
if (ServiceProductOption::productHasOptions($this->id_product)) {
if (!$idServiceProductOption = Tools::getValue('id_service_product_option')) {
$this->errors[] = Tools::displayError('Cannot add service without a option.');
} else {
if (!ServiceProductOption::productHasOptions($this->id_product, $idServiceProductOption)) {
$this->errors[] = Tools::displayError('The selected option is not available.');
}
}
}
} else {
$this->errors[] = Tools::displayError('Cannot add service without a hotel.');
}
}
} else {
$this->errors[] = Tools::displayError('cannot add product without room in cart');
$this->errors[] = Tools::displayError('cannot add service without room in cart');
}
}
@@ -511,7 +597,6 @@ class CartControllerCore extends FrontController
/*
* To add Rooms in hotel cart
*/
if ($product->booking_product) {
$objHotelCartBookingData = new HotelCartBookingData();
$roomDemand = json_decode(Tools::getValue('roomDemands'), true);
@@ -544,19 +629,41 @@ class CartControllerCore extends FrontController
$this->availQty = $total_available_rooms + $req_rm;
}
$this->context->cookie->avail_rooms = $this->availQty;
} else {
$update_quantity = $this->context->cart->updateQty(
$this->qty,
} elseif ($product->service_product_type == Product::SERVICE_PRODUCT_lINKED_WITH_HOTEL) {
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
$update_quantity = $objRoomTypeServiceProductCartDetail->updateCartServiceProduct(
$this->context->cart->id,
$this->id_product,
$this->id_product_attribute,
$this->customization_id,
$operator,
$this->id_address_delivery
$this->qty,
$id_hotel,
false,
isset($idServiceProductOption) ? $idServiceProductOption : null
);
if ($operator == 'up') {
$this->context->cookie->currentAddedProduct = json_encode(array(
'id_product' => $this->id_product,
'qty' => $this->qty
'id_hotel' => $id_hotel,
'qty' => $this->qty,
'id_service_product_option' => isset($idServiceProductOption) ? $idServiceProductOption : null
));
}
} elseif ($product->service_product_type == Product::SERVICE_PRODUCT_STANDALONE) {
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
$update_quantity = $objRoomTypeServiceProductCartDetail->updateCartServiceProduct(
$this->context->cart->id,
$this->id_product,
$operator,
$this->qty,
false,
false,
isset($idServiceProductOption) ? $idServiceProductOption : null
);
if ($operator == 'up') {
$this->context->cookie->currentAddedProduct = json_encode(array(
'id_product' => $this->id_product,
'qty' => $this->qty,
'id_service_product_option' => isset($idServiceProductOption) ? $idServiceProductOption : null
));
}
}
@@ -651,11 +758,12 @@ class CartControllerCore extends FrontController
if (empty($this->errors)) {
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
if ($objRoomTypeServiceProductCartDetail->updateCartServiceProduct(
$idCartBooking,
$idServiceProduct,
$qty,
$this->context->cart->id,
$operator
$idServiceProduct,
$operator,
$qty,
false,
$idCartBooking
)) {
$this->ajaxDie(json_encode(array(
'hasError' => false

View File

@@ -516,7 +516,7 @@ class GuestTrackingControllerCore extends FrontController
}
} else {
// get all products that are independent.
if ($type_value['product_service_type'] == Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE) {
if ($type_value['product_service_type'] == Product::SERVICE_PRODUCT_STANDALONE) {
$product = new Product($type_value['product_id'], false, $this->context->language->id);
$cover_image_arr = $product->getCover($type_value['product_id']);

View File

@@ -146,7 +146,8 @@ class OrderConfirmationControllerCore extends FrontController
$hotelCartBookingData = new HotelCartBookingData();
$objBookingDemand = new HotelBookingDemands();
$objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail();
$cart_service_products = array();
$cart_standalone_service_products = array();
$cart_hotel_service_products = array();
$cart_htl_data = array();
foreach ($cartOrders as $cartOrder) {
$idOrder = $cartOrder['id_order'];
@@ -155,10 +156,7 @@ class OrderConfirmationControllerCore extends FrontController
if (!empty($orderProducts)) {
foreach ($orderProducts as $type_key => $type_value) {
if (in_array($type_value['product_id'], $processed_product)) {
continue;
}
$processed_product[] = $type_value['product_id'];
$product = new Product($type_value['product_id'], false, $this->context->language->id);
@@ -176,6 +174,11 @@ class OrderConfirmationControllerCore extends FrontController
$order_bk_data = $obj_htl_bk_dtl->getOnlyOrderBookingData($idOrder, $customer->id_guest, $type_value['product_id']);
}
if ($rm_dtl = $obj_rm_type->getRoomTypeInfoByIdProduct($type_value['product_id'])) {
if (in_array($type_value['product_id'], $processed_product)) {
continue;
}
$processed_product[] = $type_value['product_id'];
$cart_htl_data[$type_key]['id_order'] = $idOrder;
$cart_htl_data[$type_key]['id_product'] = $type_value['product_id'];
$cart_htl_data[$type_key]['cover_img'] = $cover_img;
@@ -355,7 +358,7 @@ class OrderConfirmationControllerCore extends FrontController
$totalRoomsBooked += 1;
}
} else if ($product->service_product_type == Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE) {
} else if ($product->service_product_type == ProductCore::SERVICE_PRODUCT_lINKED_WITH_HOTEL) {
$cover_image_arr = $product->getCover($type_value['product_id']);
if (!empty($cover_image_arr)) {
@@ -363,15 +366,41 @@ class OrderConfirmationControllerCore extends FrontController
} else {
$type_value['cover_img'] = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code.'-default', 'small_default');
}
// $orderTotalInfo['total_service_products_te'] += $type_value['total_price_tax_excl'];
// $orderTotalInfo['total_service_products_ti'] += $type_value['total_price_tax_incl'];
$cart_service_products[] = $type_value;
$serviceProducts = $objRoomTypeServiceProductOrderDetail->getProducts($idOrder, $type_value['id_order_detail'], $type_value['product_id']);
foreach ($serviceProducts as $serviceProduct) {
$type_value['total_price_tax_excl'] = $serviceProduct['total_price_tax_excl'];
$type_value['total_price_tax_incl'] = $serviceProduct['total_price_tax_incl'];
$type_value['product_quantity'] = $serviceProduct['quantity'];
$type_value['option_name'] = $serviceProduct['option_name'];
$orderTotalInfo['total_service_products_te'] += $type_value['total_price_tax_excl'];
$orderTotalInfo['total_service_products_ti'] += $type_value['total_price_tax_incl'];
$cart_hotel_service_products[] = $type_value;
}
} else if ($product->service_product_type == Product::SERVICE_PRODUCT_STANDALONE) {
$cover_image_arr = $product->getCover($type_value['product_id']);
if (!empty($cover_image_arr)) {
$type_value['cover_img'] = $this->context->link->getImageLink($product->link_rewrite, $product->id.'-'.$cover_image_arr['id_image'], 'small_default');
} else {
$type_value['cover_img'] = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code.'-default', 'small_default');
}
$serviceProducts = $objRoomTypeServiceProductOrderDetail->getProducts($idOrder, $type_value['id_order_detail'], $type_value['product_id']);
foreach ($serviceProducts as $serviceProduct) {
$type_value['total_price_tax_excl'] = $serviceProduct['total_price_tax_excl'];
$type_value['total_price_tax_incl'] = $serviceProduct['total_price_tax_incl'];
$type_value['product_quantity'] = $serviceProduct['quantity'];
$type_value['option_name'] = $serviceProduct['option_name'];
$orderTotalInfo['total_service_products_te'] += $type_value['total_price_tax_excl'];
$orderTotalInfo['total_service_products_ti'] += $type_value['total_price_tax_incl'];
$cart_standalone_service_products[] = $type_value;
}
}
}
if (!empty($cart_service_products)) {
$this->context->smarty->assign('cart_service_products', $cart_service_products);
if (!empty($cart_hotel_service_products)) {
$this->context->smarty->assign('cart_hotel_service_products', $cart_hotel_service_products);
}
if (!empty($cart_standalone_service_products)) {
$this->context->smarty->assign('cart_standalone_service_products', $cart_standalone_service_products);
}
}
if (!$objCartOrder->hasInvoice()) {
@@ -386,8 +415,8 @@ class OrderConfirmationControllerCore extends FrontController
$orderTotalInfo['total_services_ti'] += $objCartOrder->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 0);
$orderTotalInfo['total_convenience_fee_te'] += $objCartOrder->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT);
$orderTotalInfo['total_convenience_fee_ti'] += $objCartOrder->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT);
// $orderTotalInfo['total_service_products_te'] += $objCartOrder->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE);
// $orderTotalInfo['total_service_products_ti'] += $objCartOrder->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE);
// $orderTotalInfo['total_service_products_te'] += $objCartOrder->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_STANDALONE);
// $orderTotalInfo['total_service_products_ti'] += $objCartOrder->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_STANDALONE);
$orderTotalInfo['total_discounts'] += $objCartOrder->total_discounts;
$orderTotalInfo['total_discounts_te'] += $objCartOrder->total_discounts_tax_excl;
$orderTotalInfo['total_tax'] += $objCartOrder->total_paid_tax_incl - $objCartOrder->total_paid_tax_excl;
@@ -403,7 +432,6 @@ class OrderConfirmationControllerCore extends FrontController
$this->context->smarty->assign('orderTotalInfo', $orderTotalInfo);
$this->context->smarty->assign('orders_has_invoice', $orders_has_invoice);
}
if (!empty($cart_htl_data)) {
$this->context->smarty->assign('cart_htl_data', $cart_htl_data);
}
@@ -423,6 +451,8 @@ class OrderConfirmationControllerCore extends FrontController
'objOrderCurrency' => (new Currency($order->id_currency)),
'use_tax' => Configuration::get('PS_TAX'),
'group_use_tax' => (Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC),
'order_history' => $order->getHistory((int)$this->context->language->id, false, true),
'overbooking_order_states' => OrderState::getOverBookingStates()
)
);

View File

@@ -61,6 +61,7 @@ class OrderDetailControllerCore extends FrontController
$carrier = new Carrier((int)$order->id_carrier, (int)$order->id_lang);
$addressInvoice = new Address((int)$order->id_address_invoice);
$addressDelivery = new Address((int)$order->id_address_delivery);
$addressTax = new Address((int)$order->id_address_tax);
$inv_adr_fields = AddressFormat::getOrderedAddressFields($addressInvoice->id_country);
$dlv_adr_fields = AddressFormat::getOrderedAddressFields($addressDelivery->id_country);
@@ -92,6 +93,9 @@ class OrderDetailControllerCore extends FrontController
$processedProducts = array();
$cartHotelData = array();
$cartServiceProducts = array();
$hotelServiceProducts = array();
$standaloneServiceProducts = array();
$serviceProductsFormatted = array();
$total_demands_price_te = 0;
$total_demands_price_ti = 0;
$total_convenience_fee_te = 0;
@@ -99,27 +103,26 @@ class OrderDetailControllerCore extends FrontController
$roomTypes = array();
$objOrderReturn = new OrderReturn();
$refundedAmount = 0;
if ($refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($order->id, 0, 1)) {
$refundedAmount = $objOrderReturn->getRefundedAmount($order->id);
}
$refundedAmount = $objOrderReturn->getRefundedAmount($order->id);
$refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($order->id, 0, 1);
$refundReqProducts = $objOrderReturn->getOrderRefundRequestedProducts($order->id, 0, 1);
if (!empty($products)) {
foreach ($products as $type_key => $type_value) {
if (in_array($type_value['product_id'], $processedProducts)) {
continue;
}
$product = new Product($type_value['product_id'], false, $this->context->language->id);
$cover_image_arr = $product->getCover($type_value['product_id']);
if (!empty($cover_image_arr)) {
$type_value['cover_img'] = $this->context->link->getImageLink($product->link_rewrite, $product->id.'-'.$cover_image_arr['id_image'], 'home_default');
} else {
$type_value['cover_img'] = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code.'-default', 'home_default');
}
if ($type_value['is_booking_product']) {
$processedProducts[] = $type_value['product_id'];
$product = new Product($type_value['product_id'], false, $this->context->language->id);
$cover_image_arr = $product->getCover($type_value['product_id']);
if (!empty($cover_image_arr)) {
$cover_img = $this->context->link->getImageLink($product->link_rewrite, $product->id.'-'.$cover_image_arr['id_image'], 'home_default');
} else {
$cover_img = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code.'-default', 'home_default');
}
if (isset($customer->id)) {
$obj_cart = new Cart($order->id_cart);
$order_bk_data = $objBookingDetail->getOnlyOrderBookingData($order->id, $obj_cart->id_guest, $type_value['product_id'], $customer->id);
@@ -127,7 +130,7 @@ class OrderDetailControllerCore extends FrontController
$order_bk_data = $objBookingDetail->getOnlyOrderBookingData($order->id, $customer->id_guest, $type_value['product_id']);
}
$cartHotelData[$type_key]['id_product'] = $type_value['product_id'];
$cartHotelData[$type_key]['cover_img'] = $cover_img;
$cartHotelData[$type_key]['cover_img'] = $type_value['cover_img'];
$objBookingDemand = new HotelBookingDemands();
@@ -359,7 +362,7 @@ class OrderDetailControllerCore extends FrontController
0,
0,
0,
1,
1,
1,
1
);
@@ -376,18 +379,31 @@ class OrderDetailControllerCore extends FrontController
1
);
}
} else {
// get all products that are independent.
if ($type_value['product_service_type'] == Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE) {
$product = new Product($type_value['product_id'], false, $this->context->language->id);
$cover_image_arr = $product->getCover($type_value['product_id']);
if (!empty($cover_image_arr)) {
$type_value['cover_img'] = $this->context->link->getImageLink($product->link_rewrite, $product->id.'-'.$cover_image_arr['id_image'], 'small_default');
} else {
$type_value['cover_img'] = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code.'-default', 'small_default');
} else if ($type_value['product_service_type'] == Product::SERVICE_PRODUCT_lINKED_WITH_HOTEL) {
$hotelProducts = $objRoomTypeServiceProductOrderDetail->getProducts($id_order, $type_value['id_order_detail'], $type_value['product_id']);
foreach ($hotelProducts as $hotelProduct) {
$hotelServiceProducts[] = array_merge($type_value, $hotelProduct);
if (!isset($serviceProductsFormatted[$hotelProduct['id_product']])) {
$serviceProductsFormatted[$hotelProduct['id_product']] = array(
'id_product' => $hotelProduct['id_product'],
'name' => $hotelProduct['name'],
'options' => array()
);
}
$cartServiceProducts[] = $type_value;
$serviceProductsFormatted[$hotelProduct['id_product']]['options'][] = $hotelProduct;
}
} else if ($type_value['product_service_type'] == Product::SERVICE_PRODUCT_STANDALONE) {
$standaloneProducts = $objRoomTypeServiceProductOrderDetail->getProducts($id_order, $type_value['id_order_detail'], $type_value['product_id']);
foreach ($standaloneProducts as $standaloneProduct) {
$standaloneServiceProducts[] = array_merge($type_value, $standaloneProduct);
if (!isset($serviceProductsFormatted[$standaloneProduct['id_product']])) {
$serviceProductsFormatted[$standaloneProduct['id_product']] = array(
'id_product' => $standaloneProduct['id_product'],
'name' => $standaloneProduct['name'],
'options' => array()
);
}
$serviceProductsFormatted[$standaloneProduct['id_product']]['options'][] = $standaloneProduct;
}
}
@@ -399,13 +415,7 @@ class OrderDetailControllerCore extends FrontController
$objHotelBookingDetail = new HotelBookingDetail();
$htlBookingDetail = $objHotelBookingDetail->getOrderCurrentDataByOrderId($order->id);
$idHotel = HotelBookingDetail::getIdHotelByIdOrder($order->id);
$objHotelBranchInformation = new HotelBranchInformation($idHotel, $this->context->language->id);
$hotelAddressInfo = HotelBranchInformation::getAddress($idHotel);
$objHotelBranchRefundRules = new HotelBranchRefundRules();
$hotelRefundRules = $objHotelBranchRefundRules->getHotelRefundRules($idHotel, 0, 1);
// ddd($serviceProductsFormatted);
$this->context->smarty->assign(
array(
'id_cms_refund_policy' => Configuration::get('WK_GLOBAL_REFUND_POLICY_CMS'),
@@ -420,13 +430,26 @@ class OrderDetailControllerCore extends FrontController
'order_has_invoice' => $order->hasInvoice(),
'cart_htl_data' => $cartHotelData,
'cart_service_products' => $cartServiceProducts,
'obj_hotel_branch_information' => $objHotelBranchInformation,
'hotel_address_info' => $hotelAddressInfo,
'hotel_refund_rules' => $hotelRefundRules,
'hotel_service_products' => $hotelServiceProducts,
'standalone_service_products' => $standaloneServiceProducts,
'service_products_formatted' => $serviceProductsFormatted,
'view_on_map' => Configuration::get('WK_GOOGLE_ACTIVE_MAP'),
)
);
if ($idHotel = $addressTax->id_hotel) {
$objHotelBranchInformation = new HotelBranchInformation($idHotel, $this->context->language->id);
$hotelAddressInfo = HotelBranchInformation::getAddress($idHotel);
$objHotelBranchRefundRules = new HotelBranchRefundRules();
$hotelRefundRules = $objHotelBranchRefundRules->getHotelRefundRules($idHotel, 0, 1);
$this->context->smarty->assign(array(
'obj_hotel_branch_information' => $objHotelBranchInformation,
'hotel_address_info' => $hotelAddressInfo,
'hotel_refund_rules' => $hotelRefundRules,
));
}
$this->context->smarty->assign(
array(
'hasOrderPaid' => $order->hasBeenPaid(),
@@ -434,6 +457,7 @@ class OrderDetailControllerCore extends FrontController
'refund_allowed' => (int) $order->isReturnable(),
'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id),
'refundReqBookings' => $refundReqBookings,
'refundReqProducts' => $refundReqProducts,
'completeRefundRequestOrCancel' => $order->hasCompletelyRefunded(0, 1),
'refundedAmount' => $refundedAmount,
'shop_name' => strval(Configuration::get('PS_SHOP_NAME')),
@@ -552,10 +576,11 @@ class OrderDetailControllerCore extends FrontController
$idOrder = Tools::getValue('id_order');
$idsHtlBooking = Tools::getValue('bookings_to_refund');
$idServiceProductOrderDetails = Tools::getValue('id_room_type_service_product_order_detail');
$cancellationReason = trim(Tools::getValue('cancellation_reason'));
if (!$idsHtlBooking) {
$this->errors[] = Tools::displayError('Please select at least on room for cancellation.');
if (!$idsHtlBooking && !$idServiceProductOrderDetails) {
$this->errors[] = Tools::displayError('Please select at least on room/product for cancellation.');
}
if (!$cancellationReason) {
@@ -568,23 +593,33 @@ class OrderDetailControllerCore extends FrontController
$objOrder = new Order($idOrder);
if (!(Validate::isLoadedObject($objOrder) && $objOrder->id_customer == $this->context->customer->id)) {
$this->errors[] = Tools::displayError('Something went wrong. Please try later.');
} elseif ($idsHtlBooking) {
foreach ($idsHtlBooking as $idHtlBooking) {
$objHotelBookingDetail = new HotelBookingDetail($idHtlBooking);
if ($objHotelBookingDetail->id_customer != $objOrder->id_customer) {
$this->errors[] = Tools::displayError('Something went wrong. Please try later.');
break;
}
} else {
if ($idsHtlBooking) {
foreach ($idsHtlBooking as $idHtlBooking) {
$objHotelBookingDetail = new HotelBookingDetail($idHtlBooking);
if ($objHotelBookingDetail->id_customer != $objOrder->id_customer) {
$this->errors[] = Tools::displayError('Something went wrong. Please try later.');
break;
}
// the room has already been checked in/checked out, room will not be able to be cancelled by the customer
if ($objHotelBookingDetail->id_status != HotelBookingDetail::STATUS_ALLOTED) {
$this->errors[] = Tools::displayError('Some selected rooms have already been checked-in/checked-out.');
break;
}
// the room has already been checked in/checked out, room will not be able to be cancelled by the customer
if ($objHotelBookingDetail->id_status != HotelBookingDetail::STATUS_ALLOTED) {
$this->errors[] = Tools::displayError('Some selected rooms have already been checked-in/checked-out.');
break;
}
if (OrderReturn::getOrdersReturnDetail($objOrder->id, 0, $idHtlBooking)) {
$this->errors[] = Tools::displayError('Some selected rooms have already been requested for cancellation.');
break;
if (OrderReturn::getOrdersReturnDetail($objOrder->id, 0, $idHtlBooking)) {
$this->errors[] = Tools::displayError('Some selected rooms have already been requested for cancellation.');
break;
}
}
}
if ($idServiceProductOrderDetails) {
foreach ($idServiceProductOrderDetails as $idServiceProductOrderDetail) {
if (OrderReturn::getOrdersReturnDetail($objOrder->id, 0, 0, $idServiceProductOrderDetail)) {
$this->errors[] = Tools::displayError('Some selected rooms have already been requested for cancellation.');
break;
}
}
}
}
@@ -600,22 +635,39 @@ class OrderDetailControllerCore extends FrontController
$objOrderReturn->refunded_amount = 0;
$objOrderReturn->save();
if ($objOrderReturn->id) {
foreach ($idsHtlBooking as $idHtlBooking) {
$objHtlBooking = new HotelBookingDetail($idHtlBooking);
$numDays = $objHtlBooking->getNumberOfDays(
$objHtlBooking->date_from,
$objHtlBooking->date_to
);
$objOrderReturnDetail = new OrderReturnDetail();
$objOrderReturnDetail->id_order_return = $objOrderReturn->id;
$objOrderReturnDetail->id_order_detail = $objHtlBooking->id_order_detail;
$objOrderReturnDetail->product_quantity = $numDays;
$objOrderReturnDetail->id_htl_booking = $idHtlBooking;
$objOrderReturnDetail->refunded_amount = 0;
if (!$objOrder->getCartRules() && $objOrder->getTotalPaid() <= 0) {
$objOrderReturnDetail->id_customization = 1;
if ($idsHtlBooking) {
foreach ($idsHtlBooking as $idHtlBooking) {
$objHtlBooking = new HotelBookingDetail($idHtlBooking);
$numDays = $objHtlBooking->getNumberOfDays(
$objHtlBooking->date_from,
$objHtlBooking->date_to
);
$objOrderReturnDetail = new OrderReturnDetail();
$objOrderReturnDetail->id_order_return = $objOrderReturn->id;
$objOrderReturnDetail->id_order_detail = $objHtlBooking->id_order_detail;
$objOrderReturnDetail->product_quantity = $numDays;
$objOrderReturnDetail->id_htl_booking = $idHtlBooking;
$objOrderReturnDetail->refunded_amount = 0;
if (!$objOrder->getCartRules() && $objOrder->getTotalPaid() <= 0) {
$objOrderReturnDetail->id_customization = 1;
}
$objOrderReturnDetail->save();
}
}
if ($idServiceProductOrderDetails) {
foreach ($idServiceProductOrderDetails as $idServiceProductOrderDetail) {
$objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail($idServiceProductOrderDetail);
$objOrderReturnDetail = new OrderReturnDetail();
$objOrderReturnDetail->id_order_return = $objOrderReturn->id;
$objOrderReturnDetail->id_order_detail = $objRoomTypeServiceProductOrderDetail->id_order_detail;
$objOrderReturnDetail->product_quantity = $objRoomTypeServiceProductOrderDetail->quantity;
$objOrderReturnDetail->id_room_type_service_product_order_detail = $idServiceProductOrderDetail;
$objOrderReturnDetail->refunded_amount = 0;
if (!$objOrder->getCartRules() && $objOrder->getTotalPaid() <= 0) {
$objOrderReturnDetail->id_customization = 1;
}
$objOrderReturnDetail->save();
}
$objOrderReturnDetail->save();
}
}

View File

@@ -391,6 +391,8 @@ class OrderOpcControllerCore extends ParentOrderController
$this->ajaxDie($this->submitCustomerGuestDetail());
exit;
break;
case 'getOpcData':
$this->ajaxDie($this->getOpcData());
default:
throw new PrestaShopException('Unknown method "'.Tools::getValue('method').'"');
}
@@ -431,11 +433,6 @@ class OrderOpcControllerCore extends ParentOrderController
*/
public function initContent()
{
// validate room types before payment by customer
if ($orderRestrictErr = HotelCartBookingData::validateCartBookings()) {
$this->errors = array_merge($this->errors, $orderRestrictErr);
}
parent::initContent();
/* id_carrier is not defined in database before choosing a carrier, set it to a default one to match a potential cart _rule */
@@ -500,14 +497,12 @@ class OrderOpcControllerCore extends ParentOrderController
// $objGlobalDemand = new HotelRoomTypeGlobalDemand();
// $allDemands = $objGlobalDemand->getAllDemands();
// $objCurrency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
$this->_assignCheckoutVars();
$this->context->smarty->assign(
array(
'orderRestrictErr' => count($orderRestrictErr) ? 1 : 0,
// 'allDemands' => $allDemands,
// 'defaultcurrencySign' => $objCurrency->sign,
'THEME_DIR' => _THEME_DIR_,
'PS_REGISTRATION_PROCESS_TYPE' => Configuration::get('PS_REGISTRATION_PROCESS_TYPE'),
'PS_ROOM_PRICE_AUTO_ADD_BREAKDOWN' => Configuration::get('PS_ROOM_PRICE_AUTO_ADD_BREAKDOWN'),
'free_shipping' => $free_shipping,
'isGuest' => isset($this->context->cookie->is_guest) ? $this->context->cookie->is_guest : 0,
'countries' => $countries,
@@ -590,51 +585,7 @@ class OrderOpcControllerCore extends ParentOrderController
$this->addJS(_THEME_JS_DIR_ . 'advanced-payment-api.js');
$this->setTemplate(_PS_THEME_DIR_ . 'order-opc-advanced.tpl');
} else {
// set used objects in the below code
// $objBookingDetail = new HotelBookingDetail();
// $objHtlRoomType = new HotelRoomType();
$cartProducts = $this->context->cart->getProducts();
if (!empty($cartProducts)) {
if ($cartBookingInfo = HotelCartBookingData::getHotelCartBookingData()) {
$this->context->smarty->assign('cart_htl_data', $cartBookingInfo);
}
$objHotelServiceProductCartDetail = new HotelServiceProductCartDetail();
if ($normalCartProduct = $objHotelServiceProductCartDetail->getHotelProducts($this->context->cart->id, 0, 0, 0, null, null, true)) {
$this->context->smarty->assign('cart_normal_data', $normalCartProduct);
}
// For Advanced Payment work
$objAdvPayment = new HotelAdvancedPayment();
if ($objAdvPayment->isAdvancePaymentAvailableForCurrentCart()) {
if (Tools::isSubmit('submitAdvPayment')) {
if (Tools::getValue('payment_type') == Order::ORDER_PAYMENT_TYPE_ADVANCE) {
$this->context->cart->is_advance_payment = 1;
} else {
$this->context->cart->is_advance_payment = 0;
}
$this->context->cart->save();
Tools::redirect($this->context->link->getPageLink('order-opc'));
}
// set if advance payment is selected by the customer
if ($this->context->cart->is_advance_payment) {
$this->context->smarty->assign('is_advance_payment', 1);
}
// get advance payment amount and send data to the template
$advPaymentAmount = $this->context->cart->getOrderTotal(true, Cart::ADVANCE_PAYMENT);
$this->context->smarty->assign(array(
'advance_payment_active'=> 1,
'advPaymentAmount'=> $advPaymentAmount,
'dueAmount'=> ($this->context->cart->getOrderTotal() - $advPaymentAmount),
));
}
}
$this->_assignShoppingCart();
$this->setTemplate(_PS_THEME_DIR_.'order-opc.tpl');
}
}
@@ -1144,4 +1095,20 @@ class OrderOpcControllerCore extends ParentOrderController
$this->context->cart->save();
}
}
public function getOpcData()
{
$response = array('success' => false);
if ($this->context->cart->getProducts()) {
$this->_assignCheckoutVars();
$this->_assignShoppingCart();
$response['success'] = true;
$response['shopping_cart'] = $this->context->smarty->fetch(_PS_THEME_DIR_.'shopping-cart.tpl');
$response['cart_total_block'] = $this->context->smarty->fetch(_PS_THEME_DIR_.'cart-total-block.tpl');
} else {
$response['reload'] = 1;
}
return json_encode($response);
}
}

View File

@@ -57,6 +57,8 @@ class OrderReturnControllerCore extends FrontController
) {
$isCanceledBookings = true;
}
$refundReqProducts = $objOrderReturn->getOrderRefundRequestedProducts($objOrderReturn->id_order, $objOrderReturn->id);
$voucher = '';
if (Validate::isLoadedObject($objCartRule = new CartRule($objOrderReturn->id_return_type))) {
$voucher = $objCartRule->name[$this->context->language->id];
@@ -66,6 +68,7 @@ class OrderReturnControllerCore extends FrontController
array (
'orderReturnInfo' => (array)$objOrderReturn,
'refundReqBookings' => $refundReqBookings,
'refundReqProducts' => $refundReqProducts,
'isCanceledBookings' => $isCanceledBookings,
'orderInfo' => (array) $objOrder,
'orderCurrency' => (array) $orderCurrency,

View File

@@ -299,6 +299,95 @@ class ParentOrderControllerCore extends FrontController
return true;
}
protected function _assignCheckoutVars()
{
if ($orderRestrictErr = HotelCartBookingData::validateCartBookings()) {
$this->errors = array_merge($this->errors, $orderRestrictErr);
}
$show_option_allow_separate_package = (!$this->context->cart->isAllProductsInStock(true) && Configuration::get('PS_SHIP_WHEN_AVAILABLE'));
$advanced_payment_api = (bool)Configuration::get('PS_ADVANCED_PAYMENT_API');
$this->context->smarty->assign(array(
'THEME_DIR' => _THEME_DIR_,
'PS_ROOM_PRICE_AUTO_ADD_BREAKDOWN' => Configuration::get('PS_ROOM_PRICE_AUTO_ADD_BREAKDOWN'),
'orderRestrictErr' => count($orderRestrictErr) ? 1 : 0,
'show_option_allow_separate_package' => $show_option_allow_separate_package,
'advanced_payment_api' => $advanced_payment_api
));
}
protected function _assignShoppingCart()
{
$summary = $this->context->cart->getSummaryDetails();
$cartProducts = $this->context->cart->getProducts();
if (!empty($cartProducts)) {
if ($cartBookingInfo = HotelCartBookingData::getHotelCartBookingData()) {
$this->context->smarty->assign('cart_htl_data', $cartBookingInfo);
}
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
if ($hotelProducts = $objRoomTypeServiceProductCartDetail->getProducts(
$this->context->cart->id,
0,
Product::SERVICE_PRODUCT_lINKED_WITH_HOTEL,
0,
0,
null,
0,
0,
null,
null,
true
)) {
$this->context->smarty->assign('hotel_products', $hotelProducts);
}
$standaloneProducts = $objRoomTypeServiceProductCartDetail->getProducts(
$this->context->cart->id,
0,
ProductCore::SERVICE_PRODUCT_STANDALONE
);
if (count($standaloneProducts)) {
$this->context->smarty->assign('standalone_products', $standaloneProducts);
}
// For Advanced Payment work
$objAdvPayment = new HotelAdvancedPayment();
if ($objAdvPayment->isAdvancePaymentAvailableForCurrentCart()) {
if (Tools::isSubmit('submitAdvPayment')) {
if (Tools::getValue('payment_type') == Order::ORDER_PAYMENT_TYPE_ADVANCE) {
$this->context->cart->is_advance_payment = 1;
} else {
$this->context->cart->is_advance_payment = 0;
}
$this->context->cart->save();
Tools::redirect($this->context->link->getPageLink('order-opc'));
}
// set if advance payment is selected by the customer
if ($this->context->cart->is_advance_payment) {
$this->context->smarty->assign('is_advance_payment', 1);
}
// get advance payment amount and send data to the template
$advPaymentAmount = $this->context->cart->getOrderTotal(true, Cart::ADVANCE_PAYMENT);
$this->context->smarty->assign(array(
'advance_payment_active'=> 1,
'advPaymentAmount'=> $advPaymentAmount,
'dueAmount'=> ($this->context->cart->getOrderTotal() - $advPaymentAmount),
));
}
}
$this->context->smarty->assign($summary);
$this->context->smarty->assign(array(
'HOOK_SHOPPING_CART' => Hook::exec('displayShoppingCartFooter', $summary),
'HOOK_SHOPPING_CART_EXTRA' => Hook::exec('displayShoppingCart', $summary)
));
}
protected function _assignSummaryInformations()
{
$summary = $this->context->cart->getSummaryDetails();
@@ -362,9 +451,6 @@ class ParentOrderControllerCore extends FrontController
}
}
$show_option_allow_separate_package = (!$this->context->cart->isAllProductsInStock(true) && Configuration::get('PS_SHIP_WHEN_AVAILABLE'));
$advanced_payment_api = (bool)Configuration::get('PS_ADVANCED_PAYMENT_API');
$this->context->smarty->assign($summary);
$this->context->smarty->assign(array(
'token_cart' => Tools::getToken(false),
@@ -379,9 +465,7 @@ class ParentOrderControllerCore extends FrontController
'CUSTOMIZE_TEXTFIELD' => Product::CUSTOMIZE_TEXTFIELD,
'lastProductAdded' => $this->context->cart->getLastProduct(),
'displayVouchers' => $available_cart_rules,
'show_option_allow_separate_package' => $show_option_allow_separate_package,
'smallSize' => Image::getSize(ImageType::getFormatedName('small')),
'advanced_payment_api' => $advanced_payment_api
));
@@ -398,7 +482,15 @@ class ParentOrderControllerCore extends FrontController
$this->context->customer->logout();
Tools::redirect('');
} elseif (!Customer::getAddressesTotalById($this->context->customer->id)) {
$multi = (int)Tools::getValue('multi-shipping');
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail();
if (count($objRoomTypeServiceProductCartDetail->getProducts(
$this->context->cart->id,
0,
Product::SERVICE_PRODUCT_STANDALONE
))) {
$multi = (int)Tools::getValue('multi-shipping');
Tools::redirect('index.php?controller=address&back='.urlencode('order.php?step=1'.($multi ? '&multi-shipping='.$multi : '')));
}
}
$customer = $this->context->customer;

View File

@@ -117,12 +117,13 @@ class ProductControllerCore extends FrontController
}
$objHotelRoomType = new HotelRoomType();
$hotelRoomInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($this->product->id);
$idHotel = (int) $hotelRoomInfo['id_hotel'];
if (!HotelHelper::validateDateRangeForHotel($dateFrom, $dateTo, $idHotel)) {
Tools::redirect($this->context->link->getPageLink('pagenotfound'));
} else if (!$this->product->booking_product || ($this->product->booking_product && !$this->product->show_at_front)) {
Tools::redirect($this->context->link->getPageLink('pagenotfound'));
if ($hotelRoomInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($this->product->id)) {
$idHotel = (int) $hotelRoomInfo['id_hotel'];
if (!HotelHelper::validateDateRangeForHotel($dateFrom, $dateTo, $idHotel)) {
Tools::redirect($this->context->link->getPageLink('pagenotfound'));
} else if (!$this->product->booking_product || ($this->product->booking_product && !$this->product->show_at_front)) {
Tools::redirect($this->context->link->getPageLink('pagenotfound'));
}
}
if (!Validate::isLoadedObject($this->product)) {
@@ -445,7 +446,7 @@ class ProductControllerCore extends FrontController
}
$this->assignBookingFormVars($this->product->id, $date_from, $date_to, $occupancy_value);
$this->assignServiceProductVars();
$this->assignRoomServiceProductVars();
// product price after imposing feature prices...
if ($useTax) {
@@ -474,6 +475,8 @@ class ProductControllerCore extends FrontController
if (Tools::getValue('error')) {
$this->context->smarty->assign('error', Tools::getValue('error'));
}
} else {
$this->assignServiceProductVars();
}
// send all the common variables for all type of products
@@ -524,7 +527,7 @@ class ProductControllerCore extends FrontController
$this->setTemplate(_PS_THEME_DIR_.'product.tpl');
}
public function assignServiceProductVars()
public function assignRoomServiceProductVars()
{
// get service products for room type
$p = 1;
@@ -801,6 +804,66 @@ class ProductControllerCore extends FrontController
return true;
}
public function assignServiceProductVars(
$idServiceProductOption = false,
$quantity = false,
$idHotel = false
) {
$smartyVars = array();
if (Product::SERVICE_PRODUCT_lINKED_WITH_HOTEL == $this->product->service_product_type) {
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
if ($associatedHotels = $objRoomTypeServiceProduct->getAssociatedHotelsAndRoomType($this->product->id)['hotel']) {
foreach ($associatedHotels as $key => $hotel) {
if (Validate::isLoadedObject($objHotel = new HotelBranchInformation($hotel, $this->context->language->id))) {
$associatedHotels[$key] = array('id_hotel' => $hotel, 'name' => $objHotel->hotel_name);
} else {
unset($associatedHotels[$key]);
}
}
$smartyVars['associated_hotels'] = $associatedHotels;
}
}
if ($idHotel) {
$smartyVars['service_id_hotel'] = $idHotel;
}
$useTax = HotelBookingDetail::useTax();
$objServiceProductOption = new ServiceProductOption();
if ($serviceProductOptions = $objServiceProductOption->getProductOptions($this->product->id)) {
foreach ($serviceProductOptions as &$serviceProductOption) {
if ($idServiceProductOption == null) {
$idServiceProductOption = $serviceProductOption['id_service_product_option'];
}
$serviceProductOption['price'] = RoomTypeServiceProductPrice::getPrice(
$this->product->id,
$idHotel,
$serviceProductOption['id_service_product_option'],
$useTax,
$quantity
);
}
}
$smartyVars['service_product_option'] = $serviceProductOptions;
$smartyVars['service_price'] = RoomTypeServiceProductPrice::getPrice(
$this->product->id,
$idHotel,
$idServiceProductOption,
$useTax,
$quantity
);
if ($quantity) {
$smartyVars['quantity'] = $quantity;
}
if ($idServiceProductOption) {
$smartyVars['id_service_product_option'] = $idServiceProductOption;
}
$this->context->smarty->assign($smartyVars);
return true;
}
/**
* Assign price and tax to the template
*/
@@ -1270,35 +1333,45 @@ class ProductControllerCore extends FrontController
{
$response = array('status' => false);
$idProduct = (int) Tools::getValue('id_product');
$dateFrom = Tools::getValue('room_check_in');
$dateTo = Tools::getValue('room_check_out');
$occupancy = Tools::getValue('occupancy');
if (Configuration::get('PS_FRONT_ROOM_UNIT_SELECTION_TYPE') == HotelBookingDetail::PS_ROOM_UNIT_SELECTION_TYPE_OCCUPANCY) {
if (!Validate::isOccupancy($occupancy)) {
$occupancy = array();
if ($this->product->booking_product) {
$dateFrom = Tools::getValue('room_check_in');
$dateTo = Tools::getValue('room_check_out');
$occupancy = Tools::getValue('occupancy');
if (Configuration::get('PS_FRONT_ROOM_UNIT_SELECTION_TYPE') == HotelBookingDetail::PS_ROOM_UNIT_SELECTION_TYPE_OCCUPANCY) {
if (!Validate::isOccupancy($occupancy)) {
$occupancy = array();
}
} else {
$occupancy = Tools::getValue('qty', 1);
}
$roomTypeDemands = Tools::getValue('room_type_demands');
$roomServiceProducts = Tools::getValue('room_service_products');
$dateFrom = date('Y-m-d H:i:s', strtotime($dateFrom));
$dateTo = date('Y-m-d H:i:s', strtotime($dateTo));
$this->assignRoomServiceProductVars();
if ($this->assignBookingFormVars(
$idProduct,
$dateFrom,
$dateTo,
$occupancy,
$roomTypeDemands,
$roomServiceProducts
)) {
}
} else {
$occupancy = Tools::getValue('qty', 1);
$idHotel = Tools::getValue('service_id_hotel');
$id_service_product_option = Tools::getValue('id_service_product_option');
$quantity = Tools::getValue('service_product_qty');
$this->assignServiceProductVars(
$id_service_product_option,
$quantity,
$idHotel
);
}
$roomTypeDemands = Tools::getValue('room_type_demands');
$roomServiceProducts = Tools::getValue('room_service_products');
$dateFrom = date('Y-m-d H:i:s', strtotime($dateFrom));
$dateTo = date('Y-m-d H:i:s', strtotime($dateTo));
$this->assignServiceProductVars();
if ($this->assignBookingFormVars(
$idProduct,
$dateFrom,
$dateTo,
$occupancy,
$roomTypeDemands,
$roomServiceProducts
)) {
$html = $this->context->smarty->fetch('_partials/booking-form.tpl');
$response['status'] = true;
$response['html_booking_form'] = $html;
}
$html = $this->context->smarty->fetch('_partials/booking-form.tpl');
$response['status'] = true;
$response['html_booking_form'] = $html;
$this->ajaxDie(json_encode($response));
}