Merge branch 'develop' into gli-1949
This commit is contained in:
@@ -180,7 +180,7 @@ class AddressCore extends ObjectModel
|
||||
{
|
||||
// for customer address we need to check of customer address already exists.
|
||||
if ($this->id_customer) {
|
||||
if ($id_address = Customer::getCustomerIdAddress($this->id_customer, false)) {
|
||||
if ($this->deleted == 0 && $id_address = Customer::getCustomerIdAddress($this->id_customer, false)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -196,6 +196,8 @@ class AddressCore extends ObjectModel
|
||||
|
||||
public function update($null_values = false)
|
||||
{
|
||||
|
||||
$context = Context::getContext();
|
||||
// Empty related caches
|
||||
if (isset(self::$_idCountries[$this->id])) {
|
||||
unset(self::$_idCountries[$this->id]);
|
||||
@@ -208,9 +210,42 @@ class AddressCore extends ObjectModel
|
||||
Customer::resetAddressCache($this->id_customer, $this->id);
|
||||
}
|
||||
|
||||
// If address is already used in any order, it will not be edited directly, set address to "deleted" and create a new address
|
||||
if ($this->isUsed() && $this->deleted == 0) {
|
||||
return $this->updateUsedAddress($this);
|
||||
}
|
||||
|
||||
return parent::update($null_values);
|
||||
}
|
||||
|
||||
/**
|
||||
* If address is already used in any order
|
||||
* set address to "deleted" and create a new address
|
||||
* @param Address $address
|
||||
* @return bool
|
||||
*/
|
||||
public function updateUsedAddress(Address $address)
|
||||
{
|
||||
$objOldAddress = new Address($address->id);
|
||||
$address->id = $address->id_address = null;
|
||||
|
||||
if ($objOldAddress->delete() && $address->save()) {
|
||||
// we need to change the address id in the current cart as the deleted ID can assigned in context->cart.
|
||||
if ($customerCarts = Cart::getCustomerCarts($objOldAddress->id_customer, false)) {
|
||||
foreach ($customerCarts as $cart) {
|
||||
$objCart = new Cart($cart['id_cart']);
|
||||
if ($cart['id_address_invoice'] == $objOldAddress->id) {
|
||||
$objCart->updateAddressId($objOldAddress->id, $address->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ObjectModel::delete()
|
||||
*/
|
||||
@@ -222,12 +257,12 @@ class AddressCore extends ObjectModel
|
||||
// reset checkout process if addresses deletes
|
||||
CheckoutProcess::refreshCheckoutProcess();
|
||||
|
||||
if (!$this->isUsed()) {
|
||||
return parent::delete();
|
||||
} else {
|
||||
if ($this->isUsed()) {
|
||||
$this->deleted = true;
|
||||
return $this->update();
|
||||
}
|
||||
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -252,10 +287,9 @@ class AddressCore extends ObjectModel
|
||||
|
||||
// for customer address we need to check of customer address already exists.
|
||||
// if we are editing an address we do not need to validate already created address.
|
||||
if (!Validate::isLoadedObject($this)) {
|
||||
if (!Validate::isLoadedObject($this) && $this->deleted != 0) {
|
||||
if ($idCustomer = Tools::getValue('id_customer')) {
|
||||
if ($id_address = Customer::getCustomerIdAddress($idCustomer)) {
|
||||
|
||||
$errors[] = sprintf(Tools::displayError('Customer address already exists. Id address: #%d'), $id_address);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -602,13 +602,19 @@ class OrderCore extends ObjectModel
|
||||
$is_booking = null,
|
||||
$product_service_type = null,
|
||||
$product_auto_add = null,
|
||||
$product_price_addition_type = null
|
||||
$product_price_addition_type = null,
|
||||
$ids_order_detail = []
|
||||
) {
|
||||
$sql = 'SELECT *
|
||||
FROM `'._DB_PREFIX_.'order_detail` od
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product = od.product_id)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_shop` ps ON (ps.id_product = p.id_product AND ps.id_shop = od.id_shop)
|
||||
WHERE od.`id_order` = '.(int)$this->id;
|
||||
|
||||
if ($ids_order_detail) {
|
||||
$sql .= ' AND od.`id_order_detail` IN ('.implode(',', $ids_order_detail).')';
|
||||
}
|
||||
|
||||
if ($is_booking !== null) {
|
||||
$sql .= ' AND od.`is_booking_product` = '. (int)$is_booking;
|
||||
if (!$is_booking && $product_service_type !== null) {
|
||||
@@ -954,21 +960,30 @@ class OrderCore extends ObjectModel
|
||||
*
|
||||
* @param int $id_customer Customer id
|
||||
* @param bool $show_hidden_status Display or not hidden order statuses
|
||||
* @param bool $skip_id_address_invoice Skip orders from this id_address_invoice
|
||||
* @return array Customer orders
|
||||
*/
|
||||
public static function getCustomerOrders($id_customer, $show_hidden_status = false, Context $context = null)
|
||||
public static function getCustomerOrders($id_customer, $show_hidden_status = false, Context $context = null, $id_address_invoice = null, $skip_address = 0)
|
||||
{
|
||||
if (!$context) {
|
||||
$context = Context::getContext();
|
||||
}
|
||||
|
||||
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT o.*, (SELECT SUM(od.`product_quantity`) FROM `'._DB_PREFIX_.'order_detail` od WHERE od.`id_order` = o.`id_order`) nb_products
|
||||
$sql = 'SELECT o.*, (SELECT SUM(od.`product_quantity`) FROM `'._DB_PREFIX_.'order_detail` od WHERE od.`id_order` = o.`id_order`) nb_products
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
WHERE o.`id_customer` = '.(int)$id_customer.
|
||||
Shop::addSqlRestriction(Shop::SHARE_ORDER).'
|
||||
WHERE o.`id_customer` = '.(int)$id_customer;
|
||||
|
||||
// if you want orders from / not from a specific id_address_invoice
|
||||
if (!is_null($id_address_invoice)) {
|
||||
$sql .= ' AND o.`id_address_invoice`';
|
||||
$sql .= ($skip_address ? ' != ' : ' = ').(int)$id_address_invoice;
|
||||
}
|
||||
|
||||
$sql .= Shop::addSqlRestriction(Shop::SHARE_ORDER).'
|
||||
GROUP BY o.`id_order`
|
||||
ORDER BY o.`date_add` DESC');
|
||||
ORDER BY o.`date_add` DESC';
|
||||
|
||||
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
if (!$res) {
|
||||
return array();
|
||||
}
|
||||
@@ -1091,11 +1106,12 @@ class OrderCore extends ObjectModel
|
||||
$bookingProducts = null,
|
||||
$product_service_type = null,
|
||||
$product_auto_add = null,
|
||||
$product_price_addition_type = null
|
||||
$product_price_addition_type = null,
|
||||
$ids_order_detail = []
|
||||
) {
|
||||
// update
|
||||
if (!$products) {
|
||||
$products = $this->getProductsDetail($bookingProducts, $product_service_type, $product_auto_add, $product_price_addition_type);
|
||||
$products = $this->getProductsDetail($bookingProducts, $product_service_type, $product_auto_add, $product_price_addition_type, $ids_order_detail);
|
||||
}
|
||||
|
||||
$return = 0;
|
||||
@@ -1116,11 +1132,12 @@ class OrderCore extends ObjectModel
|
||||
$bookingProducts = null,
|
||||
$product_service_type = null,
|
||||
$product_auto_add = null,
|
||||
$product_price_addition_type = null
|
||||
$product_price_addition_type = null,
|
||||
$ids_order_detail = []
|
||||
) {
|
||||
/* Retro-compatibility (now set directly on the validateOrder() method) */
|
||||
if (!$products) {
|
||||
$products = $this->getProductsDetail($bookingProducts, $product_service_type, $product_auto_add, $product_price_addition_type);
|
||||
$products = $this->getProductsDetail($bookingProducts, $product_service_type, $product_auto_add, $product_price_addition_type, $ids_order_detail);
|
||||
}
|
||||
|
||||
$return = 0;
|
||||
|
||||
@@ -413,7 +413,7 @@ class OrderInvoiceCore extends ObjectModel
|
||||
// - 'total_price_tax_excl'
|
||||
// - 'total_amount'
|
||||
$breakdown = array();
|
||||
$order_detail = $order->getOrderDetailList();
|
||||
$order_detail = $this->getProducts();
|
||||
$order_detail = array_filter($order_detail, function($v) {
|
||||
return ($v['is_booking_product']
|
||||
|| ($v['product_auto_add']
|
||||
@@ -482,7 +482,7 @@ class OrderInvoiceCore extends ObjectModel
|
||||
// - 'total_price_tax_excl'
|
||||
// - 'total_amount'
|
||||
$breakdown = array();
|
||||
$order_detail = $order->getOrderDetailList();
|
||||
$order_detail = $this->getProducts();
|
||||
$order_detail = array_filter($order_detail, function($v) {
|
||||
return (!$v['is_booking_product'] && !$v['product_auto_add'] && $v['product_service_type'] == Product::SERVICE_PRODUCT_WITH_ROOMTYPE);
|
||||
});
|
||||
@@ -546,7 +546,7 @@ class OrderInvoiceCore extends ObjectModel
|
||||
// - 'total_price_tax_excl'
|
||||
// - 'total_amount'
|
||||
$breakdown = array();
|
||||
$order_detail = $order->getOrderDetailList();
|
||||
$order_detail = $this->getProducts();
|
||||
$order_detail = array_filter($order_detail, function($v) {
|
||||
return (!$v['is_booking_product']
|
||||
&& $v['product_auto_add']
|
||||
@@ -616,7 +616,7 @@ class OrderInvoiceCore extends ObjectModel
|
||||
// - 'total_price_tax_excl'
|
||||
// - 'total_amount'
|
||||
$breakdown = array();
|
||||
$order_detail = $order->getOrderDetailList();
|
||||
$order_detail = $this->getProducts();
|
||||
$order_detail = array_filter($order_detail, function($v) {
|
||||
return (!$v['is_booking_product'] && $v['product_service_type'] == Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE);
|
||||
});
|
||||
@@ -674,8 +674,10 @@ class OrderInvoiceCore extends ObjectModel
|
||||
$order = $this->getOrder();
|
||||
}
|
||||
$breakdown = array();
|
||||
$order_details = $this->getProducts();
|
||||
$objBookingDemand = new HotelBookingDemands();
|
||||
$details = $objBookingDemand->getExtraDemandsTaxesDetails($order->id);
|
||||
$order_details = array_column($order_details, 'id_order_detail');
|
||||
$details = $objBookingDemand->getExtraDemandsTaxesDetails($order->id, $order_details);
|
||||
if (!$this->useOneAfterAnotherTaxComputationMethod()) {
|
||||
$grouped_details = array();
|
||||
foreach ($details as $row) {
|
||||
@@ -1013,7 +1015,7 @@ class OrderInvoiceCore extends ObjectModel
|
||||
$payments = OrderPaymentDetail::getByInvoiceId($this->id);
|
||||
foreach ($payments as $payment) {
|
||||
/** @var OrderPayment $payment */
|
||||
$amount += $payment['amount'];
|
||||
$amount += ($payment['amount'] / $payment['conversion_rate']);
|
||||
}
|
||||
Cache::store($cache_id, $amount);
|
||||
return $amount;
|
||||
|
||||
@@ -349,9 +349,9 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
|
||||
if ($type_value)
|
||||
if (isset($customer->id)) {
|
||||
$cart_obj = new Cart($this->order->id_cart);
|
||||
$order_bk_data = $obj_htl_bk_dtl->getOnlyOrderBookingData($this->order->id, $cart_obj->id_guest, $type_value['product_id'], $customer->id);
|
||||
$order_bk_data = $obj_htl_bk_dtl->getOnlyOrderBookingData($this->order->id, $cart_obj->id_guest, $type_value['product_id'], $customer->id, $type_value['id_order_detail']);
|
||||
} else {
|
||||
$order_bk_data = $obj_htl_bk_dtl->getOnlyOrderBookingData($this->order->id, $customer->id_guest, $type_value['product_id']);
|
||||
$order_bk_data = $obj_htl_bk_dtl->getOnlyOrderBookingData($this->order->id, $customer->id_guest, $type_value['product_id'], 0, $type_value['id_order_detail']);
|
||||
}
|
||||
|
||||
$cart_htl_data[$type_key]['id_product'] = $type_value['product_id'];
|
||||
@@ -396,7 +396,8 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
|
||||
$data_v['date_to'],
|
||||
0,
|
||||
1,
|
||||
0
|
||||
0,
|
||||
$type_value['id_order_detail']
|
||||
);
|
||||
$cart_htl_data[$type_key]['date_diff'][$date_join]['extra_demands_price_ti'] = $objBookingDemand->getRoomTypeBookingExtraDemands(
|
||||
$order_obj->id,
|
||||
@@ -406,7 +407,8 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
|
||||
$data_v['date_to'],
|
||||
0,
|
||||
1,
|
||||
1
|
||||
1,
|
||||
$type_value['id_order_detail']
|
||||
);
|
||||
$cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services'] = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts(
|
||||
$order_obj->id,
|
||||
@@ -549,14 +551,25 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
|
||||
$footer['total_extra_demands_te'] = $totalDemandsPriceTE;
|
||||
}
|
||||
}
|
||||
$footer['room_price_tax_excl'] = $this->order->getTotalProductsWithoutTaxes(false, true) + $this->order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM);
|
||||
$footer['room_price_tax_incl'] = $this->order->getTotalProductsWithTaxes(false, true) + $this->order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM);
|
||||
// $footer['service_products_price_tax_excl'] = $this->order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE);
|
||||
// $footer['service_products_price_tax_incl'] = $this->order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE);
|
||||
$footer['additional_service_price_tax_excl'] = $this->order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 0) + $totalDemandsPriceTE;
|
||||
$footer['additional_service_price_tax_incl'] = $this->order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 0) + $totalDemandsPriceTI;
|
||||
$footer['total_convenience_fee_te'] = $this->order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT);
|
||||
$footer['total_convenience_fee_ti'] = $this->order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT);
|
||||
|
||||
$footer['room_price_tax_excl'] = 0;
|
||||
$footer['room_price_tax_incl'] = 0;
|
||||
$footer['additional_service_price_tax_excl'] = 0;
|
||||
$footer['additional_service_price_tax_incl'] =0;
|
||||
$footer['total_convenience_fee_te'] = 0;
|
||||
$footer['total_convenience_fee_ti'] = 0;
|
||||
if ($idsOrderDetail = array_column($order_details, 'id_order_detail')) {
|
||||
$footer['room_price_tax_excl'] = $this->order->getTotalProductsWithoutTaxes(false, true, null, null, null, $idsOrderDetail) + $this->order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM, $idsOrderDetail);
|
||||
$footer['room_price_tax_incl'] = $this->order->getTotalProductsWithTaxes(false, true, null, null, null, $idsOrderDetail) + $this->order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM, $idsOrderDetail);
|
||||
// $footer['service_products_price_tax_excl'] = $this->order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE);
|
||||
// $footer['service_products_price_tax_incl'] = $this->order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE);
|
||||
$footer['additional_service_price_tax_excl'] = $this->order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 0, null, $idsOrderDetail) + $totalDemandsPriceTE;
|
||||
$footer['additional_service_price_tax_incl'] = $this->order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 0, null, $idsOrderDetail) + $totalDemandsPriceTI;
|
||||
$footer['total_convenience_fee_te'] = $this->order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT, $idsOrderDetail);
|
||||
$footer['total_convenience_fee_ti'] = $this->order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT, $idsOrderDetail);
|
||||
}
|
||||
$footer['total_paid_real'] = $this->order_invoice->getTotalPaid();
|
||||
|
||||
$data = array(
|
||||
'cart_htl_data' => $cart_htl_data,
|
||||
'service_product_data' => $service_product_data,
|
||||
@@ -676,6 +689,7 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
|
||||
'ecotax_tax' => $this->order_invoice->getEcoTaxTaxesBreakdown(),
|
||||
'wrapping_tax' => $this->order_invoice->getWrappingTaxesBreakdown(),
|
||||
);
|
||||
|
||||
foreach ($breakdowns as $type => $bd) {
|
||||
if (empty($bd)) {
|
||||
unset($breakdowns[$type]);
|
||||
|
||||
Reference in New Issue
Block a user