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();
             }
         }
     }
 }
 public function hookDisplayLeftColumn()
 {
     if ($this->context->controller->php_self == 'category') {
         $this->context->controller->addJS(_PS_MODULE_DIR_ . $this->name . '/views/js/wkhotelfilterblock.js');
         $this->context->controller->addCSS(_PS_MODULE_DIR_ . $this->name . '/views/css/wkhotelfilterblock.css');
         $all_feat = FeatureCore::getFeatures($this->context->language->id);
         $htl_id_category = Tools::getValue('id_category');
         $id_hotel = HotelBranchInformation::getHotelIdByIdCategory($htl_id_category);
         $max_adult = HotelRoomType::getMaxAdults($id_hotel);
         $max_child = HotelRoomType::getMaxChild($id_hotel);
         $category = new Category($htl_id_category);
         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_rm_type = new HotelRoomType();
         $room_types = $obj_rm_type->getIdProductByHotelId($id_hotel);
         $prod_price = array();
         if ($room_types) {
             foreach ($room_types as $key => $value) {
                 $prod_price[] = Product::getPriceStatic($value['id_product']);
             }
         }
         if (Configuration::get('PS_REWRITING_SETTINGS')) {
             $cat_link = $this->context->link->getCategoryLink($category) . '?date_from=' . $date_from . '&date_to=' . $date_to;
         } else {
             $cat_link = $this->context->link->getCategoryLink($category) . '&date_from=' . $date_from . '&date_to=' . $date_to;
         }
         $currency = $this->context->currency;
         $config = $this->getConfigFieldsValues();
         $obj_booking_detail = new HotelBookingDetail();
         $num_days = $obj_booking_detail->getNumberOfDays($date_from, $date_to);
         $ratting_img = _MODULE_DIR_ . $this->name . '/views/img/stars-sprite-image.png';
         $this->context->smarty->assign(array('all_feat' => $all_feat, 'max_adult' => $max_adult, 'max_child' => $max_child, 'cat_link' => $cat_link, 'ratting_img' => $ratting_img, 'currency' => $currency, 'date_from' => $date_from, 'date_to' => $date_to, 'num_days' => $num_days, 'config' => $config, 'min_price' => $prod_price ? min($prod_price) : 0, 'max_price' => $prod_price ? max($prod_price) : 0));
         return $this->display(__FILE__, 'htlfilterblock.tpl');
     }
 }
 public function ajaxProcessProductRoomsBookingDetailsOnMonthChange()
 {
     $month = Tools::getValue('month');
     $year = Tools::getValue('year');
     $query_date = $year . '-' . $month . '-04';
     $start_date = date('Y-m-01', strtotime($query_date));
     // hard-coded '01' for first day
     $last_day_this_month = date('Y-m-t', strtotime($query_date));
     $hotel_id = Tools::getValue('id_hotel');
     $room_type = Tools::getValue('id_product');
     $adult = Tools::getValue('num_adults');
     $children = Tools::getValue('num_children');
     $num_rooms = 1;
     $obj_booking_dtl = new HotelBookingDetail();
     while ($start_date <= $last_day_this_month) {
         $cal_date_from = $start_date;
         $cal_date_to = date('Y-m-d', strtotime($cal_date_from) + 86400);
         $booking_calendar_data[$cal_date_from] = $obj_booking_dtl->getBookingData($cal_date_from, $cal_date_to, $hotel_id, $room_type, $adult, $children, $num_rooms, 1);
         $start_date = date('Y-m-d', strtotime($start_date) + 86400);
     }
     if ($booking_calendar_data) {
         die(Tools::jsonEncode($booking_calendar_data));
     } else {
         die(0);
     }
 }
 /**
  * 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');
     }
 }
                die(Tools::jsonEncode(array('status' => 'failed2')));
            }
        } else {
            die(Tools::jsonEncode(array('status' => 'failed3')));
        }
    } else {
        die(Tools::jsonEncode(array('status' => 'failed4')));
    }
}
if (isset($delete) && $delete) {
    $obj_room_type = new HotelRoomType();
    $room_info_by_id_product = $obj_room_type->getRoomTypeInfoByIdProduct($id_product);
    if ($room_info_by_id_product) {
        $id_hotel = $room_info_by_id_product['id_hotel'];
        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) {
 public function filterResults()
 {
     $this->display_header = false;
     $this->display_footer = false;
     $date_from = Tools::getValue('date_from');
     $date_to = Tools::getValue('date_to');
     $htl_id_category = Tools::getValue('id_category');
     $sort_by = Tools::getValue('sort_by');
     $sort_value = Tools::getValue('sort_value');
     $filter_data = Tools::getValue('filter_data');
     // echo "<pre>";
     // print_r($filter_data);
     // die;
     $adult = 0;
     $child = 0;
     $ratting = 0;
     $amenities = 0;
     $price = 0;
     if (!empty($filter_data)) {
         foreach ($filter_data as $key => $value) {
             if ($key == 'adult') {
                 $adult = min($value);
             } elseif ($key == 'children') {
                 $child = min($value);
             } elseif ($key == 'ratting') {
                 $ratting = min($value);
             } elseif ($key == 'amenities') {
                 $amenities = array();
                 foreach ($value as $a_k => $a_v) {
                     $amenities[] = $a_v;
                 }
             } elseif ($key == 'price') {
                 $price = array();
                 $price['from'] = $value[0];
                 $price['to'] = $value[1];
             }
         }
     }
     if (Module::isInstalled('hotelreservationsystem')) {
         require_once _PS_MODULE_DIR_ . 'hotelreservationsystem/define.php';
         $id_hotel = HotelBranchInformation::getHotelIdByIdCategory($htl_id_category);
         $id_cart = $this->context->cart->id;
         $id_guest = $this->context->cookie->id_guest;
         $obj_booking_dtl = new HotelBookingDetail();
         $booking_data = $obj_booking_dtl->DataForFrontSearch($date_from, $date_to, $id_hotel, 0, 0, $adult, $child, $ratting, $amenities, $price, $id_cart, $id_guest);
         if ($sort_by && $sort_value) {
             $indi_arr = array();
             if ($sort_value == 1) {
                 $direction = SORT_ASC;
             } elseif ($sort_value == 2) {
                 $direction = SORT_DESC;
             }
             foreach ($booking_data['rm_data'] as $s_k => $s_v) {
                 if ($sort_by == 1) {
                     $indi_arr[$s_k] = $s_v['ratting'];
                 } elseif ($sort_by == 2) {
                     $indi_arr[$s_k] = $s_v['price'];
                 }
             }
             array_multisort($indi_arr, $direction, $booking_data['rm_data']);
         }
         die(Tools::jsonEncode($booking_data));
     }
 }
 public function renderView()
 {
     $order = new Order(Tools::getValue('id_order'));
     if (!Validate::isLoadedObject($order)) {
         $this->errors[] = Tools::displayError('The order cannot be found within your database.');
     }
     $customer = new Customer($order->id_customer);
     $carrier = new Carrier($order->id_carrier);
     $products = $this->getProducts($order);
     $currency = new Currency((int) $order->id_currency);
     // Carrier module call
     $carrier_module_call = null;
     if ($carrier->is_module) {
         $module = Module::getInstanceByName($carrier->external_module_name);
         if (method_exists($module, 'displayInfoByCart')) {
             $carrier_module_call = call_user_func(array($module, 'displayInfoByCart'), $order->id_cart);
         }
     }
     // Retrieve addresses information
     $addressInvoice = new Address($order->id_address_invoice, $this->context->language->id);
     if (Validate::isLoadedObject($addressInvoice) && $addressInvoice->id_state) {
         $invoiceState = new State((int) $addressInvoice->id_state);
     }
     if ($order->id_address_invoice == $order->id_address_delivery) {
         $addressDelivery = $addressInvoice;
         if (isset($invoiceState)) {
             $deliveryState = $invoiceState;
         }
     } else {
         $addressDelivery = new Address($order->id_address_delivery, $this->context->language->id);
         if (Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state) {
             $deliveryState = new State((int) $addressDelivery->id_state);
         }
     }
     $this->toolbar_title = sprintf($this->l('Order #%1$d (%2$s) - %3$s %4$s'), $order->id, $order->reference, $customer->firstname, $customer->lastname);
     if (Shop::isFeatureActive()) {
         $shop = new Shop((int) $order->id_shop);
         $this->toolbar_title .= ' - ' . sprintf($this->l('Shop: %s'), $shop->name);
     }
     // gets warehouses to ship products, if and only if advanced stock management is activated
     $warehouse_list = null;
     $order_details = $order->getOrderDetailList();
     foreach ($order_details as $order_detail) {
         $product = new Product($order_detail['product_id']);
         if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management) {
             $warehouses = Warehouse::getWarehousesByProductId($order_detail['product_id'], $order_detail['product_attribute_id']);
             foreach ($warehouses as $warehouse) {
                 if (!isset($warehouse_list[$warehouse['id_warehouse']])) {
                     $warehouse_list[$warehouse['id_warehouse']] = $warehouse;
                 }
             }
         }
     }
     $payment_methods = array();
     foreach (PaymentModule::getInstalledPaymentModules() as $payment) {
         $module = Module::getInstanceByName($payment['name']);
         if (Validate::isLoadedObject($module) && $module->active) {
             $payment_methods[] = $module->displayName;
         }
     }
     // display warning if there are products out of stock
     $display_out_of_stock_warning = false;
     $current_order_state = $order->getCurrentOrderState();
     if (Configuration::get('PS_STOCK_MANAGEMENT') && (!Validate::isLoadedObject($current_order_state) || $current_order_state->delivery != 1 && $current_order_state->shipped != 1)) {
         $display_out_of_stock_warning = true;
     }
     // products current stock (from stock_available)
     foreach ($products as &$product) {
         // Get total customized quantity for current product
         $customized_product_quantity = 0;
         if (is_array($product['customizedDatas'])) {
             foreach ($product['customizedDatas'] as $customizationPerAddress) {
                 foreach ($customizationPerAddress as $customizationId => $customization) {
                     $customized_product_quantity += (int) $customization['quantity'];
                 }
             }
         }
         $product['customized_product_quantity'] = $customized_product_quantity;
         $product['current_stock'] = StockAvailable::getQuantityAvailableByProduct($product['product_id'], $product['product_attribute_id'], $product['id_shop']);
         $resume = OrderSlip::getProductSlipResume($product['id_order_detail']);
         $product['quantity_refundable'] = $product['product_quantity'] - $resume['product_quantity'];
         $product['amount_refundable'] = $product['total_price_tax_excl'] - $resume['amount_tax_excl'];
         $product['amount_refundable_tax_incl'] = $product['total_price_tax_incl'] - $resume['amount_tax_incl'];
         $product['amount_refund'] = Tools::displayPrice($resume['amount_tax_incl'], $currency);
         $product['refund_history'] = OrderSlip::getProductSlipDetail($product['id_order_detail']);
         $product['return_history'] = OrderReturn::getProductReturnDetail($product['id_order_detail']);
         // if the current stock requires a warning
         if ($product['current_stock'] == 0 && $display_out_of_stock_warning) {
             $this->displayWarning($this->l('This product is out of stock: ') . ' ' . $product['product_name']);
         }
         if ($product['id_warehouse'] != 0) {
             $warehouse = new Warehouse((int) $product['id_warehouse']);
             $product['warehouse_name'] = $warehouse->name;
             $warehouse_location = WarehouseProductLocation::getProductLocation($product['product_id'], $product['product_attribute_id'], $product['id_warehouse']);
             if (!empty($warehouse_location)) {
                 $product['warehouse_location'] = $warehouse_location;
             } else {
                 $product['warehouse_location'] = false;
             }
         } else {
             $product['warehouse_name'] = '--';
             $product['warehouse_location'] = false;
         }
     }
     $gender = new Gender((int) $customer->id_gender, $this->context->language->id);
     $history = $order->getHistory($this->context->language->id);
     foreach ($history as &$order_state) {
         $order_state['text-color'] = Tools::getBrightness($order_state['color']) < 128 ? 'white' : 'black';
     }
     //by webkul to get data to show hotel rooms order data on order detail page
     $cart_id = Cart::getCartIdByOrderId(Tools::getValue('id_order'));
     $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');
             $cust_obj = new Customer($value['id_customer']);
             $cart_detail_data[$key]['alloted_cust_name'] = $cust_obj->firstname . ' ' . $cust_obj->lastname;
             $cart_detail_data[$key]['alloted_cust_email'] = $cust_obj->email;
             $cart_detail_data[$key]['avail_rooms_to_swap'] = (new HotelBookingDetail())->getAvailableRoomsForSwaping($value['date_from'], $value['date_to'], $value['id_product'], $value['id_hotel']);
             $obj_booking_dtl = new HotelBookingDetail();
             $num_days = $obj_booking_dtl->getNumberOfDays($cart_detail_data[$key]['date_from'], $cart_detail_data[$key]['date_to']);
             //quantity of product
             $cart_detail_data[$key]['amt_with_qty'] = $value['amount'] * $num_days;
         }
     }
     //end
     //by webkul to send order status on order detail page
     $obj_bookin_detail = new HotelBookingDetail();
     $htl_booking_data_order_id = $obj_bookin_detail->getBookingDataByOrderId(Tools::getValue('id_order'));
     if ($htl_booking_data_order_id) {
         foreach ($htl_booking_data_order_id as $key => $value) {
             $htl_booking_data_order_id[$key]['room_num'] = (new HotelRoomInformation())->getHotelRoomInfoById($value['id_room']);
             $htl_booking_data_order_id[$key]['order_status'] = $value['id_status'];
             $htl_booking_data_order_id[$key]['date_from'] = (new DateTime($value['date_from']))->format('d-M Y');
             $htl_booking_data_order_id[$key]['date_to'] = (new DateTime($value['date_to']))->format('d-M Y');
         }
     }
     $htl_order_status = HotelOrderStatus::getAllHotelOrderStatus();
     //end
     // Smarty assign
     $this->tpl_view_vars = array('htl_booking_order_data' => $htl_booking_data_order_id, 'hotel_order_status' => $htl_order_status, 'cart_detail_data' => $cart_detail_data, 'order' => $order, 'cart' => new Cart($order->id_cart), 'customer' => $customer, 'gender' => $gender, 'customer_addresses' => $customer->getAddresses($this->context->language->id), 'addresses' => array('delivery' => $addressDelivery, 'deliveryState' => isset($deliveryState) ? $deliveryState : null, 'invoice' => $addressInvoice, 'invoiceState' => isset($invoiceState) ? $invoiceState : null), 'customerStats' => $customer->getStats(), 'products' => $products, 'discounts' => $order->getCartRules(), 'orders_total_paid_tax_incl' => $order->getOrdersTotalPaid(), 'total_paid' => $order->getTotalPaid(), 'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id), 'customer_thread_message' => CustomerThread::getCustomerMessages($order->id_customer, null, $order->id), 'orderMessages' => OrderMessage::getOrderMessages($order->id_lang), 'messages' => Message::getMessagesByOrderId($order->id, true), 'carrier' => new Carrier($order->id_carrier), 'history' => $history, 'states' => OrderState::getOrderStates($this->context->language->id), 'warehouse_list' => $warehouse_list, 'sources' => ConnectionsSource::getOrderSources($order->id), 'currentState' => $order->getCurrentOrderState(), 'currency' => new Currency($order->id_currency), 'currencies' => Currency::getCurrenciesByIdShop($order->id_shop), 'previousOrder' => $order->getPreviousOrderId(), 'nextOrder' => $order->getNextOrderId(), 'current_index' => self::$currentIndex, 'carrierModuleCall' => $carrier_module_call, 'iso_code_lang' => $this->context->language->iso_code, 'id_lang' => $this->context->language->id, 'can_edit' => $this->tabAccess['edit'] == 1, 'current_id_lang' => $this->context->language->id, 'invoices_collection' => $order->getInvoicesCollection(), 'not_paid_invoices_collection' => $order->getNotPaidInvoicesCollection(), 'payment_methods' => $payment_methods, 'invoice_management_active' => Configuration::get('PS_INVOICE', null, null, $order->id_shop), 'display_warehouse' => (int) Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'), 'HOOK_CONTENT_ORDER' => Hook::exec('displayAdminOrderContentOrder', array('order' => $order, 'products' => $products, 'customer' => $customer)), 'HOOK_CONTENT_SHIP' => Hook::exec('displayAdminOrderContentShip', array('order' => $order, 'products' => $products, 'customer' => $customer)), 'HOOK_TAB_ORDER' => Hook::exec('displayAdminOrderTabOrder', array('order' => $order, 'products' => $products, 'customer' => $customer)), 'HOOK_TAB_SHIP' => Hook::exec('displayAdminOrderTabShip', array('order' => $order, 'products' => $products, 'customer' => $customer)));
     return parent::renderView();
 }
 /**
  * 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');
 }
Esempio n. 9
0
 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;
 }
Esempio n. 10
0
 /**
  * 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 postProcess()
 {
     if (Tools::isSubmit('swap_allocated_rooms')) {
         $current_room_id = Tools::getValue('id_room');
         $current_room = Tools::getValue('curr_room_num');
         $date_from = Tools::getValue('date_from');
         $date_to = Tools::getValue('date_to');
         $swapped_room_id = Tools::getValue('swapped_avail_rooms');
         $obj_booking_dtl = new HotelBookingDetail();
         $room_swapped = $obj_booking_dtl->reallocateRoomWithAvailableSameRoomType($current_room_id, $date_from, $date_to, $swapped_room_id);
         if (!$room_swapped) {
             $this->errors[] = Tools::displayError('Some error occured. Please try again.');
         }
     }
     parent::postProcess();
 }
 public function deleteRoomDataFromOrderLine($id_cart, $id_guest, $id_product, $date_from, $date_to)
 {
     $result = Db::getInstance()->executeS("SELECT * FROM `" . _DB_PREFIX_ . "htl_cart_booking_data` WHERE `id_cart`=" . $id_cart . " AND `id_guest`=" . $id_guest . " AND `id_product`=" . $id_product . " AND `date_from`= '{$date_from}' AND `date_to`= '{$date_to}'");
     $num_rm = Db::getInstance()->NumRows();
     $obj_htl_bk_dtl = new HotelBookingDetail();
     $num_days = $obj_htl_bk_dtl->getNumberOfDays($date_from, $date_to);
     $qty = (int) $num_rm * (int) $num_days;
     if ($qty) {
         $this->context = Context::getContext();
         $update_quantity = $this->context->cart->updateQty($qty, $id_product, null, false, 'down');
         $delete_rooms = Db::getInstance()->delete('htl_cart_booking_data', "`id_cart`=" . $id_cart . " AND `id_guest`=" . $id_guest . " AND `id_product`=" . $id_product . " AND `date_from`= '{$date_from}' AND `date_to`= '{$date_to}'");
         if ($delete_rooms) {
             return true;
         }
         return false;
     } else {
         return false;
     }
 }
Esempio n. 14
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);
 }