Jump to content

Change shipping address for current CART/Order - during checkout ?


Chægga

Recommended Posts

*Update*

 

just to make it clear:

its for the 5 step checkout, and i want it to change depending on what shipping methods their is picked

 

 

Hey men
 
I'm working on a module, and i'm trying to change the shipping Address of the current "order/cart" during checkout - but i seem unable to figure out how to do it!
 
I figured that i should use something like:

 

new Address($products->id_address_delivery);

 

this as you might expect gives me the current address, but how do i go about changing it and updating the order on the current cart/order then?

I have looked a little on the $OrderController, $Cart & $Address, but still seem to be unable to how and when to change the adress

 

<3

Chæg

Edited by Chægga (see edit history)
Link to comment
Share on other sites

 

Try:

$this->context->cart->id_address_delivery = $new_id_address;
$this->context->cart->update();

By $new_id_address, you mean the new address object? also is their a way you can hook into the button for the next step or somethign similar - so my JS sends the data when finishing up the current step

Link to comment
Share on other sites

No, just the ID of your new address.

 

Im sorry if im a little stupid, but when i get the current address by

new Address($products->id_address_delivery);

 

That will fx. give me a new Address object with ID 230, if i then change some values in the addresss object - it will be the same ID, dont i need to somehow save a new address object and then return that id?

Link to comment
Share on other sites

Then you don't need to update the cart, only the address by using $address->update(); though the address won't update on the page until the page refreshes.

 

I see there is an actionCartSave hook that lets you do things whenever the contents of the cart changes. Maybe that will let you do what you want?

Link to comment
Share on other sites

Then you don't need to update the cart, only the address by using $address->update(); though the address won't update on the page until the page refreshes.

 

I see there is an actionCartSave hook that lets you do things whenever the contents of the cart changes. Maybe that will let you do what you want?

 

Will that not just update the Address for the user? or will it only be updated for the current order?

Btw i apprciate you taking time to help out, you are truely a white knight!

Link to comment
Share on other sites

It will update the address everywhere, since the address is referenced by ID in the cart and order.

 

my next stupid question, want that just carry on to next time he orders something then? if you update his address everywhere, what when he makes a new order or his third order - want it be to the same address as it was change to on the first order? I want it only change for the current order

Link to comment
Share on other sites

Yes, it will. In that case, you'll need to create a new address and then set the new ID to the cart.

 

When creating a new address you mean i can just do

new Address(id = xxx

                      City = xxx

                      Zipcode = xxx

                      .....

                      .....

                      .....

                      .....

                     )

 

and then put the ID of the object into the cart and update? or do i have to save it somewhere in the DB everytime - instead of just having a temporary Address ?

Edited by Chægga (see edit history)
Link to comment
Share on other sites

If it's a new address, you need to use $address->add(); and if it's an existing address use $address->update();

 

Then you need to set the ID of the address to the cart and then use $cart->update();

 

I'm not sure whether you can use $address->id after calling add() though. You may need to write a query to get the last added address ID.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...