importer: only modify the price tiers that have mapped columns
authorTony Cook <tony@develop-help.com>
Tue, 28 May 2013 05:37:42 +0000 (15:37 +1000)
committerTony Cook <tony@develop-help.com>
Tue, 28 May 2013 05:37:42 +0000 (15:37 +1000)
site/cgi-bin/modules/BSE/Importer/Target/Product.pm
t/130-importer/030-product.t

index fef5e5d6936b8fea9a191fd85e0c2cd1f918e9cb..6a2c4dd70f713132f066f1c33f24b6cd554f3bf6 100644 (file)
@@ -8,7 +8,7 @@ use BSE::TB::ProductOptions;
 use BSE::TB::ProductOptionValues;
 use BSE::TB::PriceTiers;
 
-our $VERSION = "1.004";
+our $VERSION = "1.005";
 
 =head1 NAME
 
@@ -280,7 +280,7 @@ sub fill_leaf {
     }
   }
 
-  my %prices;
+  my %prices = map { $_->tier_id => $_->retailPrice } $leaf->prices;
   for my $tier_id (keys %{$self->{price_tiers}}) {
     my $price = $entry{"tier_price_$tier_id"};
     if (defined $price && $price =~ /\d/) {
index e55e874f2eac38368467e818cf3071b51d847d75..5c61b85b2c7f79f4f7c31943ceb940df1eb8b40d 100644 (file)
@@ -10,7 +10,7 @@ BEGIN {
     or plan skip_all => "Text::CSV not available";
 }
 
-plan tests => 8;
+plan tests => 11;
 
 BEGIN {
   unshift @INC, File::Spec->catdir(BSE::Test::base_dir(), "cgi-bin", "modules");
@@ -80,6 +80,8 @@ CFG
      product_code => "C$when",
     );
 
+  $testa->set_prices({ 1 => 400 });
+
   {
     my $fh = File::Temp->new;
     my $filename = $fh->filename;
@@ -110,6 +112,15 @@ EOS
     is_deeply([ $imp->leaves ], [], "should be no updated articles");
   }
 
+ SKIP:
+  {
+    my @prices = $testa->prices;
+    is(@prices, 1, "should still be a tier price")
+      or skip "No prices found", 2;
+    is($prices[0]->tier_id, 1, "check tier id");
+    is($prices[0]->retailPrice, 400, "check tier price");
+  }
+
   END {
     $testa->remove($cfg) if $testa;
   }