VirtueMart Forum

VirtueMart 2 + 3 => Virtuemart Development and bug reports => Topic started by: restodo on June 12, 2014, 03:59:51 am

Title: [SOLVED] Add/edit shipping address always keep last entered even If I add a new
Post by: restodo on June 12, 2014, 03:59:51 am
Hello,

I'm using VM 2.6.6 & Joomla 2.5.20.

In the maintenance account page when a user add the first shipping address the form opens empty, this is good.
The user filled all the fields and finally save. With this procedure I've one shipping address.

Now If the same user wants to add another shipping address from maintenance account page, when he clicked on Add/Edit shipment address link, the form opens with last information of the other shipping address.

Could you tell me how can I solved it?
I think in some part of the code is missing some "clear form"


Greets from Argentina.
Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: GJC Web Design on June 12, 2014, 11:49:27 am
afaik this is how it works - if you then scroll down you will see a link   'Add/Edit shipment address'  where you add a "further" shipping address

these will collect at the bottom as links for later use

perhaps not the best scheme - the link could be better worded and moved too the top etc


[attachment cleanup by admin]
Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: restodo on June 12, 2014, 15:41:36 pm
afaik this is how it works - if you then scroll down you will see a link   'Add/Edit shipment address'  where you add a "further" shipping address

these will collect at the bottom as links for later use

perhaps not the best scheme - the link could be better worded and moved too the top etc

Hello, yes that's fine.

My problem happens when a user clicked on  'Add/Edit shipment address' after he left a shipping address registered. The form to enter e new shipping address has the information of the first he entered (all the fields of this form are filled).

Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: GJC Web Design on June 12, 2014, 15:47:26 pm
that's what I mean - the same happens here - that is why it says 'Add/Edit shipment address'

and offers you the last one to edit or click the link to add a new one - it has been like this in VM2 for as long as I can remember
Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: restodo on June 12, 2014, 16:46:08 pm
that's what I mean - the same happens here - that is why it says 'Add/Edit shipment address'

and offers you the last one to edit or click the link to add a new one - it has been like this in VM2 for as long as I can remember

Oh I'm sorry, now I understand.

Do you know how can I create a function to Add (only) Shipping address ? similar to editaddressST ?
Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: GJC Web Design on June 12, 2014, 17:10:05 pm
It would need coding and testing - all things are possible given enough effort and therefore time and therefore money..  ;)
Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: restodo on June 12, 2014, 20:08:07 pm
It would need coding and testing - all things are possible given enough effort and therefore time and therefore money..  ;)

Thanks for your offer but I'm looking for some support of official virtuemart forum.

Besides the function Add/Edit Shipping Address comes from the earlies VM2 version, I think it's a bug because it's a requirement to have a possibility to add a new shipping address with all fields empties.


Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: GJC Web Design on June 12, 2014, 20:42:31 pm
But it isn't a bug - afaik this has always been so in VM - you may not like it but that doesn't mean it's a bug

you click Add/Edit shipment address

form opens with the last ST address - you edit it and save under a new Address Nickname and there it is...

Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: AH on June 13, 2014, 10:25:27 am
Thought I had better check as I ma just working on "tidying" up the look and feel of this part of my checkout

If the account holder is logged in then the shipping address is blank

If you add a shipping address, it uses this in current checkout until another one is chosen

That behaviour is logical for most customers

What is not so easy to see is that you can click a link to add another address see my image
(I have styled this section so yours will look different)



[attachment cleanup by admin]
Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: restodo on June 13, 2014, 23:46:40 pm
Yes, you've styled your Add/Edit Shipping Address but I understand what you're saying.

I'm still thinking that the way VM 2 works on Add/Edit Shipping Address is wrong and it's a bug.
Every e-commerce platform has an option to Add a Shipping Address and other to Edit, not the same function like VM 2.

My solution was to edit one file of my template override files (edit_address.php) and add the following script at the end.

<script type="text/javascript">
   var loc = window.location.href;
   var palabra = 'new';
   if (loc.indexOf(palabra) >= 0) {
   setTimeout(function(){
         resetForm();
    }, 0);
    }
   function resetForm(){
         $(':input','#userForm')
         .not(':button, :submit, :reset, :hidden')
         .val('')
         .removeAttr('checked')
         .removeAttr('selected');
   }
</script>

Then when a user select Add/Edit Shipping Address will erase all the fields of the userForm and when select any registered Shipping Address will not.

It's not the best way but helps.

Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: AH on June 14, 2014, 11:05:32 am
Yep I can see that will work for you.

The only problem I have with that is, it does not clear the session data and the original shipto address is still stored

If the user clicks cancel the original address is therefore still shown.

I have to say that I prefer the VM workflow
Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: restodo on June 14, 2014, 20:31:55 pm
Yep I can see that will work for you.

The only problem I have with that is, it does not clear the session data and the original shipto address is still stored

If the user clicks cancel the original address is therefore still shown.

I have to say that I prefer the VM workflow

Yes, you're right. If the user clicks Cancel the original address still shows but I'm using tabs in user account so I see for a second and then dissappear.

Do you know a way to clear session of Shipping Address ?
Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: AH on June 15, 2014, 02:39:57 am
No I have never tried to clear session data

Maybe someone else has an idea.

As I said, I like the workflow provided, so do not need to clear session data myself.
Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: GJC Web Design on June 15, 2014, 11:22:01 am
Code: [Select]

if (empty($cartData)) {
$session = JFactory::getSession($options);
$cartSession = $session->get('vmcart', 0, 'vm');
} else {
$cartSession=$cartData;
}
$sessionCart = unserialize( $cartSession );
unset($sessionCart->lists['shipTo']);


Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: AH on June 15, 2014, 12:00:16 pm
Thanks GJC

I wonder why the devs did not do this in place of that (very odd looking IMHO)  "Forget this address" tick box on the current implementation.
Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: restodo on June 19, 2014, 03:39:02 am
Code: [Select]

if (empty($cartData)) {
$session = JFactory::getSession($options);
$cartSession = $session->get('vmcart', 0, 'vm');
} else {
$cartSession=$cartData;
}
$sessionCart = unserialize( $cartSession );
unset($sessionCart->lists['shipTo']);




Thanks for you answer but it doesn't work on my site because I'm trying to do in maintenance account not in cart page.
Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: GJC Web Design on June 19, 2014, 09:19:16 am
Code: [Select]
$session = JFactory::getSession($options);
$cartSession = $session->get('vmcart', 0, 'vm');
$sessionCart = unserialize( $cartSession );
unset($sessionCart->ST);
Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: restodo on June 19, 2014, 19:12:32 pm
Thanks again but it doesn't work.

I've tried to add your lines to /controllers/user.php and /views/user/view.html.php without any success.

Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: GJC Web Design on June 19, 2014, 20:48:21 pm
put it in the template!!!!

does work...
Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: restodo on June 20, 2014, 00:06:25 am
put it in the template!!!!

does work...

I've put in edit_address.php of my template and it doesn't work.

Do you think I have to put in other file of my template?
Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: Milbo on June 20, 2014, 08:45:27 am
Code: [Select]
$session = JFactory::getSession($options);
$cartSession = $session->get('vmcart', 0, 'vm');
$sessionCart = unserialize( $cartSession );
unset($sessionCart->ST);

no this wont work. use getCart, set the ST to 0, then use the function to store the cart in the session.
Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: restodo on June 20, 2014, 20:36:59 pm
Code: [Select]
$session = JFactory::getSession($options);
$cartSession = $session->get('vmcart', 0, 'vm');
$sessionCart = unserialize( $cartSession );
unset($sessionCart->ST);

no this wont work. use getCart, set the ST to 0, then use the function to store the cart in the session.

I've tried to do the following without luck.

$cart = VirtueMartCart::getCart(false);
$sessionCart = unserialize( $cart );
unset($sessionCart->ST);
$cart->setCartIntoSession();

Could you tell me what's wrong?
Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: GJC Web Design on June 20, 2014, 21:56:48 pm
why not

Code: [Select]
$addrtype = JRequest::getVar('addrtype');

if($addrtype=='ST'){
echo "<script type='text/javascript'>
jQuery(document).ready(function(){
jQuery('.adminForm.user-details input').val('');
});
</script>";
}
Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: restodo on June 20, 2014, 22:23:29 pm
why not

Code: [Select]
$addrtype = JRequest::getVar('addrtype');

if($addrtype=='ST'){
echo "<script type='text/javascript'>
jQuery(document).ready(function(){
jQuery('.adminForm.user-details input').val('');
});
</script>";
}

Works better than my script but final result is the same. When a user clics Cancel, the form fields are filled with session address.

Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: GJC Web Design on June 20, 2014, 23:32:01 pm
I really don't understand what your trying to achieve???

I thought u wanted a blank form when they are in their account management and want to add a new shipping address????

If they then click Cancel why does it matter if the session ST address appears????

It then just goes back to the index.php?option=com_virtuemart&view=user&Itemid=165 - isn't life far too short to be spent on things like this????

Just off to polish my roof tiles...  ;)
Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: Milbo on June 21, 2014, 02:11:04 am
$cart = VirtueMartCart::getCart();
$cart->ST = 0;
$cart->STsameAsBT = 1;
$cart->setCartIntoSession();

no unserialize or somethign like that. If you do something like that, you do not use the provided VM API.
Title: Re: Add/edit shipping address always keep last entered even If I want to add a new
Post by: restodo on June 21, 2014, 02:52:34 am
$cart = VirtueMartCart::getCart();
$cart->ST = 0;
$cart->STsameAsBT = 1;
$cart->setCartIntoSession();

no unserialize or somethign like that. If you do something like that, you do not use the provided VM API.


Thanks Milbo, I put your code in edit.php of my template and works perfect!