public function receipt() { check_admin_referer('wp_ajax_shopp_order_receipt'); if (0 == intval($_GET['id'])) { die('-1'); } ShoppPurchase(new ShoppPurchase((int) $_GET['id'])); echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n\t\t\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\t\t<html><head><title>" . get_bloginfo('name') . ' — ' . __('Order', 'Shopp') . ' #' . shopp('purchase', 'get-id') . "</title>"; echo '<style type="text/css">body { padding: 20px; font-family: Arial,Helvetica,sans-serif; }</style>'; echo "<link rel='stylesheet' href='" . shopp_template_url('shopp.css') . "' type='text/css' />"; echo "</head><body>"; echo apply_filters('shopp_admin_order_receipt', shopp('purchase', 'get-receipt', 'template=receipt-admin.php')); if (isset($_GET['print']) && $_GET['print'] == 'auto') { echo '<script type="text/javascript">window.onload = function () { window.print(); window.close(); }</script>'; } echo "</body></html>"; exit; }
<div class="wrap shopp"> <div class="icon32"></div> <?php if (ShoppPurchase()->id > 0) { ?> <h2><?php Shopp::_e('Order #%d', (int) $Purchase->id); ?> <a href="<?php echo esc_url(add_query_arg(array('page' => $this->page(), 'id' => 'new'), admin_url('admin.php'))); ?> " class="add-new-h2"><?php Shopp::_e('Add New'); ?> </a> </h2> <?php } else { ?> <h2><?php Shopp::_e('New Order'); ?> </h2> <?php } ?> <?php $this->notices(); ?>
/** * Iterate over the customer purchases * * @api `shopp('customer.purchases')` * @since 1.1 * * @param string $result The output * @param array $options The options * @param ShoppCustomer $O The working object * @return bool True if the next order exists, false otherwise **/ public static function purchases($result, $options, $O) { $null = null; $Storefront = ShoppStorefront(); if (!isset($Storefront->_purchases_loop)) { reset($Storefront->purchases); ShoppPurchase(current($Storefront->purchases)); $Storefront->_purchases_loop = true; } else { ShoppPurchase(next($Storefront->purchases)); } if (current($Storefront->purchases) !== false) { return true; } else { unset($Storefront->_purchases_loop); ShoppPurchase($null); return false; } }
/** * 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('' => ' '); $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('' => ' '), (array) $regions[$Purchase->country]); $Purchase->_shipping_states = array_merge(array('' => ' '), (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'); }
function shipto_meta_box($Purchase) { ?> <?php if (isset($_POST['edit-shipping-address']) || empty(ShoppPurchase()->shipping)) { ?> <form action="<?php echo ShoppAdminController::url(array('page' => $page, 'id' => $Purchase->id)); ?> " method="post" id="shipping-address-editor"> <?php $names = explode(' ', $Purchase->shipname); $firstname = array_shift($names); $lastname = join(' ', $names); $address = array('${type}' => 'shipping', '${firstname}' => $firstname, '${lastname}' => $lastname, '${address}' => $Purchase->shipaddress, '${xaddress}' => $Purchase->shipxaddress, '${city}' => $Purchase->shipcity, '${state}' => $Purchase->shipstate, '${postcode}' => $Purchase->shippostcode, '${country}' => $Purchase->shipcountry, '${statemenu}' => Shopp::menuoptions($Purchase->_shipping_states, $Purchase->shipstate, true), '${countrymenu}' => Shopp::menuoptions($Purchase->_countries, $Purchase->shipcountry, true)); echo ShoppUI::template(order_address_editor(), $address); ?> </form> <?php return; } ?> <form action="<?php echo ShoppAdminController::url(array('id' => $Purchase->id)); ?> " method="post" id="shipping-address-editor"></form> <div class="display"> <form action="<?php echo ShoppAdminController::url(array('id' => $Purchase->id)); ?> " method="post"> <?php $targets = shopp_setting('target_markets'); ?> <input type="hidden" id="edit-shipping-address-data" value="<?php $shipname = explode(' ', $Purchase->shipname); $shipfirst = array_shift($shipname); $shiplast = join(' ', $shipname); $address = array('action' => 'update-address', 'type' => 'shipping', 'firstname' => $shipfirst, 'lastname' => $shiplast, 'address' => $Purchase->shipaddress, 'xaddress' => $Purchase->shipxaddress, 'city' => $Purchase->shipcity, 'state' => $Purchase->shipstate, 'postcode' => $Purchase->shippostcode, 'country' => $Purchase->shipcountry, 'statemenu' => Shopp::menuoptions($Purchase->_shipping_states, $Purchase->shipstate, true), 'countrymenu' => Shopp::menuoptions($Purchase->_countries, $Purchase->shipcountry, true)); $js = preg_replace('/\\${([-\\w]+)}/', '$1', json_encode($address)); shopp_custom_script('orders', 'address["shipping"] = ' . $js . ';'); echo esc_attr(json_encode($address)); ?> " /> <input type="submit" id="edit-shipping-address" name="edit-shipping-address" value="<?php _e('Edit', 'Shopp'); ?> " class="button-secondary button-edit" /> </form> <address><big><?php echo esc_html($Purchase->shipname); ?> </big><br /> <?php echo esc_html($Purchase->shipaddress); ?> <br /> <?php if (!empty($Purchase->shipxaddress)) { echo esc_html($Purchase->shipxaddress) . "<br />"; } ?> <?php echo esc_html("{$Purchase->shipcity}" . (!empty($Purchase->shipstate) ? ', ' : '') . " {$Purchase->shipstate} {$Purchase->shippostcode}"); ?> <br /> <?php echo $targets[$Purchase->shipcountry]; ?> </address> </div> <?php }
/** * Generates the order receipt markup using the `receipt.php` template file * * @api `shopp('checkout.receipt')` * @since 1.0 * * @param string $result The output * @param array $options The options * @param ShoppOrder $O The working object * @return string The receipt markup **/ public static function receipt($result, $options, $O) { $Purchase = ShoppPurchase(); if (!$Purchase) { return false; } if (!$Purchase->exists()) { return false; } return $Purchase->receipt(); }
/** * shopp_add_order - create an order from the cart and associate with a customer * * @api * @since 1.2 * * @param int $customer the customer that the order will be created for * @return bool|ShoppPurchase false on failure, Purchase object of recently created order on success **/ function shopp_add_order($customer = false) { // check customer if (!($Customer = shopp_customer((int) $customer))) { shopp_debug(__FUNCTION__ . " failed: Invalid customer."); return false; } if (!shopp_cart_items_count()) { shopp_debug(__FUNCTION__ . " failed: No items in cart."); return false; } $Order = ShoppOrder(); $Order->Customer = $Customer; $Order->Billing = $Customer->Billing; $Order->Billing->cardtype = 'api'; $Order->Shipping = $Customer->Shipping; shopp_add_order_event(false, 'purchase', array('gateway' => 'GatewayFramework')); shopp_empty_cart(); return ($Purchase = ShoppPurchase()) ? $Purchase : false; }
/** * Resets the session and redirects to the thank you page * * @author Jonathan Davis * @since 1.1 * * @return void **/ public function success() { if (!empty($this->inprogress)) { $this->purchase = $this->inprogress; ShoppPurchase(new ShoppPurchase($this->purchase)); $this->inprogress = false; // Remove the order processing lock delete_transient('shopp_order_' . ShoppShopping()->session()); do_action('shopp_order_success', ShoppPurchase()); Shopping::resession(); } if (false !== $this->purchase) { Shopp::redirect(Shopp::url(false, 'thanks')); } }
/** * Loads an order by id associated with only this customer * * @author Jonathan Davis * @since 1.3 * * @param int $id The purchase record ID * @return void **/ public function order($id) { $Purchase = new ShoppPurchase(array('id' => (int) $id, 'customer' => $this->id)); if ($Purchase->exists()) { ShoppPurchase($Purchase); $Purchase->load_purchased(); return; } shopp_add_error(Shopp::__('Order number %s could not be found in your order history.', (int) $id), SHOPP_AUTH_ERR); }
public function order() { if (empty($this->order)) { return false; } // If global purchase context is not a loaded Purchase object, load the purchase associated with the order $Purchase = ShoppPurchase(); if (!isset($Purchase->id) || empty($Purchase->id) || $this->order != $Purchase->id) { $Purchase = ShoppPurchase(new ShoppPurchase($this->order)); } if (!isset($Purchase->id) || empty($Purchase->id)) { return false; } if (empty($Purchase->purchased)) { $Purchase->load_purchased(); } return $Purchase; }
public function returned() { if ($this->id() != $_GET['rmtpay']) { return; } // Not our offsite payment $request = array_merge(array('merchant_order_id' => false, 'key' => false, 'order_number' => false, 'total' => false, 'credit_card_processed' => false, 'invoice_id' => false, 'pay_method' => false), $_GET); extract($request, EXTR_SKIP); if (Shopp::str_true($this->settings['verify']) && !$this->verify($key)) { shopp_add_error(Shopp::__('The order submitted by 2Checkout could not be verified.'), SHOPP_TRXN_ERR); Shopp::redirect(Shopp::url(false, 'checkout')); } if (empty($merchant_order_id)) { shopp_add_error(Shopp::__('The order submitted by 2Checkout did not specify a transaction ID.'), SHOPP_TRXN_ERR); Shopp::redirect(Shopp::url(false, 'checkout')); } $Purchase = ShoppPurchase(new ShoppPurchase((int) $merchant_order_id)); if (!$Purchase->exists()) { shopp_add_error(Shopp::__('The order submitted by 2Checkout did not match any submitted orders.'), SHOPP_TRXN_ERR); Shopp::redirect(Shopp::url(false, 'checkout')); } if ('Y' != $credit_card_processed) { shopp_add_order_event($Purchase->id, 'auth-fail', array('amount' => $total, 'error' => 'Declined', 'message' => Shopp::__('The payment was not completed succesfully'), 'gateway' => $this->module)); shopp_add_error(Shopp::__('The order submitted by 2Checkout did not match any submitted orders.'), SHOPP_TRXN_ERR); Shopp::redirect(Shopp::url(false, 'checkout')); } $this->Order->inprogress = $Purchase->id; add_action('shopp_authed_order_event', array(ShoppOrder(), 'notify')); add_action('shopp_authed_order_event', array(ShoppOrder(), 'accounts')); add_action('shopp_authed_order_event', array(ShoppOrder(), 'success')); shopp_add_order_event($Purchase->id, 'authed', array('txnid' => $order_number, 'amount' => (double) $total, 'fees' => false, 'gateway' => $this->module, 'paymethod' => '2Checkout', 'paytype' => $pay_method, 'payid' => $invoice_id, 'capture' => true)); Shopp::redirect(Shopp::url(false, 'thanks', false)); }
function screen() { 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(); } 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']); if (!empty($_POST['message'])) { $message = $_POST['message']; $Purchase->message['note'] = $message; } 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(); } 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']); } // Create a new 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->customer = $Customer->id; $Purchase->copydata($Customer); $Purchase->save(); // New billing address, create record for new customer if (isset($_POST['billing']) && is_array($_POST['billing']) && empty($_POST['billing']['id'])) { $Billing = new BillingAddress($_POST['billing']); $Billing->customer = $Customer->id; $Billing->save(); } // New shipping address, create record for new customer if (isset($_POST['shipping']) && is_array($_POST['shipping']) && empty($_POST['shipping']['id'])) { $Shipping = new ShippingAddress($_POST['shipping']); $Shipping->customer = $Customer->id; $Shipping->save(); } } else { $this->notice(Shopp::__('An unknown error occured. The customer could not be created.'), '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(Shopp::__('The selected customer was not found.'), 'error'); } } if (isset($_POST['save-item']) && isset($_POST['lineid'])) { if (isset($_POST['lineid']) && '' == $_POST['lineid']) { $lineid = 'new'; } else { $lineid = (int) $_POST['lineid']; } $name = $_POST['itemname']; if (!empty($_POST['product'])) { list($productid, $priceid) = explode('-', $_POST['product']); $Product = new ShoppProduct($productid); $Price = new ShoppPrice($priceid); $name = $Product->name; if (Shopp::__('Price & Delivery') != $Price->label) { $name .= ": {$Price->label}"; } } // Create a cart representation of the order to recalculate order totals $Cart = new ShoppCart(); $taxcountry = $Purchase->country; $taxstate = $Purchase->state; if (!empty($Purchase->shipcountry) && !empty($Purchase->shipstate)) { $taxcountry = $Purchase->shipcountry; $taxstate = $Purchase->shipstate; } ShoppOrder()->Tax->location($taxcountry, $taxstate); if ('new' == $lineid) { $NewLineItem = new ShoppPurchased(); $NewLineItem->purchase = $Purchase->id; $Purchase->purchased[] = $NewLineItem; } foreach ($Purchase->purchased as &$Purchased) { $CartItem = new ShoppCartItem($Purchased); if ($Purchased->id == $lineid || 'new' == $lineid && empty($Purchased->id)) { if (!empty($_POST['product'])) { list($CartItem->product, $CartItem->priceline) = explode('-', $_POST['product']); } elseif (!empty($_POST['id'])) { list($CartItem->product, $CartItem->priceline) = explode('-', $_POST['id']); } $CartItem->name = $name; $CartItem->unitprice = Shopp::floatval($_POST['unitprice']); $Cart->additem((int) $_POST['quantity'], $CartItem); $CartItem = $Cart->get($CartItem->fingerprint()); $Purchased->name = $CartItem->name; $Purchased->product = $CartItem->product; $Purchased->price = $CartItem->priceline; $Purchased->quantity = $CartItem->quantity; $Purchased->unitprice = $CartItem->unitprice; $Purchased->total = $CartItem->total; $Purchased->save(); } else { $Cart->additem($CartItem->quantity, $CartItem); } } $Cart->Totals->register(new OrderAmountShipping(array('id' => 'cart', 'amount' => $Purchase->freight))); $Purchase->total = $Cart->total(); $Purchase->subtotal = $Cart->total('order'); $Purchase->discount = $Cart->total('discount'); $Purchase->tax = $Cart->total('tax'); $Purchase->freight = $Cart->total('shipping'); $Purchase->save(); $Purchase->load_purchased(); } if (!empty($_POST['save-totals'])) { $totals = array(); if (!empty($_POST['totals'])) { $totals = $_POST['totals']; } $objects = array('tax' => 'OrderAmountTax', 'shipping' => 'OrderAmountShipping', 'discount' => 'OrderAmountDiscount'); $methods = array('fee' => 'fees', 'tax' => 'taxes', 'shipping' => 'shipfees', 'discount' => 'discounts'); $total = 0; foreach ($totals as $property => $fields) { if (empty($fields)) { continue; } if (count($fields) > 1) { if (isset($fields['labels'])) { $labels = $fields['labels']; unset($fields['labels']); if (count($fields) > count($labels)) { $totalfield = array_pop($fields); } $fields = array_combine($labels, $fields); } $fields = array_map(array('Shopp', 'floatval'), $fields); $entries = array(); $OrderAmountObject = isset($objects[$property]) ? $objects[$property] : 'OrderAmountFee'; foreach ($fields as $label => $amount) { $entries[] = new $OrderAmountObject(array('id' => count($entries) + 1, 'label' => $label, 'amount' => $amount)); } $savetotal = isset($methods[$property]) ? $methods[$property] : $fees; $Purchase->{$savetotal}($entries); $sum = array_sum($fields); if ($sum > 0) { $Purchase->{$property} = $sum; } } else { $Purchase->{$property} = Shopp::floatval($fields[0]); } $total += 'discount' == $property ? $Purchase->{$property} * -1 : $Purchase->{$property}; } $Purchase->total = $Purchase->subtotal + $total; $Purchase->save(); } if (!empty($_GET['rmvline'])) { $lineid = (int) $_GET['rmvline']; if (isset($Purchase->purchased[$lineid])) { $Purchase->purchased[$lineid]->delete(); unset($Purchase->purchased[$lineid]); } $Cart = new ShoppCart(); $taxcountry = $Purchase->country; $taxstate = $Purchase->state; if (!empty($Purchase->shipcountry) && !empty($Purchase->shipstate)) { $taxcountry = $Purchase->shipcountry; $taxstate = $Purchase->shipstate; } ShoppOrder()->Tax->location($taxcountry, $taxstate); foreach ($Purchase->purchased as &$Purchased) { $Cart->additem($Purchased->quantity, new ShoppCartItem($Purchased)); } $Cart->Totals->register(new OrderAmountShipping(array('id' => 'cart', 'amount' => $Purchase->freight))); $Purchase->total = $Cart->total(); $Purchase->subtotal = $Cart->total('order'); $Purchase->discount = $Cart->total('discount'); $Purchase->tax = $Cart->total('tax'); $Purchase->freight = $Cart->total('shipping'); $Purchase->save(); $Purchase->load_purchased(); } 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(); } $targets = shopp_setting('target_markets'); $default = array('' => ' '); $Purchase->_countries = array_merge($default, ShoppLookup::countries()); $regions = Lookup::country_zones(); $Purchase->_billing_states = array_merge($default, (array) $regions[$Purchase->country]); $Purchase->_shipping_states = array_merge($default, (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('*', ShoppBaseLocale()->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(''); } $Purchase->taxes(); $Purchase->discounts(); $columns = get_column_headers($this->id); $hidden = get_hidden_columns($this->id); include $this->ui('new.php'); }
/** * Helper to apply or exclude taxes from a single amount based on inclusive tax settings and the tax option * * internal * @since 1.3 * * @param float $amount The amount to add taxes to, or exclude taxes from * @param ShoppProduct $O The product to get properties from * @param boolean $istaxed Whether the amount can be taxed * @param boolean $taxoption The Theme API tax option given the the tag * @param array $taxrates A list of taxrates that apply to the product and amount * @return float The amount with tax added or tax excluded **/ private static function _taxes($amount, ShoppPurchased $Item, $taxoption = null, $quantity = 1) { $inclusivetax = self::_inclusive_taxes(ShoppPurchase()); if (isset($taxoption) && $inclusivetax ^ $taxoption) { if ($taxoption) { $amount += $Item->unittax * $quantity; } else { $amount = $amount -= $Item->unittax * $quantity; } } return (double) $amount; }