use strict;
use Config;
-our $VERSION = "1.008";
+our $VERSION = "1.009";
=head1 NAME
or die "No entries found for profile $profile\n";
my %map;
- for my $map (grep /^map_\w+$/, keys %ids) {
+ for my $map (grep /^map_[\w.-]+$/, keys %ids) {
(my $out = $map) =~ s/^map_//;
my $in = $ids{$map};
$in =~ /^\d+$/
$self->{map} = \%map;
my %set;
- for my $set (grep /^set_\w+$/, keys %ids) {
+ for my $set (grep /^set_[\w.-]+$/, keys %ids) {
(my $out = $set) =~ s/^set_//;
$set{$out} = $ids{$set};
}
$self->{set} = \%set;
my %xform;
- for my $xform (grep /^xform_\w+$/, keys %ids) {
+ for my $xform (grep /^xform_[\w.-]+$/, keys %ids) {
(my $out = $xform) =~ s/^xform_//;
$map{$out}
or die "Xform for $out but no mapping\n";
use BSE::TB::ProductOptionValues;
use BSE::TB::PriceTiers;
-our $VERSION = "1.011";
+our $VERSION = "1.012";
=head1 NAME
C<< prodoptI<index>_values >> - define the values for a product
option, separated by the configured C<prodop_value_sep>.
+=item * C<< prodoptI<index>_custom.I<name> >> - define custom values
+called I<name> for each value specified by C<< prodoptI<index>_values
+>>, separated by the configured C<prodop_value_sep>.
+
=item *
C<< tier_price_I<tier_id> >> - set the product price for the specified
or next;
my @values = split /\Q$self->{prodopt_value_sep}/, $values
or next;
+ my @custom = grep /^prodopt${opt_num}_custom\./, keys %entry;
+
+ my %custom_values;
+ for my $custom_name (@custom) {
+ (my $name = $custom_name) =~ s/^prodopt${opt_num}_custom\.//;
+ $custom_values{$name} = [ split /\Q$self->{prodopt_value_sep}/, $entry{$custom_name} ];
+ }
my $option = BSE::TB::ProductOptions->make
(
display_order => $ordering++,
);
+ my $index = 0;
for my $value (@values) {
my $entry = BSE::TB::ProductOptionValues->make
(
value => $value,
display_order => $ordering++,
);
+
+ for my $name (keys %custom_values) {
+ if ($index < @{$custom_values{$name}}) {
+ $entry->set_custom($name => $custom_values{$name}[$index]);
+ }
+ }
+ $entry->save;
+
+ ++$index;
}
}
codes=1
code_field=product_code
update_only=1
+
+[import profile withoption$when]
+map_linkAlias=1
+map_title=2
+map_prodopt1_name=3
+map_prodopt1_values=4
+map_prodopt1_custom.value_price=5
+map_retailPrice=6
+source=CSV
+skiplines=0
CFG
{
}
}
+{
+ my @added;
+
+ my $fh = File::Temp->new;
+ my $filename = $fh->filename;
+
+ print $fh <<EOS;
+test$when,"Test product option import $when","Colour","Red|Green|Blue","0|100|0",100
+EOS
+ close $fh;
+ my $imp = BSE::Importer->new(cfg => $cfg, profile => "withoption$when",
+ callback => sub { note @_ });
+ $imp->process($filename);
+
+ is_deeply([ $imp->errors ], [], "check no errors");
+
+ @added = sort { $a->title cmp $b->title } $imp->leaves;
+ is(@added, 1, "Only added one");
+ my $one = $added[0];
+ is($one->title, "Test product option import $when", "check the title is set");
+ my @options = $one->db_options;
+ is(@options, 1, "should be one option");
+ is($options[0]->name, "Colour", "name of option");
+ my @values = $options[0]->values;
+ is(@values, 3, "should be three options");
+ is($values[0]->value, "Red", "first value text correct");
+ is($values[1]->get_custom("value_price"), "100", "second custom field correct");
+
+ END {
+ $_->remove($cfg) for @added;
+ }
+}
+
done_testing();