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; }
/** 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();
/** * 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); } }