Attached is a patch that provides the Money CCK field as a mapping target for http://drupal.org/project/feeds (the successor to FeedAPI).

Caveat: only the 'amount' value is currently exposed; for this to work, a default currency needs to be specified for the content type.

Comments

markus_petrux’s picture

Status: Needs review » Needs work

CCK fields may have several columns, and I think the feeds mapper should support that, either allowing the user to choose from different sources, or allowing them specify defaults. So when money_feeds_set_target() is invoked. the currency should be provided in $value argument.

Other than that, I would happily commit this. One thing I would "touch" tough is that it should be implemented on a separate file, just like diff integration in money module.

smokris’s picture

StatusFileSize
new2.15 KB
new344 bytes

Ah, good point. I moved it to a separate file (of course, rename it to take off the ".txt" extension and remove the funky underscores drupal.org added).

Since we have two columns, we need two mappings (one field for amount, one field for currency). I've modified the code to do this. How does this look?

markus_petrux’s picture

Status: Needs work » Needs review

Looks better. Thanks

There are a few things that concern me. I looked briefly at feeds module code, and it seems to me the node is not being validated after the mappers have populated content, and so the feed could inject data that is not valid. This is specially important with CCK fields, or any other data that limits allowed values to a set, or that have other specific validators. For example:

1) Money fields allow users specify allowed list of currencies, so we should not accept a currency that is not allowed.
2) Users should be able to map the amount and the currency. Both are tied together. Money field does not allow amounts without currency.
3) CCK fields could be configured to be required, so this check should be enforced here somehow.
4) CCK field may or may not accept multiple values, or a fixed number of multiple values. This check should also be enforced here somehow.

Before committing support for feeds to money module, I would appreciate some feedback on that. Otherwise, I may end up getting support request and bug reports for something that I have no control, and lack of time too.

Keeping the patch here still allows users to test. And once this is considered stable, then I would happily commit. :)

markus_petrux’s picture

Status: Needs review » Needs work

This patch needs work, but I think Feeds module integration with CCK also needs work. Otherwise, it's a potential source of inconsistencies, hence unexpected behavior. If invalid data is saved with the node, then there may be modules that do not work as expected. Feeds module should validate the node before saving.

summit’s picture

Subscribing,
Any progress in this field please? Is this the way of solution to get a cck currency field within feeds scope?

Thanks a lot in advance for your reply!
,greetings, Martijn

BenK’s picture

Subscribing

kenorb’s picture

I'm not sure about current, but this patch works great:
#1010312: Mapper for CCK money field.

twistor’s picture

At least we're all in one place now. #1010312: Mapper for CCK money field..

hanno’s picture

@markus_petrix #4: the feeds module doesn't validate data nor use default values, same for the other mappers and I suppose this is by design. As the feeds module doesn't accept user generated content, it assumes that the data in the feeds is 100% correct, or is corrected by helper modules like the feeds tamper module.

So, this module could just deliver a mapper and users should provide correct data, or correct it by a module or helper modules.

joseph.olstad’s picture

Hi, it appears the D6 money mapper does not work with the D7 money field that I'm using. I'm working on this issue right now, if someone else has already solved this problem using the nouriassafi's sandbox: Drupal 7 port of Money CCK Field, then please let me know. I'm using the nouriassafi sandbox version (excellent version by the way, and I'm trying to find a way to add a mapper for it)

I've noticed that the commerce feeds module might provide some clues http://drupal.org/project/commerce_feeds. So that's where I'm at right now, hopefully I'll come back with a solution shortly if no one else does first.

joseph.olstad’s picture

StatusFileSize
new2.67 KB

See attachment called money.diff for the D7 money feed mapper code, this requires the nouriassafi D7 version of the money module http://drupal.org/sandbox/nouriassafi/1619328

I will be doing more testing tomorrow but what I tested so far works. see follow up.

joseph.olstad’s picture

StatusFileSize
new3.27 KB

updated D7 feeds integration money mapper

kenorb’s picture

Status: Needs work » Closed (duplicate)
kenorb’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Closed (duplicate) » Needs work

Patch #13 can be integrated with latest 7.x version, but it needs some work, as some of the variables are hardcoded.
E.g.

$currency = "CAD"; //hard coding to Canadian Dollars, TODO: please fix this

And there are some TODOs.

kenorb’s picture

Status: Needs work » Needs review

Patch #2 looks much better, but it needs to be integrated with the latest 7.x and tested.

kenorb’s picture

Status: Needs review » Fixed

Committed on Mar 30, no issue reported, so marking it as fixed.

joseph.olstad’s picture

Just a note to those that might stumble upon this and not realize that there's an easy way to do currency without needing the "money" module (nothing against the money module, it's just that most people probably don't need all of it's features and I found that it required extra work to integrate into some other contributed modules such as feeds for example), there is a much easier way to do currency that is contrib module friendly (as it's using core field types such as decimal).

An easy/clean/safe way to do localized currency (in this case french and english Canadian dollars) is with a standard decimal field, simply add a "custom formatter" to it using the "Custom Formatters" module (7.x-2.2 or higher) as follows:

Formatter name: money_cad

Description: Money - Canadian, Monnaie - Canadien

Format: PHP

field types: number_decimal, computed

Formatter: (code)
global $language;

$amount = $variables['#items'][0]['value'];

if ($language->language == 'en') {
$amount = '$ ' . number_format($amount, 2, '.' , ',' );
} elseif ($language->language == 'fr') {
$amount = number_format($amount, 2, ',' , ' ' ) . ' $';
}

return $amount;

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

dubs’s picture

Issue summary: View changes

Hi - just to let you know, the wrong patch was committed for D7 - it should have been the version here https://drupal.org/files/money_1.diff.

Thanks :-)

dubs’s picture

Status: Closed (fixed) » Patch (to be ported)

Just adding this comment to re-open - please see above comment about wrong patch for D7

kenorb’s picture

Status: Patch (to be ported) » Needs work
StatusFileSize
new3.18 KB

Attached recent patch in git format with removed trailing spaces, etc.
There are lot of TODOs and FIXMEs in that patch with some hardcoded variables (like language, CAD currency, etc.).
I think it needs more work to commit.

noodlemanny’s picture

I'm getting a 'Hunk #1 failed at 543' when trying to apply the patch from #22. This is with the most up to date version of the money module. I really have very little experience with applying patches so lack the understanding to determine what's wrong and if its fixable.