Added feature for adding standard product in cart
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user