Skip to content

Instantly share code, notes, and snippets.

@tedkulp
Created November 20, 2008 12:01
Show Gist options
  • Save tedkulp/27025 to your computer and use it in GitHub Desktop.
Save tedkulp/27025 to your computer and use it in GitHub Desktop.
<?php
#-------------------------------------------------------------------------
# Module: Cart - A simple example frontend form module
# Version: 1.0, calguy1000 <calguy1000@cmsmadesimple.org>
#
#-------------------------------------------------------------------------
# CMS - CMS Made Simple is (c) 2005 by Ted Kulp (wishy@cmsmadesimple.org)
# This project's homepage is: http://www.cmsmadesimple.org
# The module's homepage is: http://dev.cmsmadesimple.org/projects/skeleton/
#
#-------------------------------------------------------------------------
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Or read it online: http://www.gnu.org/licenses/licenses.html#GPL
#
#-------------------------------------------------------------------------
if( !isset($gCms) ) exit;
$viewcartpage = '';
if (isset($params['viewcartpage']))
{
$manager =& $gCms->GetHierarchyManager();
$node =& $manager->sureGetNodeByAlias($params['viewcartpage']);
if (isset($node))
{
$content =& $node->GetContent();
if (isset($content))
{
$viewcartpage = $content->Id();
}
}
else
{
$node =& $manager->sureGetNodeById($params['viewcartpage']);
if (isset($node))
{
$viewcartpage = $params['viewcartpage'];
}
}
}
$destpage = $returnid;
if( $viewcartpage != '' )
{
$destpage = $viewcartpage;
}
// Expand the cart
if( isset($params['cart_adjust']) )
{
// editing the current cart
$items = $this->GetItems();
// override the quantity checkbox
$idx = 0;
foreach( $params as $key => $value )
{
if( preg_match( '/cart_quantity_/', $key ) )
{
$idx = (int)substr($key,14);
$items[$idx]->quantity = $value;
}
}
$newitems = array();
foreach( $items as $oneitem )
{
if( $oneitem->quantity > 0 )
{
$newitems[] = $oneitem;
}
}
// re-package the cart
$this->SetItems($newitems);
$this->RedirectContent($returnid);
}
//$products =& $this->GetModuleInstance('Products');
$smarty->assign('shipping_price',$this->GetShippingCost());
$smarty->assign('cartsubtotal',$this->GetSubTotal());
$smarty->assign('cartweight',$this->GetTotalWeight());
$smarty->assign('carttaxes',$this->GetTaxes()); // implement in template
$smarty->assign('carttotal',$this->GetCartTotal());
$cartobjs = array();
$idx = 0;
$items = $this->GetItems();
foreach( $items as $oneitem )
{
$obj = $oneitem;
/*
$obj->flds = $products->GetFieldDefsForProduct( $obj->product_id );
$obj->categories = $products->GetCategoriesForProduct( $obj->product_id );
$obj->quantity_box = $this->CreateInputText($id,'cart_quantity_'.$idx,
$obj->quantity,3,3);
*/
$obj->remove_link = $this->CreateLink($id, 'viewcart', $returnid, 'Remove', array('remove_item' => $idx));
$cartobjs[] = $obj;
$idx++;
}
$smarty->assign('cartitems',$cartobjs);
// stop here
$smarty->assign('subtotal_text',$this->Lang('subtotal'));
$smarty->assign('pricetext',$this->Lang('price'));
$smarty->assign('quantitytext',$this->Lang('quantity'));
$smarty->assign('shipping_text',$this->Lang('shipping'));
$smarty->assign('total_text',$this->Lang('total'));
$smarty->assign('total_weight_text',$this->Lang('total_weight'));
$smarty->assign('currencysymbol', '');
$smarty->assign('weightunits', '');
if( !isset($params['hideform']) )
{
$smarty->assign('formstart',$this->CGCreateFormStart($id,'viewcart',$destpage));
$smarty->assign('formend',$this->CreateFormEnd());
$smarty->assign('submit_name',$id.'cart_adjust');
$smarty->assign('submit_text',$this->Lang('submit'));
}
$thetemplate = 'viewcartform_'.$this->GetPreference('viewcartform_dflt');
if( isset($params['viewcarttemplate'] ) )
{
$thetemplate = 'viewcartform_'.$params['viewcarttemplate'];
}
echo $this->ProcessTemplateFromDatabase($thetemplate);
// EOF
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment