function get_user() { if (!isset($this->user)) { $this->user = cmClassFactory::getInstanceOf(CSHOP_CLASSES_USER, $this->db); if (!$this->header or !isset($this->header['user_id'])) { $this->fetch(array('user_id')); } $this->user->set_id($this->header['user_id']); } return $this->user; }
} // control flags $ACTION = null; $SHOWFORM = false; $SUCCESS = null; $errs = array(); $msg = ''; /** define set of actions this script can perform **/ define('OP_NEW_USER', 'CREATE ACCOUNT'); define('OP_VIEW_ACCOUNT', 'YOUR PROFILE'); define('OP_EDIT_PROFILE', 'UPDATE PROFILE'); define('OP_EDIT_ADDR', 'UPDATE ADDRESS'); define('OP_KILL_ADDR', 'DELETE ADDRESS'); define('OP_SHOW_ORDERS', 'YOUR ORDER HISTORY'); define('OP_EDIT_LOGIN', 'UPDATE LOGIN'); $cart = cmClassFactory::getInstanceOf(CSHOP_CLASSES_CART, $pdb); /* decide what currency to show. They would have set this in the cart */ $sess::register('CSHOP_CURRENCY_DISPLAY'); $cart->set_display_currency($CSHOP_CURRENCY_DISPLAY); /** setup smarty with a method from the $cart object to convery currencies */ $smarty->register_modifier('currency_format', array(&$cart, 'currency_format')); // setup the minicart $smarty->assign('minicart', $cart->get_minicart_values()); $smarty->assign('cartitems', $cart->fetch_items()); /** decide on a course of action **/ if ($userinfo and empty($_POST)) { // flags in GET causes various forms to display $ACTION = OP_VIEW_ACCOUNT; if (isset($_GET['op_prof'])) { $ACTION = OP_EDIT_PROFILE; $SHOWFORM = true;
/** if there was a sucessful POST, do a redirect */ /*{{{*/ if ($msg and !count($errs) and $ACTION) { // send back to self with messageness header("Location: {$_SERVER['PHP_SELF']}?{$base_get_vars}&info=" . base64_encode($msg)); exit; } /*}}}*/ if ($ACTION) { $SHOWFORM = true; } /* either show an adding/editing form **************************************************/ /*{{{*/ if ($SHOWFORM) { /* get all categories which can be included in any bundle */ $cat = cmClassFactory::getSingletonOf(CSHOP_CLASSES_PRODUCT_CATEGORY, $pdb); $cats = $cat->get_categories_for_bundles(array('name', 'id')); $cat_options = array(); if (empty($cats)) { $errs[] = 'No Product Categories have been flagged as being available to bundle here.'; } else { foreach ($cats as $c) { $cat_options[$c['id']] = $c['name']; } } $fex->add_element('required_cats', array('', 'bundler_cats', $cat_options, 0)); $fex->add_element('op', array($ACTION, 'submit')); // the button if ($ACTION == OP_EDIT) { $bundle->set_id($req_id); $vals = $bundle->fetch();
} elseif (isset($_POST[$reqIdKey]) and isset($_POST['op_kill'])) { $itemid = $_POST[$reqIdKey]; $ACTION = OP_KILL; } elseif (isset($_POST[$reqIdKey]) and isset($_POST['op_pass'])) { $itemid = $_POST[$reqIdKey]; $ACTION = OP_PASS; } elseif (isset($_GET[$reqIdKey]) and !empty($_GET[$reqIdKey])) { $itemid = $_GET[$reqIdKey]; $ACTION = OP_EDIT; } elseif (isset($_GET['op_add'])) { $ACTION = OP_ADD; } else { $SHOWFORM = false; } /** **/ $user = cmClassFactory::getInstanceOf(CSHOP_CLASSES_USER, $pdb); $pagetitle = 'Users'; $table_title = 'User'; $table_namecol = 'email'; /** POST rec'd, check valid, proc. upload and save if OK */ if (isset($_POST['op']) and ($ACTION == OP_ADD or $ACTION == OP_EDIT)) { $mosh = new mosh_tool(); $mosh->form_field_prefix = ''; $vals = array(); $img_vals = array(); if ($errs = $mosh->check_form($user->get_colmap())) { // handled below } else { $vals = $mosh->get_form_vals($user->colmap); $user->db->pushErrorHandling(PEAR_ERROR_RETURN); if ($ACTION == OP_EDIT) {
/** * add or edit product relations - called from w/in IFRAME in products editor * * $Id: store.product_relations.php,v 1.1 2008/06/12 15:58:22 sbeam Exp $ */ error_reporting(E_ALL); require_once CONFIG_DIR . 'cshop.config.php'; require_once 'formex.class.php'; require_once 'mosh_tool.class.php'; require_once "fu_HTML_Table.class.php"; $thing = 'Product Relations'; $ACTION = null; define('OP_ADD', 'Add new ' . $thing); define('OP_EDIT', 'Update ' . $thing); $pc = cmClassFactory::getInstanceOf(CSHOP_CLASSES_PRODUCT, $pdb); $msg = null; $productid = null; $errs = array(); $ACTION = OP_EDIT; /** decide on a course of action... **/ if (isset($_POST['f_op']) and $_POST['f_op'] == OP_EDIT) { $productid = $_POST['f_nid']; $ACTION = OP_EDIT; } elseif (isset($_GET['nid']) and !empty($_GET['nid'])) { $productid = $_GET['nid']; } /** **/ if (!$productid) { trigger_error("productid was not passed", E_USER_ERROR); }
function payment_method_factory() { return cmClassFactory::getInstanceOf(CSHOP_CLASSES_PAYMETHOD, $this->db); }
/** find out how much I am worth * @param $amt float the amount of the order so far (subtotal) * @return float */ function calculate_discount($amt, $product_id = null) { if ($this->fetch(null, true)) { $does_apply = true; if (!empty($this->header['cm_coupons_categories']) && $product_id) { $does_apply = false; $product = cmClassFactory::getInstanceOf(CSHOP_CLASSES_PRODUCT, $this->db); $product->set_id($product_id); $product_cats = $product->fetch_product_categories(); foreach ($product_cats as $pcat) { if (in_array($pcat['id'], $this->header['cm_coupons_categories'])) { $does_apply = true; } } } if ($does_apply) { if ($this->header['percent_off']) { return $amt * $this->header['percent_off'] / 100; } else { return $amt < $this->header['amt_off'] ? $amt : $this->header['amt_off']; } } else { return 0; } } }
} /** setup smarty with a method from the $cart object to convery currencies */ $smarty->register_modifier('currency_format', array(&$cart, 'currency_format')); /** here is where the order is offically created **/ if (isset($_POST['op_confirm'])) { $order = cmClassFactory::getInstanceOf(CSHOP_CLASSES_ORDER, $pdb); $order->set_user($user); $order->set_cart($cart); $res = $order->create(); $gate = cmPaymentGateway::factory(CSHOP_CLASSES_PAYMENT_GATEWAY, $user, $pay, $order); $gate->setErrorHandling(PEAR_ERROR_RETURN); $PAYMENT_SUCCESS = false; /* check all giftcards attached to this cart for validity. If any fail, set $payment_error_type */ if (CSHOP_ACCEPT_GIFTCARDS) { foreach ($cart->get_giftcards() as $gc_vals) { $gc = cmClassFactory::getInstanceOf(CSHOP_CLASSES_GIFTCARD, $pdb); $gc->setErrorHandling(PEAR_ERROR_RETURN); $gc->set_id($gc_vals['id']); // send request to GC processor, make sure it's still valid for the req. amt $res = $gc->redeem($order); if (PEAR::isError($res)) { $payment_error = $res->getMessage(); $payment_error_type = 'INVALID GIFTCARD'; trigger_error("Giftcard could not be redeemed: {$payment_error}", E_USER_NOTICE); } } } if (CSHOP_DO_TAKE_COUPONS) { if ($coup = $cart->get_discount_descrip()) { if ($cart_total <= 0) { $payment_error_type = 'FULL COUPONS';
/** * add or edit product options - called from w/in IFRAME in products editor * * $Id: store.product_categories.php,v 1.1 2008/06/12 15:58:22 sbeam Exp $ */ error_reporting(E_ALL); require_once CONFIG_DIR . 'cshop.config.php'; require_once 'formex.class.php'; require_once 'mosh_tool.class.php'; require_once "fu_HTML_Table.class.php"; $thing = 'Product Categories'; $ACTION = null; define('OP_ADD', 'Add new ' . $thing); define('OP_EDIT', 'Update ' . $thing); $pc = cmClassFactory::getInstanceOf(CSHOP_CLASSES_PRODUCT, $pdb); $pcat = cmClassFactory::getInstanceOf(CSHOP_CLASSES_PRODUCT_CATEGORY, $pdb); $msg = null; $productid = null; $errs = array(); $ACTION = OP_EDIT; /** decide on a course of action... **/ if (isset($_POST['f_op']) and $_POST['f_op'] == OP_EDIT) { $productid = $_POST['f_nid']; $ACTION = OP_EDIT; } elseif (isset($_GET['nid']) and !empty($_GET['nid'])) { $productid = $_GET['nid']; } /** **/ if (!$productid) { trigger_error("productid was not passed", E_USER_ERROR); }
// get download token if (empty($_GET['tok']) or empty($_GET['file_token'])) { trigger_error('required parameter missing', E_USER_ERROR); } if (!$order->set_id_by_token($_GET['tok'])) { trigger_error('order id not found', E_USER_ERROR); } $orderinfo = $order->fetch(); if ($orderinfo['user_id'] != $auth_uid) { if ($auth->conditional_login()) { // will show login form if not logged in yet. trigger_error("illegal attempt to access order", E_USER_ERROR); } else { trigger_error("order access deferred pending login", E_USER_WARNING); exit; } } // look up product info $item_info = $order->fetch_downloadable_by_token($_GET['file_token']); if (!$item_info) { trigger_error("unknown download token", E_USER_ERROR); } // // check logged-in user has access to it if ($item_info['order_id'] != $orderinfo['id']) { trigger_error("illegal attempt to access download", E_USER_ERROR); } $filename = preg_replace('/[^\\w\\d._-]+/', '_', $item_info['product_descrip']) . '.zip'; header('Content-Disposition: attachment; filename="' . $filename . '"'); $downlo = cmClassFactory::getInstanceOf(CSHOP_CLASSES_DOWNLOADS, $pdb); $downlo->digital_download_dumper($item_info['product_id']);
function generate_order_token() { if (!$this->get_id()) { return; } $order = cmClassFactory::getSingletonOf(CSHOP_CLASSES_ORDER, $this->db); $tok = $order->create_order_token(); try { $this->store(array('order_token' => $tok)); } catch (Exception $e) { if ($e->getCode() == DB_ERROR_ALREADY_EXISTS) { $tok = $this->generate_order_token(); } else { throw $e; } } return $tok; }
$fex->add_element('username', array('Username/email', 'text', null, array('class' => 'cartLogin'), 1)); $fex->add_element('password', array('Password', 'password', null, array('class' => 'cartLogin'), 1)); $tpl = 'checkout_login.tpl'; } else { $fex->max_size = 20; $fex->add_element($colmap); if ($ACTION == OP_GET_SHIP_ADDR) { if (CSHOP_ALLOW_ANON_ACCOUNT and $auth->has_bypass_flag()) { $fex->add_element($user->get_anon_colmap()); } if (!$cart->requires_shipping()) { // bypass shipping addr form if everything is not shippable $smarty->assign('skip_shipping_addr', true); } $op_new_ship = isset($_GET['op_add_ship']); $ship = cmClassFactory::getInstanceOf(CSHOP_CLASSES_SHIPMETHOD, $pdb); /* limits the country select if need be, depending on the ship method */ if ($countrylist = $ship->get_avail_countries()) { $fex->set_elem_attrib('country', 'limit_to', $countrylist); } if (empty($errs) && !$op_new_ship and $shipping = $user->fetchShippingAddr()) { $smarty->assign('has_shipping', true); $fex->add_element('shipping_addr_id', array(null, 'hidden', $shipping['id'])); // set the shipto name to the customers name if available if (empty($shipping['name']) and isset($userinfo['cust_name'])) { $shipping['name'] = $userinfo['cust_name']; } $fex->elem_vals = $shipping; // set defaults for the shipping addr here } if (isset($auth->auth['first_time'])) {
/** * Bundle does some acrobatics to pull the inventory for each contained product, as well as itself. * @param $skus array of product skus contained in the bundle * @param $qty how many to pull (applies to Bundle and all products) */ function pull_inventory($skus, $qty) { $do_inventory = $this->get_header('do_inventory'); if ($do_inventory) { $product = cmClassFactory::getSingletonOf(CSHOP_CLASSES_PRODUCT, $this->db); $sth = $this->db->prepare("SELECT id FROM {$this->_inventory_table} WHERE sku = ?"); foreach ($skus as $sku) { $res = $this->db->execute($sth, $sku); if ($row = $res->fetchRow()) { $res = $product->pull_inventory($row['id'], $qty); if (!$res or PEAR::isError($res)) { trigger_error("No effect when deducting inventory qty '{$qty}' for sku '{$sku}' ({$res})", E_USER_WARNING); } } else { trigger_error("Unknown SKU '{$sku}' found in bundle items", E_USER_WARNING); } } $sql = sprintf("UPDATE cm_bundles SET qty_inventory = (qty_inventory - %d) WHERE id = %d", $qty, $this->get_id()); return $this->db->query($sql); } }