diff --git a/classes/Address.php b/classes/Address.php index 58a17e07e..7533f2ac1 100644 --- a/classes/Address.php +++ b/classes/Address.php @@ -41,6 +41,11 @@ class AddressCore extends ObjectModel */ public $id_warehouse = null; + /** + * @var int Hotel id which address belongs to + */ + public $id_hotel = null; + /** @var int Country id */ public $id_country; @@ -115,6 +120,7 @@ class AddressCore extends ObjectModel 'id_manufacturer' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false), 'id_supplier' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false), 'id_warehouse' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false), + 'id_hotel' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false), 'id_country' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_state' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId'), 'alias' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 32), diff --git a/classes/Cart.php b/classes/Cart.php index 4ac4cbcdf..1815a64e5 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -335,11 +335,7 @@ class CartCore extends ObjectModel foreach ($products as $product) { // products refer to the cart details - if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') { - $address_id = (int)$cart->id_address_invoice; - } else { - $address_id = (int)$product['id_address_delivery']; - } // Get delivery address of the product from the cart + $address_id = Cart::getIdAddressForTaxCalculation($product['id_product']); if (!Address::addressExists($address_id)) { $address_id = null; } @@ -630,8 +626,6 @@ class CartCore extends ObjectModel return array(); } - $ecotax_rate = (float)Tax::getProductEcotaxRate($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); - $apply_eco_tax = Product::$_taxCalculationMethod == PS_TAX_INC && (int)Configuration::get('PS_TAX'); $cart_shop_context = Context::getContext()->cloneContext(); foreach ($result as &$row) { @@ -647,11 +641,8 @@ class CartCore extends ObjectModel $row['weight'] = (float)$row['weight_attribute']; } - if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') { - $address_id = (int)$this->id_address_invoice; - } else { - $address_id = (int)$row['id_address_delivery']; - } + // hotel address for tax calculation + $address_id = Cart::getIdAddressForTaxCalculation($row['id_product']); if (!Address::addressExists($address_id)) { $address_id = null; } @@ -1492,7 +1483,6 @@ class CartCore extends ObjectModel $price_calculator = Adapter_ServiceLocator::get('Adapter_ProductPriceCalculator'); $configuration = Adapter_ServiceLocator::get('Core_Business_ConfigurationInterface'); - $ps_tax_address_type = $configuration->get('PS_TAX_ADDRESS_TYPE'); $ps_use_ecotax = $configuration->get('PS_USE_ECOTAX'); $ps_round_type = $configuration->get('PS_ROUND_TYPE'); $ps_ecotax_tax_rules_group_id = $configuration->get('PS_ECOTAX_TAX_RULES_GROUP_ID'); @@ -1590,11 +1580,8 @@ class CartCore extends ObjectModel $virtual_context->shop = new Shop((int)$product['id_shop']); } - if ($ps_tax_address_type == 'id_address_invoice') { - $id_address = (int)$this->id_address_invoice; - } else { - $id_address = (int)$product['id_address_delivery']; - } // Get delivery address of the product from the cart + // hotel address for tax calculation + $id_address = Cart::getIdAddressForTaxCalculation($product['id_product']); if (!$address_factory->addressExists($id_address)) { $id_address = null; } @@ -2691,6 +2678,11 @@ class CartCore extends ObjectModel return $collection; } + public static function getIdAddressForTaxCalculation($id_product) + { + return HotelRoomType::getHotelIdAddressByIdProduct($id_product); + } + /** * Set the delivery option and id_carrier, if there is only one carrier */ diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index 010dcf4a8..bc5f49d27 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -295,6 +295,7 @@ abstract class PaymentModuleCore extends Module $order->id_customer = (int)$this->context->cart->id_customer; $order->id_address_invoice = (int)$this->context->cart->id_address_invoice; $order->id_address_delivery = (int)$id_address; + $order->id_address_tax = (int)Cart::getIdAddressForTaxCalculation($order->product_list[0]['id_product']); $order->id_currency = $this->context->currency->id; $order->id_lang = (int)$this->context->cart->id_lang; $order->id_cart = (int)$this->context->cart->id; @@ -482,8 +483,9 @@ abstract class PaymentModuleCore extends Module $product_var_tpl_list = array(); foreach ($order->product_list as $product) { - $price = Product::getPriceStatic((int)$product['id_product'], false, ($product['id_product_attribute'] ? (int)$product['id_product_attribute'] : null), 6, null, false, true, $product['cart_quantity'], false, (int)$order->id_customer, (int)$order->id_cart, (int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); - $price_wt = Product::getPriceStatic((int)$product['id_product'], true, ($product['id_product_attribute'] ? (int)$product['id_product_attribute'] : null), 2, null, false, true, $product['cart_quantity'], false, (int)$order->id_customer, (int)$order->id_cart, (int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); + $price = Product::getPriceStatic((int)$product['id_product'], false, ($product['id_product_attribute'] ? (int)$product['id_product_attribute'] : null), 6, null, false, true, $product['cart_quantity'], false, (int)$order->id_customer, (int)$order->id_cart); + $price_wt = Product::getPriceStatic((int)$product['id_product'], true, ($product['id_product_attribute'] ? (int)$product['id_product_attribute'] : null), 2, null, false, true, $product['cart_quantity'], false, (int)$order->id_customer, (int)$order->id_cart); + $product_price = Product::getTaxCalculationMethod() == PS_TAX_EXC ? Tools::ps_round($price, 2) : $price_wt; diff --git a/classes/Product.php b/classes/Product.php index 1fff837fe..aaef49d31 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -488,11 +488,8 @@ class ProductCore extends ObjectModel $this->manufacturer_name = Manufacturer::getNameById((int)$this->id_manufacturer); $this->supplier_name = Supplier::getNameById((int)$this->id_supplier); $address = null; - if (is_object($context->cart) && $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')} != null) { - $address = $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}; - } - - $this->tax_rate = $this->getTaxesRate(new Address($address)); + $id_address = Cart::getIdAddressForTaxCalculation($this->id); + $this->tax_rate = $this->getTaxesRate(new Address($id_address)); $this->new = $this->isNew(); @@ -2844,21 +2841,16 @@ class ProductCore extends ObjectModel $id_state = 0; $zipcode = 0; - if (!$id_address && Validate::isLoadedObject($cur_cart)) { - $id_address = $cur_cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}; - } - if ($id_address) { $address_infos = Address::getCountryAndState($id_address); - if ($address_infos['id_country']) { - $id_country = (int)$address_infos['id_country']; - $id_state = (int)$address_infos['id_state']; - $zipcode = $address_infos['postcode']; - } - } elseif (isset($context->customer->geoloc_id_country)) { - $id_country = (int)$context->customer->geoloc_id_country; - $id_state = (int)$context->customer->id_state; - $zipcode = $context->customer->postcode; + } else { + $address_infos = Address::getCountryAndState(Cart::getIdAddressForTaxCalculation($id_product)); + } + + if ($address_infos['id_country']) { + $id_country = (int)$address_infos['id_country']; + $id_state = (int)$address_infos['id_state']; + $zipcode = $address_infos['postcode']; } if (Tax::excludeTaxeOption()) { @@ -2965,7 +2957,7 @@ class ProductCore extends ObjectModel (int)$id_product, $id_shop, $id_currency, - $id_country, + (int)$context->country->id, $id_group, $quantity, $id_product_attribute, @@ -3160,7 +3152,7 @@ class ProductCore extends ObjectModel $quantity = $cart_quantity ? $cart_quantity : $quantity; $id_currency = (int)$context->currency->id; - $ids = Address::getCountryAndState((int)$context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); + $ids = Address::getCountryAndState(cart::getIdAddressForTaxCalculation($id_product)); $id_country = $ids['id_country'] ? (int)$ids['id_country'] : (int)Configuration::get('PS_COUNTRY_DEFAULT'); return (bool)SpecificPrice::getSpecificPrice((int)$id_product, $context->shop->id, $id_currency, $id_country, $id_group, $quantity, null, 0, 0, $quantity); } @@ -5048,7 +5040,7 @@ class ProductCore extends ObjectModel public function getTaxesRate(Address $address = null) { if (!$address || !$address->id_country) { - $address = Address::initialize(); + $address = Address::initialize(Cart::getIdAddressForTaxCalculation($this->id)); } $tax_manager = TaxManagerFactory::getManager($address, $this->id_tax_rules_group); diff --git a/classes/order/Order.php b/classes/order/Order.php index fbc292b4a..548e58610 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -40,6 +40,9 @@ class OrderCore extends ObjectModel /** @var int Invoice address id */ public $id_address_invoice; + /** @var int Hotel address id */ + public $id_address_tax; + public $id_shop_group; public $id_shop; @@ -196,6 +199,7 @@ class OrderCore extends ObjectModel 'fields' => array( 'id_address_delivery' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_address_invoice' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), + 'id_address_tax' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_cart' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_currency' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_shop_group' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), @@ -747,6 +751,7 @@ class OrderCore extends ObjectModel public function getTaxesAverageUsed() { + // @todo should use order table to get tax average return Cart::getTaxesAverageUsed((int)$this->id_cart); } @@ -1349,7 +1354,7 @@ class OrderCore extends ObjectModel return; } - $address = new Address((int)$this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); + $address = new Address((int)$this->id_address_tax); $carrier = new Carrier((int)$this->id_carrier); $tax_calculator = $carrier->getTaxCalculator($address); $order_invoice->total_discount_tax_excl = $this->total_discounts_tax_excl; @@ -2482,7 +2487,7 @@ class OrderCore extends ObjectModel if ($refundFlag) { foreach ($refundBookings as $refundRow) { if (Validate::isLoadedObject( - $objReturnState = new OrderReturnState($refundRow['current_state'] + $objReturnState = new OrderReturnState($refundRow['state'] ))) { if ($refundFlag == OrderReturnState::ORDER_RETURN_STATE_FLAG_REFUNDED && !$objReturnState->refunded diff --git a/classes/order/OrderDetail.php b/classes/order/OrderDetail.php index 02666c3e5..f71db0527 100644 --- a/classes/order/OrderDetail.php +++ b/classes/order/OrderDetail.php @@ -412,7 +412,7 @@ class OrderDetailCore extends ObjectModel public function updateTaxAmount($order) { $this->setContext((int)$this->id_shop); - $address = new Address((int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); + $address = new Address((int)$order->id_address_tax); $tax_manager = TaxManagerFactory::getManager($address, (int)Product::getIdTaxRulesGroupByIdProduct((int)$this->product_id, $this->context)); $this->tax_calculator = $tax_manager->getTaxCalculator(); @@ -509,7 +509,7 @@ class OrderDetailCore extends ObjectModel $this->ecotax_tax_rate = 0; if (!empty($product['ecotax'])) { - $this->ecotax_tax_rate = Tax::getProductEcotaxRate($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); + $this->ecotax_tax_rate = Tax::getProductEcotaxRate($order->id_address_tax); } } @@ -561,7 +561,7 @@ class OrderDetailCore extends ObjectModel protected function setDetailProductPrice(Order $order, Cart $cart, $product) { $this->setContext((int)$product['id_shop']); - Product::getPriceStatic((int)$product['id_product'], true, (int)$product['id_product_attribute'], 6, null, false, true, $product['cart_quantity'], false, (int)$order->id_customer, (int)$order->id_cart, (int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}, $specific_price, true, true, $this->context); + Product::getPriceStatic((int)$product['id_product'], true, (int)$product['id_product_attribute'], 6, null, false, true, $product['cart_quantity'], false, (int)$order->id_customer, (int)$order->id_cart, null, $specific_price, true, true, $this->context); $this->specificPrice = $specific_price; $this->original_product_price = Product::getPriceStatic($product['id_product'], false, (int)$product['id_product_attribute'], 6, null, false, false, 1, false, null, null, null, $null, true, true, $this->context); $this->product_price = $this->original_product_price; @@ -587,7 +587,7 @@ class OrderDetailCore extends ObjectModel $unit_price = Product::getPriceStatic((int)$product['id_product'], true, ($product['id_product_attribute'] ? intval($product['id_product_attribute']) : null), - 2, null, false, true, 1, false, (int)$order->id_customer, null, (int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}, $null, true, true, $this->context); + 2, null, false, true, 1, false, (int)$order->id_customer, null, null, $null, true, true, $this->context); $this->product_quantity_discount = 0.00; if ($quantity_discount) { $this->product_quantity_discount = $unit_price; @@ -672,7 +672,7 @@ class OrderDetailCore extends ObjectModel */ public function createList(Order $order, Cart $cart, $id_order_state, $product_list, $id_order_invoice = 0, $use_taxes = true, $id_warehouse = 0) { - $this->vat_address = new Address((int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); + $this->vat_address = new Address((int)$order->id_address_tax); $this->customer = new Customer((int)$order->id_customer); $this->id_order = $order->id; @@ -708,7 +708,7 @@ class OrderDetailCore extends ObjectModel $carrier = OrderInvoice::getCarrier((int)$this->id_order_invoice); if (isset($carrier) && Validate::isLoadedObject($carrier)) { - $tax_rate = $carrier->getTaxesRate(new Address((int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); + $tax_rate = $carrier->getTaxesRate(new Address((int)$order->id_address_tax)); } $this->total_shipping_price_tax_excl = (float)$product['additional_shipping_cost']; diff --git a/classes/order/OrderSlip.php b/classes/order/OrderSlip.php index 28b2916ca..f64269d75 100644 --- a/classes/order/OrderSlip.php +++ b/classes/order/OrderSlip.php @@ -357,7 +357,7 @@ class OrderSlipCore extends ObjectModel $order_detail->product_quantity_refunded += $numDays; } - $address = Address::initialize($order->id_address_invoice, false); + $address = Address::initialize($order->id_address_tax, false); $id_address = (int)$address->id; $id_tax_rules_group = Product::getIdTaxRulesGroupByIdProduct((int)$order_detail->product_id); $tax_calculator = TaxManagerFactory::getManager($address, $id_tax_rules_group)->getTaxCalculator(); diff --git a/classes/pdf/HTMLTemplateInvoice.php b/classes/pdf/HTMLTemplateInvoice.php index befe153e7..8d2c7c0c9 100644 --- a/classes/pdf/HTMLTemplateInvoice.php +++ b/classes/pdf/HTMLTemplateInvoice.php @@ -532,7 +532,7 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate { $debug = Tools::getValue('debug'); - $address = new Address((int)$this->order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); + $address = new Address((int)$this->order->id_address_tax); $tax_exempt = Configuration::get('VATNUMBER_MANAGEMENT') && !empty($address->vat_number) && $address->id_country != Configuration::get('VATNUMBER_COUNTRY'); diff --git a/classes/pdf/HTMLTemplateOrderSlip.php b/classes/pdf/HTMLTemplateOrderSlip.php index ee7ccc793..8178636e6 100644 --- a/classes/pdf/HTMLTemplateOrderSlip.php +++ b/classes/pdf/HTMLTemplateOrderSlip.php @@ -198,7 +198,7 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice */ public function getTaxTabContent() { - $address = new Address((int)$this->order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); + $address = new Address((int)$this->order->id_address_tax); $tax_exempt = Configuration::get('VATNUMBER_MANAGEMENT') && !empty($address->vat_number) && $address->id_country != Configuration::get('VATNUMBER_COUNTRY'); diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 15157bf43..1046dcccc 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -1944,7 +1944,7 @@ class AdminOrdersControllerCore extends AdminController false, $order->id_customer, $cart->id, - $order->{Configuration::get('PS_TAX_ADDRESS_TYPE', null, null, $order->id_shop)} + $order->id_address_tax ); // Creating specific price if needed @@ -2248,12 +2248,13 @@ class AdminOrdersControllerCore extends AdminController $obj_cart_bk_data->id_hotel, $idLang ))) { + $addressInfo = $objHotelBranch->getAddress($obj_cart_bk_data->id_hotel); $objHtlBkDtl->hotel_name = $objHotelBranch->hotel_name; - $objHtlBkDtl->city = $objHotelBranch->city; - $objHtlBkDtl->state = State::getNameById($objHotelBranch->state_id); - $objHtlBkDtl->country = Country::getNameById($idLang, $objHotelBranch->country_id); - $objHtlBkDtl->zipcode = $objHotelBranch->zipcode; - $objHtlBkDtl->phone = $objHotelBranch->phone; + $objHtlBkDtl->city = $addressInfo['city']; + $objHtlBkDtl->state = State::getNameById($addressInfo['id_state']); + $objHtlBkDtl->country = Country::getNameById($idLang, $addressInfo['id_country']); + $objHtlBkDtl->zipcode = $addressInfo['postcode'];; + $objHtlBkDtl->phone = $addressInfo['phone']; $objHtlBkDtl->email = $objHotelBranch->email; $objHtlBkDtl->check_in_time = $objHotelBranch->check_in; $objHtlBkDtl->check_out_time = $objHotelBranch->check_out; @@ -3312,7 +3313,7 @@ class AdminOrdersControllerCore extends AdminController $roomDemands = Tools::getValue('room_demands'); if ($roomDemands = json_decode($roomDemands, true)) { $order = new Order($objBookingDetail->id_order); - $vatAddress = new Address((int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); + $vatAddress = new Address((int)$order->id_address_tax); $idLang = (int)$order->id_lang; $idProduct = $objBookingDetail->id_product; $objHtlBkDtl = new HotelBookingDetail(); diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index c9ad78a71..e45b5b3fb 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -207,10 +207,11 @@ class AdminProductsControllerCore extends AdminController LEFT JOIN `'._DB_PREFIX_.'shop` shop ON (shop.id_shop = '.$id_shop.') LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_product` = a.`id_product` AND image_shop.`cover` = 1 AND image_shop.id_shop = '.$id_shop.') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_image` = image_shop.`id_image`) - LEFT JOIN `'._DB_PREFIX_.'product_download` pd ON (pd.`id_product` = a.`id_product` AND pd.`active` = 1)'; + LEFT JOIN `'._DB_PREFIX_.'product_download` pd ON (pd.`id_product` = a.`id_product` AND pd.`active` = 1) + LEFT JOIN `'._DB_PREFIX_.'address` aa ON (aa.`id_hotel` = hb.`id`)'; $this->_select .= ' (SELECT COUNT(hri.`id`) FROM `'._DB_PREFIX_.'htl_room_information` hri WHERE hri.`id_product` = a.`id_product`) as num_rooms, '; - $this->_select .= 'hrt.`adult`, hrt.`children`, hb.`id` as id_hotel, hb.`city`, hbl.`hotel_name`, '; + $this->_select .= 'hrt.`adult`, hrt.`children`, hb.`id` as id_hotel, aa.`city`, hbl.`hotel_name`, '; $this->_select .= 'shop.`name` AS `shopname`, a.`id_shop_default`, '; $this->_select .= $alias_image.'.`id_image` AS `id_image`, cl.`name` AS `name_category`, '.$alias.'.`price`, 0 AS `price_final`, a.`is_virtual`, pd.`nb_downloadable`, sav.`quantity` AS `sav_quantity`, '.$alias.'.`active`, IF(sav.`quantity`<=0, 1, 0) AS `badge_danger`'; @@ -3856,6 +3857,9 @@ class AdminProductsControllerCore extends AdminController 'link' => new Link(), 'pack' => new Pack() )); + + // get hotel address for this room type + $address_infos = Address::getCountryAndState(Cart::getIdAddressForTaxCalculation($obj->id)); } else { $this->displayWarning($this->l('You must save this room type before adding specific pricing')); $product->id_tax_rules_group = (int)Product::getIdTaxRulesGroupMostUsed(); @@ -3863,7 +3867,14 @@ class AdminProductsControllerCore extends AdminController } $address = new Address(); - $address->id_country = (int)$this->context->country->id; + // $address->id_country = (int)$this->context->country->id; + if (!$address_infos) { + $address->id_country = (int)$this->context->country->id; + } else { + $address->id_country = (int)$address_infos['id_country']; + $address->id_state = (int)$address_infos['id_state']; + $address->zipcode = $address_infos['postcode']; + } $tax_rules_groups = TaxRulesGroup::getTaxRulesGroups(true); $tax_rates = array( 0 => array( diff --git a/controllers/admin/AdminTaxesController.php b/controllers/admin/AdminTaxesController.php index 0c6c0bfdc..e5c6bef16 100644 --- a/controllers/admin/AdminTaxesController.php +++ b/controllers/admin/AdminTaxesController.php @@ -71,21 +71,22 @@ class AdminTaxesControllerCore extends AdminController 'desc' => $this->l('Select whether or not to display tax on a distinct line in the cart.'), 'cast' => 'intval', 'type' => 'bool'), - 'PS_TAX_ADDRESS_TYPE' => array( - 'title' => $this->l('Based on'), - 'cast' => 'pSQL', - 'type' => 'select', - 'list' => array( - array( - 'name' => $this->l('Invoice address'), - 'id' => 'id_address_invoice' - ), - array( - 'name' => $this->l('Delivery address'), - 'id' => 'id_address_delivery') - ), - 'identifier' => 'id' - ), + // 'PS_TAX_ADDRESS_TYPE' => array( + // 'title' => $this->l('Based on'), + // 'cast' => 'pSQL', + // 'type' => 'select', + // 'list' => array( + // array( + // 'name' => $this->l('Invoice address'), + // 'id' => 'id_address_invoice' + // ), + // array( + // 'name' => $this->l('Delivery address'), + // 'id' => 'id_address_delivery') + // ), + // ), + // 'identifier' => 'id' + // ), 'PS_USE_ECOTAX' => array( 'title' => $this->l('Use ecotax'), 'desc' => $ecotax_desc, diff --git a/controllers/front/AuthController.php b/controllers/front/AuthController.php index 96c3ea223..ee494227e 100644 --- a/controllers/front/AuthController.php +++ b/controllers/front/AuthController.php @@ -449,20 +449,21 @@ class AuthControllerCore extends FrontController $objHtlCart = new HotelCartBookingData(); if ($htlCartInfo = $objHtlCart->getCartCurrentDataByCartId($this->context->cart->id)) { if (isset($htlCartInfo[0]['id_hotel']) && ($idHotel = $htlCartInfo[0]['id_hotel'])) { - if (Validate::isLoadedObject($objHotel = new HotelBranchInformation($idHotel))) { - $_POST['lastname'] = Tools::getValue('customer_lastname'); - $_POST['firstname'] = Tools::getValue('customer_firstname'); - $_POST['address1'] = $objHotel->address; - $_POST['city'] = $objHotel->city; - $_POST['postcode'] = $objHotel->zipcode; - $_POST['alias'] = 'My address'; - $_POST['id_country'] = $objHotel->country_id; - $_POST['id_state'] = $objHotel->state_id; - $_POST['auto_generated'] = true; - // if form is shorter then address name will be customer name - $lastnameAddress = $_POST['lastname']; - $firstnameAddress = $_POST['firstname']; - + if ($objHotel = new HotelBranchInformation()) { + if ($address_info = $objHotel->getAddress($idHotel)) { + $_POST['lastname'] = Tools::getValue('customer_lastname'); + $_POST['firstname'] = Tools::getValue('customer_firstname'); + $_POST['address1'] = $address_info['address1']; + $_POST['city'] = $address_info['city']; + $_POST['postcode'] = $address_info['postcode']; + $_POST['alias'] = 'My address'; + $_POST['id_country'] = $address_info['id_country']; + $_POST['id_state'] = $address_info['id_state']; + $_POST['auto_generated'] = true; + // if form is shorter then address name will be customer name + $lastnameAddress = $_POST['lastname']; + $firstnameAddress = $_POST['firstname']; + } } } } @@ -586,7 +587,7 @@ class AuthControllerCore extends FrontController } elseif (!$country->need_identification_number) { $$addresses_type->dni = null; } - + if (Tools::isSubmit('submitAccount') || Tools::isSubmit('submitGuestAccount')) { if (!($country = new Country($$addresses_type->id_country, Configuration::get('PS_LANG_DEFAULT'))) || !Validate::isLoadedObject($country)) { $this->errors[] = Tools::displayError('Country is invalid'); diff --git a/controllers/front/ParentOrderController.php b/controllers/front/ParentOrderController.php index 57a353345..97a66c919 100644 --- a/controllers/front/ParentOrderController.php +++ b/controllers/front/ParentOrderController.php @@ -311,7 +311,7 @@ class ParentOrderControllerCore extends FrontController $productAttributeId = (int)isset($productUpdate['id_product_attribute']) ? $productUpdate['id_product_attribute'] : $productUpdate['product_attribute_id']; if (isset($customizedDatas[$productId][$productAttributeId])) { - $productUpdate['tax_rate'] = Tax::getProductTaxRate($productId, $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); + $productUpdate['tax_rate'] = Tax::getProductTaxRate($productId, Cart::getIdAddressForTaxCalculation($productId)); } } diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index 2d85e00c0..7cd04cf15 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -280,9 +280,9 @@ class ProductControllerCore extends FrontController $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; + $addressInfo = $obj_hotel_branch->getAddress($room_info_by_product_id['id_hotel']); + $hotel_location = $addressInfo['city']. + ($addressInfo['id_state']?', '.$addressInfo['state']:'').', '.$addressInfo['country']; $obj_hotel_feaures_ids = $obj_hotel_branch->getFeaturesOfHotelByHotelId($hotel_id); @@ -470,7 +470,7 @@ class ProductControllerCore extends FrontController } // Tax - $tax = (float)$this->product->getTaxesRate(new Address((int)$this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); + $tax = (float)$this->product->getTaxesRate(); $this->context->smarty->assign('tax_rate', $tax); $product_price_with_tax = Product::getPriceStatic($this->product->id, true, null, 6); @@ -479,7 +479,7 @@ class ProductControllerCore extends FrontController } $product_price_without_eco_tax = (float)$product_price_with_tax - $this->product->ecotax; - $ecotax_rate = (float)Tax::getProductEcotaxRate($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); + $ecotax_rate = (float)Tax::getProductEcotaxRate(Cart::getIdAddressForTaxCalculation($this->product->id)); if (Product::$_taxCalculationMethod == PS_TAX_INC && (int)Configuration::get('PS_TAX')) { $ecotax_tax_amount = Tools::ps_round($this->product->ecotax * (1 + $ecotax_rate / 100), 2); } else { @@ -510,7 +510,7 @@ class ProductControllerCore extends FrontController } } - $address = new Address($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); + $address = new Address(Cart::getIdAddressForTaxCalculation($this->product->id)); $this->context->smarty->assign( array( 'quantity_discounts' => $this->formatQuantityDiscounts($quantity_discounts, null, (float)$tax, $ecotax_tax_amount), diff --git a/install/data/db_structure.sql b/install/data/db_structure.sql index 60fc52813..a3aa8160d 100644 --- a/install/data/db_structure.sql +++ b/install/data/db_structure.sql @@ -25,6 +25,7 @@ CREATE TABLE `PREFIX_address` ( `id_manufacturer` int(10) unsigned NOT NULL DEFAULT '0', `id_supplier` int(10) unsigned NOT NULL DEFAULT '0', `id_warehouse` int(10) unsigned NOT NULL DEFAULT '0', + `id_hotel` int(10) unsigned NOT NULL DEFAULT '0', `alias` varchar(32) NOT NULL, `company` varchar(255) DEFAULT NULL, `lastname` varchar(32) NOT NULL, @@ -1101,6 +1102,7 @@ CREATE TABLE `PREFIX_orders` ( `id_currency` int(10) unsigned NOT NULL, `id_address_delivery` int(10) unsigned NOT NULL, `id_address_invoice` int(10) unsigned NOT NULL, + `id_address_tax` int(10) unsigned NOT NULL, `current_state` int(10) unsigned NOT NULL, `secure_key` varchar(32) NOT NULL DEFAULT '-1', `payment` varchar(255) NOT NULL, diff --git a/modules/hotelreservationsystem/classes/HotelBranchInformation.php b/modules/hotelreservationsystem/classes/HotelBranchInformation.php index fb4561107..cbbe4cd0e 100644 --- a/modules/hotelreservationsystem/classes/HotelBranchInformation.php +++ b/modules/hotelreservationsystem/classes/HotelBranchInformation.php @@ -22,18 +22,12 @@ class HotelBranchInformation extends ObjectModel { public $id_category; public $hotel_name; - public $phone; public $email; public $check_in; public $check_out; public $description; public $short_description; public $rating; - public $city; - public $state_id; - public $country_id; - public $zipcode; - public $address; public $policies; public $active; public $latitude; @@ -50,16 +44,10 @@ class HotelBranchInformation extends ObjectModel 'multilang' => true, 'fields' => array( 'id_category' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), - 'phone' => array('type' => self::TYPE_STRING,'validate' => 'isPhoneNumber', 'size' => 32), 'email' => array('type' => self::TYPE_STRING,'validate' => 'isEmail', 'size' => 255), 'rating' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'check_in' => array('type' => self::TYPE_STRING), 'check_out' => array('type' => self::TYPE_STRING), - 'address' => array('type' => self::TYPE_STRING), - 'city' => array('type' => self::TYPE_STRING, 'validate' => 'isCityName', 'required' => true, 'size' => 64), - 'state_id' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), - 'country_id' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), - 'zipcode' => array('type' => self::TYPE_STRING), 'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'latitude' => array('type' => self::TYPE_FLOAT), 'longitude' => array('type' => self::TYPE_FLOAT), @@ -317,29 +305,36 @@ class HotelBranchInformation extends ObjectModel if (!$idLang) { $idLang = Context::getContext()->language->id; } - $sql = 'SELECT hbi.*, hbl.`policies`, hbl.`hotel_name`, hbl.`description`, hbl.`short_description`'; - if ($detailedInfo) { - $sql .= ', hi.id as id_cover_img, s.`name` as `state_name`, cl.`name` as country_name'; - } - $sql .= ' FROM `'._DB_PREFIX_.'htl_branch_info` hbi'; - $sql .= ' LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbl - ON (hbl.`id` = hbi.`id` AND hbl.`id_lang` = '.(int)$idLang.')'; - if ($detailedInfo) { - $sql .= ' LEFT JOIN `'._DB_PREFIX_.'htl_image` hi ON (hi.`id_hotel` = hbi.`id` AND hi.`cover` = 1)'; - $sql .= ' LEFT JOIN `'._DB_PREFIX_.'state` s ON (s.`id_state` = hbi.`state_id`)'; - $sql .= ' LEFT JOIN `'._DB_PREFIX_. - 'country_lang` cl ON (cl.`id_country` = hbi.`country_id` AND cl.`id_lang` = '.(int)$idLang.')'; - } - $sql .= ' WHERE 1'; - if ($active == 1 || $active == 0) { - $sql .= ' AND hbi.`active` = '.(int)$active; - } - if ($idHotel) { - $sql .= ' AND hbi.`id` = '.(int)$idHotel; - return Db::getInstance()->getRow($sql); - } else { - return Db::getInstance()->executeS($sql); + $cache_id = 'hotelBranch::hotelBranchesInfo'.(int)$idLang.'-'.(int)$active.'-'.(int)$detailedInfo.'-'.(int)$idHotel; + if (!Cache::isStored($cache_id)) { + $sql = 'SELECT hbi.*, hbl.`policies`, hbl.`hotel_name`, hbl.`description`, hbl.`short_description`'; + if ($detailedInfo) { + $sql .= ', hi.id as id_cover_img, a.`city`, s.`name` as `state_name`, cl.`name` as country_name'; + } + $sql .= ' FROM `'._DB_PREFIX_.'htl_branch_info` hbi'; + $sql .= ' LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbl + ON (hbl.`id` = hbi.`id` AND hbl.`id_lang` = '.(int)$idLang.')'; + if ($detailedInfo) { + $sql .= ' LEFT JOIN `'._DB_PREFIX_.'htl_image` hi ON (hi.`id_hotel` = hbi.`id` AND hi.`cover` = 1)'; + $sql .= ' LEFT JOIN `'._DB_PREFIX_.'address` a ON (a.`id_hotel` = hbi.`id`)'; + $sql .= ' LEFT JOIN `'._DB_PREFIX_.'state` s ON (s.`id_state` = a.`id_state`)'; + $sql .= ' LEFT JOIN `'._DB_PREFIX_. + 'country_lang` cl ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = '.(int)$idLang.')'; + } + $sql .= ' WHERE 1'; + if ($active == 1 || $active == 0) { + $sql .= ' AND hbi.`active` = '.(int)$active; + } + if ($idHotel) { + $sql .= ' AND hbi.`id` = '.(int)$idHotel; + $result = Db::getInstance()->getRow($sql); + } else { + $result = Db::getInstance()->executeS($sql); + } + Cache::store($cache_id, $result); + return $result; } + return Cache::retrieve($cache_id); } /** @@ -357,6 +352,47 @@ class HotelBranchInformation extends ObjectModel return Db::getInstance()->executeS($sql); } + /** + * [getHotelIdAddress: get id_address for current hotel] + * + * @return int + */ + public function getHotelIdAddress() + { + return Db::getInstance()->getValue( + 'SELECT `id_address` from `'._DB_PREFIX_.'address` WHERE `id_hotel` = '.(int)$this->id.' AND `deleted` = 0 + '); + } + + /** + * [getAddress: get complete address for hotel by id_hotel] + * + * @param [int] $id_hotel + * @param int $id_lang + * @return array + */ + public function getAddress($id_hotel, $id_lang = false) + { + if (!$id_lang) + $id_lang = Context::getContext()->language->id; + + $cache_id = 'hotelBranch::getAddress'.(int)$id_hotel.'-'.(int)$id_lang; + if (!Cache::isStored($cache_id)) { + $sql = 'SELECT a.*, cl.`name` AS country, s.`name` AS state, s.`iso_code` AS state_iso + FROM `'._DB_PREFIX_.'address` a + LEFT JOIN `'._DB_PREFIX_.'country` c ON (a.`id_country` = c.`id_country`) + LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (c.`id_country` = cl.`id_country`) + LEFT JOIN `'._DB_PREFIX_.'state` s + ON (s.`id_state` = a.`id_state` AND`id_lang` = '.(int)$id_lang.') + WHERE `id_hotel` = '.(int)$id_hotel.' AND a.`deleted` = 0'; + + $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); + Cache::store($cache_id, $result); + return $result; + } + return Cache::retrieve($cache_id); + } + /** * Deprecated * [hotelBranchInfoById : Hotel's information By its id]. diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index 61cd21458..ac3db9f25 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -863,9 +863,12 @@ class HotelCartBookingData extends ObjectModel 1, $roomDetail['id_hotel'] )) { - $hotelInfo['location'] = $hotelInfo['hotel_name'].', '.$hotelInfo['city'].', '.State::getNameById($hotelInfo['state_id']).', '. - Country::getNameById($idLang, $hotelInfo['country_id']) - .', '.$hotelInfo['zipcode']; + $addressInfo = $objHotelBranch->getAddress($roomDetail['id_hotel']); + + $hotelInfo['location'] = $hotelInfo['hotel_name'].', '.$addressInfo['city']. + ($addressInfo['id_state']?', '.$addressInfo['state']:'').', '. + $addressInfo['country'].', '.$addressInfo['postcode']; + // append hotel features if ($hotelFeaureIds = $objHotelBranch->getFeaturesOfHotelByHotelId($roomDetail['id_hotel'])) { diff --git a/modules/hotelreservationsystem/classes/HotelHelper.php b/modules/hotelreservationsystem/classes/HotelHelper.php index 962498120..1db381ff2 100644 --- a/modules/hotelreservationsystem/classes/HotelHelper.php +++ b/modules/hotelreservationsystem/classes/HotelHelper.php @@ -352,10 +352,8 @@ class HotelHelper public function saveDummyHotelBranchInfo() { - $def_cont_id = Country::getDefaultCountryId(); $obj_hotel_info = new HotelBranchInformation(); $obj_hotel_info->active = 1; - $obj_hotel_info->phone = '0987654321'; $obj_hotel_info->email = 'hotelprime@htl.com'; $obj_hotel_info->check_in = '12:00'; $obj_hotel_info->check_out = '11:00'; @@ -373,19 +371,31 @@ class HotelHelper } $obj_hotel_info->rating = 3; - $obj_hotel_info->city = 'DefCity'; + + $obj_hotel_info->save(); + $htl_id = $obj_hotel_info->id; + + // add hotel address info + $def_cont_id = Country::getDefaultCountryId(); + if ($states = State::getStatesByIdCountry($def_cont_id)) { $state_id = $states[0]['id_state']; } else { $state_id = 0; } - $obj_hotel_info->state_id = $state_id; - $obj_hotel_info->country_id = $def_cont_id; - $obj_hotel_info->zipcode = self::getRandomZipcodeByForCountry($def_cont_id); - $obj_hotel_info->address = 'Monticello Dr, Montgomery, AL 36117, USA'; - $obj_hotel_info->save(); + $objAddress = new Address(); + $objAddress->id_hotel = $htl_id; + $objAddress->phone = '0987654321'; + $objAddress->city = 'DefCity'; + $objAddress->id_state = $state_id; + $objAddress->id_country = $def_cont_id; + $objAddress->postcode = self::getRandomZipcodeByForCountry($def_cont_id); + $objAddress->address1 = 'Monticello Dr, Montgomery, AL 36117, USA'; + $objAddress->alias = 'The Hotel Prime'; + $objAddress->lastname = 'The Hotel Prime'; + $objAddress->firstname = 'The Hotel Prime'; - $htl_id = $obj_hotel_info->id; + $objAddress->save(); $grp_ids = array(); $obj_grp = new Group(); diff --git a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php index 5bad7f2ce..4ec8282c2 100644 --- a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php +++ b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php @@ -33,7 +33,7 @@ class HotelReservationSystemDb `date_upd` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_room_information` ( `id` int(11) NOT NULL AUTO_INCREMENT, `id_product` int(11) NOT NULL, @@ -46,20 +46,14 @@ class HotelReservationSystemDb `date_upd` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_branch_info` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `id_category` int(10) unsigned NOT NULL, - `phone` varchar(32) DEFAULT NULL, `email` varchar(128) NOT NULL, `check_in` varchar(255) DEFAULT NULL, `check_out` varchar(255) DEFAULT NULL, `rating` int(2) unsigned NOT NULL, - `city` varchar(64) NOT NULL, - `state_id` int(10) unsigned NOT NULL, - `country_id` int(10) unsigned NOT NULL, - `zipcode` varchar(12) NOT NULL, - `address` text DEFAULT NULL, `active` tinyint(1) unsigned NOT NULL DEFAULT '0', `latitude` decimal(10,8) NOT NULL, `longitude` decimal(11,8) NOT NULL, @@ -70,7 +64,7 @@ class HotelReservationSystemDb `date_upd` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_branch_info_lang` ( `id` int(10) unsigned NOT NULL, `id_lang` int(10) unsigned NOT NULL, @@ -80,7 +74,7 @@ class HotelReservationSystemDb `policies` text, PRIMARY KEY (`id`, `id_lang`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_image` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `id_hotel` int(10) unsigned NOT NULL, @@ -88,7 +82,7 @@ class HotelReservationSystemDb `cover` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_branch_features` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `id_hotel` int(10) unsigned NOT NULL, @@ -97,7 +91,7 @@ class HotelReservationSystemDb `date_upd` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_features` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `parent_feature_id` int(10) unsigned NOT NULL, @@ -107,14 +101,14 @@ class HotelReservationSystemDb `date_upd` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_features_lang` ( `id` int(10) unsigned NOT NULL, `id_lang` int(10) unsigned NOT NULL, `name` varchar(255) NOT NULL, PRIMARY KEY (`id`, `id_lang`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_cart_booking_data` ( `id` int(11) NOT NULL AUTO_INCREMENT, `id_cart` int(11) NOT NULL, @@ -137,7 +131,7 @@ class HotelReservationSystemDb `date_upd` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_booking_detail` ( `id` int(11) NOT NULL AUTO_INCREMENT, `id_product` int(11) NOT NULL, @@ -177,7 +171,7 @@ class HotelReservationSystemDb `date_upd` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_booking_demands` ( `id_booking_demand` int(11) NOT NULL AUTO_INCREMENT, `id_htl_booking` int(11) NOT NULL, @@ -193,7 +187,7 @@ class HotelReservationSystemDb `date_upd` datetime NOT NULL, PRIMARY KEY (`id_booking_demand`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_booking_demands_tax` ( `id_booking_demand` int(11) NOT NULL AUTO_INCREMENT, `id_tax` int(11) NOT NULL, @@ -201,19 +195,19 @@ class HotelReservationSystemDb `total_amount` DECIMAL(16, 6) NOT NULL DEFAULT '0.00', PRIMARY KEY (`id_booking_demand`, `id_tax`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_room_status` ( `id` int(11) NOT NULL AUTO_INCREMENT, `status` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_room_allotment_type` ( `id` int(11) NOT NULL AUTO_INCREMENT, `type` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_advance_payment` ( `id` int(11) NOT NULL AUTO_INCREMENT, `id_product` int(11) NOT NULL, @@ -227,7 +221,7 @@ class HotelReservationSystemDb `date_upd` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_order_refund_rules` ( `id_refund_rule` int(11) NOT NULL AUTO_INCREMENT, `payment_type` int(2) unsigned NOT NULL, @@ -238,7 +232,7 @@ class HotelReservationSystemDb `date_upd` datetime NOT NULL, PRIMARY KEY (`id_refund_rule`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_order_refund_rules_lang` ( `id_refund_rule` int(10) unsigned NOT NULL, `id_lang` int(10) unsigned NOT NULL, @@ -246,7 +240,7 @@ class HotelReservationSystemDb `description` text, PRIMARY KEY (`id_refund_rule`, `id_lang`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_branch_refund_rules` ( `id_hotel_refund_rule` int(11) NOT NULL AUTO_INCREMENT, `id_refund_rule` int(10) unsigned NOT NULL, @@ -256,7 +250,7 @@ class HotelReservationSystemDb `date_upd` datetime NOT NULL, PRIMARY KEY (`id_hotel_refund_rule`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_order_restrict_date` ( `id` int(11) NOT NULL AUTO_INCREMENT, `id_hotel` int(11) NOT NULL, @@ -265,7 +259,7 @@ class HotelReservationSystemDb `date_upd` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_room_type_feature_pricing` ( `id_feature_price` int(11) NOT NULL AUTO_INCREMENT, `id_product` int(11) NOT NULL, @@ -282,20 +276,20 @@ class HotelReservationSystemDb `date_upd` datetime NOT NULL, PRIMARY KEY (`id_feature_price`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_room_type_feature_pricing_lang` ( `id_feature_price` int(10) unsigned NOT NULL, `id_lang` int(10) unsigned NOT NULL, `feature_price_name` varchar(255) character set utf8 NOT NULL, PRIMARY KEY (`id_feature_price`, `id_lang`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_room_type_feature_pricing_group` ( `id_feature_price` int(10) unsigned NOT NULL, `id_group` int(10) unsigned NOT NULL, PRIMARY KEY (`id_feature_price`,`id_group`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_room_type_global_demand` ( `id_global_demand` int(11) NOT NULL AUTO_INCREMENT, `price` decimal(20,6) NOT NULL DEFAULT '0.000000', @@ -305,14 +299,14 @@ class HotelReservationSystemDb `date_upd` datetime NOT NULL, PRIMARY KEY (`id_global_demand`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_room_type_global_demand_lang` ( `id_global_demand` int(10) unsigned NOT NULL, `id_lang` int(10) unsigned NOT NULL, `name` varchar(255) character set utf8 NOT NULL, PRIMARY KEY (`id_global_demand`, `id_lang`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_room_type_global_demand_advance_option` ( `id_option` int(11) NOT NULL AUTO_INCREMENT, `id_global_demand` int(11) NOT NULL, @@ -321,14 +315,14 @@ class HotelReservationSystemDb `date_upd` datetime NOT NULL, PRIMARY KEY (`id_option`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_room_type_global_demand_advance_option_lang` ( `id_option` int(10) unsigned NOT NULL, `id_lang` int(10) unsigned NOT NULL, `name` varchar(255) character set utf8 NOT NULL, PRIMARY KEY (`id_option`, `id_lang`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_room_type_demand_price` ( `id_room_type_demand_price` int(11) NOT NULL AUTO_INCREMENT, `id_product` int(10) unsigned NOT NULL, @@ -339,7 +333,7 @@ class HotelReservationSystemDb `date_upd` datetime NOT NULL, PRIMARY KEY (`id_room_type_demand_price`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_room_type_demand` ( `id_room_type_demand` int(11) NOT NULL AUTO_INCREMENT, `id_product` int(10) unsigned NOT NULL, @@ -348,7 +342,7 @@ class HotelReservationSystemDb `date_upd` datetime NOT NULL, PRIMARY KEY (`id_room_type_demand`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_room_disable_dates` ( `id` int(11) NOT NULL AUTO_INCREMENT, `id_room_type` int(11) NOT NULL, @@ -360,7 +354,7 @@ class HotelReservationSystemDb `date_upd` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", - + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_access` ( `id_profile` int(10) unsigned NOT NULL, `id_hotel` int(10) unsigned NOT NULL, diff --git a/modules/hotelreservationsystem/classes/HotelRoomType.php b/modules/hotelreservationsystem/classes/HotelRoomType.php index 9fd4c3afc..714a3e1ae 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomType.php +++ b/modules/hotelreservationsystem/classes/HotelRoomType.php @@ -97,6 +97,22 @@ class HotelRoomType extends ObjectModel return Db::getInstance()->getRow($sql); } + /** + * [getHotelIdAddressByIdProduct: get room type location by id_product] + * + * @param [int] $id_product + * @return int + */ + public static function getHotelIdAddressByIdProduct($id_product) + { + return Db::getInstance()->getValue( + 'SELECT `id_address` from `'._DB_PREFIX_.'address` a + INNER JOIN `'._DB_PREFIX_.'htl_room_type` hrt + ON (hrt.`id_hotel` = a.`id_hotel`) + WHERE hrt.`id_product` = '.(int)$id_product.' AND a.`deleted` = 0 + '); + } + /** * [getRoomTypeByHotelId :: To get All room types informations which belong to the hotel having id passed as $hotel_id]. * diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeDemand.php b/modules/hotelreservationsystem/classes/HotelRoomTypeDemand.php index 4d7cbef3e..58706f81c 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeDemand.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeDemand.php @@ -146,23 +146,16 @@ class HotelRoomTypeDemand extends ObjectModel $idState = 0; $zipcode = 0; - if (!$id_address && Validate::isLoadedObject($curCart)) { - $id_address = $curCart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}; - } - if ($id_address) { $addressInfos = Address::getCountryAndState($id_address); - if ($addressInfos['id_country']) { - $idCountry = (int)$addressInfos['id_country']; - $idState = (int)$addressInfos['id_state']; - $zipcode = $addressInfos['postcode']; - } - } elseif (isset($context->customer->geoloc_id_country)) { - $idCountry = (int)$context->customer->geoloc_id_country; - $idState = (int)$context->customer->id_state; - $zipcode = $context->customer->postcode; + } else { + $addressInfos = Address::getCountryAndState(Cart::getIdAddressForTaxCalculation($idProduct)); + } + if ($addressInfos['id_country']) { + $idCountry = (int)$addressInfos['id_country']; + $idState = (int)$addressInfos['id_state']; + $zipcode = $addressInfos['postcode']; } - if (Tax::excludeTaxeOption()) { $useTax = false; } diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index 26718aaef..13a33e685 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -38,11 +38,12 @@ class AdminAddHotelController extends ModuleAdminController $this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbl ON (a.id = hbl.id AND hbl.`id_lang` = '.(int) $this->context->language->id.')'; - $this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'state` s ON (s.`id_state` = a.`state_id`)'; + $this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'address` aa ON (aa.`id_hotel` = a.`id`)'; + $this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'state` s ON (s.`id_state` = aa.`id_state`)'; $this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'country_lang` cl - ON (cl.`id_country` = a.`country_id` AND cl.`id_lang` = '.(int) $this->context->language->id.')'; + ON (cl.`id_country` = aa.`id_country` AND cl.`id_lang` = '.(int) $this->context->language->id.')'; - $this->_select = ' hbl.`hotel_name`, s.`name` as `state_name`, cl.`name` as country_name'; + $this->_select = ' hbl.`hotel_name`, aa.`city`, s.`name` as `state_name`, cl.`name` as country_name'; $this->fields_list = array( 'id' => array( @@ -125,9 +126,10 @@ class AdminAddHotelController extends ModuleAdminController if ($this->display == 'edit') { $idHotel = Tools::getValue('id'); - $hotelBranchInfo = (array) (new HotelBranchInformation($idHotel)); + $hotelBranchInfo = new HotelBranchInformation($idHotel); - $statesbycountry = State::getStatesByIdCountry($hotelBranchInfo['country_id']); + $addressInfo = $hotelBranchInfo->getAddress($idHotel); + $statesbycountry = State::getStatesByIdCountry($addressInfo['id_country']); $states = array(); if ($statesbycountry) { @@ -137,8 +139,9 @@ class AdminAddHotelController extends ModuleAdminController } } $smartyVars['edit'] = 1; - $smartyVars['state_var'] = $states; - $smartyVars['hotel_info'] = $hotelBranchInfo; + $smartyVars['state_var'] = $states; + $smartyVars['address_info'] = $addressInfo; + $smartyVars['hotel_info'] = (array) $hotelBranchInfo; //Hotel Images $objHotelImage = new HotelImage(); if ($hotelAllImages = $objHotelImage->getAllImagesByHotelId($idHotel)) { @@ -367,16 +370,10 @@ class AdminAddHotelController extends ModuleAdminController ); } } - $objHotelBranch->phone = $phone; $objHotelBranch->email = $email; $objHotelBranch->check_in = $check_in; $objHotelBranch->check_out = $check_out; $objHotelBranch->rating = $rating; - $objHotelBranch->city = $city; - $objHotelBranch->state_id = $state; - $objHotelBranch->country_id = $country; - $objHotelBranch->zipcode = $zipcode; - $objHotelBranch->address = $address; $objHotelBranch->latitude = $latitude; $objHotelBranch->longitude = $longitude; $objHotelBranch->map_formated_address = $map_formated_address; @@ -387,6 +384,26 @@ class AdminAddHotelController extends ModuleAdminController $categsBeforeUpd = $objHotelBranch->getAllHotelCategories(); if ($newIdHotel = $objHotelBranch->id) { + + // getHotel address + if ($idHotelAddress = $objHotelBranch->getHotelIdAddress()) { + $objAddress = new Address($idHotelAddress); + } else { + $objAddress = new Address(); + } + $objAddress->id_hotel = $newIdHotel; + $objAddress->id_country = $country; + $objAddress->id_state = $state; + $objAddress->city = $city; + $objAddress->postcode = $zipcode; + $objAddress->alias = Tools::getValue('hotel_name_'.$defaultLangId); + $objAddress->lastname = Tools::getValue('hotel_name_'.$defaultLangId); + $objAddress->firstname = Tools::getValue('hotel_name_'.$defaultLangId); + $objAddress->address1 = $address; + $objAddress->phone = $phone; + + $objAddress->save(); + // Save refund rules of the hotels if ($hotelRefundRules = Tools::getValue('htl_refund_rules')) { foreach ($hotelRefundRules as $key => $idRefundRule) { diff --git a/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php b/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php index 54c783038..4d32141db 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php @@ -392,6 +392,9 @@ class AdminOrderRefundRequestsController extends ModuleAdminController $objOrderReturn->refunded_amount = $totalRefundedAmount; if ($objOrderReturn->save()) { + // change state of the order refund + $objOrderReturn->changeIdOrderReturnState($idRefundState, $idOrderReturn); + if ($objRefundState->refunded || $objRefundState->denied) { // check if order is paid the set status of the order to refunded $objOrderHistory = new OrderHistory(); @@ -503,9 +506,6 @@ class AdminOrderRefundRequestsController extends ModuleAdminController } } - // change state of the order refund - $objOrderReturn->changeIdOrderReturnState($idRefundState, $idOrderReturn); - // redirect with success if process completed successfully Tools::redirectAdmin( self::$currentIndex.'&conf=4&id_order_return='.$idOrderReturn. diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php index 0a0c2544f..2cb6a4b62 100644 --- a/modules/hotelreservationsystem/hotelreservationsystem.php +++ b/modules/hotelreservationsystem/hotelreservationsystem.php @@ -359,7 +359,7 @@ class hotelreservationsystem extends Module $obj_adv_payment = new HotelAdvancedPayment(); $orderProducts = $order->product_list; - $vatAddress = new Address((int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); + $vatAddress = new Address((int)$order->id_address_tax); $idLang = (int)$cart->id_lang; @@ -411,14 +411,16 @@ class hotelreservationsystem extends Module ))) { $objHtlBkDtl->hotel_name = $objHotelBranch->hotel_name; $objHtlBkDtl->room_type_name = $product['name']; - $objHtlBkDtl->city = $objHotelBranch->city; - $objHtlBkDtl->state = State::getNameById($objHotelBranch->state_id); - $objHtlBkDtl->country = Country::getNameById($idLang, $objHotelBranch->country_id); - $objHtlBkDtl->zipcode = $objHotelBranch->zipcode; - $objHtlBkDtl->phone = $objHotelBranch->phone; $objHtlBkDtl->email = $objHotelBranch->email; $objHtlBkDtl->check_in_time = $objHotelBranch->check_in; $objHtlBkDtl->check_out_time = $objHotelBranch->check_out; + if ($hotelAddress = $objHotelBranch->getAddress($objCartBkData->id_hotel)) { + $objHtlBkDtl->city = $hotelAddress['city']; + $objHtlBkDtl->state = $hotelAddress['state']; + $objHtlBkDtl->country = $hotelAddress['country']; + $objHtlBkDtl->zipcode = $hotelAddress['postcode']; + $objHtlBkDtl->phone = $hotelAddress['phone']; + } } if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($idProduct)) { $objHtlBkDtl->adult = $roomTypeInfo['adult']; diff --git a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl index 32447a834..41bb1334e 100644 --- a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl @@ -129,7 +129,7 @@
- +
@@ -146,7 +146,7 @@
- +
@@ -188,7 +188,7 @@ {if $country_var} {foreach $country_var as $countr} - + {/foreach} {/if} @@ -204,7 +204,7 @@ {if isset($edit)} {if $state_var} {foreach $state_var as $state} - + {/foreach} {/if} {else} @@ -217,13 +217,13 @@
- +
- +