public function hookActionProductSave($params)
 {
     $isToggling = Tools::getValue('statusproduct');
     if (isset($isToggling)) {
         $obj_htl_rm_info = new HotelRoomType();
         $htl_rm_info = $obj_htl_rm_info->getRoomTypeInfoByIdProduct($params['id_product']);
         if (isset($htl_rm_info) && $htl_rm_info) {
             $prod_htl_id = $htl_rm_info['id_hotel'];
             if (isset($prod_htl_id) && $prod_htl_id) {
                 $obj_hotel = new HotelBranchInformation($prod_htl_id);
                 if (!$obj_hotel->active) {
                     $obj_hotel->toggleStatus();
                 }
             }
         }
     } else {
         if ($params['id_product']) {
             $obj_htl_rm_info = new HotelRoomType();
             $htl_rm_info = $obj_htl_rm_info->getRoomTypeInfoByIdProduct($params['id_product']);
             if (isset($htl_rm_info) && $htl_rm_info) {
                 $prod_htl_id = $htl_rm_info['id_hotel'];
                 if (isset($prod_htl_id) && $prod_htl_id) {
                     $obj_hotel = new HotelBranchInformation($prod_htl_id);
                     if (!$obj_hotel->active) {
                         $obj_product = new Product($params['id_product']);
                         if ($obj_product->active == 1) {
                             $obj_product->toggleStatus();
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * @param Product $obj
  * @throws Exception
  * @throws PrestaShopException
  * @throws SmartyException
  */
 public function initFormBooking($obj)
 {
     $data = $this->createTemplate($this->tpl_form);
     if ($obj->id) {
         if ($this->product_exists_in_shop) {
             $data->assign(array('product' => $obj));
             $date_from = Tools::getValue('date_from');
             $date_to = Tools::getValue('date_to');
             $obj_rm_type = new HotelRoomType();
             $obj_booking_dtl = new HotelBookingDetail();
             $rm_info = $obj_rm_type->getRoomTypeInfoByIdProduct($obj->id);
             if ($rm_info) {
                 if ($date_from && $date_to) {
                     $search_flag = 1;
                     $start_date = $date_from;
                     $last_date = $date_to;
                 } else {
                     $date_from = date('Y-m-d');
                     $date_to = date('Y-m-d', strtotime($date_from) + 86400);
                     $start_date = date('Y-m-01');
                     // hard-coded '01' for first day
                     $last_date = date('Y-m-t');
                 }
                 $booking_data = $obj_booking_dtl->getBookingData($date_from, $date_to, $rm_info['id_hotel'], $obj->id, $rm_info['adult'], $rm_info['children'], 0);
                 while ($start_date <= $last_date) {
                     $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($date_from, $date_to, $rm_info['id_hotel'], $obj->id, $rm_info['adult'], $rm_info['children'], 0, 1);
                     $start_date = date('Y-m-d', strtotime($start_date) + 86400);
                 }
                 if (isset($search_flag) && $search_flag) {
                     if ($booking_data['stats']['num_avail'] > 0) {
                         $check_css_condition_var = 'available';
                     } else {
                         if ($booking_data['stats']['num_part_avai'] > 0) {
                             $check_css_condition_var = 'part_available';
                         } else {
                             $check_css_condition_var = 'unavailable';
                         }
                     }
                 } else {
                     if ($booking_data['stats']['num_avail'] > 0) {
                         $check_css_condition_var = 'default_available';
                     } else {
                         if ($booking_data['stats']['num_part_avai'] > 0) {
                             $check_css_condition_var = 'default_part_available';
                         } else {
                             $check_css_condition_var = 'default_unavailable';
                         }
                     }
                 }
                 $data->assign(array('rooms_info' => $rm_info, 'check_calendar_var' => 1, 'date_from' => $date_from, 'date_to' => $date_to, 'booking_data' => $booking_data, 'booking_calendar_data' => $booking_calendar_data, 'htl_config' => 1, 'check_css_condition_var' => $check_css_condition_var));
             } else {
                 $this->displayWarning($this->l('First you have to fill Room configuration.'));
             }
         } else {
             $this->displayWarning($this->l('You must save the product in this shop before managing hotel configuration.'));
         }
     } else {
         $this->displayWarning($this->l('You must save this product before managing hotel configuration.'));
     }
     $this->tpl_form_vars['custom_form'] = $data->fetch();
 }
Ejemplo n.º 3
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');
     }
 }
                } else {
                    die(Tools::jsonEncode(array('status' => 'unavailable_quantity', 'avail_rooms' => $total_available_rooms)));
                }
            } else {
                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 {
 /**
  * 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');
 }
Ejemplo n.º 6
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;
 }
Ejemplo n.º 7
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');
 }
Ejemplo n.º 8
0
 /**
  * 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));
 }
Ejemplo n.º 9
0
 public function DataForFrontSearch($date_from, $date_to, $id_hotel, $id_product = 0, $for_room_type = 0, $adult = 0, $children = 0, $ratting = -1, $amenities = 0, $price = 0, $id_cart = 0, $id_guest = 0)
 {
     require_once _PS_MODULE_DIR_ . 'productcomments/ProductComment.php';
     $this->context = Context::getContext();
     $booking_data = $this->getBookingData($date_from, $date_to, $id_hotel, $id_product, $adult, $children, 0, 0, 1, 0, 0, 0, $id_cart, $id_guest);
     // ddd($booking_data);
     if (!$for_room_type) {
         if (!empty($booking_data)) {
             $obj_rm_type = new HotelRoomType();
             foreach ($booking_data['rm_data'] as $key => $value) {
                 if (empty($value['data']['available'])) {
                     unset($booking_data['rm_data'][$key]);
                 } else {
                     $prod_ratting = ProductComment::getAverageGrade($value['id_product'])['grade'];
                     if ($prod_ratting === NULL) {
                         $prod_ratting = 0;
                     }
                     if ($prod_ratting < $ratting && $ratting != -1) {
                         unset($booking_data['rm_data'][$key]);
                     } else {
                         $product = new Product($value['id_product'], false, $this->context->language->id);
                         $product_feature = $product->getFrontFeaturesStatic($this->context->language->id, $value['id_product']);
                         $prod_amen = array();
                         if (!empty($amenities) && $amenities) {
                             $prod_amen = $amenities;
                             foreach ($product_feature as $a_key => $a_val) {
                                 if (($pa_key = array_search($a_val['id_feature'], $prod_amen)) !== false) {
                                     unset($prod_amen[$pa_key]);
                                     if (empty($prod_amen)) {
                                         break;
                                     }
                                 }
                             }
                             if (!empty($prod_amen)) {
                                 unset($booking_data['rm_data'][$key]);
                             }
                         }
                         if (empty($prod_amen)) {
                             $prod_price = Product::getPriceStatic($value['id_product']);
                             if (empty($price) || $price['from'] <= $prod_price && $price['to'] >= $prod_price) {
                                 $cover_image_arr = $product->getCover($value['id_product']);
                                 if (!empty($cover_image_arr)) {
                                     $cover_img = $this->context->link->getImageLink($product->link_rewrite, $product->id . '-' . $cover_image_arr['id_image'], 'home_default');
                                 } else {
                                     $cover_img = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code . "-default", 'home_default');
                                 }
                                 $room_left = count($booking_data['rm_data'][$key]['data']['available']);
                                 $rm_dtl = $obj_rm_type->getRoomTypeInfoByIdProduct($value['id_product']);
                                 $booking_data['rm_data'][$key]['name'] = $product->name;
                                 $booking_data['rm_data'][$key]['image'] = $cover_img;
                                 $booking_data['rm_data'][$key]['description'] = $product->description_short;
                                 $booking_data['rm_data'][$key]['feature'] = $product_feature;
                                 $booking_data['rm_data'][$key]['price'] = $prod_price;
                                 if ($room_left <= (int) Configuration::get('WK_ROOM_LEFT_WARNING_NUMBER')) {
                                     $booking_data['rm_data'][$key]['room_left'] = $room_left;
                                 }
                                 $booking_data['rm_data'][$key]['adult'] = $rm_dtl['adult'];
                                 $booking_data['rm_data'][$key]['children'] = $rm_dtl['children'];
                                 $booking_data['rm_data'][$key]['ratting'] = $prod_ratting;
                                 $booking_data['rm_data'][$key]['num_review'] = ProductComment::getCommentNumber($value['id_product']);
                                 if (Configuration::get('PS_REWRITING_SETTINGS')) {
                                     $booking_data['rm_data'][$key]['product_link'] = $this->context->link->getProductLink($product) . '?date_from=' . $date_from . '&date_to=' . $date_to;
                                 } else {
                                     $booking_data['rm_data'][$key]['product_link'] = $this->context->link->getProductLink($product) . '&date_from=' . $date_from . '&date_to=' . $date_to;
                                 }
                             } else {
                                 unset($booking_data['rm_data'][$key]);
                             }
                         }
                     }
                 }
             }
         }
     }
     return $booking_data;
 }
Ejemplo n.º 10
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);
 }