public function action_index() { $args = array('seller' => Seller::active()); $pagination = Pagination::forge('customer_pagination', array('total_items' => Service_Customer_Order::count($args))); $orders = Service_Customer_Order::find(array_merge($args, array('offset' => $pagination->offset, 'limit' => $pagination->per_page, 'order_by' => array('updated_at' => 'desc')))); $this->view->orders = $orders; $this->view->pagination = $pagination; }
/** * Attempts to get a customer product option from a given ID. * * @param int $id Customer product option ID. * * @return Model_Customer_Product_Option */ protected function get_option($id) { $option = Service_Customer_Product_Option::find_one(array('id' => $id, 'status' => 'all')); if (!$option || $option->customer->seller != Seller::active()) { throw new HttpNotFoundException(); } return $option; }
/** * Attempts to get a customer from a given ID. * * @param int $id Customer ID. * * @return \Model_Customer */ protected function get_customer($id) { if (!$id) { throw new HttpNotFoundException(); } $customer = \Service_Customer::find_one($id); if (!$customer || $customer->seller != \Seller::active()) { throw new HttpNotFoundException(); } return $customer; }
/** * Attempts to get a customer from a given ID. * * @param int $id Customer ID. * * @return Model_Customer */ protected function get_customer($id) { if (!$id) { throw new HttpNotFoundException(); } $customer = Service_Customer::find_one(array('id' => $id, 'status' => 'all')); if (!$customer || $customer->seller != Seller::active()) { throw new HttpNotFoundException(); } return $customer; }
/** * Attempts to get a contact from a given ID. * * @param int $id Contact ID. * * @return Model_Contact */ protected function get_contact($customer_id, $id) { $customer = $this->get_customer($customer_id); if ($customer->seller != Seller::active()) { throw new HttpNotFoundException(); } $contact = Service_Contact::find_one($id); if (!$contact || $contact != Service_Contact::primary($customer)) { throw new HttpNotFoundException(); } return $contact; }
/** * Gets customer conversion statistics. * * @return void */ public function get_conversion() { $names = array('total', 'total_active', 'total_subscribed'); $statistics = \Service_Statistic::recent(array('seller' => \Seller::active(), 'type' => 'customer', 'name' => $names)); $data = array(); foreach ($statistics as $stat) { $date = $stat->date; $data[$date][$stat->name] = (int) $stat->value; } if (!empty($data)) { ksort($data[$date]); } $this->response($data); }
/** * POST Index action. * * @return void */ public function post_index() { $this->get_index(); $validator = Validation_Seller::update(); if (!$validator->run()) { Session::set_alert('error', __('form.error')); $this->view->errors = $validator->error(); return; } $data = $validator->validated(); if (!Service_Seller::update(Seller::active(), $data)) { Session::set_alert('error', 'There was an error updating the seller.'); return; } Session::set_alert('success', 'The seller has been updated.'); }
/** * Deletes a seller API key. * * @param int $id API key. * * @return void */ public function action_delete($id = null) { if (!$id) { throw new HttpNotFoundException(); } $key = Service_Api_Key::find_one($id); if (!$key || $key->seller != Seller::active()) { throw new HttpNotFoundException(); } if (!Service_Api_Key::delete($key)) { Session::set_alert('error', 'There was an error removing the API key.'); } else { Session::set_alert('success', 'The API key has been removed.'); } Response::redirect('settings/api'); }
/** * Gets one or more customer product options. * * @param int $customer_id Customer ID. * @param int $id Product option ID. * * @return void */ public function get_index($customer_id = null, $id = null) { if (!$customer_id) { throw new HttpNotFoundException(); } $customer = \Service_Customer::find_one($customer_id); if (!$customer || $customer->seller != \Seller::active()) { throw new HttpNotFoundException(); } if (!$id) { $products = \Service_Customer_Product_Option::find(array('customer' => $customer)); } else { $products = \Service_Customer_Product_Option::find_one($id); if (!$products || $products->customer != $customer) { throw new HttpNotFoundException(); } } $this->response($products); }
/** * Updates a seller. * * @param int $id Seller ID. * * @return void */ public function put_index($id = null) { if (!$id) { throw new HttpNotFoundException(); } $seller = \Service_Seller::find_one($id); if (!$seller || $seller != \Seller::active()) { throw new HttpNotFoundException(); } $validator = \Validation_Seller::update(); if (!$validator->run(\Input::put())) { throw new HttpBadRequestException($validator->errors()); } $data = $validator->validated(); $seller = \Service_Seller::update($seller, $data); if (!$seller) { throw new HttpServerErrorException(); } $this->response($seller); }
/** * Attempts to get a product meta from a given ID. * * @param int $id Product meta ID. * * @return Model_Product_Meta */ protected function get_meta($id) { $meta = Service_Product_Meta::find_one($id); if (!$meta || $meta->product->seller != Seller::active()) { throw new HttpNotFoundException(); } return $meta; }
/** * Checks for api key authentication. * * @return bool */ protected function _prepare_key_auth() { // Skip auth for front-end interface. if (\Seller::active()) { return true; } \Config::load('api', true); $api_key = \Input::param('api_key', \Config::get('api.key')); if (!$api_key) { return false; } $api_key = \Service_Api_Key::find_one(array('key' => $api_key)); if (!$api_key) { return false; } if ($api_key->seller) { \Seller::set($api_key->seller); } return true; }
/** * Attempts to get a payment method from a given ID. * * @param int $id Payment method ID. * @param \Model_Customer $customer Customer the payment method should belong to. * * @return \Model_Customer_Paymentmethod */ protected function get_paymentmethod($id, \Model_Customer $customer) { if (!$id) { throw new HttpNotFoundException(); } $payment_method = \Service_Customer_Paymentmethod::find_one($id); if (!$payment_method || $payment_method->customer != $customer || $payment_method->customer->seller != \Seller::active()) { throw new HttpNotFoundException(); } return $payment_method; }
/** * Attempts to get a seller's primary gateway. * * @return Model_Gateway */ public function get_gateway() { $gateway = Service_Gateway::find_one(array('seller' => Seller::active())); if (!$gateway) { throw new HttpNotFoundException(); } return $gateway; }
/** * Attempts to get a product option from a given ID. * * @param int $id Product option ID. * * @return Model_Product_Option */ protected function get_option($id) { $option = Service_Product_Option::find_one($id); if (!$option || $option->product->seller != Seller::active()) { throw new HttpNotFoundException(); } return $option; }
/** * Attempts to get a product meta option from a given ID. * * @param int $id Product meta option ID. * @param \Model_Product_Meta $meta Product meta the option should belong to. * * @return \Model_Product_Meta_Option */ protected function get_option($id, \Model_Product_Meta $meta) { if (!$id) { throw new HttpNotFoundException(); } $option = \Service_Product_Meta_Option::find_one($id); if (!$option || $option->meta != $meta || $option->meta->product->seller != \Seller::active()) { throw new HttpNotFoundException(); } return $option; }
/** * Attempts to get a seller callback from a given ID. * * @param int $id Seller callback ID. * * @return Model_Seller_Callback */ protected function get_callback($id) { $callback = Service_Seller_Callback::find_one(array('id' => $id, 'seller' => Seller::active())); if (!$callback) { throw new HttpNotFoundException(); } return $callback; }
/** * Attempts to get a product from a given ID. * * @param int $id Product ID. * * @return Model_Product */ protected function get_product($id) { $product = Service_Product::find_one($id); if (!$product || $product->seller != Seller::active()) { throw new HttpNotFoundException(); } return $product; }
/** * Attempts to get a contact from a given ID. * * @param int $id Contact ID. * * @return \Model_Contact */ protected function get_contact($id) { if (!$id) { throw new HttpNotFoundException(); } $contact = \Service_Contact::find_one($id); if (!$contact || !\Arr::key_exists(\Seller::active()->contacts, $contact->id)) { throw new HttpNotFoundException(); } return $contact; }
/** * Attempts to get a gateway from a given ID. * * @param int $id Gateway ID. * * @return \Model_Gateway */ protected function get_gateway($id) { if (!$id) { throw new HttpNotFoundException(); } $gateway = \Service_Gateway::find_one(array('id' => $id, 'seller' => \Seller::active())); if (!$gateway) { throw new HttpNotFoundException(); } return $gateway; }
/** * Attempts to get a product option fee from a given ID. * * @param int $id Product option fee ID. * * @return Model_Product_Option_Fee */ protected function get_fee($id) { $fee = Service_Product_Option_Fee::find_one($id); if (!$fee || $fee->option->product->seller != Seller::active()) { throw new HttpNotFoundException(); } return $fee; }
/** * Sets the active seller. * * @param Model_Seller $seller The seller to set as active. * * @return void */ public static function set(Model_Seller $seller) { Session::set(self::$namespace . '.id', $seller->id); self::$active = $seller; }
<?php Casset::less('less/layouts/default/config.less', true, 'base'); Casset::less('less/layouts/default/layout.less', true, 'base'); Casset::less('less/layouts/default/config.less', true, 'page'); Casset::js('libs/jquery/jquery.min.js', false, 'base'); Casset::js('libs/jquery/plugins/jquery.validate.js', true, 'page'); Casset::js('libs/bootstrap/js/bootstrap-alert.js', true, 'base'); Casset::js('libs/bootstrap/js/bootstrap-modal.js', true, 'base'); Casset::js('libs/bootstrap/js/bootstrap-transition.js', true, 'base'); Casset::js('libs/bootstrap/plugins/bootbox/bootbox.js', true, 'base'); Casset::js('libs/bootstrap/plugins/bootstrap-hover-dropdown.js', true, 'base'); Casset::js('js/common.js', true, 'base'); Casset::js('js/common/common.validate.js', true, 'page'); $app_name = Config::get('app_name'); $seller = Seller::active(); $sellers = Seller::all(); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title> <?php echo $app_name; ?> <?php if (!empty($title) && empty($breadcrumbs)) { ?> - <?php
/** * Attempts to get a contact from a given ID. * * @param int $id Contact ID. * * @return Model_Contact */ protected function get_contact($id) { $contact = Service_Contact::find_one($id); if (!$contact || !in_array($contact, Seller::active()->contacts)) { throw new HttpNotFoundException(); } return $contact; }
/** * Deletes a product. * * @param int $id Product ID. * * @return void */ public function delete_index($id = null) { if (!$id) { throw new HttpNotFoundException(); } $product = \Service_Product::find_one($id, \Seller::active()); if (!$product || $product->seller != \Seller::active()) { throw new HttpNotFoundException(); } $deleted = \Service_Product::delete($product); if (!$deleted) { throw new HttpServerErrorException(); } }