2 replies [Last post]
incaic's picture
Offline
Joined: 10/13/2007
Juice: 115
Was this information Helpful?

Hello,

Not sure if this is a bug, but the following clears out the product shipping location instead of updating it. Am I not allowed to update this using node_save?

<?php
$nid
= 2;
$prod = node_load($nid);
$prod->shipping_address->street1 = "123 Main St.";
node_save($prod);
?>

I'm using DRUPAL-6--2-0-RC6 and see that function uc_quote_nodeapi in uc_quote.module is checking for $node->street1. Shouldn't it be checking $node->shipping_address-street1 instead?

We use node_save quite a bit. If this is intended behavior, is there a suggested workaround?

Thanks for any help,
Edwin-

EDIT: all node_save calls clear out the shipping location address. Sad

<?php
$nid
= 2;
$prod = node_load($nid);
node_save($prod);
?>
Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: uc_quote_product_locations - node_save

I think this is one of the biggest problems with the node module. If you don't set up your node form a certain way, what you give to node_save() is not the same thing you get out of node_load(). If you want, I can give you all the details with the way Form API works, but for now, just do something like this:

<?php
  $node
= node_load($nid);
  foreach (
$node->shipping_address as $key => $value) {
   
$node->$key = $value;
  }
 
node_save($node);
?>
incaic's picture
Offline
Joined: 10/13/2007
Juice: 115
Thanks Lyle! I'm interested

Thanks Lyle!

I'm interested with the details with the way Form API works. Please do send any info my way.

Unfortunately, we use node_save in many places, so instead I added the following:

<?php
function <hook>_nodeapi(&$node, $op, $ap=NULL, $a4=NULL) {
  if (
uc_product_is_product($node->type)) {
    switch (
$op) {
      case
'presave' :
        if (
$node->shipping_address) {
          foreach (
$node->shipping_address as $key => $val) {
           
$node->$key = $val;
          }
        }
        break;
    }
  }
}
?>