Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi create my own node type "Address". In the node edit form I add:
if (!empty($node_address)) {
// Example 1: create an edit form for address ID 2 from user 1.
$address = UcAddressesAddressBook::get($user->uid)->getAddressById($node_address->aid);
$form['address'] = array(
'#type' => 'uc_addresses_address',
'#uc_addresses_address' => $address,
);
$form['address_serialize'] = array(
'#type' => 'value',
'#value' => serialize($address)
)
}
else {
// Example 2: create an edit form for a new address for user 1.
$address = UcAddressesAddressBook::get($user->uid)->addAddress();
$form['address'] = array(
'#type' => 'uc_addresses_address',
'#uc_addresses_address' => $address
);
$form['address_serialize'] = array(
'#type' => 'value',
'#value' => serialize($address)
)
Now I get address form to node edit form. But when I submit the form in the hook_insert I get only array of fields of the address form:
$node->address is only array of fields of the address form, so I can not use $node->address->save(); because it is not object of UcAddressesAddress type!!!
So I add the variable 'address_serialize'. Now in the hook_insert I get instance of UcAddressesAddress:
$address = unserialize($node->address_serialize);
if ($address instanceof UcAddressesAddress) {
$address->save();
}
But in the uc_address table new address is not save!!!
Can you help me please.
Thanks Marinex
Comment | File | Size | Author |
---|---|---|---|
#10 | uc_addresses_node.tar_.gz | 47.78 KB | marinex |
#6 | uc_addresses_node.fields.inc_.txt | 2.89 KB | marinex |
#4 | uc_address_node.dev_.txt | 9.34 KB | marinex |
Comments
Comment #0.0
marinex CreditAttribution: marinex commentedsmall correct
Comment #1
MegaChriz CreditAttribution: MegaChriz commentedI have never tried to attach an UcAddressesAddress to a node type, so it can be that it doesn't work nicely. Normally, I pick up the address in the form submit function, like this for example (function
uc_addresses_get_address_form_submit()
in uc_addresses.pages.inc):What you could try is to look how an address is handled when an user registers. I think that comes the closest to your situation. See
uc_addresses_user()
in uc_addresses.module. Anyway, I think you shouldn't serialize the address in the form definition. The Drupal Form API should take care for serializing the address (when the form is cached) or just recreate the address.I'm glad to hear you are experimenting with extending Ubercart Addresses. Let me know if you are able to get this fixed (and how).
Comment #2
marinex CreditAttribution: marinex commentedSo I have simple solution - I add own submit handler and there I call address instance:
Everything works great, thanks for your effort (great module).
M.
Comment #3
MegaChriz CreditAttribution: MegaChriz commentedThanks for reporting back. I only had the feeling that one of the last lines isn't quite right:
Are the address values right in $node? The previous code lines imply that the values are in
$node->address
. And one other note: by using drupal_write_record() the uc_addresses hooks won't be invoked (likehook_uc_addresses_address_update()
).There was also an other method I forgot to mention. You can also load an address and populate it with new values using the
setMultipleFields()
method:Comment #4
marinex CreditAttribution: marinex commentedYes, address values are right in $node (hook_load), but I need only one value 'aid', because I insert address form to node edit form with:
in the hook_load() I added address values to node(I need only one value 'aid'):
return db_fetch_object(db_query('SELECT * FROM {uc_addresses} WHERE nid = %d', $node->nid));
When I create a new address:
First, in the custom handler I save new address without NID and VID, because at this time node is not created.
Second, after that in the hook insert I only update this new address with NID and VID. I use uc_addresses table.
Insted of the:
it can be used db query like this:
BUT it is has same result as drupal_write_record.
I think the hook_uc_addresses_address_update() and others should be work normal way.
I attach my dev module :-) this is early dev. version.
Comment #5
MegaChriz CreditAttribution: MegaChriz commentedI agree with you that using
drupal_write_record()
is better than usingdb_query()
. I mentioned it because if you write to the uc_addresses table directly, other modules will not get a chance to respond to that event. I don't mean writing to the table directly is wrong, I was just telling what the consequences are. Anyway, using the address book API is the preferable way. I'm not sure if you registered the vid and nid fields via the hookhook_uc_addresses_fields()
(it's not in your attached module file), but if you did, you could just do this:Interesting, thanks for sharing! It could become a solution for issue #711764: uc_addresses CCK Field as well! :-)
Nice comment :). I can't not make much of it. I only know a few Czech words, for example: "podmasli".
Comment #6
marinex CreditAttribution: marinex commentedI have registred vid and nid fields with:
This is in dev module. I attach my fields. I thought that is right way. Anything wrong? If yes could you help me?
Comment #7
MegaChriz CreditAttribution: MegaChriz commentedI have not executed the code, but it looks right. So you could also use the
setField()
method for the nid and vid fields. And if it doesn't work, you'll get an UcAddressesInvalidFieldException (this exception is thrown if you try to set a field where Ubercart Addresses doesn't know about).Good luck with the further development. :-)
Comment #8
marinex CreditAttribution: marinex commentedThanks, At the moment I am doing integration views. Once this module will be finished, so I upload it here and you can add it as submodule ;-)
M.
Comment #10
marinex CreditAttribution: marinex commented@MegaChriz
So I am here :-) as I promised I attach my module.
My modul work, there is implemet Vertical tab, views2/3 (there are default view), CCK
I think the the Views should be used as address book (I call it Glossary), I suggest rename "Address list" in the original module (UC Address) to "Default addresses" and remove every addresses (one template) from there and put there only default addresses for Ubercart (Billing and Shipping). Sorry for my English.
TO DO:
1) in my module I re-use your tokens from uc_addresses but system return "Duplicate tokens" in the status report page! But I think it work.
look at row 509 uc_addresses_node_token_list
2) I tried also to implement Feed API but I am not familiar with. In my module there are some code... but need to do!
3) Integrate Invite module or RSVP modules
Comment #11
marinex CreditAttribution: marinex commentedI rename this issue :-)
Comment #12
MegaChriz CreditAttribution: MegaChriz commentedThanks for your work! :-) I see you put a lot of time in it. I hope to find time to review your work, but it may take a while before I will get to it (December is usually a very busy month). At first glance I see a few minor coding standards issues (tabs instead of spaces in uc_addresses_node.fields.inc) and a few code comments are in Czech (for example
Dodělat verzování i pro adresy pak to bude mít smysl!
on line 407 in uc_addresses_node.module). I saw also a syntax error on line 288 in FeedsUcAddressesNodeProcessor.inc:'description' => t('The nickname of this address, like "Home", "Office", "Anna's apartment."'),
The single quote in "Anna's" is not escaped.
I understand that the module is not in a finished state yet (you pointed out some Todo's in #10), so the few minor issues I saw at first glance won't stop me from reviewing it (when I have found the time to do that).
I already made plans to implement this, see #1433034: Redesign the address book page using Views (first for the Drupal 7 version, then for the Drupal 6 version). Or are you pointing to the Views integration code in your uc_addresses_node module?
About your suggestion in #8 to add this a submodule: I'm not sure yet, maybe it would fit better in it's own project. Because the more code, the more time it will cost to maintain the module (more cases to test, potentially more bugs). Also, it's my intention that the 7.x-1.x version can at least do what the 6.x-2.x version can do, so that would mean the module should be ported to Drupal 7 first before it can be added as a submodule.
Well, I should first try out the module and see how I think about it after that. ;-)
Comment #13
marinex CreditAttribution: marinex commentedThe Views in uc_addresses_node is tied with this module and is specifically intended to work with this module; and is compatible with uc_views_addresses. I think this integration is light solution but effective. Unlike uc_views_addresses I also integrated uc_zones and uc_countries tables.
Comment #13.0
marinex CreditAttribution: marinex commentedsmall correct