finish the import routine. Next, testing
This commit is contained in:
parent
17c7a0ad7a
commit
4712ba2823
1 changed files with 23 additions and 3 deletions
|
|
@ -44,7 +44,7 @@ sub exportProducts {
|
||||||
@columns = map { $_ eq 'shortdescription' ? 'shortdesc' : $_ } @columns;
|
@columns = map { $_ eq 'shortdescription' ? 'shortdesc' : $_ } @columns;
|
||||||
while (my $product = WebGUI::Asset::Sku::Product->getAllProducts($session)) {
|
while (my $product = WebGUI::Asset::Sku::Product->getAllProducts($session)) {
|
||||||
my $mastersku = $product->get('sku');
|
my $mastersku = $product->get('sku');
|
||||||
my $collateri = $product->getAllCollateral();
|
my $collateri = $product->getAllCollateral('variantsJSON');
|
||||||
foreach my $collateral (@{ $collateri }) {
|
foreach my $collateral (@{ $collateri }) {
|
||||||
my @productFields = @{ $collateral }{ @columns };
|
my @productFields = @{ $collateral }{ @columns };
|
||||||
$productData .= WebGUI::Test::joinCSV($mastersku, @productFields);
|
$productData .= WebGUI::Test::joinCSV($mastersku, @productFields);
|
||||||
|
|
@ -142,19 +142,39 @@ sub importProducts {
|
||||||
##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');
|
my $fetchProductId = $session->db->prepare('select assetId from Product where mastersku=? order by revisionDate DESC limit 1');
|
||||||
foreach my $productRow (@productData) {
|
my $node = WebGUI::Asset::Sku::Product->getProductImportNode($session);
|
||||||
|
PRODUCT: foreach my $productRow (@productData) {
|
||||||
my %productRow;
|
my %productRow;
|
||||||
##Order the data according to the headers, in whatever order they exist.
|
##Order the data according to the headers, in whatever order they exist.
|
||||||
@productRow { @headers } = @{ $productRow };
|
@productRow{ @headers } = @{ $productRow };
|
||||||
$fetchProductId->execute([$productRow->{mastersku}]);
|
$fetchProductId->execute([$productRow->{mastersku}]);
|
||||||
my ($assetId) = $fetchProductId->hashRef->{assetId};
|
my ($assetId) = $fetchProductId->hashRef->{assetId};
|
||||||
##If the assetId exists, we update data for it
|
##If the assetId exists, we update data for it
|
||||||
if ($assetId) {
|
if ($assetId) {
|
||||||
my $product = WebGUI::Asset->newPending($session, $assetId);
|
my $product = WebGUI::Asset->newPending($session, $assetId);
|
||||||
|
if ($productRow{title} ne $product->getTitle) {
|
||||||
|
$product->update({ title => $product->fixTitle($productRow{title}) });
|
||||||
|
}
|
||||||
##Error handling for locked assets
|
##Error handling for locked assets
|
||||||
|
next PRODUCT if $product->isLocked;
|
||||||
|
my $collaterals = $product->getAllCollateral('variantsJSON');
|
||||||
|
my $collateralSet = 0;
|
||||||
|
ROW: foreach my $collateral (@{ $collaterals }) {
|
||||||
|
next ROW unless $collateral->{sku} eq $productRow->{sku};
|
||||||
|
@{ $collateral}{@headers} = @productRow{ @headers };
|
||||||
|
$product->setCollateral('variantsJSON', 'variantId', $collateral->{variantId}, $collateral);
|
||||||
|
$collateralSet=1;
|
||||||
|
}
|
||||||
|
if (!$collateralSet) {
|
||||||
|
##It must be a new variant
|
||||||
|
$product->setCollateral('variantsJSON', 'variantId', 'new', \%productRow);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
##Insert a new product;
|
##Insert a new product;
|
||||||
|
my $newProduct = $node->addChild({className => 'WebGUI::Asset::Sku::Product'});
|
||||||
|
$newProduct->update({ title => $newProduct->fixTitle($productRow{title}) });
|
||||||
|
$newProduct->setCollateral('variantsJSON', 'variantId', 'new', \%productRow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue