Exemple #1
0
 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;
 }
Exemple #2
0
}
// 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;
Exemple #3
0
} 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);
}
Exemple #5
0
 function payment_method_factory()
 {
     return cmClassFactory::getInstanceOf(CSHOP_CLASSES_PAYMETHOD, $this->db);
 }
Exemple #6
0
 /** 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;
         }
     }
 }
Exemple #7
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);
}
Exemple #9
0
// 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']);
Exemple #10
0
 /** remove the items in the cart from the inventory (tracked by
  * products_inventory items, i.e. SKU's 
  * @return true on success
  */
 function pull_inventory()
 {
     $cart_items = $this->fetch_items();
     if (count($cart_items)) {
         $product = cmClassFactory::getSingletonOf(CSHOP_CLASSES_PRODUCT, $this->db);
         foreach ($cart_items as $item) {
             if (defined('CSHOP_USE_BUNDLES') && CSHOP_USE_BUNDLES && $item['is_bundle']) {
                 $bundle = cmClassFactory::getInstanceOf(CSHOP_CLASSES_BUNDLE, $this->db);
                 $bundle->set_id($item['product_id']);
                 $skus = array_keys($item['product_attribs']);
                 $res = $bundle->pull_inventory($skus, $item['qty']);
             } else {
                 if (empty($item['is_digital'])) {
                     # dont pull inventory for non-physical goods
                     $res = $product->pull_inventory($item['inventory_id'], $item['qty']);
                 }
             }
             if (PEAR::isError($res)) {
                 // sux
                 trigger_error("Error in cmCart::pull_inventory() for line item {$item['id']}: " . $res->getMessage(), E_USER_WARNING);
             }
             $this->after_pull_inventory($item['product_id'], $item['qty'], $item['price']);
         }
     }
 }
Exemple #11
0
     $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'])) {