/** * 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); }
/** * Handles checkout request flow control * * @author Jonathan Davis * @since 1.2.3 * * @return void **/ public function request() { // Check if an in progress order was already completed if (!empty($this->inprogress)) { $Purchase = new ShoppPurchase($this->inprogress); if ($Purchase->exists() && in_array($Purchase->txnstatus, array('authed', 'captured'))) { return $this->success(); } } // Check if an in progress order processing (from another process/tab/window) completed if (!empty($_REQUEST['inprogress']) && !empty($this->purchase)) { $Purchase = new ShoppPurchase($this->purchase); if ($Purchase->exists()) { // Verify it exists and redirect to thanks Shopp::redirect(Shopp::url(false, 'thanks')); } } if (!empty($_REQUEST['rmtpay'])) { return do_action('shopp_remote_payment'); } if (array_key_exists('checkout', $_POST)) { $checkout = strtolower($_POST['checkout']); switch ($checkout) { case 'process': do_action('shopp_process_checkout'); break; case 'confirmed': do_action('shopp_confirm_order'); break; } } elseif (array_key_exists('shipmethod', $_POST)) { do_action('shopp_process_shipmethod'); } }
public function save_totals() { if (!$this->form('save-totals')) { return; } $Purchase = new ShoppPurchase($this->form('id')); if (!$Purchase->exists()) { return; } $totals = array(); if ($this->form('totals')) { $totals = $this->form('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(); }