Skip to content

Commit

Permalink
Merge pull request #1161 from shreesh-webkul/gli-2217
Browse files Browse the repository at this point in the history
Updated: id_address_delivery is now set as 0 by default
  • Loading branch information
rohit053 authored Aug 22, 2024
2 parents 1cd39ce + 8d2fc83 commit a07113b
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 51 deletions.
18 changes: 4 additions & 14 deletions admin/themes/default/template/controllers/orders/form.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -1459,22 +1459,12 @@
$('#address_delivery, #address_invoice').show();
}
/*Changed by webkul to make delivery and invoice addresses same*/
$('#id_address_delivery').html(addresses_delivery_options).hide();
$('#id_address_invoice').html(addresses_delivery_options).hide();
$('#address_delivery_detail').html(address_delivery_detail);
$('#address_invoice_detail').html(address_delivery_detail);
$('#edit_delivery_address').attr('href', delivery_address_edit_link);
$('#edit_invoice_address').attr('href', delivery_address_edit_link);
/*END*/
/*Original*/
/*$('#id_address_delivery').html(addresses_delivery_options);
$('#id_address_invoice').html(addresses_invoice_options);
$('#id_address_invoice').html(addresses_invoice_options).hide();
$('#address_delivery_detail').html(address_delivery_detail);
$('#address_invoice_detail').html(address_invoice_detail);
$('#edit_delivery_address').attr('href', delivery_address_edit_link);
$('#edit_invoice_address').attr('href', invoice_address_edit_link);*/
$('#edit_invoice_address').attr('href', invoice_address_edit_link);
}
function updateAddresses()
Expand Down Expand Up @@ -2004,7 +1994,7 @@
<div id="addresses_err" class="alert alert-warning" style="display:none;"></div>
<div class="row">
<div id="address_delivery" class="col-xs-6 col-sm-6">
<div id="address_delivery" class="col-xs-6 col-sm-6 hidden">
<h4>
<i class="icon-map-marker"></i>
{l s='Customer Address'}
Expand All @@ -2017,7 +2007,7 @@
<div id="address_delivery_detail"></div>
</div>
</div>
<div id="address_invoice" class="col-lg-6 hidden">
<div id="address_invoice" class="col-lg-6">
<h4>
<i class="icon-file-text"></i>
{l s='Invoice'}
Expand Down
8 changes: 2 additions & 6 deletions classes/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -1078,8 +1078,6 @@ public function updateQty($quantity, $id_product, $id_product_attribute = null,
if (Context::getContext()->customer->id) {
if ($id_address_delivery == 0 && (int)$this->id_address_delivery) { // The $id_address_delivery is null, use the cart delivery address
$id_address_delivery = $this->id_address_delivery;
} elseif ($id_address_delivery == 0) { // The $id_address_delivery is null, get the default customer address
$id_address_delivery = (int)Address::getFirstCustomerAddressId((int)Context::getContext()->customer->id);
} elseif (!Customer::customerHasAddress(Context::getContext()->customer->id, $id_address_delivery)) { // The $id_address_delivery must be linked with customer
$id_address_delivery = 0;
}
Expand Down Expand Up @@ -4109,7 +4107,7 @@ public function duplicate()
$cart->id_shop_group = $this->id_shop_group;

if (!Customer::customerHasAddress((int)$cart->id_customer, (int)$cart->id_address_delivery)) {
$cart->id_address_delivery = (int)Address::getFirstCustomerAddressId((int)$cart->id_customer);
$cart->id_address_delivery = 0;
}

if (!Customer::customerHasAddress((int)$cart->id_customer, (int)$cart->id_address_invoice)) {
Expand Down Expand Up @@ -4501,11 +4499,9 @@ public function setNoMultishipping()
public function autosetProductAddress()
{
$id_address_delivery = 0;
// Get the main address of the customer

if ((int)$this->id_address_delivery > 0) {
$id_address_delivery = (int)$this->id_address_delivery;
} else {
$id_address_delivery = (int)Address::getFirstCustomerAddressId(Context::getContext()->customer->id);
}

if (!$id_address_delivery) {
Expand Down
2 changes: 0 additions & 2 deletions classes/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,6 @@ public function updateCustomer(Customer $customer, $loginCustomer = 0)
$this->cart->setDeliveryOption(null);
}
$this->cart->id_customer = (int) $customer->id;
$this->cart->updateAddressId($this->cart->id_address_delivery, (int) Address::getFirstCustomerAddressId((int) ($customer->id)));
$this->cart->id_address_delivery = (int) Address::getFirstCustomerAddressId((int) ($customer->id));
$this->cart->id_address_invoice = (int) Address::getFirstCustomerAddressId((int) ($customer->id));

// update id guest in htl_cart_booking_data for bookings added to the cart as a visitor
Expand Down
15 changes: 7 additions & 8 deletions classes/controller/FrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,13 @@ public function init()
$cart->update();
}
/* Select an address if not set */
if (isset($cart) && (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0 ||
!isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) && $this->context->cookie->id_customer) {
if (isset($cart)
&& (!isset($cart->id_address_invoice)
|| $cart->id_address_invoice == 0
)
&& $this->context->cookie->id_customer
) {
$to_update = false;
if (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0) {
$to_update = true;
$cart->id_address_delivery = (int)Address::getFirstCustomerAddressId($cart->id_customer);
}
if (!isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) {
$to_update = true;
$cart->id_address_invoice = (int)Address::getFirstCustomerAddressId($cart->id_customer);
Expand All @@ -391,8 +391,7 @@ public function init()
$cart->id_shop = $this->context->shop->id;
if ($this->context->cookie->id_customer) {
$cart->id_customer = (int)$this->context->cookie->id_customer;
$cart->id_address_delivery = (int)Address::getFirstCustomerAddressId($cart->id_customer);
$cart->id_address_invoice = (int)$cart->id_address_delivery;
$cart->id_address_invoice = (int)Address::getFirstCustomerAddressId($cart->id_customer);
} else {
$cart->id_address_delivery = 0;
$cart->id_address_invoice = 0;
Expand Down
25 changes: 12 additions & 13 deletions controllers/admin/AdminCartsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,19 +395,19 @@ public function ajaxPreProcess()
$this->context->cart->id_currency = (($id_currency = (int)Tools::getValue('id_currency')) ? $id_currency : Configuration::get('PS_CURRENCY_DEFAULT'));
}

$addresses = $customer->getAddresses((int)$this->context->cart->id_lang);
$id_address_delivery = (int)Tools::getValue('id_address_delivery');
$id_address_invoice = (int)Tools::getValue('id_address_invoice');
if (Validate::isLoadedObject($customer)) {
$addresses = $customer->getAddresses((int)$this->context->cart->id_lang);
$id_address_delivery = (int)Tools::getValue('id_address_delivery');
$id_address_invoice = (int)Tools::getValue('id_address_invoice');

if (!$this->context->cart->id_address_invoice && isset($addresses[0])) {
$this->context->cart->id_address_invoice = (int)$addresses[0]['id_address'];
} elseif ($id_address_invoice) {
$this->context->cart->id_address_invoice = (int)$id_address_delivery;
}
if (!$this->context->cart->id_address_delivery && isset($addresses[0])) {
$this->context->cart->id_address_delivery = $addresses[0]['id_address'];
} elseif ($id_address_delivery) {
$this->context->cart->id_address_delivery = (int)$id_address_delivery;
if (!$this->context->cart->id_address_invoice && isset($addresses[0])) {
$this->context->cart->id_address_invoice = (int)$addresses[0]['id_address'];
} elseif ($id_address_invoice) {
$this->context->cart->id_address_invoice = (int)$id_address_delivery;
}
if ($id_address_delivery) {
$this->context->cart->id_address_delivery = (int)$id_address_delivery;
}
}
$this->context->cart->setNoMultishipping();

Expand All @@ -417,7 +417,6 @@ public function ajaxPreProcess()
$this->context->cart->secure_key = $this->context->customer->secure_key;
$addresses = $customer->getAddresses((int)$this->context->cart->id_lang);
$this->context->cart->id_address_invoice = (int)$addresses[0]['id_address'];
$this->context->cart->id_address_delivery = (int)$addresses[0]['id_address'];
$this->context->cart->setNoMultishipping();
}
/*END*/
Expand Down
1 change: 0 additions & 1 deletion controllers/front/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,6 @@ protected function processSubmitAccount()
$customer->addGroups(array((int)Configuration::get('PS_GUEST_GROUP')));
}

$this->context->cart->id_address_delivery = (int)Address::getFirstCustomerAddressId((int)$customer->id);
$this->context->cart->id_address_invoice = (int)Address::getFirstCustomerAddressId((int)$customer->id);
if (isset($address_invoice) && Validate::isLoadedObject($address_invoice)) {
$this->context->cart->id_address_invoice = (int)$address_invoice->id;
Expand Down
4 changes: 0 additions & 4 deletions controllers/front/ParentOrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,6 @@ protected function _assignAddress()

/* Setting default addresses for cart */
if (count($customerAddresses)) {
if ((!isset($this->context->cart->id_address_delivery) || empty($this->context->cart->id_address_delivery)) || !Address::isCountryActiveById((int)$this->context->cart->id_address_delivery)) {
$this->context->cart->id_address_delivery = (int)$customerAddresses[0]['id_address'];
$update = 1;
}
if ((!isset($this->context->cart->id_address_invoice) || empty($this->context->cart->id_address_invoice)) || !Address::isCountryActiveById((int)$this->context->cart->id_address_invoice)) {
$this->context->cart->id_address_invoice = (int)$customerAddresses[0]['id_address'];
$update = 1;
Expand Down
3 changes: 0 additions & 3 deletions modules/hotelreservationsystem/classes/HotelBookingDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -2748,9 +2748,6 @@ public function createQloCartForBookingFromChannel($params)
if (!$this->context->cart->id_address_invoice && isset($addresses[0])) {
$this->context->cart->id_address_invoice = (int)$addresses[0]['id_address'];
}
if (!$this->context->cart->id_address_delivery && isset($addresses[0])) {
$this->context->cart->id_address_delivery = $addresses[0]['id_address'];
}
$this->context->cart->setNoMultishipping();

if ($this->context->cart->save()) {
Expand Down

0 comments on commit a07113b

Please sign in to comment.