Fix two bugs with importing product data.
Begin to build code for adding and editing products.
This commit is contained in:
parent
12fbd6a65c
commit
e562a45b10
2 changed files with 22 additions and 3 deletions
|
|
@ -96,7 +96,7 @@ sub importProducts {
|
||||||
my @headers = WebGUI::Text::splitCSV($headers);
|
my @headers = WebGUI::Text::splitCSV($headers);
|
||||||
WebGUI::Error::InvalidFile->throw(error => qq{Bad header found in the CSV file}, brokenFile => $filePath)
|
WebGUI::Error::InvalidFile->throw(error => qq{Bad header found in the CSV file}, brokenFile => $filePath)
|
||||||
unless (join(q{-}, sort @headers) eq 'mastersku-price-quantity-shortdescription-sku-title-weight')
|
unless (join(q{-}, sort @headers) eq 'mastersku-price-quantity-shortdescription-sku-title-weight')
|
||||||
and (scalar @headers == 5);
|
and (scalar @headers == 7);
|
||||||
my @productData = ();
|
my @productData = ();
|
||||||
my $line = 1;
|
my $line = 1;
|
||||||
while (my $productRow = <$table>) {
|
while (my $productRow = <$table>) {
|
||||||
|
|
@ -104,13 +104,29 @@ sub importProducts {
|
||||||
$productRow =~ s/\s*#.+$//;
|
$productRow =~ s/\s*#.+$//;
|
||||||
next unless $productRow;
|
next unless $productRow;
|
||||||
local $_;
|
local $_;
|
||||||
my @productRow = map { tr/|/,/; $_; } WebGUI::Text::splitCSV($productRow);
|
my @productRow = WebGUI::Text::splitCSV($productRow);
|
||||||
WebGUI::Error::InvalidFile->throw(error => qq{Error found in the CSV file}, brokenFile => $filePath, brokenLine => $line)
|
WebGUI::Error::InvalidFile->throw(error => qq{Error found in the CSV file}, brokenFile => $filePath, brokenLine => $line)
|
||||||
unless scalar @productRow == 5;
|
unless scalar @productRow == 7;
|
||||||
push @productData, [ @productRow ];
|
push @productData, [ @productRow ];
|
||||||
}
|
}
|
||||||
##Okay, if we got this far, then the data looks fine.
|
##Okay, if we got this far, then the data looks fine.
|
||||||
return unless scalar @productData;
|
return unless scalar @productData;
|
||||||
|
my $fetchProductId = $session->db->prepare('select assetId from Product where mastersku=? order by revisionDate DESC limit 1');
|
||||||
|
foreach my $productRow (@productData) {
|
||||||
|
my %productRow;
|
||||||
|
##Order the data according to the headers, in whatever order they exist.
|
||||||
|
@productRow { @headers } = @{ $productRow };
|
||||||
|
$fetchProductId->execute([$productRow->{mastersku}]);
|
||||||
|
my ($assetId) = $fetchProductId->hashRef->{assetId};
|
||||||
|
##If the assetId exists, we update data for it
|
||||||
|
if ($assetId) {
|
||||||
|
my $product = WebGUI::Asset->newPending($session, $assetId);
|
||||||
|
##Error handling for locked assets
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
##Insert a new product;
|
||||||
|
}
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ use Data::Dumper;
|
||||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||||
use WebGUI::Session;
|
use WebGUI::Session;
|
||||||
use WebGUI::Text;
|
use WebGUI::Text;
|
||||||
|
use WebGUI::Asset::Sku::Product;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Init
|
# Init
|
||||||
|
|
@ -53,6 +54,8 @@ SKIP: {
|
||||||
#
|
#
|
||||||
#######################################################################
|
#######################################################################
|
||||||
|
|
||||||
|
my $importNode = WebGUI::Asset::Sku::Product->getProductImportNode($session);
|
||||||
|
|
||||||
eval { WebGUI::Shop::Products::importProducts($session); };
|
eval { WebGUI::Shop::Products::importProducts($session); };
|
||||||
$e = Exception::Class->caught();
|
$e = Exception::Class->caught();
|
||||||
isa_ok($e, 'WebGUI::Error::InvalidParam', 'importProducts: error handling for an undefined path to file');
|
isa_ok($e, 'WebGUI::Error::InvalidParam', 'importProducts: error handling for an undefined path to file');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue