News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Variable initialization in saveAddressInCart

Started by anantmaks, December 23, 2017, 09:05:27 AM

Previous topic - Next topic

anantmaks

VirtueMart Version: 3.2.10
Currently working on cart part I found that a variable $address is being incorrectly handled, correct me if I am wrong. In saveAddressInCart method under 'cart' helper file, within a condition an index of address is filled as $address['email'] = $jUser->email; and after the end of that condition, address is then being initialized as an array $address = array(); . Isn't it wrong or I am missing something?
Anant Garg
Ghaziabad, India

Studio 42

$jUser->email is an object member (string) that fill the $address['email'] (string)
All 2 are strings, so it's right.
If you do $jUser->email = $address['email']  it's valid too because all are strings.

anantmaks

Thanks for following up @studio42, though my question was not that. I am seeking for an answer on why $address is initialized as an array "$address = array();" after the actual assignment "$address['email'] = $jUser->email;". And what is the purpose of assignment then, if it is being initialized afterwards. Shouldn't it be initialized right in the beginning
Anant Garg
Ghaziabad, India

Milbo

Hello anantmaks, you are right.

This case is only for already registered joomla users, but not registered vm users (more for old migrations and such). So it did not hurt. I checked the svn for the whole year 2017 and the error seems to be there all the time.

I suggest this fix

$jUser = JFactory::getUser();
if(!empty($jUser->email)) $data['email'] = $jUser->email;
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

anantmaks

Thanks Max for the reply. So, if it doesn't hurt so does it mean to be use that way only? I am not getting if it is important to be used in that way only, initializing something after assigning a value!
Anant Garg
Ghaziabad, India