Chægga Posted August 10, 2016 Share Posted August 10, 2016 (edited) *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 August 10, 2016 by Chægga (see edit history) Link to comment Share on other sites More sharing options...
rocky Posted August 11, 2016 Share Posted August 11, 2016 Try: $this->context->cart->id_address_delivery = $new_id_address; $this->context->cart->update(); Link to comment Share on other sites More sharing options...
Chægga Posted August 11, 2016 Author Share Posted August 11, 2016 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 More sharing options...
rocky Posted August 11, 2016 Share Posted August 11, 2016 No, just the ID of your new address. Link to comment Share on other sites More sharing options...
Chægga Posted August 11, 2016 Author Share Posted August 11, 2016 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 More sharing options...
rocky Posted August 11, 2016 Share Posted August 11, 2016 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 More sharing options...
Chægga Posted August 11, 2016 Author Share Posted August 11, 2016 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 More sharing options...
rocky Posted August 11, 2016 Share Posted August 11, 2016 It will update the address everywhere, since the address is referenced by ID in the cart and order. Link to comment Share on other sites More sharing options...
Chægga Posted August 11, 2016 Author Share Posted August 11, 2016 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 More sharing options...
rocky Posted August 11, 2016 Share Posted August 11, 2016 Yes, it will. In that case, you'll need to create a new address and then set the new ID to the cart. Link to comment Share on other sites More sharing options...
Chægga Posted August 12, 2016 Author Share Posted August 12, 2016 (edited) 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 August 12, 2016 by Chægga (see edit history) Link to comment Share on other sites More sharing options...
rocky Posted August 12, 2016 Share Posted August 12, 2016 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 More sharing options...
ZaxxaDK Posted August 12, 2016 Share Posted August 12, 2016 (edited) just bookmarking this Edited August 12, 2016 by ZaxxaDK (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now