Example #1
0
/**
 * Remove a meta entry by meta id, or parent id, context, type, and name
 *
 * @api
 * @since 1.2
 *
 * @param int $id (required) - meta entry id or, with context, the parent object id
 * @param int $context (required for parent object id) - the parent object context
 * @param string $name (required with parent object context) - the meta name
 * @param string $type  (optional default: meta) - the meta type
 * @return bool true if the meta entry was removed, false on failure
 **/
function shopp_rmv_meta($id = false, $context = false, $name = false, $type = 'meta')
{
    if (!($id || $id && $context)) {
        shopp_debug(__FUNCTION__ . " failed: Must specify at least a meta id or parent id and context.");
        return false;
    }
    // remove existing meta record by meta id
    if ($id && !$context) {
        $meta = new ShoppMetaObject();
        $meta->load($id);
        if ($meta->id) {
            $meta->delete();
        }
        return true;
    }
    // fully spec'd meta entry
    if ($id && $context && $type && $name) {
        $meta = new ShoppMetaObject();
        $meta->load(array('parent' => $id, 'context' => $context, 'type' => $type, 'name' => $name));
        if ($meta->id) {
            $meta->delete();
        }
        return true;
    }
    // general meta entries
    if ($id && $context) {
        $table = ShoppDatabaseObject::tablename(ShoppMetaObject::$table);
        $id = db::escape($id);
        $context = db::escape($context);
        $name = db::escape($name);
        $type = db::escape($type);
        $where = "parent={$id} AND context='{$context}'";
        $where .= $type && !empty($type) ? " AND type='{$type}'" : "";
        $where .= $name && !empty($name) ? " AND type='{$name}'" : "";
        return db::query("DELETE FROM {$table} WHERE {$where}");
    }
}
Example #2
0
 /**
  * Interface processor for the order manager
  *
  * @author Jonathan Davis
  * @return void
  **/
 public function manager()
 {
     global $Shopp, $Notes;
     global $is_IIS;
     if (!current_user_can('shopp_orders')) {
         wp_die(__('You do not have sufficient permissions to access this page.', 'Shopp'));
     }
     $Purchase = ShoppPurchase();
     $Purchase->Customer = new ShoppCustomer($Purchase->customer);
     $Gateway = $Purchase->gateway();
     if (!empty($_POST["send-note"])) {
         $user = wp_get_current_user();
         shopp_add_order_event($Purchase->id, 'note', array('note' => stripslashes($_POST['note']), 'user' => $user->ID));
         $Purchase->load_events();
     }
     // Handle Order note processing
     if (!empty($_POST['note'])) {
         $this->addnote($Purchase->id, stripslashes($_POST['note']), !empty($_POST['send-note']));
     }
     if (!empty($_POST['delete-note'])) {
         $noteid = key($_POST['delete-note']);
         $Note = new ShoppMetaObject(array('id' => $noteid, 'type' => 'order_note'));
         $Note->delete();
     }
     if (!empty($_POST['edit-note'])) {
         $noteid = key($_POST['note-editor']);
         $Note = new ShoppMetaObject(array('id' => $noteid, 'type' => 'order_note'));
         $Note->value->message = stripslashes($_POST['note-editor'][$noteid]);
         $Note->save();
     }
     $Notes = new ObjectMeta($Purchase->id, 'purchase', 'order_note');
     if (isset($_POST['submit-shipments']) && isset($_POST['shipment']) && !empty($_POST['shipment'])) {
         $shipments = $_POST['shipment'];
         foreach ((array) $shipments as $shipment) {
             shopp_add_order_event($Purchase->id, 'shipped', array('tracking' => $shipment['tracking'], 'carrier' => $shipment['carrier']));
         }
         $updated = __('Shipping notice sent.', 'Shopp');
         // Save shipping carrier default preference for the user
         $userid = get_current_user_id();
         $setting = 'shopp_shipping_carrier';
         if (!get_user_meta($userid, $setting, true)) {
             add_user_meta($userid, $setting, $shipment['carrier']);
         } else {
             update_user_meta($userid, $setting, $shipment['carrier']);
         }
         unset($_POST['ship-notice']);
         $Purchase->load_events();
     }
     if (isset($_POST['order-action']) && 'refund' == $_POST['order-action']) {
         if (!current_user_can('shopp_refund')) {
             wp_die(__('You do not have sufficient permissions to carry out this action.', 'Shopp'));
         }
         $user = wp_get_current_user();
         $reason = (int) $_POST['reason'];
         $amount = Shopp::floatval($_POST['amount']);
         $Purchase->load_events();
         if (!empty($_POST['message'])) {
             $message = $_POST['message'];
             $Purchase->message['note'] = $message;
         }
         if ($amount <= $Purchase->captured - $Purchase->refunded) {
             if (!Shopp::str_true($_POST['send'])) {
                 // Force the order status
                 shopp_add_order_event($Purchase->id, 'notice', array('user' => $user->ID, 'kind' => 'refunded', 'notice' => __('Marked Refunded', 'Shopp')));
                 shopp_add_order_event($Purchase->id, 'refunded', array('txnid' => $Purchase->txnid, 'gateway' => $Gateway->module, 'amount' => $amount));
                 shopp_add_order_event($Purchase->id, 'voided', array('txnorigin' => $Purchase->txnid, 'txnid' => time(), 'gateway' => $Gateway->module));
             } else {
                 shopp_add_order_event($Purchase->id, 'refund', array('txnid' => $Purchase->txnid, 'gateway' => $Gateway->module, 'amount' => $amount, 'reason' => $reason, 'user' => $user->ID));
             }
             if (!empty($_POST['message'])) {
                 $this->addnote($Purchase->id, $_POST['message']);
             }
             $Purchase->load_events();
         } else {
             $this->notice(Shopp::__('Refund failed. Cannot refund more than the current balance.'), 'error');
         }
     }
     if (isset($_POST['order-action']) && 'cancel' == $_POST['order-action']) {
         if (!current_user_can('shopp_void')) {
             wp_die(__('You do not have sufficient permissions to carry out this action.', 'Shopp'));
         }
         // unset($_POST['refund-order']);
         $user = wp_get_current_user();
         $reason = (int) $_POST['reason'];
         $message = '';
         if (!empty($_POST['message'])) {
             $message = $_POST['message'];
             $Purchase->message['note'] = $message;
         } else {
             $message = 0;
         }
         if (!Shopp::str_true($_POST['send'])) {
             // Force the order status
             shopp_add_order_event($Purchase->id, 'notice', array('user' => $user->ID, 'kind' => 'cancelled', 'notice' => __('Marked Cancelled', 'Shopp')));
             shopp_add_order_event($Purchase->id, 'voided', array('txnorigin' => $Purchase->txnid, 'txnid' => time(), 'gateway' => $Gateway->module));
         } else {
             shopp_add_order_event($Purchase->id, 'void', array('txnid' => $Purchase->txnid, 'gateway' => $Gateway->module, 'reason' => $reason, 'user' => $user->ID, 'note' => $message));
         }
         if (!empty($_POST['message'])) {
             $this->addnote($Purchase->id, $_POST['message']);
         }
         $Purchase->load_events();
     }
     if (isset($_POST['billing']) && is_array($_POST['billing'])) {
         $Purchase->updates($_POST['billing']);
         $Purchase->save();
     }
     if (isset($_POST['shipping']) && is_array($_POST['shipping'])) {
         $shipping = array();
         foreach ($_POST['shipping'] as $name => $value) {
             $shipping["ship{$name}"] = $value;
         }
         $Purchase->updates($shipping);
         $Purchase->shipname = $shipping['shipfirstname'] . ' ' . $shipping['shiplastname'];
         $Purchase->save();
     }
     if (isset($_POST['order-action']) && 'update-customer' == $_POST['order-action'] && !empty($_POST['customer'])) {
         $Purchase->updates($_POST['customer']);
         $Purchase->save();
     }
     if (isset($_POST['cancel-edit-customer'])) {
         unset($_POST['order-action'], $_POST['edit-customer'], $_POST['select-customer']);
     }
     if (isset($_POST['order-action']) && 'new-customer' == $_POST['order-action'] && !empty($_POST['customer']) && !isset($_POST['cancel-edit-customer'])) {
         $Customer = new ShoppCustomer();
         $Customer->updates($_POST['customer']);
         $Customer->password = wp_generate_password(12, true);
         if ('wordpress' == shopp_setting('account_system')) {
             $Customer->create_wpuser();
         } else {
             unset($_POST['loginname']);
         }
         $Customer->save();
         if ((int) $Customer->id > 0) {
             $Purchase->copydata($Customer);
             $Purchase->save();
         } else {
             $this->notice(__('An unknown error occured. The customer could not be created.', 'Shopp'), 'error');
         }
     }
     if (isset($_GET['order-action']) && 'change-customer' == $_GET['order-action'] && !empty($_GET['customerid'])) {
         $Customer = new ShoppCustomer((int) $_GET['customerid']);
         if ((int) $Customer->id > 0) {
             $Purchase->copydata($Customer);
             $Purchase->customer = $Customer->id;
             $Purchase->save();
         } else {
             $this->notice(__('The selected customer was not found.', 'Shopp'), 'error');
         }
     }
     if (isset($_POST['save-item']) && !empty($_POST['lineid'])) {
         // Create a cart representation of the order to recalculate order totals
         $Cart = new ShoppCart();
         foreach ($Purchase->purchased as $OrderItem) {
             $CartItem = new Item($OrderItem);
             $Cart->contents[$OrderItem->id] = $CartItem;
         }
         $purchasedid = (int) $_POST['lineid'];
         $Purchased = $Purchase->purchased[$purchasedid];
         if ($Purchased->id) {
             $override_total = Shopp::floatval($_POST['total']) != $Purchased->total;
             // Override total
             $Item = $Cart->contents[$purchasedid];
             $Item->quantity($_POST['quantity']);
             $Item->unitprice = Shopp::floatval($_POST['unitprice']);
             $Item->retotal();
             $Purchased->quantity = $Item->quantity;
             $Purchased->unitprice = $Item->unitprice;
             $Purchased->unittax = $Item->unittax;
             $Purchased->total = $Item->total;
             if ($override_total) {
                 $Purchased->total = Shopp::floatval($_POST['total']);
             }
             $Purchased->save();
         }
         $Cart->retotal = true;
         $Cart->totals();
         $Purchase->copydata($Cart->Totals);
         $Purchase->save();
     }
     if (isset($_POST['charge']) && $Gateway && $Gateway->captures) {
         if (!current_user_can('shopp_capture')) {
             wp_die(__('You do not have sufficient permissions to carry out this action.', 'Shopp'));
         }
         $user = wp_get_current_user();
         shopp_add_order_event($Purchase->id, 'capture', array('txnid' => $Purchase->txnid, 'gateway' => $Purchase->gateway, 'amount' => $Purchase->capturable(), 'user' => $user->ID));
         $Purchase->load_events();
     }
     $base = shopp_setting('base_operations');
     $targets = shopp_setting('target_markets');
     $countries = array('' => '&nbsp;');
     $countrydata = Lookup::countries();
     foreach ($countrydata as $iso => $c) {
         if ($base['country'] == $iso) {
             $base_region = $c['region'];
         }
         $countries[$iso] = $c['name'];
     }
     $Purchase->_countries = $countries;
     $regions = Lookup::country_zones();
     $Purchase->_billing_states = array_merge(array('' => '&nbsp;'), (array) $regions[$Purchase->country]);
     $Purchase->_shipping_states = array_merge(array('' => '&nbsp;'), (array) $regions[$Purchase->shipcountry]);
     // Setup shipping carriers menu and JS data
     $carriers_menu = $carriers_json = array();
     $shipping_carriers = (array) shopp_setting('shipping_carriers');
     // The store-preferred shipping carriers
     $shipcarriers = Lookup::shipcarriers();
     // The full list of available shipping carriers
     $notrack = Shopp::__('No Tracking');
     // No tracking label
     $default = get_user_meta(get_current_user_id(), 'shopp_shipping_carrier', true);
     if (isset($shipcarriers[$default])) {
         $carriers_menu[$default] = $shipcarriers[$default]->name;
         $carriers_json[$default] = array($shipcarriers[$default]->name, $shipcarriers[$default]->trackpattern);
     } else {
         $carriers_menu['NOTRACKING'] = $notrack;
         $carriers_json['NOTRACKING'] = array($notrack, false);
     }
     $serviceareas = array('*', $base['country']);
     foreach ($shipcarriers as $code => $carrier) {
         if ($code == $default) {
             continue;
         }
         if (!empty($shipping_carriers) && !in_array($code, $shipping_carriers)) {
             continue;
         }
         if (!in_array($carrier->areas, $serviceareas)) {
             continue;
         }
         $carriers_menu[$code] = $carrier->name;
         $carriers_json[$code] = array($carrier->name, $carrier->trackpattern);
     }
     if (isset($shipcarriers[$default])) {
         $carriers_menu['NOTRACKING'] = $notrack;
         $carriers_json['NOTRACKING'] = array($notrack, false);
     }
     if (empty($statusLabels)) {
         $statusLabels = array('');
     }
     include $this->ui('order.php');
 }
Example #3
0
 public function delete()
 {
     if (!$this->form('delete-note')) {
         return;
     }
     $id = key($this->form('delete-note'));
     $Note = new ShoppMetaObject(array('id' => $id, 'type' => 'order_note'));
     if (!$Note->exists()) {
         return;
     }
     $Note->delete();
     $this->notice(Shopp::__('Note deleted.'));
 }