public function hookActionValidateOrder($data)
 {
     $cart = $data['cart'];
     $order = $data['order'];
     $customer = $data['customer'];
     $cart_products = $cart->getProducts();
     foreach ($cart_products as $k => $v) {
         $obj_cart_bk_data = new HotelCartBookingData();
         $cart_bk_data = $obj_cart_bk_data->getOnlyCartBookingData($cart->id, $cart->id_guest, $v['id_product']);
         if ($cart_bk_data) {
             foreach ($cart_bk_data as $cb_k => $cb_v) {
                 $obj_cart_bk_data = new HotelCartBookingData($cb_v['id']);
                 $obj_cart_bk_data->id_order = $order->id;
                 $obj_cart_bk_data->id_customer = $customer->id;
                 $obj_cart_bk_data->save();
                 $obj_htl_bk_dtl = new HotelBookingDetail();
                 $obj_htl_bk_dtl->id_product = $v['id_product'];
                 $obj_htl_bk_dtl->id_order = $order->id;
                 $obj_htl_bk_dtl->id_cart = $cart->id;
                 $obj_htl_bk_dtl->id_room = $obj_cart_bk_data->id_room;
                 $obj_htl_bk_dtl->id_hotel = $obj_cart_bk_data->id_hotel;
                 $obj_htl_bk_dtl->id_customer = $customer->id;
                 $obj_htl_bk_dtl->booking_type = $obj_cart_bk_data->booking_type;
                 $obj_htl_bk_dtl->id_status = 1;
                 $obj_htl_bk_dtl->comment = $obj_cart_bk_data->comment;
                 $obj_htl_bk_dtl->date_from = $obj_cart_bk_data->date_from;
                 $obj_htl_bk_dtl->date_to = $obj_cart_bk_data->date_to;
                 $obj_htl_bk_dtl->save();
             }
         }
     }
 }
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     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 */
     if (empty($this->context->cart->id_carrier)) {
         $checked = $this->context->cart->simulateCarrierSelectedOutput();
         $checked = (int) Cart::desintifier($checked);
         $this->context->cart->id_carrier = $checked;
         $this->context->cart->update();
         CartRule::autoRemoveFromCart($this->context);
         CartRule::autoAddToCart($this->context);
     }
     // SHOPPING CART
     $this->_assignSummaryInformations();
     // WRAPPING AND TOS
     $this->_assignWrappingAndTOS();
     if (Configuration::get('PS_RESTRICT_DELIVERED_COUNTRIES')) {
         $countries = Carrier::getDeliveredCountries($this->context->language->id, true, true);
     } else {
         $countries = Country::getCountries($this->context->language->id, true);
     }
     // If a rule offer free-shipping, force hidding shipping prices
     $free_shipping = false;
     foreach ($this->context->cart->getCartRules() as $rule) {
         if ($rule['free_shipping'] && !$rule['carrier_restriction']) {
             $free_shipping = true;
             break;
         }
     }
     $this->context->smarty->assign(array('free_shipping' => $free_shipping, 'isGuest' => isset($this->context->cookie->is_guest) ? $this->context->cookie->is_guest : 0, 'countries' => $countries, 'sl_country' => (int) Tools::getCountry(), 'PS_GUEST_CHECKOUT_ENABLED' => Configuration::get('PS_GUEST_CHECKOUT_ENABLED'), 'errorCarrier' => Tools::displayError('You must choose a carrier.', false), 'errorTOS' => Tools::displayError('You must accept the Terms of Service.', false), 'isPaymentStep' => isset($_GET['isPaymentStep']) && $_GET['isPaymentStep'], 'genders' => Gender::getGenders(), 'one_phone_at_least' => (int) Configuration::get('PS_ONE_PHONE_AT_LEAST'), 'HOOK_CREATE_ACCOUNT_FORM' => Hook::exec('displayCustomerAccountForm'), 'HOOK_CREATE_ACCOUNT_TOP' => Hook::exec('displayCustomerAccountFormTop')));
     $years = Tools::dateYears();
     $months = Tools::dateMonths();
     $days = Tools::dateDays();
     $this->context->smarty->assign(array('years' => $years, 'months' => $months, 'days' => $days));
     /* Load guest informations */
     if ($this->isLogged && $this->context->cookie->is_guest) {
         $this->context->smarty->assign('guestInformations', $this->_getGuestInformations());
     }
     // ADDRESS
     if ($this->isLogged) {
         $this->_assignAddress();
     }
     // CARRIER
     $this->_assignCarrier();
     // PAYMENT
     $this->_assignPayment();
     Tools::safePostVars();
     $newsletter = Configuration::get('PS_CUSTOMER_NWSL') || Module::isInstalled('blocknewsletter') && Module::getInstanceByName('blocknewsletter')->active;
     $this->context->smarty->assign('newsletter', $newsletter);
     $this->context->smarty->assign('optin', (bool) Configuration::get('PS_CUSTOMER_OPTIN'));
     $this->context->smarty->assign('field_required', $this->context->customer->validateFieldsRequiredDatabase());
     $this->_processAddressFormat();
     $link = new Link();
     if (Tools::getValue('deleteFromOrderLine')) {
         $id_product = Tools::getValue('id_product');
         $date_from = Tools::getValue('date_from');
         $date_to = Tools::getValue('date_to');
         $obj_cart_bk_data = new HotelCartBookingData();
         $cart_data_dlt = $obj_cart_bk_data->deleteRoomDataFromOrderLine($this->context->cart->id, $this->context->cart->id_guest, $id_product, $date_from, $date_to);
         if ($cart_data_dlt) {
             Tools::redirect($link->getPageLink('order', null, $this->context->language->id));
         }
     }
     if ((bool) Configuration::get('PS_ADVANCED_PAYMENT_API')) {
         $this->addJS(_THEME_JS_DIR_ . 'advanced-payment-api.js');
         $this->setTemplate(_PS_THEME_DIR_ . 'order-opc-advanced.tpl');
     } else {
         if (Module::isInstalled('hotelreservationsystem')) {
             require_once _PS_MODULE_DIR_ . 'hotelreservationsystem/define.php';
             $obj_cart_bk_data = new HotelCartBookingData();
             $obj_htl_bk_dtl = new HotelBookingDetail();
             $obj_rm_type = new HotelRoomType();
             $htl_rm_types = $this->context->cart->getProducts();
             if (!empty($htl_rm_types)) {
                 foreach ($htl_rm_types as $type_key => $type_value) {
                     $product = new Product($type_value['id_product'], false, $this->context->language->id);
                     $cover_image_arr = $product->getCover($type_value['id_product']);
                     if (!empty($cover_image_arr)) {
                         $cover_img = $this->context->link->getImageLink($product->link_rewrite, $product->id . '-' . $cover_image_arr['id_image'], 'small_default');
                     } else {
                         $cover_img = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code . "-default", 'small_default');
                     }
                     $unit_price = Product::getPriceStatic($type_value['id_product'], true, null, 6, null, false, true, 1);
                     if (isset($this->context->customer->id)) {
                         $cart_bk_data = $obj_cart_bk_data->getOnlyCartBookingData($this->context->cart->id, $this->context->cart->id_guest, $type_value['id_product']);
                     } else {
                         $cart_bk_data = $obj_cart_bk_data->getOnlyCartBookingData($this->context->cart->id, $this->context->cart->id_guest, $type_value['id_product']);
                     }
                     $rm_dtl = $obj_rm_type->getRoomTypeInfoByIdProduct($type_value['id_product']);
                     $cart_htl_data[$type_key]['id_product'] = $type_value['id_product'];
                     $cart_htl_data[$type_key]['cover_img'] = $cover_img;
                     $cart_htl_data[$type_key]['name'] = $product->name;
                     $cart_htl_data[$type_key]['unit_price'] = $unit_price;
                     $cart_htl_data[$type_key]['adult'] = $rm_dtl['adult'];
                     $cart_htl_data[$type_key]['children'] = $rm_dtl['children'];
                     foreach ($cart_bk_data as $data_k => $data_v) {
                         $date_join = strtotime($data_v['date_from']) . strtotime($data_v['date_to']);
                         if (isset($cart_htl_data[$type_key]['date_diff'][$date_join])) {
                             $cart_htl_data[$type_key]['date_diff'][$date_join]['num_rm'] += 1;
                             $num_days = $cart_htl_data[$type_key]['date_diff'][$date_join]['num_days'];
                             $vart_quant = (int) $cart_htl_data[$type_key]['date_diff'][$date_join]['num_rm'] * $num_days;
                             $amount = Product::getPriceStatic($type_value['id_product'], true, null, 6, null, false, true, 1);
                             $amount *= $vart_quant;
                             $cart_htl_data[$type_key]['date_diff'][$date_join]['amount'] = $amount;
                         } else {
                             $num_days = $obj_htl_bk_dtl->getNumberOfDays($data_v['date_from'], $data_v['date_to']);
                             $cart_htl_data[$type_key]['date_diff'][$date_join]['num_rm'] = 1;
                             $cart_htl_data[$type_key]['date_diff'][$date_join]['data_form'] = $data_v['date_from'];
                             $cart_htl_data[$type_key]['date_diff'][$date_join]['data_to'] = $data_v['date_to'];
                             $cart_htl_data[$type_key]['date_diff'][$date_join]['num_days'] = $num_days;
                             $amount = Product::getPriceStatic($type_value['id_product'], true, null, 6, null, false, true, 1);
                             $amount *= $num_days;
                             $cart_htl_data[$type_key]['date_diff'][$date_join]['amount'] = $amount;
                             $cart_htl_data[$type_key]['date_diff'][$date_join]['link'] = $link->getPageLink('order', null, $this->context->language->id, "id_product=" . $type_value['id_product'] . "&deleteFromOrderLine=1&date_from=" . $data_v['date_from'] . "&date_to=" . $data_v['date_to']);
                         }
                     }
                 }
                 $this->context->smarty->assign('cart_htl_data', $cart_htl_data);
             }
         }
         $this->setTemplate(_PS_THEME_DIR_ . 'order-opc.tpl');
     }
 }
        if ($id_hotel) {
            $obj_booking_dtl = new HotelBookingDetail();
            $hotel_room_data = $obj_booking_dtl->DataForFrontSearch($date_from, $date_to, $id_hotel, $id_product, 1);
            if ($hotel_room_data) {
                $total_available_rooms = $hotel_room_data['stats']['num_avail'];
            }
        }
    }
    $obj_htl_cart_booking_data = new HotelCartBookingData();
    $result = $obj_htl_cart_booking_data->deleteCartBookingDataOnRemoveFromBlockCart($id_cart, $id_product);
    if ($result) {
        die(Tools::jsonEncode(array('status' => 'success', 'avail_rooms' => $total_available_rooms)));
    } else {
        die(Tools::jsonEncode(array('status' => 'failed')));
    }
}
if (isset($delete_room_form_cart) && $delete_room_form_cart) {
    $num_rooms_to_decr_from_cart = Tools::getValue('num_rooms');
    $obj_htl_cart_booking_data = new HotelCartBookingData();
    $delete_room_from_cart_booking_data = $obj_htl_cart_booking_data->deleteCartDataByIdProductIdCart($id_cart, $id_product, $date_from, $date_to);
    if ($delete_room_from_cart_booking_data) {
        $cart_obj = new Cart($id_cart);
        $update_cart_product = $cart_obj->updateQty($num_rooms_to_decr_from_cart, $id_product, null, false, $operator = 'down', 0, null, true);
        if ($update_cart_product) {
            die(Tools::jsonEncode(array('status' => 'success', 'msg' => 'successfully cart product updated.')));
        } else {
            die(Tools::jsonEncode(array('status' => 'failed', 'msg' => 'error while updating cart product.')));
        }
    }
    die(Tools::jsonEncode(array('status' => 'failed', 'msg' => 'error while deleting room from cart booking table.')));
}
 public function ajaxProcessDeleteRoomProcess()
 {
     $dt_frm = Tools::getValue('date_from');
     $dt_to = Tools::getValue('date_to');
     $cart_id = Tools::getValue('id_cart');
     $id_product = Tools::getValue('id_product');
     $del_id = Tools::getValue('del_id');
     $room_id = Tools::getValue('id_room');
     $obj_hotel_cart_detail = new HotelCartBookingData();
     $deleted = $obj_hotel_cart_detail->deleteRowHotelCustomerCartDetail($del_id);
     if ($deleted) {
         $obj_product_process = new HotelCartBookingData();
         $date_from = date_create($dt_frm);
         $date_to = date_create($dt_to);
         $diff = date_diff($date_from, $date_to);
         $changed = $obj_product_process->changeProductDataByRoomId($room_id, $id_product, $diff->days, $cart_id);
         if ($changed) {
             die('deleted');
         } else {
             die(false);
         }
     } else {
         die(false);
     }
 }
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     if (!($id_order = (int) Tools::getValue('id_order')) || !Validate::isUnsignedId($id_order)) {
         $this->errors[] = Tools::displayError('Order ID required');
     } else {
         $order = new Order($id_order);
         if (Validate::isLoadedObject($order) && $order->id_customer == $this->context->customer->id) {
             $id_order_state = (int) $order->getCurrentState();
             $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);
             $inv_adr_fields = AddressFormat::getOrderedAddressFields($addressInvoice->id_country);
             $dlv_adr_fields = AddressFormat::getOrderedAddressFields($addressDelivery->id_country);
             $invoiceAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressInvoice, $inv_adr_fields);
             $deliveryAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressDelivery, $dlv_adr_fields);
             if ($order->total_discounts > 0) {
                 $this->context->smarty->assign('total_old', (double) $order->total_paid - $order->total_discounts);
             }
             $products = $order->getProducts();
             /* DEPRECATED: customizedDatas @since 1.5 */
             $customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart);
             Product::addCustomizationPrice($products, $customizedDatas);
             OrderReturn::addReturnedQuantity($products, $order->id);
             $order_status = new OrderState((int) $id_order_state, (int) $order->id_lang);
             $customer = new Customer($order->id_customer);
             //by webkul to show order details properly on order history page
             if (Module::isInstalled('hotelreservationsystem')) {
                 require_once _PS_MODULE_DIR_ . 'hotelreservationsystem/define.php';
                 $obj_cart_bk_data = new HotelCartBookingData();
                 $obj_htl_bk_dtl = new HotelBookingDetail();
                 $obj_rm_type = new HotelRoomType();
                 if (!empty($products)) {
                     foreach ($products as $type_key => $type_value) {
                         $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'], 'small_default');
                         } else {
                             $cover_img = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code . "-default", 'small_default');
                         }
                         $unit_price = Product::getPriceStatic($type_value['product_id'], true, null, 6, null, false, true, 1);
                         if (isset($customer->id)) {
                             $cart_bk_data = $obj_cart_bk_data->getOnlyCartBookingData($order->id_cart, (new Cart($order->id_cart))->id_guest, $type_value['product_id'], $customer->id);
                         } else {
                             $cart_bk_data = $obj_cart_bk_data->getOnlyCartBookingData($order->id_cart, $customer->id_guest, $type_value['product_id']);
                         }
                         $rm_dtl = $obj_rm_type->getRoomTypeInfoByIdProduct($type_value['product_id']);
                         $cart_htl_data[$type_key]['id_product'] = $type_value['product_id'];
                         $cart_htl_data[$type_key]['cover_img'] = $cover_img;
                         $cart_htl_data[$type_key]['name'] = $product->name;
                         $cart_htl_data[$type_key]['unit_price'] = $unit_price;
                         $cart_htl_data[$type_key]['adult'] = $rm_dtl['adult'];
                         $cart_htl_data[$type_key]['children'] = $rm_dtl['children'];
                         foreach ($cart_bk_data as $data_k => $data_v) {
                             $date_join = strtotime($data_v['date_from']) . strtotime($data_v['date_to']);
                             if (isset($cart_htl_data[$type_key]['date_diff'][$date_join])) {
                                 $cart_htl_data[$type_key]['date_diff'][$date_join]['num_rm'] += 1;
                                 $num_days = $cart_htl_data[$type_key]['date_diff'][$date_join]['num_days'];
                                 $vart_quant = (int) $cart_htl_data[$type_key]['date_diff'][$date_join]['num_rm'] * $num_days;
                                 $amount = Product::getPriceStatic($type_value['product_id'], true, null, 6, null, false, true, 1);
                                 $amount *= $vart_quant;
                                 $cart_htl_data[$type_key]['date_diff'][$date_join]['amount'] = $amount;
                             } else {
                                 $num_days = $obj_htl_bk_dtl->getNumberOfDays($data_v['date_from'], $data_v['date_to']);
                                 $cart_htl_data[$type_key]['date_diff'][$date_join]['num_rm'] = 1;
                                 $cart_htl_data[$type_key]['date_diff'][$date_join]['data_form'] = $data_v['date_from'];
                                 $cart_htl_data[$type_key]['date_diff'][$date_join]['data_to'] = $data_v['date_to'];
                                 $cart_htl_data[$type_key]['date_diff'][$date_join]['num_days'] = $num_days;
                                 $amount = Product::getPriceStatic($type_value['product_id'], true, null, 6, null, false, true, 1);
                                 $amount *= $num_days;
                                 $cart_htl_data[$type_key]['date_diff'][$date_join]['amount'] = $amount;
                             }
                         }
                     }
                     $this->context->smarty->assign('cart_htl_data', $cart_htl_data);
                 }
             }
             //end
             $this->context->smarty->assign(array('shop_name' => strval(Configuration::get('PS_SHOP_NAME')), 'order' => $order, 'return_allowed' => (int) $order->isReturnable(), 'currency' => new Currency($order->id_currency), 'order_state' => (int) $id_order_state, 'invoiceAllowed' => (int) Configuration::get('PS_INVOICE'), 'invoice' => OrderState::invoiceAvailable($id_order_state) && count($order->getInvoicesCollection()), 'logable' => (bool) $order_status->logable, 'order_history' => $order->getHistory($this->context->language->id, false, true), 'products' => $products, 'discounts' => $order->getCartRules(), 'carrier' => $carrier, 'address_invoice' => $addressInvoice, 'invoiceState' => Validate::isLoadedObject($addressInvoice) && $addressInvoice->id_state ? new State($addressInvoice->id_state) : false, 'address_delivery' => $addressDelivery, 'inv_adr_fields' => $inv_adr_fields, 'dlv_adr_fields' => $dlv_adr_fields, 'invoiceAddressFormatedValues' => $invoiceAddressFormatedValues, 'deliveryAddressFormatedValues' => $deliveryAddressFormatedValues, 'deliveryState' => Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state ? new State($addressDelivery->id_state) : false, 'is_guest' => false, 'messages' => CustomerMessage::getMessagesByOrderId((int) $order->id, false), 'CUSTOMIZE_FILE' => Product::CUSTOMIZE_FILE, 'CUSTOMIZE_TEXTFIELD' => Product::CUSTOMIZE_TEXTFIELD, 'isRecyclable' => Configuration::get('PS_RECYCLABLE_PACK'), 'use_tax' => Configuration::get('PS_TAX'), 'group_use_tax' => Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC, 'customizedDatas' => $customizedDatas, 'reorderingAllowed' => !(bool) Configuration::get('PS_DISALLOW_HISTORY_REORDERING')));
             if ($carrier->url && $order->shipping_number) {
                 $this->context->smarty->assign('followup', str_replace('@', $order->shipping_number, $carrier->url));
             }
             $this->context->smarty->assign('HOOK_ORDERDETAILDISPLAYED', Hook::exec('displayOrderDetail', array('order' => $order)));
             Hook::exec('actionOrderDetail', array('carrier' => $carrier, 'order' => $order));
             unset($carrier, $addressInvoice, $addressDelivery);
         } else {
             $this->errors[] = Tools::displayError('This order cannot be found.');
         }
         unset($order);
     }
     $this->setTemplate(_PS_THEME_DIR_ . 'order-detail.tpl');
 }
 public function cartBookingDataForMail($order)
 {
     $customer = new Customer($order->id_customer);
     //by webkul to show order details properly on order history page
     $products = $order->getProducts();
     if (Module::isInstalled('hotelreservationsystem')) {
         require_once _PS_MODULE_DIR_ . 'hotelreservationsystem/define.php';
         $obj_cart_bk_data = new HotelCartBookingData();
         $obj_htl_bk_dtl = new HotelBookingDetail();
         $obj_rm_type = new HotelRoomType();
         if (!empty($products)) {
             $cart_htl_data = array();
             foreach ($products as $type_key => $type_value) {
                 $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'], 'small_default');
                 } else {
                     $cover_img = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code . "-default", 'small_default');
                 }
                 $unit_price = Product::getPriceStatic($type_value['product_id'], true, null, 6, null, false, true, 1);
                 if (isset($customer->id)) {
                     $cart_bk_data = $obj_cart_bk_data->getOnlyCartBookingData($order->id_cart, (new Cart($order->id_cart))->id_guest, $type_value['product_id'], $customer->id);
                 } else {
                     $cart_bk_data = $obj_cart_bk_data->getOnlyCartBookingData($order->id_cart, $customer->id_guest, $type_value['product_id']);
                 }
                 $rm_dtl = $obj_rm_type->getRoomTypeInfoByIdProduct($type_value['product_id']);
                 $cart_htl_data[$type_key]['id_product'] = $type_value['product_id'];
                 $cart_htl_data[$type_key]['cover_img'] = $cover_img;
                 $cart_htl_data[$type_key]['name'] = $product->name;
                 $cart_htl_data[$type_key]['unit_price'] = $unit_price;
                 $cart_htl_data[$type_key]['adult'] = $rm_dtl['adult'];
                 $cart_htl_data[$type_key]['children'] = $rm_dtl['children'];
                 foreach ($cart_bk_data as $data_k => $data_v) {
                     $date_join = strtotime($data_v['date_from']) . strtotime($data_v['date_to']);
                     if (isset($cart_htl_data[$type_key]['date_diff'][$date_join])) {
                         $cart_htl_data[$type_key]['date_diff'][$date_join]['num_rm'] += 1;
                         $num_days = $cart_htl_data[$type_key]['date_diff'][$date_join]['num_days'];
                         $vart_quant = (int) $cart_htl_data[$type_key]['date_diff'][$date_join]['num_rm'] * $num_days;
                         $amount = Product::getPriceStatic($type_value['product_id'], true, null, 6, null, false, true, 1);
                         $amount *= $vart_quant;
                         $cart_htl_data[$type_key]['date_diff'][$date_join]['amount'] = $amount;
                     } else {
                         $num_days = $obj_htl_bk_dtl->getNumberOfDays($data_v['date_from'], $data_v['date_to']);
                         $cart_htl_data[$type_key]['date_diff'][$date_join]['num_rm'] = 1;
                         $cart_htl_data[$type_key]['date_diff'][$date_join]['data_form'] = $data_v['date_from'];
                         $cart_htl_data[$type_key]['date_diff'][$date_join]['data_to'] = $data_v['date_to'];
                         $cart_htl_data[$type_key]['date_diff'][$date_join]['num_days'] = $num_days;
                         $amount = Product::getPriceStatic($type_value['product_id'], true, null, 6, null, false, true, 1);
                         $amount *= $num_days;
                         $cart_htl_data[$type_key]['date_diff'][$date_join]['amount'] = $amount;
                     }
                 }
             }
         }
     }
     return $cart_htl_data;
 }
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     if (!$this->errors) {
         if (Pack::isPack((int) $this->product->id) && !Pack::isInStock((int) $this->product->id)) {
             $this->product->quantity = 0;
         }
         $this->product->description = $this->transformDescriptionWithImg($this->product->description);
         // Assign to the template the id of the virtual product. "0" if the product is not downloadable.
         $this->context->smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id));
         $this->context->smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
         if (Tools::isSubmit('submitCustomizedDatas')) {
             // If cart has not been saved, we need to do it so that customization fields can have an id_cart
             // We check that the cookie exists first to avoid ghost carts
             if (!$this->context->cart->id && isset($_COOKIE[$this->context->cookie->getName()])) {
                 $this->context->cart->add();
                 $this->context->cookie->id_cart = (int) $this->context->cart->id;
             }
             $this->pictureUpload();
             $this->textRecord();
             $this->formTargetFormat();
         } elseif (Tools::getIsset('deletePicture') && !$this->context->cart->deleteCustomizationToProduct($this->product->id, Tools::getValue('deletePicture'))) {
             $this->errors[] = Tools::displayError('An error occurred while deleting the selected picture.');
         }
         $pictures = array();
         $text_fields = array();
         if ($this->product->customizable) {
             $files = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_FILE, true);
             foreach ($files as $file) {
                 $pictures['pictures_' . $this->product->id . '_' . $file['index']] = $file['value'];
             }
             $texts = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_TEXTFIELD, true);
             foreach ($texts as $text_field) {
                 $text_fields['textFields_' . $this->product->id . '_' . $text_field['index']] = str_replace('<br />', "\n", $text_field['value']);
             }
         }
         $this->context->smarty->assign(array('pictures' => $pictures, 'textFields' => $text_fields));
         $this->product->customization_required = false;
         $customization_fields = $this->product->customizable ? $this->product->getCustomizationFields($this->context->language->id) : false;
         if (is_array($customization_fields)) {
             foreach ($customization_fields as $customization_field) {
                 if ($this->product->customization_required = $customization_field['required']) {
                     break;
                 }
             }
         }
         // Assign template vars related to the category + execute hooks related to the category
         $this->assignCategory();
         // Assign template vars related to the price and tax
         $this->assignPriceAndTax();
         // Assign template vars related to the images
         $this->assignImages();
         // Assign attribute groups to the template
         $this->assignAttributesGroups();
         // Assign attributes combinations to the template
         $this->assignAttributesCombinations();
         // Pack management
         $pack_items = Pack::isPack($this->product->id) ? Pack::getItemTable($this->product->id, $this->context->language->id, true) : array();
         $this->context->smarty->assign('packItems', $pack_items);
         $this->context->smarty->assign('packs', Pack::getPacksTable($this->product->id, $this->context->language->id, true, 1));
         if (isset($this->category->id) && $this->category->id) {
             $return_link = Tools::safeOutput($this->context->link->getCategoryLink($this->category));
         } else {
             $return_link = 'javascript: history.back();';
         }
         $accessories = $this->product->getAccessories($this->context->language->id);
         if ($this->product->cache_is_pack || count($accessories)) {
             $this->context->controller->addCSS(_THEME_CSS_DIR_ . 'product_list.css');
         }
         if ($this->product->customizable) {
             $customization_datas = $this->context->cart->getProductCustomization($this->product->id, null, true);
         }
         // by webkul
         $htl_features = array();
         $obj_hotel_room_type = new HotelRoomType();
         $room_info_by_product_id = $obj_hotel_room_type->getRoomTypeInfoByIdProduct($this->product->id);
         $hotel_id = $room_info_by_product_id['id_hotel'];
         if (isset($hotel_id) && $hotel_id) {
             $obj_hotel_branch = new HotelBranchInformation();
             $hotel_info_by_id = $obj_hotel_branch->hotelBranchInfoById($hotel_id);
             $hotel_policies = $hotel_info_by_id['policies'];
             $hotel_name = $hotel_info_by_id['hotel_name'];
             $country = Country::getNameById($this->context->language->id, $hotel_info_by_id['country_id']);
             $state = State::getNameById($hotel_info_by_id['state_id']);
             $hotel_location = $hotel_info_by_id['city'] . ', ' . $state . ', ' . $country;
             $obj_hotel_feaures_ids = $obj_hotel_branch->getFeaturesOfHotelByHotelId($hotel_id);
             if (isset($obj_hotel_feaures_ids) && $obj_hotel_feaures_ids) {
                 foreach ($obj_hotel_feaures_ids as $key => $value) {
                     $obj_htl_ftr = new HotelFeatures();
                     $htl_info = $obj_htl_ftr->getFeatureInfoById($value['feature_id']);
                     $htl_features[] = $htl_info['name'];
                 }
             }
         }
         $date_from = Tools::getValue('date_from');
         $date_to = Tools::getValue('date_to');
         if (!($date_from = Tools::getValue('date_from'))) {
             $date_from = date('Y-m-d');
             $date_to = date('Y-m-d', strtotime($date_from) + 86400);
         }
         if (!($date_to = Tools::getValue('date_to'))) {
             $date_to = date('Y-m-d', strtotime($date_from) + 86400);
         }
         $obj_booking_detail = new HotelBookingDetail();
         $num_days = $obj_booking_detail->getNumberOfDays($date_from, $date_to);
         $priceDisplay = Group::getPriceDisplayMethod(Group::getCurrent()->id);
         if (!$priceDisplay || $priceDisplay == 2) {
             $price_tax = true;
         } elseif ($priceDisplay == 1) {
             $price_tax = false;
         }
         $price_tax_incl = Product::getPriceStatic($this->product->id, $price_tax);
         $total_price = $price_tax_incl * $num_days;
         $obj_booking_dtl = new HotelBookingDetail();
         $hotel_room_data = $obj_booking_dtl->DataForFrontSearch($date_from, $date_to, $hotel_id, $this->product->id, 1);
         $obj_htl_cart_booking_data = new HotelCartBookingData();
         $num_cart_rooms = $obj_htl_cart_booking_data->getCountRoomsByIdCartIdProduct($this->context->cart->id, $this->product->id, $date_from, $date_to);
         if ($hotel_room_data) {
             $total_available_rooms = $hotel_room_data['stats']['num_avail'] - $num_cart_rooms;
         }
         //end
         $location_enable = Configuration::get('WK_HOTEL_LOCATION_ENABLE');
         $hotel_branch_obj = new HotelBranchInformation();
         $hotel_info = $hotel_branch_obj->getActiveHotelBranchesInfo();
         $search_data['date_from'] = $date_from;
         $search_data['date_to'] = $date_to;
         $search_data['htl_dtl'] = $hotel_branch_obj->hotelBranchInfoById($hotel_id);
         if (Tools::getValue('error')) {
             $this->context->smarty->assign('error', Tools::getValue('error'));
         }
         $this->context->smarty->assign(array('stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), 'customizationFields' => $customization_fields, 'id_customization' => empty($customization_datas) ? null : $customization_datas[0]['id_customization'], 'accessories' => $accessories, 'return_link' => $return_link, 'product' => $this->product, 'product_manufacturer' => new Manufacturer((int) $this->product->id_manufacturer, $this->context->language->id), 'token' => Tools::getToken(false), 'ratting_img_path' => _MODULE_DIR_ . 'hotelreservationsystem/views/img/Slices/icons-sprite.png', 'num_reviews' => ProductComment::getCommentNumber($this->product->id), 'ratting' => ProductComment::getAverageGrade($this->product->id)['grade'], 'total_available_rooms' => $total_available_rooms, 'all_hotels_info' => $hotel_info, 'location_enable' => $location_enable, 'total_price' => $total_price, 'product_controller_url' => $this->context->link->getPageLink('product'), 'num_days' => $num_days, 'date_from' => $date_from, 'date_to' => $date_to, 'hotel_location' => $hotel_location, 'hotel_name' => $hotel_name, 'hotel_policies' => $hotel_policies, 'hotel_features' => $htl_features, 'ftr_img_src' => _PS_IMG_ . 'rf/', 'features' => $this->product->getFrontFeatures($this->context->language->id), 'attachments' => $this->product->cache_has_attachments ? $this->product->getAttachments($this->context->language->id) : array(), 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock), 'last_qties' => (int) Configuration::get('PS_LAST_QTIES'), 'HOOK_EXTRA_LEFT' => Hook::exec('displayLeftColumnProduct'), 'HOOK_EXTRA_RIGHT' => Hook::exec('displayRightColumnProduct'), 'HOOK_PRODUCT_OOS' => Hook::exec('actionProductOutOfStock', array('product' => $this->product)), 'HOOK_PRODUCT_ACTIONS' => Hook::exec('displayProductButtons', array('product' => $this->product)), 'HOOK_PRODUCT_TAB' => Hook::exec('displayProductTab', array('product' => $this->product)), 'HOOK_PRODUCT_TAB_CONTENT' => Hook::exec('displayProductTabContent', array('product' => $this->product)), 'HOOK_PRODUCT_CONTENT' => Hook::exec('displayProductContent', array('product' => $this->product)), 'display_qties' => (int) Configuration::get('PS_DISPLAY_QTIES'), 'display_ht' => !Tax::excludeTaxeOption(), 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'), 'ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int) Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'errors' => $this->errors, 'body_classes' => array($this->php_self . '-' . $this->product->id, $this->php_self . '-' . $this->product->link_rewrite, 'category-' . (isset($this->category) ? $this->category->id : ''), 'category-' . (isset($this->category) ? $this->category->getFieldByLang('link_rewrite') : '')), 'display_discount_price' => Configuration::get('PS_DISPLAY_DISCOUNT_PRICE'), 'search_data' => $search_data));
     }
     $this->setTemplate(_PS_THEME_DIR_ . 'product.tpl');
 }
 /**
  * Returns the template's HTML content
  *
  * @return string HTML content
  */
 public function getContent()
 {
     $invoiceAddressPatternRules = Tools::jsonDecode(Configuration::get('PS_INVCE_INVOICE_ADDR_RULES'), true);
     $deliveryAddressPatternRules = Tools::jsonDecode(Configuration::get('PS_INVCE_DELIVERY_ADDR_RULES'), true);
     $invoice_address = new Address((int) $this->order->id_address_invoice);
     $country = new Country((int) $invoice_address->id_country);
     if ($this->order_invoice->invoice_address) {
         $formatted_invoice_address = $this->order_invoice->invoice_address;
     } else {
         $formatted_invoice_address = AddressFormat::generateAddress($invoice_address, $invoiceAddressPatternRules, '<br />', ' ');
     }
     $delivery_address = null;
     $formatted_delivery_address = '';
     if (isset($this->order->id_address_delivery) && $this->order->id_address_delivery) {
         if ($this->order_invoice->delivery_address) {
             $formatted_delivery_address = $this->order_invoice->delivery_address;
         } else {
             $delivery_address = new Address((int) $this->order->id_address_delivery);
             $formatted_delivery_address = AddressFormat::generateAddress($delivery_address, $deliveryAddressPatternRules, '<br />', ' ');
         }
     }
     $customer = new Customer((int) $this->order->id_customer);
     $order_details = $this->order_invoice->getProducts();
     $has_discount = false;
     foreach ($order_details as $id => &$order_detail) {
         // Find out if column 'price before discount' is required
         if ($order_detail['reduction_amount_tax_excl'] > 0) {
             $has_discount = true;
             $order_detail['unit_price_tax_excl_before_specific_price'] = $order_detail['unit_price_tax_excl_including_ecotax'] + $order_detail['reduction_amount_tax_excl'];
         } elseif ($order_detail['reduction_percent'] > 0) {
             $has_discount = true;
             $order_detail['unit_price_tax_excl_before_specific_price'] = 100 * $order_detail['unit_price_tax_excl_including_ecotax'] / (100 - 15);
         }
         // Set tax_code
         $taxes = OrderDetail::getTaxListStatic($id);
         $tax_temp = array();
         foreach ($taxes as $tax) {
             $obj = new Tax($tax['id_tax']);
             $tax_temp[] = sprintf($this->l('%1$s%2$s%%'), $obj->rate + 0, '&nbsp;');
         }
         $order_detail['order_detail_tax'] = $taxes;
         $order_detail['order_detail_tax_label'] = implode(', ', $tax_temp);
     }
     unset($tax_temp);
     unset($order_detail);
     if (Configuration::get('PS_PDF_IMG_INVOICE')) {
         foreach ($order_details as &$order_detail) {
             if ($order_detail['image'] != null) {
                 $name = 'product_mini_' . (int) $order_detail['product_id'] . (isset($order_detail['product_attribute_id']) ? '_' . (int) $order_detail['product_attribute_id'] : '') . '.jpg';
                 $path = _PS_PROD_IMG_DIR_ . $order_detail['image']->getExistingImgPath() . '.jpg';
                 $order_detail['image_tag'] = preg_replace('/\\.*' . preg_quote(__PS_BASE_URI__, '/') . '/', _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR, ImageManager::thumbnail($path, $name, 45, 'jpg', false), 1);
                 if (file_exists(_PS_TMP_IMG_DIR_ . $name)) {
                     $order_detail['image_size'] = getimagesize(_PS_TMP_IMG_DIR_ . $name);
                 } else {
                     $order_detail['image_size'] = false;
                 }
             }
         }
         unset($order_detail);
         // don't overwrite the last order_detail later
     }
     $cart_rules = $this->order->getCartRules($this->order_invoice->id);
     $free_shipping = false;
     foreach ($cart_rules as $key => $cart_rule) {
         if ($cart_rule['free_shipping']) {
             $free_shipping = true;
             /**
              * Adjust cart rule value to remove the amount of the shipping.
              * We're not interested in displaying the shipping discount as it is already shown as "Free Shipping".
              */
             $cart_rules[$key]['value_tax_excl'] -= $this->order_invoice->total_shipping_tax_excl;
             $cart_rules[$key]['value'] -= $this->order_invoice->total_shipping_tax_incl;
             /**
              * Don't display cart rules that are only about free shipping and don't create
              * a discount on products.
              */
             if ($cart_rules[$key]['value'] == 0) {
                 unset($cart_rules[$key]);
             }
         }
     }
     $product_taxes = 0;
     foreach ($this->order_invoice->getProductTaxesBreakdown($this->order) as $details) {
         $product_taxes += $details['total_amount'];
     }
     $product_discounts_tax_excl = $this->order_invoice->total_discount_tax_excl;
     $product_discounts_tax_incl = $this->order_invoice->total_discount_tax_incl;
     if ($free_shipping) {
         $product_discounts_tax_excl -= $this->order_invoice->total_shipping_tax_excl;
         $product_discounts_tax_incl -= $this->order_invoice->total_shipping_tax_incl;
     }
     $products_after_discounts_tax_excl = $this->order_invoice->total_products - $product_discounts_tax_excl;
     $products_after_discounts_tax_incl = $this->order_invoice->total_products_wt - $product_discounts_tax_incl;
     $shipping_tax_excl = $free_shipping ? 0 : $this->order_invoice->total_shipping_tax_excl;
     $shipping_tax_incl = $free_shipping ? 0 : $this->order_invoice->total_shipping_tax_incl;
     $shipping_taxes = $shipping_tax_incl - $shipping_tax_excl;
     $wrapping_taxes = $this->order_invoice->total_wrapping_tax_incl - $this->order_invoice->total_wrapping_tax_excl;
     $total_taxes = $this->order_invoice->total_paid_tax_incl - $this->order_invoice->total_paid_tax_excl;
     $footer = array('products_before_discounts_tax_excl' => $this->order_invoice->total_products, 'product_discounts_tax_excl' => $product_discounts_tax_excl, 'products_after_discounts_tax_excl' => $products_after_discounts_tax_excl, 'products_before_discounts_tax_incl' => $this->order_invoice->total_products_wt, 'product_discounts_tax_incl' => $product_discounts_tax_incl, 'products_after_discounts_tax_incl' => $products_after_discounts_tax_incl, 'product_taxes' => $product_taxes, 'shipping_tax_excl' => $shipping_tax_excl, 'shipping_taxes' => $shipping_taxes, 'shipping_tax_incl' => $shipping_tax_incl, 'wrapping_tax_excl' => $this->order_invoice->total_wrapping_tax_excl, 'wrapping_taxes' => $wrapping_taxes, 'wrapping_tax_incl' => $this->order_invoice->total_wrapping_tax_incl, 'ecotax_taxes' => $total_taxes - $product_taxes - $wrapping_taxes - $shipping_taxes, 'total_taxes' => $total_taxes, 'total_paid_tax_excl' => $this->order_invoice->total_paid_tax_excl, 'total_paid_tax_incl' => $this->order_invoice->total_paid_tax_incl);
     foreach ($footer as $key => $value) {
         $footer[$key] = Tools::ps_round($value, _PS_PRICE_COMPUTE_PRECISION_, $this->order->round_mode);
     }
     /**
      * Need the $round_mode for the tests.
      */
     $round_type = null;
     switch ($this->order->round_type) {
         case Order::ROUND_TOTAL:
             $round_type = 'total';
             break;
         case Order::ROUND_LINE:
             $round_type = 'line';
             break;
         case Order::ROUND_ITEM:
             $round_type = 'item';
             break;
         default:
             $round_type = 'line';
             break;
     }
     $display_product_images = Configuration::get('PS_PDF_IMG_INVOICE');
     $tax_excluded_display = Group::getPriceDisplayMethod($customer->id_default_group);
     $layout = $this->computeLayout(array('has_discount' => $has_discount));
     $legal_free_text = Hook::exec('displayInvoiceLegalFreeText', array('order' => $this->order));
     if (!$legal_free_text) {
         $legal_free_text = Configuration::get('PS_INVOICE_LEGAL_FREE_TEXT', (int) Context::getContext()->language->id, null, (int) $this->order->id_shop);
     }
     $order_obj = new Order($this->order->id);
     $this->context = Context::getContext();
     $products = $order_obj->getProducts();
     if (Module::isInstalled('hotelreservationsystem')) {
         require_once _PS_MODULE_DIR_ . 'hotelreservationsystem/define.php';
         $obj_cart_bk_data = new HotelCartBookingData();
         $obj_htl_bk_dtl = new HotelBookingDetail();
         $obj_rm_type = new HotelRoomType();
         $customer = new Customer($this->order->id_customer);
         if (!empty($products)) {
             $cart_bk_data = array();
             foreach ($products as $type_key => $type_value) {
                 $product = new Product($type_value['product_id'], false, $this->context->language->id);
                 $unit_price = Product::getPriceStatic($type_value['product_id'], true, null, 6, null, false, true, 1);
                 $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'], 'small_default');
                 } else {
                     $cover_img = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code . "-default", 'small_default');
                 }
                 if (isset($customer->id)) {
                     $cart_bk_data = $obj_cart_bk_data->getOnlyCartBookingData($this->order->id_cart, (new Cart($this->order->id_cart))->id_guest, $type_value['product_id'], $customer->id);
                 } else {
                     $cart_bk_data = $obj_cart_bk_data->getOnlyCartBookingData($this->order->id_cart, $customer->id_guest, $type_value['product_id']);
                 }
                 $rm_dtl = $obj_rm_type->getRoomTypeInfoByIdProduct($type_value['product_id']);
                 $cart_htl_data[$type_key]['id_product'] = $type_value['product_id'];
                 $cart_htl_data[$type_key]['cover_img'] = $cover_img;
                 $cart_htl_data[$type_key]['name'] = $product->name;
                 $cart_htl_data[$type_key]['unit_price'] = Tools::convertPrice($unit_price, $this->order->id_currency);
                 $cart_htl_data[$type_key]['adult'] = $rm_dtl['adult'];
                 $cart_htl_data[$type_key]['children'] = $rm_dtl['children'];
                 foreach ($cart_bk_data as $data_k => $data_v) {
                     $date_join = strtotime($data_v['date_from']) . strtotime($data_v['date_to']);
                     if (isset($cart_htl_data[$type_key]['date_diff'][$date_join])) {
                         $cart_htl_data[$type_key]['date_diff'][$date_join]['num_rm'] += 1;
                         $num_days = $cart_htl_data[$type_key]['date_diff'][$date_join]['num_days'];
                         $vart_quant = (int) $cart_htl_data[$type_key]['date_diff'][$date_join]['num_rm'] * $num_days;
                         $amount = Product::getPriceStatic($type_value['product_id'], true, null, 6, null, false, true, 1);
                         $amount *= $vart_quant;
                         $cart_htl_data[$type_key]['date_diff'][$date_join]['amount'] = Tools::convertPrice($amount, $this->order->id_currency);
                     } else {
                         $num_days = $obj_htl_bk_dtl->getNumberOfDays($data_v['date_from'], $data_v['date_to']);
                         $cart_htl_data[$type_key]['date_diff'][$date_join]['num_rm'] = 1;
                         $cart_htl_data[$type_key]['date_diff'][$date_join]['data_form'] = $data_v['date_from'];
                         $cart_htl_data[$type_key]['date_diff'][$date_join]['data_to'] = $data_v['date_to'];
                         $cart_htl_data[$type_key]['date_diff'][$date_join]['num_days'] = $num_days;
                         $amount = Product::getPriceStatic($type_value['product_id'], true, null, 6, null, false, true, 1);
                         $amount *= $num_days;
                         $cart_htl_data[$type_key]['date_diff'][$date_join]['amount'] = Tools::convertPrice($amount, $this->order->id_currency);
                     }
                 }
             }
         }
     }
     $data = array('cart_htl_data' => $cart_htl_data, 'order' => $this->order, 'order_invoice' => $this->order_invoice, 'order_details' => $order_details, 'cart_rules' => $cart_rules, 'delivery_address' => $formatted_delivery_address, 'invoice_address' => $formatted_invoice_address, 'addresses' => array('invoice' => $invoice_address, 'delivery' => $delivery_address), 'tax_excluded_display' => $tax_excluded_display, 'display_product_images' => $display_product_images, 'layout' => $layout, 'tax_tab' => $this->getTaxTabContent(), 'customer' => $customer, 'footer' => $footer, 'ps_price_compute_precision' => _PS_PRICE_COMPUTE_PRECISION_, 'round_type' => $round_type, 'legal_free_text' => $legal_free_text);
     if (Tools::getValue('debug')) {
         die(json_encode($data));
     }
     $this->smarty->assign($data);
     $tpls = array('style_tab' => $this->smarty->fetch($this->getTemplate('invoice.style-tab')), 'addresses_tab' => $this->smarty->fetch($this->getTemplate('invoice.addresses-tab')), 'summary_tab' => $this->smarty->fetch($this->getTemplate('invoice.summary-tab')), 'product_tab' => $this->smarty->fetch($this->getTemplate('invoice.product-tab')), 'tax_tab' => $this->getTaxTabContent(), 'payment_tab' => $this->smarty->fetch($this->getTemplate('invoice.payment-tab')), 'total_tab' => $this->smarty->fetch($this->getTemplate('invoice.total-tab')));
     $this->smarty->assign($tpls);
     return $this->smarty->fetch($this->getTemplateByCountry($country->iso_code));
 }
 public function ajaxProcessAddDataToCart()
 {
     // for Add Quantity
     $id_room = Tools::getValue('id_room');
     $booking_type = Tools::getValue('booking_type');
     $comment = Tools::getValue('comment');
     // for both (add , delete)
     $id_hotel = Tools::getValue('id_hotel');
     $id_product = Tools::getValue('id_prod');
     $date_from = Tools::getValue('date_from');
     $date_to = Tools::getValue('date_to');
     $search_id_prod = Tools::getValue('search_id_prod');
     $search_date_from = Tools::getValue('search_date_from');
     $search_date_to = Tools::getValue('search_date_to');
     // for delete quantity
     $id_cart = Tools::getValue('id_cart');
     $id_cart_book_data = Tools::getValue('id_cart_book_data');
     $ajax_delete = Tools::getValue('ajax_delete');
     // If delete from cart(not for room list delete(pagebottom tabs))
     $opt = Tools::getValue('opt');
     // if 1 then add quantity or if 0 means delete quantity
     // discuss later
     //
     // $obj_hotel_info = new HotelBranchInformation();
     // $hotel_info = $obj_hotel_info->hotelBranchInfoById($id_hotel);
     // $date_from = date('Y-m-d H:i:s', strtotime("$date_from +".date('H', strtotime($hotel_info['check_in']))." hours +".date('i', strtotime($hotel_info['check_in']))." minutes"));
     // $date_to = date('Y-m-d H:i:s', strtotime("$date_to +".date('H', strtotime($hotel_info['check_out']))." hours +".date('i', strtotime($hotel_info['check_out']))." minutes"));
     $obj_booking_dtl = new HotelBookingDetail();
     $num_day = $obj_booking_dtl->getNumberOfDays($date_from, $date_to);
     //quantity of product
     $product = new Product($id_product, false, Configuration::get('PS_LANG_DEFAULT'));
     // $id_product_attribute = $product->getDefaultIdProductAttribute();
     if ($opt) {
         // $cart_rules = $this->context->cart->getCartRules();
         $amount = Product::getPriceStatic($id_product, true, null, 6, null, false, true, $num_day);
     }
     if ($opt) {
         $direction = 'up';
     } else {
         $direction = 'down';
     }
     $this->context->cart->updateQty($num_day, $id_product, null, false, $direction);
     $total_amount = $this->context->cart->getOrderTotal();
     $id_cart = $this->context->cart->id;
     $id_guest = $this->context->cookie->id_guest;
     $obj_cart_book_data = new HotelCartBookingData();
     if ($opt) {
         $obj_cart_book_data->id_cart = $id_cart;
         $obj_cart_book_data->id_guest = $id_guest;
         $obj_cart_book_data->id_product = $id_product;
         $obj_cart_book_data->id_room = $id_room;
         $obj_cart_book_data->id_hotel = $id_hotel;
         $obj_cart_book_data->amount = $amount;
         $obj_cart_book_data->booking_type = $booking_type;
         $obj_cart_book_data->comment = $comment;
         $obj_cart_book_data->date_from = $date_from;
         $obj_cart_book_data->date_to = $date_to;
         $obj_cart_book_data->save();
         $obj_rm_info = new HotelRoomInformation($id_room);
         $rms_in_cart = $obj_cart_book_data->getCountRoomsInCart($id_cart, $id_guest);
         $booking_stats = $obj_booking_dtl->getBookingData($date_from, $date_to, $id_hotel, $search_id_prod, 0, 0, 1, 1, 1, 1, 0, 0, $id_cart, $id_guest, 1);
         $cart_data = array('room_num' => $obj_rm_info->room_num, 'room_type' => Product::getProductName((int) $id_product), 'date_from' => date('Y-M-d', strtotime($date_from)), 'date_to' => date('Y-M-d', strtotime($date_to)), 'amount' => $amount, 'qty' => $num_day, 'rms_in_cart' => $rms_in_cart, 'total_amount' => $total_amount, 'booking_stats' => $booking_stats, 'id_cart_book_data' => $obj_cart_book_data->id);
         if ($obj_cart_book_data->id) {
             die(Tools::jsonEncode($cart_data));
         } else {
             die(0);
         }
     } else {
         $data_dlt = $obj_cart_book_data->deleteRowById($id_cart_book_data);
         if ($data_dlt) {
             $rms_in_cart = $obj_cart_book_data->getCountRoomsInCart($id_cart, $id_guest);
             if (!$ajax_delete) {
                 $booking_stats = $obj_booking_dtl->getBookingData($date_from, $date_to, $id_hotel, $search_id_prod, 0, 0, 1, 1, 1, 1, 0, 0, $id_cart, $id_guest, 1);
                 $cart_data = array('total_amount' => $total_amount, 'rms_in_cart' => $rms_in_cart, 'booking_stats' => $booking_stats);
             }
             if ($ajax_delete) {
                 $obj_htl_info = new HotelBranchInformation();
                 $obj_rm_type = new HotelRoomType();
                 $this->context->smarty->assign(array('id_cart' => $id_cart, 'id_guest' => $id_guest));
                 // No use of adult, child, num_rooms
                 $adult = 0;
                 $children = 0;
                 $num_rooms = 1;
                 $booking_data = array();
                 $booking_data = $obj_booking_dtl->getBookingData($search_date_from, $search_date_to, $id_hotel, $search_id_prod, $adult, $children, $num_rooms, 0, 1, 1, 1, 1, $id_cart, $id_guest, 1);
                 $this->context->smarty->assign(array('date_from' => $date_from, 'date_to' => $date_to, 'booking_data' => $booking_data, 'ajax_delete' => $ajax_delete));
                 $tpl_path = 'hotelreservationsystem/views/templates/admin/hotel_rooms_booking/helpers/view/view.tpl';
                 $room_tpl = $this->context->smarty->fetch(_PS_MODULE_DIR_ . $tpl_path);
                 $cart_data = array('total_amount' => $total_amount, 'room_tpl' => $room_tpl, 'rms_in_cart' => $rms_in_cart, 'booking_data' => $booking_data);
             }
             die(Tools::jsonEncode($cart_data));
         } else {
             die(0);
         }
     }
 }
 protected function processBulkDelete()
 {
     if (is_array($this->boxes) && !empty($this->boxes)) {
         foreach ($this->boxes as $key => $value) {
             $obj_branch_features = new HotelBranchFeatures();
             $obj_htl_cart_data = new HotelCartBookingData();
             $obj_htl_img = new HotelImage();
             $obj_htl_rm_info = new HotelRoomInformation();
             $obj_htl_rm_type = new HotelRoomType();
             $ids_product = $obj_htl_rm_type->getIdProductByHotelId($value);
             if (isset($ids_product) && $ids_product) {
                 foreach ($ids_product as $key_prod => $value_prod) {
                     $delete_cart_data = $obj_htl_cart_data->deleteBookingCartDataNotOrderedByProductId($value_prod['id_product']);
                     $delete_room_info = $obj_htl_rm_info->deleteByProductId($value_prod['id_product']);
                     $delete_room_type = $obj_htl_rm_type->deleteByProductId($value_prod['id_product']);
                     $obj_product = new Product($value_prod['id_product']);
                     $delete_product = $obj_product->delete();
                 }
             }
             $delete_branch_features = $obj_branch_features->deleteBranchFeaturesByHotelId($object->id);
             $htl_all_images = $obj_htl_img->getAllImagesByHotelId($object->id);
             foreach ($htl_all_images as $key_img => $value_img) {
                 $path_img = _PS_MODULE_DIR_ . 'hotelreservationsystem/views/img/hotel_img/' . $value_img['hotel_image_id'] . '.jpg';
                 @unlink($path_img);
             }
             $delete_htl_img = $obj_htl_img->deleteByHotelId($object->id);
         }
         parent::processBulkDelete();
     } else {
         $this->errors[] = Tools::displayError('You must select at least one element to delete.');
     }
 }
Beispiel #11
0
 public function getHotelCartBookingData()
 {
     $total_rooms = 0;
     $cart_htl_data = array();
     $priceDisplay = Group::getPriceDisplayMethod(Group::getCurrent()->id);
     if (!$priceDisplay || $priceDisplay == 2) {
         $price_tax = true;
     } elseif ($priceDisplay == 1) {
         $price_tax = false;
     }
     if (Module::isInstalled('hotelreservationsystem')) {
         require_once _PS_MODULE_DIR_ . 'hotelreservationsystem/define.php';
         $obj_cart_bk_data = new HotelCartBookingData();
         $obj_htl_bk_dtl = new HotelBookingDetail();
         $obj_rm_type = new HotelRoomType();
         $htl_rm_types = $this->context->cart->getProducts();
         if (!empty($htl_rm_types)) {
             foreach ($htl_rm_types as $type_key => $type_value) {
                 $product = new Product($type_value['id_product'], false, $this->context->language->id);
                 $cover_image_arr = $product->getCover($type_value['id_product']);
                 if (!empty($cover_image_arr)) {
                     $cover_img = $this->context->link->getImageLink($product->link_rewrite, $product->id . '-' . $cover_image_arr['id_image'], 'small_default');
                 } else {
                     $cover_img = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code . "-default", 'small_default');
                 }
                 $unit_price = Product::getPriceStatic($type_value['id_product'], $price_tax, null, 6, null, false, true, 1);
                 if (isset($this->context->customer->id)) {
                     $cart_bk_data = $obj_cart_bk_data->getOnlyCartBookingData($this->context->cart->id, $this->context->cart->id_guest, $type_value['id_product']);
                 } else {
                     $cart_bk_data = $obj_cart_bk_data->getOnlyCartBookingData($this->context->cart->id, $this->context->cart->id_guest, $type_value['id_product']);
                 }
                 $rm_dtl = $obj_rm_type->getRoomTypeInfoByIdProduct($type_value['id_product']);
                 $cart_htl_data[$type_key]['total_num_rooms'] = 0;
                 $cart_htl_data[$type_key]['id_product'] = $type_value['id_product'];
                 $cart_htl_data[$type_key]['cover_img'] = $cover_img;
                 $cart_htl_data[$type_key]['name'] = $product->name;
                 $cart_htl_data[$type_key]['unit_price'] = $unit_price;
                 $cart_htl_data[$type_key]['adult'] = $rm_dtl['adult'];
                 $cart_htl_data[$type_key]['children'] = $rm_dtl['children'];
                 if (isset($cart_bk_data) && $cart_bk_data) {
                     foreach ($cart_bk_data as $data_k => $data_v) {
                         $date_join = strtotime($data_v['date_from']) . strtotime($data_v['date_to']);
                         if (isset($cart_htl_data[$type_key]['date_diff'][$date_join])) {
                             $cart_htl_data[$type_key]['date_diff'][$date_join]['num_rm'] += 1;
                             $total_rooms += 1;
                             $num_days = $cart_htl_data[$type_key]['date_diff'][$date_join]['num_days'];
                             $vart_quant = (int) $cart_htl_data[$type_key]['date_diff'][$date_join]['num_rm'] * $num_days;
                             $amount = Product::getPriceStatic($type_value['id_product'], $price_tax, null, 6, null, false, true, 1);
                             $amount *= $vart_quant;
                             $cart_htl_data[$type_key]['date_diff'][$date_join]['amount'] = $amount;
                         } else {
                             $num_days = $obj_htl_bk_dtl->getNumberOfDays($data_v['date_from'], $data_v['date_to']);
                             $total_rooms += 1;
                             $cart_htl_data[$type_key]['date_diff'][$date_join]['num_rm'] = 1;
                             $cart_htl_data[$type_key]['date_diff'][$date_join]['data_form'] = $data_v['date_from'];
                             $cart_htl_data[$type_key]['date_diff'][$date_join]['data_to'] = $data_v['date_to'];
                             $cart_htl_data[$type_key]['date_diff'][$date_join]['num_days'] = $num_days;
                             $amount = Product::getPriceStatic($type_value['id_product'], $price_tax, null, 6, null, false, true, 1);
                             $amount *= $num_days;
                             $cart_htl_data[$type_key]['date_diff'][$date_join]['amount'] = $amount;
                         }
                     }
                     foreach ($cart_htl_data[$type_key]['date_diff'] as $key => $value) {
                         $cart_htl_data[$type_key]['total_num_rooms'] += $value['num_rm'];
                     }
                 }
             }
         }
     }
     return array('cart_htl_data' => $cart_htl_data, 'total_rooms_in_cart' => $total_rooms);
 }
 public function renderView()
 {
     /** @var Cart $cart */
     if (!($cart = $this->loadObject(true))) {
         return;
     }
     $customer = new Customer($cart->id_customer);
     $currency = new Currency($cart->id_currency);
     $this->context->cart = $cart;
     $this->context->currency = $currency;
     $this->context->customer = $customer;
     $this->toolbar_title = sprintf($this->l('Cart #%06d'), $this->context->cart->id);
     $products = $cart->getProducts();
     $customized_datas = Product::getAllCustomizedDatas((int) $cart->id);
     Product::addCustomizationPrice($products, $customized_datas);
     $summary = $cart->getSummaryDetails();
     /* Display order information */
     $id_order = (int) Order::getOrderByCartId($cart->id);
     $order = new Order($id_order);
     if (Validate::isLoadedObject($order)) {
         $tax_calculation_method = $order->getTaxCalculationMethod();
         $id_shop = (int) $order->id_shop;
     } else {
         $id_shop = (int) $cart->id_shop;
         $tax_calculation_method = Group::getPriceDisplayMethod(Group::getCurrent()->id);
     }
     if ($tax_calculation_method == PS_TAX_EXC) {
         $total_products = $summary['total_products'];
         $total_discounts = $summary['total_discounts_tax_exc'];
         $total_wrapping = $summary['total_wrapping_tax_exc'];
         $total_price = $summary['total_price_without_tax'];
         $total_shipping = $summary['total_shipping_tax_exc'];
     } else {
         $total_products = $summary['total_products_wt'];
         $total_discounts = $summary['total_discounts'];
         $total_wrapping = $summary['total_wrapping'];
         $total_price = $summary['total_price'];
         $total_shipping = $summary['total_shipping'];
     }
     foreach ($products as $k => &$product) {
         if ($tax_calculation_method == PS_TAX_EXC) {
             $product['product_price'] = $product['price'];
             $product['product_total'] = $product['total'];
         } else {
             $product['product_price'] = $product['price_wt'];
             $product['product_total'] = $product['total_wt'];
         }
         $image = array();
         if (isset($product['id_product_attribute']) && (int) $product['id_product_attribute']) {
             $image = Db::getInstance()->getRow('SELECT id_image FROM ' . _DB_PREFIX_ . 'product_attribute_image WHERE id_product_attribute = ' . (int) $product['id_product_attribute']);
         }
         if (!isset($image['id_image'])) {
             $image = Db::getInstance()->getRow('SELECT id_image FROM ' . _DB_PREFIX_ . 'image WHERE id_product = ' . (int) $product['id_product'] . ' AND cover = 1');
         }
         $product['qty_in_stock'] = StockAvailable::getQuantityAvailableByProduct($product['id_product'], isset($product['id_product_attribute']) ? $product['id_product_attribute'] : null, (int) $id_shop);
         $image_product = new Image($image['id_image']);
         $product['image'] = isset($image['id_image']) ? ImageManager::thumbnail(_PS_IMG_DIR_ . 'p/' . $image_product->getExistingImgPath() . '.jpg', 'product_mini_' . (int) $product['id_product'] . (isset($product['id_product_attribute']) ? '_' . (int) $product['id_product_attribute'] : '') . '.jpg', 45, 'jpg') : '--';
     }
     $helper = new HelperKpi();
     $helper->id = 'box-kpi-cart';
     $helper->icon = 'icon-shopping-cart';
     $helper->color = 'color1';
     $helper->title = $this->l('Total Cart', null, null, false);
     $helper->subtitle = sprintf($this->l('Cart #%06d', null, null, false), $cart->id);
     $helper->value = Tools::displayPrice($total_price, $currency);
     $kpi = $helper->generate();
     // by webkul to show rooms available in the cart
     $cart_id = $cart->id;
     $cart_detail_data = array();
     $cart_detail_data_obj = new HotelCartBookingData();
     $cart_detail_data = $cart_detail_data_obj->getCartCurrentDataByCartId((int) $cart_id);
     if ($cart_detail_data) {
         foreach ($cart_detail_data as $key => $value) {
             $product_image_id = Product::getCover($value['id_product']);
             $link_rewrite = (new Product((int) $value['id_product'], Configuration::get('PS_LANG_DEFAULT')))->link_rewrite[Configuration::get('PS_LANG_DEFAULT')];
             if ($product_image_id) {
                 $cart_detail_data[$key]['image_link'] = $this->context->link->getImageLink($link_rewrite, $product_image_id['id_image'], 'small_default');
             } else {
                 $cart_detail_data[$key]['image_link'] = $this->context->link->getImageLink($link_rewrite, $this->context->language->iso_code . "-default", 'small_default');
             }
             $cart_detail_data[$key]['room_type'] = (new Product((int) $value['id_product']))->name[Configuration::get('PS_LANG_DEFAULT')];
             $cart_detail_data[$key]['room_num'] = (new HotelRoomInformation((int) $value['id_room']))->room_num;
             $cart_detail_data[$key]['date_from'] = (new DateTime($value['date_from']))->format('d-M Y');
             $cart_detail_data[$key]['date_to'] = (new DateTime($value['date_to']))->format('d-M Y');
         }
     }
     //end
     $this->tpl_view_vars = array('cart_detail_data' => $cart_detail_data, 'kpi' => $kpi, 'products' => $products, 'discounts' => $cart->getCartRules(), 'order' => $order, 'cart' => $cart, 'currency' => $currency, 'customer' => $customer, 'customer_stats' => $customer->getStats(), 'total_products' => $total_products, 'total_discounts' => $total_discounts, 'total_wrapping' => $total_wrapping, 'total_price' => $total_price, 'total_shipping' => $total_shipping, 'customized_datas' => $customized_datas, 'tax_calculation_method' => $tax_calculation_method);
     return parent::renderView();
 }