conversion of Product from Wobjects to Skus with variants is done
This commit is contained in:
parent
6ad6cd3e5e
commit
9d2b810a05
3 changed files with 30 additions and 29 deletions
|
|
@ -636,21 +636,6 @@ sub migrateOldProduct {
|
||||||
print "\tMigrate old Product to new SKU based Products.\n" unless ($quiet);
|
print "\tMigrate old Product to new SKU based Products.\n" unless ($quiet);
|
||||||
# and here's our code
|
# and here's our code
|
||||||
##Grab data from Wobject table, and move it into Sku and Product, as appropriate.
|
##Grab data from Wobject table, and move it into Sku and Product, as appropriate.
|
||||||
print "\t\tAdding new product variants table.\n" unless ($quiet);
|
|
||||||
$session->db->write(<<'EOSQL');
|
|
||||||
CREATE TABLE Product_variants (
|
|
||||||
variantId VARCHAR(22) BINARY NOT NULL PRIMARY KEY,
|
|
||||||
varSku VARCHAR(255) BINARY NOT NULL UNIQUE,
|
|
||||||
assetId VARCHAR(22) BINARY NOT NULL,
|
|
||||||
mastersku VARCHAR(22) BINARY NOT NULL,
|
|
||||||
varTitle VARCHAR(255) BINARY NOT NULL,
|
|
||||||
shortdesc VARCHAR(30),
|
|
||||||
price FLOAT,
|
|
||||||
weight FLOAT,
|
|
||||||
quantity INT,
|
|
||||||
sequenceNumber INT
|
|
||||||
);
|
|
||||||
EOSQL
|
|
||||||
##Have to change the className's in the db, too
|
##Have to change the className's in the db, too
|
||||||
## Wobject description -> Sku description
|
## Wobject description -> Sku description
|
||||||
## Wobject displayTitle -> Sku displayTitle
|
## Wobject displayTitle -> Sku displayTitle
|
||||||
|
|
@ -674,6 +659,8 @@ EOSQL
|
||||||
$rmWobject->finish;
|
$rmWobject->finish;
|
||||||
$session->db->write(q!update asset set className='WebGUI::Asset::Sku::Product' where className='WebGUI::Asset::Wobject::Product'!);
|
$session->db->write(q!update asset set className='WebGUI::Asset::Sku::Product' where className='WebGUI::Asset::Wobject::Product'!);
|
||||||
|
|
||||||
|
## Add variants collateral column to Sku/Product
|
||||||
|
$session->db->write('alter table Product add column variantsJSON mediumtext');
|
||||||
##Build a variant for each Product.
|
##Build a variant for each Product.
|
||||||
my $productQuery = $session->db->read(<<EOSQL1);
|
my $productQuery = $session->db->read(<<EOSQL1);
|
||||||
SELECT p.assetId, p.price, p.productNumber, p.revisionDate, a.title, s.sku
|
SELECT p.assetId, p.price, p.productNumber, p.revisionDate, a.title, s.sku
|
||||||
|
|
@ -682,17 +669,14 @@ SELECT p.assetId, p.price, p.productNumber, p.revisionDate, a.title, s.sku
|
||||||
on p.assetId=a.assetId and p.revisionDate=a.revisionDate
|
on p.assetId=a.assetId and p.revisionDate=a.revisionDate
|
||||||
JOIN sku AS s
|
JOIN sku AS s
|
||||||
on p.assetId=s.assetId and p.revisionDate=s.revisionDate
|
on p.assetId=s.assetId and p.revisionDate=s.revisionDate
|
||||||
WHERE p.revisionDate=(SELECT MAX(revisionDate) FROM Product)
|
WHERE p.revisionDate=(SELECT MAX(revisionDate) FROM Product where Product.assetId=a.assetId)
|
||||||
EOSQL1
|
EOSQL1
|
||||||
#while (my $productData = $productQuery->hashRef()) {
|
while (my $productData = $productQuery->hashRef()) {
|
||||||
my $productData;
|
|
||||||
while ( () ) {
|
|
||||||
##Truncate title to 30 chars for short desc
|
##Truncate title to 30 chars for short desc
|
||||||
printf "Adding variant to %s\n", $productData->{title} unless $quiet;
|
printf "Adding variant to %s\n", $productData->{title} unless $quiet;
|
||||||
my $product = WebGUI::Asset::Sku::Product->new($session, $productData->{assetId}, 'WebGUI::Asset::Sku::Product', $productData->{revisionDate});
|
my $product = WebGUI::Asset::Sku::Product->new($session, $productData->{assetId}, 'WebGUI::Asset::Sku::Product', $productData->{revisionDate});
|
||||||
$product->setCollateral('Product_variants', 'varSku', {
|
$product->setCollateral('variantsJSON', 'new', {
|
||||||
varSku => ($productData->{productNumber} || $session->id->generate),
|
varSku => ($productData->{productNumber} || $session->id->generate),
|
||||||
mastersku => $product->get('sku'),
|
|
||||||
shortdesc => substr($productData->{title}, 0, 30),
|
shortdesc => substr($productData->{title}, 0, 30),
|
||||||
price => $productData->{price},
|
price => $productData->{price},
|
||||||
weight => 0,
|
weight => 0,
|
||||||
|
|
@ -705,8 +689,6 @@ EOSQL1
|
||||||
$session->db->write('alter table Product drop column productNumber');
|
$session->db->write('alter table Product drop column productNumber');
|
||||||
## Remove price from Product since prices are now stored in variants
|
## Remove price from Product since prices are now stored in variants
|
||||||
$session->db->write('alter table Product drop column price');
|
$session->db->write('alter table Product drop column price');
|
||||||
## Add variants collateral column
|
|
||||||
$session->db->write('alter table Product add column variantsJSON mediumtext');
|
|
||||||
|
|
||||||
## Update config file, deleting Wobject::Product and adding Sku::Product
|
## Update config file, deleting Wobject::Product and adding Sku::Product
|
||||||
$session->config->deleteFromArray('assets', 'WebGUI::Asset::Wobject::Product');
|
$session->config->deleteFromArray('assets', 'WebGUI::Asset::Wobject::Product');
|
||||||
|
|
|
||||||
|
|
@ -225,8 +225,13 @@ sub getAllCollateral {
|
||||||
my $tableName = shift;
|
my $tableName = shift;
|
||||||
return $self->{_collateral}->{$tableName} if exists $self->{_collateral}->{$tableName};
|
return $self->{_collateral}->{$tableName} if exists $self->{_collateral}->{$tableName};
|
||||||
my $json = $self->get($tableName);
|
my $json = $self->get($tableName);
|
||||||
return [] unless $json;
|
my $table;
|
||||||
my $table = from_json($json);
|
if ($json) {
|
||||||
|
$table = from_json($json);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$table = [];
|
||||||
|
}
|
||||||
$self->{_collateral}->{$tableName} = $table;
|
$self->{_collateral}->{$tableName} = $table;
|
||||||
return $table;
|
return $table;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,15 +35,14 @@ my $session = WebGUI::Test->session;
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# Tests
|
||||||
|
|
||||||
plan tests => 23; # Increment this number for each test you create
|
plan tests => 24; # Increment this number for each test you create
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# put your tests here
|
# put your tests here
|
||||||
my $root = WebGUI::Asset->getRoot($session);
|
my $root = WebGUI::Asset->getRoot($session);
|
||||||
my $product = $root->addChild({
|
my $product = $root->addChild({
|
||||||
className =>"WebGUI::Asset::Sku::Product",
|
className => "WebGUI::Asset::Sku::Product",
|
||||||
title =>"Test Donation",
|
title => "Rock Hammer",
|
||||||
price => 44.44,
|
|
||||||
});
|
});
|
||||||
isa_ok($product, "WebGUI::Asset::Sku::Product");
|
isa_ok($product, "WebGUI::Asset::Sku::Product");
|
||||||
ok(! exists $product->{_collateral}, 'object cache does not exist yet');
|
ok(! exists $product->{_collateral}, 'object cache does not exist yet');
|
||||||
|
|
@ -226,6 +225,21 @@ cmp_deeply(
|
||||||
);
|
);
|
||||||
|
|
||||||
$product->purge;
|
$product->purge;
|
||||||
|
undef $product;
|
||||||
|
|
||||||
|
my $product2 = $root->addChild({
|
||||||
|
className => "WebGUI::Asset::Sku::Product",
|
||||||
|
title => "Bible",
|
||||||
|
});
|
||||||
|
|
||||||
|
$product2->setCollateral('variantsJSON', 'new', { s => 'scooby', d => 'doo'});
|
||||||
|
cmp_deeply(
|
||||||
|
$product2->getCollateral('variantsJSON', 0),
|
||||||
|
{ s => 'scooby', d => 'doo'},
|
||||||
|
'Doing a set before get works okay',
|
||||||
|
);
|
||||||
|
|
||||||
|
$product2->purge;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Cleanup
|
# Cleanup
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue