Skip to content

Instantly share code, notes, and snippets.

@scottwalters
Last active September 2, 2015 18:31
Show Gist options
  • Save scottwalters/cbd175e40a937c68826c to your computer and use it in GitHub Desktop.
Save scottwalters/cbd175e40a937c68826c to your computer and use it in GitHub Desktop.
in a method in a Content Handler:
my $cart = WebGUI::Shop->Cart->newBySession($session);
my $asset_id = $session->db->quickScalar("select assetId from sku where sku = ?", [ $session->request->param('sku')) ]);
my $product;
if( $asset_id ) {
$product = WebGUI::Asset::Sku::Product->newById($session, $asset_id);
} else {
$product = WebGUI::Asset::Sku::Product->new($session);
}
# update $product from other post/get data here, or from pulling data from another database here
# make sure to do $product->update({ }) with all data including the sku; the sku will match for existing products but it needs to be set if we just created this
$cart->addItem($product);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment