Exemple #1
0
} elseif ($ACTION == OP_GC_LOAD && defined('CSHOP_CONTROL_SHOW_STS_GIFTCARD_LOADER') && CSHOP_CONTROL_SHOW_STS_GIFTCARD_LOADER) {
    $order->set_id_by_token($itemid);
    $gc = cmClassFactory::getInstanceOf(CSHOP_CLASSES_GIFTCARD, $pdb);
    $gc->setErrorHandling(PEAR_ERROR_RETURN);
    $orderitems = $order->fetch_items();
    $errs = array();
    foreach ($orderitems as $item) {
        if (in_array($item['id'], array_keys($_POST['gc_number']))) {
            $successful_cards = array();
            $gc_numbers = $_POST['gc_number'][$item['id']];
            # get product's STS merchant ID
            $product = cmClassFactory::getInstanceOf(CSHOP_CLASSES_PRODUCT, $pdb);
            $product->set_id($item['product_id']);
            $product_merch_id = $product->get_header('sts_merchant_id');
            # store the giftcard details as options on the order line item, so admin can see
            $oi = db_container::factory($pdb, $order->_items_table);
            $oi->set_id($item['id']);
            for ($i = 0; $i < count($gc_numbers); $i++) {
                $gc_number = trim($gc_numbers[$i]);
                if (!empty($gc_number)) {
                    if (empty($product_merch_id)) {
                        $errs[] = "Product \"{$item['product_descrip']}\" does not have a STS Merchant ID, so can\\'t be activated here.";
                    } elseif ($gc->find_by_card_number($gc_number)) {
                        $errs[] = "Card Number \"{$gc_number}\" is already in the system, and cannot be activated again.";
                    } else {
                        $res = $gc->activate($order, $product_merch_id, $item['price'], $gc_number);
                        # TESTING $res = print_r(array($product_merch_id, $item['price'], $gc_number));
                        if (!PEAR::isError($res)) {
                            $successful_cards[] = $gc->fetch(array('gc_no', 'transaction_id'));
                            # TESTING $successful_cards[] = array('gc_no'=>rand('100000000000001','999999999999999'), 'transaction_id' => '3e12982132131038oi');
                        } else {
Exemple #2
0
 /**
  * does the order contains any digital items.
  * @return bool
  */
 function fetch_digital_goods()
 {
     if (!defined('CSHOP_ENABLE_DIGITAL_DOWNLOADS') || !CSHOP_ENABLE_DIGITAL_DOWNLOADS) {
         return;
     }
     if (defined('CSHOP_DOWNLOAD_LINK_FMT')) {
         $sql = sprintf("SELECT id, product_id, product_descrip, download_token FROM %s WHERE is_digital = 1 AND order_id = %d", $this->_items_table, $this->get_id());
         $res = $this->db->query($sql);
         $items = array();
         while ($row = $res->fetchRow()) {
             if (empty($row['download_token'])) {
                 // create and save new URL if not done yet.
                 $row['download_token'] = $this->generate_download_token($row['product_id']);
                 $oi = db_container::factory($this->db, $this->_items_table);
                 $oi->set_id($row['id']);
                 $oi->store(array('download_token' => $row['download_token']));
             }
             $row['download_url'] = sprintf(CSHOP_DOWNLOAD_LINK_FMT, $this->fetch_token(), $row['download_token']);
             $items[] = $row;
         }
         return $items;
     }
 }