Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 /**
  * 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);
 }
Пример #4
0
 /**
  * Generates customers.
  *
  * @return void
  */
 protected static function customers()
 {
     $balances = array(0, 5, 10, 12.5, 24.3);
     $first_names = array('Daniel', 'Steve', 'Elon', 'Bill', 'Stephan', 'Olivia', 'Keithia', 'Caroline', 'Porschia', 'Marie');
     $last_names = array('Sposito', 'Manos', 'Myers', 'Jenkins', 'Gates', 'Jobs', 'Musk', 'Wyrick', 'Natalie', 'Stevens');
     $streets = array('Wisteria Ln', 'Pebble Creek Blvd', 'Bakerstreet Dr', 'Miranda Point', 'Infinite Loop');
     $cities = array('Oklahoma City', 'Phoenix', 'Palo Alto', 'Saigon', 'Caracas');
     $states = array('OK', 'NY', 'CA', 'WA', 'FL');
     $countries = array('US', 'VN', 'VE');
     $customers = array();
     for ($i = 1; $i <= self::TOTAL_CUSTOMERS; $i++) {
         $first_name = $first_names[array_rand($first_names)];
         $last_name = $last_names[array_rand($last_names)];
         // Random created_at between the begin date and now.
         $date = date("Y-m-d H:i:s", mt_rand(self::BEGIN_DATETIME, time()));
         $customers[] = array('balance' => $balances[array_rand($balances)], 'contact' => array('first_name' => $first_name, 'last_name' => $last_name, 'email' => $first_name . '.' . $last_name . mt_rand(1, 100) . '@gmail.com', 'address' => mt_rand(1, 5000) . ' ' . $streets[array_rand($streets)], 'city' => $cities[array_rand($cities)], 'state' => $states[array_rand($states)], 'zip' => mt_rand(10000, 99999), 'country' => $countries[array_rand($countries)]), 'status' => mt_rand(1, 10) <= 8 ? 'active' : 'deleted', 'created_at' => $date);
     }
     foreach ($customers as $data) {
         $seller = self::$sellers[array_rand(self::$sellers)];
         $customer = \Service_Customer::create($seller, $data);
         // Create a payment method for the faux customer.
         $payment_method = \Service_Customer_Paymentmethod::create($customer, self::$gateway, array('contact' => $data['contact'], 'account' => array('provider' => 'Volcano', 'number' => '6011000000000012', 'expiration_month' => '12', 'expiration_year' => '5')));
         // Subscribe a random number of customers to a product option.
         if ($customer && mt_rand(1, 10) >= 5) {
             $option = self::$product_options[$seller->id][array_rand(self::$product_options[$seller->id])];
             $order = \Service_Customer_Order::create($customer, array($option->id => 'My ' . \Str::random('alpha', 5)), null, array('created_at' => $customer->created_at));
             // Reset the order's updated_at.
             self::updateUpdatedAt($order);
         }
         // Reset the models' updated_at.
         self::updateUpdatedAt($customer);
         foreach ($customer->products as $product) {
             self::updateUpdatedAt($product);
         }
     }
     \Cli::write('Customer Simulation Complete', 'green');
 }