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

Parameter shipto with task=confirm

Started by midnas, July 03, 2013, 09:54:31 AM

Previous topic - Next topic

midnas

Hi,

Can you please check this. I'm showing $this->cart->lists['shipTo']; on cart confirm page. I want that user is able to select shipping address in last step.

I search code and find that shipto=[user_address_id] needs to be set in url. But it's not working, cause $this->ST doesn't get selected address. Also I get an error with class and array thing.

So, could you change this in components/com_virtuemart/helpers/cart.php:

      if (($this->selected_shipto = JRequest::getVar('shipto', null)) !== null) {
         JModel::addIncludePath(JPATH_VM_ADMINISTRATOR . DS . 'models');
         $userModel = JModel::getInstance('user', 'VirtueMartModel');
         $stData = $userModel->getUserAddressList(0, 'ST', $this->selected_shipto);
         $this->validateUserData('ST', $stData[0]);
      }

      if (($this->selected_shipto = JRequest::getVar('shipto', null)) !== null) {
         JModel::addIncludePath(JPATH_VM_ADMINISTRATOR . DS . 'models');
         $userModel = JModel::getInstance('user', 'VirtueMartModel');
         $stData = $userModel->getUserAddressList(0, 'ST', $this->selected_shipto);
         if ($this->validateUserData('ST', get_object_vars($stData[0])))  // validateUserData needs Array, not object
         $this->ST = get_object_vars($stData[0]); //$this->ST must get selected address
      }

If there is some other solution for this, please tell me.

Best Regards,
Sandi

Milbo

I think even setting shipto = 0 in the post would help.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

midnas

Hi Milbo,

I don't think you understand. I want to post shipto. I want that user can choose shipping address.

But if I post shipto, I get an error, because $stData[0] is object, but validateUserData need array. Also   $this->ST  never get that  $stData[0].

Original code:
      if (($this->selected_shipto = JRequest::getVar('shipto', null)) !== null) {
         JModel::addIncludePath(JPATH_VM_ADMINISTRATOR . DS . 'models');
         $userModel = JModel::getInstance('user', 'VirtueMartModel');
         $stData = $userModel->getUserAddressList(0, 'ST', $this->selected_shipto);
         $this->validateUserData('ST', $stData[0]);
      }


So this original code in cart.php is irrelevant. What does it actually do?

I change code so now it's working for me. I'm only asking you if you can check this, and if my code is right, can you fix this so it will be fixed in further versions.

Fixed code:
      if (($this->selected_shipto = JRequest::getVar('shipto', null)) !== null) {
         JModel::addIncludePath(JPATH_VM_ADMINISTRATOR . DS . 'models');
         $userModel = JModel::getInstance('user', 'VirtueMartModel');
         $stData = $userModel->getUserAddressList(0, 'ST', $this->selected_shipto);
         if ($this->validateUserData('ST', get_object_vars($stData[0])))  // validateUserData needs Array, not object
         $this->ST = get_object_vars($stData[0]); //$this->ST must get selected address
      }


Thank you for reply.

Best Regards,
Sandi

PRO

are you talking about selecting from a list of shipping address in the users account?

If so, it's not
  • is it?


midnas

Hi,

I put this in cart confirm page:

echo $this->cart->lists['shipTo'];

This returns all shipping addresses of customer with radio buttons to choose one. For example:
<input type="radio" name="shipto" id="shipto885" value="885" checked="checked">
<label for="shipto885" id="shipto885-lbl" class="radiobtn">Standard</label>
<input type="radio" name="shipto" id="shipto888" value="888">
<label for="shipto888" id="shipto888-lbl" class="radiobtn">Work address</label>


So if I post this with confirm form, I think it should change shipping address, but it's not.

so in helpers/cart.php is private function checkoutData. There is code

      if (($this->selected_shipto = JRequest::getVar('shipto', null)) !== null) {
         JModel::addIncludePath(JPATH_VM_ADMINISTRATOR . DS . 'models');
         $userModel = JModel::getInstance('user', 'VirtueMartModel');
         $stData = $userModel->getUserAddressList(0, 'ST', $this->selected_shipto);
         $this->validateUserData('ST', $stData[0]);
      }


So it defines shipto and find chosen address with getUserAddressList. But this returns object so validateUserData crashes cause it needs array.

So:

$this->validateUserData('ST', $stData[0]);  ->   $this->validateUserData('ST', get_object_vars($stData[0]))

Second thing. Now chosen address is in $stData[0]. But we need it to be in $this->ST.

So:

if ($this->validateUserData('ST', get_object_vars($stData[0]))) $this->ST = get_object_vars($stData[0]);


I'm asking what is original purpose of this code. What it does, or what it shout do?

Best Regards,
Sandi

Milbo

It is validating the first element of the array $stData.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

midnas

Hi Milbo,

Well, that is true. But why? $stData is never used. It should be used if it's validated. Or not?

That's why I'm saying you should add this in code: $this->ST = get_object_vars($stData[0]);

Best Regards,
Sandi

Milbo

Could it be taht you talk about 2.0.20b? Please test with 2.0.21 !
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

midnas

Hi Milbo!

It's the same.

Form serialize gives this:

customer_comment=&tosAccepted=0&tosAccepted=1&order_language=en-GB&STsameAsBT=0&task=checkout&option=com_virtuemart&view=cart&shipto=2

And I get this error:

Fatal error: Cannot use object of type stdClass as array in ...\administrator\components\com_virtuemart\models\user.php on line 1004

As I said, I already fixed this with code I post, but I'm asking if you can fix it, so I won't need to change code with every update. Except if this code is meant for something else, but I don't see any other use.

Best Regards,
Sandi

Milbo

I added now this


if (($this->selected_shipto = JRequest::getVar('shipto', null)) !== null) {
JModel::addIncludePath(JPATH_VM_ADMINISTRATOR . DS . 'models');
$userModel = JModel::getInstance('user', 'VirtueMartModel');
$stData = $userModel->getUserAddressList(0, 'ST', $this->selected_shipto);
$stData = get_object_vars($stData[0]);
if($this->validateUserData('ST', $stData)){
$this->ST = $stData;
}
}


okey?
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

midnas

Hi Milbo,

I missed your reply. Yes, it's ok, thank you very much!

Best Regards,
Sandi