Problem/Motivation
It should be possible to import addresses for Ubercart Addresses via a CSV-file.
Proposed resolution
I plan to provide this functionality by writing an extension to Feeds. With that module you can import data not only from CSV, but also from other sources.
Remaining tasks
-
#1831424: Turn Ubercart Addresses address into an entity
Addresses should first be implemented as entities, because the import functionality in Feeds (7.x-2.x) works with entities only. - Implement a Feeds processor for importing addresses.
- Let the Ubercart Addresses field handlers specify how fields should be mapped.
- Make sure that an user of an address can be identified by at least uid, guid (special field in Feeds), username or e-mail address.
- Write a test that tests the address import functionality.
User interface changes
In the Feeds user interface an additional Feeds processor will become available that is called "Ubercart Addresses processor".
API changes
The field handlers of Ubercart Addresses will get an additional method to handle the field mapping. This method will probably be called getMappingTargets()
.
Current status
- There's starting code available for the 6.x-2.x version: #1309546-4: Address import / Feeds integration.
- I have made a start with the extension for the 7.x-1.x version (which I haven't published yet). The Feeds part is basically working, but I need to pay extra attention to the entity integration part, because if I don't get that piece right the first time, it can later break sites that make use of the entity part (more details in #1831424: Turn Ubercart Addresses address into an entity).
Original report by zorax
Hi,
I use you wonderful module, but my customer need to add is own user book with adresses.
With node import or user import I can create new user but only (name, mail..).
How can I import adresses from a csv file for example?
Regards,
Comment | File | Size | Author |
---|---|---|---|
#12 | uc_addresses6-address-book-api-additions-1309546-12.patch | 1.72 KB | MegaChriz |
#10 | uc_addresses7-feeds-integration-1309546-10.patch | 32.77 KB | MegaChriz |
#9 | uc_addresses7-feeds-integration-1309546-9.patch | 33.34 KB | MegaChriz |
#7 | uc_addresses7-feeds-integration-1309546-7.patch | 22.42 KB | MegaChriz |
#4 | feeds_uc_addresses.zip | 11.82 KB | MegaChriz |
Comments
Comment #1
MegaChriz CreditAttribution: MegaChriz commentedI have made an experimental extension for User Import to import addresses upon user creation in the past. See my module here: #709726: Support for ubercart addresses (posted in #1). This module works only when importing users, it's not designed to import addresses after that. Also, the Extra Fields Pane integration code that is in there is outdated and will not work with the current version of Extra Fields Pane.
I have also been working on an extension module to import addresses with Feeds. This module will be compatible with Ubercart Addresses 6.x-2.x only. I have not published it yet, because I have not updated it for the latest revision of Ubercart Addresses 6.x-2.x yet. I'm too busy with getting Ubercart Addresses 6.x-2.x itself finished first.
However, if you have direct access to the database with phpMyAdmin, you could import addresses directly in the uc_addresses table. A few downsides:
- No addresses will be marked as default.
- For the country and zone fields you will first have to lookup their ID (check the uc_countries and the uc_zones tables).
I plan to finish the extension module to import addresses with Feeds in the future, but it will not be there before the first alpha release of Ubercart Addresses 6.x-2.x (which I hope to release before the end of this year).
Comment #2
zoraxthank you for this !
I will add Adresses directly with phpAdmin,
regards,
Comment #3
Michael-IDA CreditAttribution: Michael-IDA commentedSticking stub here for now:
Example, basic user migration into empty new system, keeping existing UID from old system.
- Pseudo code
- Most likely has syntax errors
- Most likely has logic errors
- One off
- Not efficient
- Throw away script
- Cut and paste what you need
- {how many more ways do I have to tell you...}
Usage:
php -f user-import.php
Comment #4
MegaChriz CreditAttribution: MegaChriz commentedOK, I had assumed that you was writing an extension to an existing module for importing data. Well, here is a sketchy version of the Feeds extension that I had made last year, when the Address book API was not yet finished. In the code some methods are called that were removed or renamed later, thus it isn't working code, but if someone wants to built it further before I will have the time do so, they will have some starting code here.
Comment #5
Michael-IDA CreditAttribution: Michael-IDA commented> I had assumed that you was writing an extension to an existing module for importing data.
No, I gave up trying to do that a long time ago, PHP is reasonably static and Drupal changes every major release...
Comment #6
MegaChriz CreditAttribution: MegaChriz commentedI have updated the issue summary. I'm moving to this to 7.x-1.x because this feature should first be fixed in that branch. After that it may be back ported to the 6.x-2.x branch if enough people like to have this feature in the 6.x-2.x version as well. Note that in #4 a "draft" of the 6.x-2.x implementation is there which may work with a few modifications.
Comment #7
MegaChriz CreditAttribution: MegaChriz commentedFirst patch for Feeds integration. You will be needing the latest dev of Feeds or else you may get a PHP fatal error if at least one address fails to import (see also #1953008-2: PHP Fatal error: Nesting level too deep - recursive dependency? in FeedsProcessor.inc on line 199).
The patch includes:
To do:
Let's see if the patch doesn't break any existing tests.
Comment #8
MegaChriz CreditAttribution: MegaChriz commentedI've the automated test for this issue as good as ready. In order to let the testbot execute the test, I first have added a dependency on the Feeds module for the test module. See commit.
New patch will follow.
Comment #9
MegaChriz CreditAttribution: MegaChriz commentedIn addition of the patch in #7, this patch adds automated tests and support for using countries in their native name when importing addresses. Using native country names is not covered by the automated test as I was not sure how to write a test for that. With manual testing it looks like it's working.
Comment #10
MegaChriz CreditAttribution: MegaChriz commentedSome cleanup and text corrections.
If this passes tests, I think it's ready for commit.
Comment #11
MegaChriz CreditAttribution: MegaChriz commentedCommitted #10.
Additions for the address book API should be backported. The Feeds integration feature itself is not planned to be backported to the 6.x-2.x version.
Comment #12
MegaChriz CreditAttribution: MegaChriz commentedAddress book API additions for the 6.x-2.x version. I don't expect it will fail tests, but you never know!
Comment #13
MegaChriz CreditAttribution: MegaChriz commentedCommitted #12.
Setting version back to 7.x-1.x, cause that is the version the Feeds integration feature was added to.
Comment #14.0
(not verified) CreditAttribution: commentedUpdated issue summary to clarify the status of this issue: which tasks need to be done prior fixing this issue and what already is done at this point.
Comment #15
gurunathan CreditAttribution: gurunathan commentedHi All,
I have enabled Ubercart addresses module.
Now I want to import users via CSV file by using Feeds module.
"Ubercart addresses" module allows to import addresses via CSV file.
But I want to import both the user and user's address by using a single CSV file.
Is it possible?
Comment #16
MegaChriz CreditAttribution: MegaChriz at WebCoo commented@gurunathan
You can use a single CSV file, but you have to you use two Feeds importers to import both users and addresses. First import all users (using the User processor) and then all addresses (using the Ubercart Addresses processor). For the address import, you can use the user's username or mail address to specify to which user the address belongs.
Your CSV file can look like this:
For the user import, you map at least "user_name" and "user_mail".
For the address import you map all the address fields you have "first_name", "postal_code", "country", etc plus either "user_name" or "user_mail".
Feeds will ignore columns from your CSV that you don't map, so you can have all the data in a single CSV file.