コード例 #1
0
ファイル: products.php プロジェクト: mehulsbhatt/volcano
 /**
  * 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;
 }
コード例 #2
0
ファイル: order.php プロジェクト: mehulsbhatt/volcano
 /**
  * Creates a new customer order.
  *
  * @param Model_Customer               $customer      The customer the order belongs to.
  * @param array                        $products      An array of one or more products to order.
  * @param Model_Customer_Paymentmethod $paymentmethod The payment method to use for the transaction.
  * @param array                        $data          Optional data.
  *
  * @return Model_Customer_Order
  */
 public static function create(Model_Customer $customer, array $products, Model_Customer_Paymentmethod $paymentmethod = null, $data = array())
 {
     if ($paymentmethod && $paymentmethod->customer != $customer) {
         return false;
     }
     if (!$paymentmethod) {
         // Use the customer's primary payment method if none is provided.
         if (!($paymentmethod = Service_Customer_Paymentmethod::primary($customer))) {
             return false;
         }
     }
     $product_options = array();
     $transaction_total = 0;
     foreach ($products as $id => $name) {
         $option = Service_Product_Option::find_one($id);
         if (!$option instanceof Model_Product_Option) {
             continue;
         }
         $product_options[] = $option;
         $transaction_total += $option->sum_fees();
     }
     // Attempt to charge the customer for the order's total.
     if (!($transaction = Service_Customer_Transaction::create($paymentmethod, $transaction_total))) {
         return false;
     }
     $order = Model_Customer_Order::forge();
     $order->customer = $customer;
     $order->transaction = $transaction;
     $order->populate($data);
     try {
         $order->save();
     } catch (FuelException $e) {
         Log::error($e);
         return false;
     }
     // Link products to customer.
     foreach ($product_options as $option) {
         Service_Customer_Product_Option::create(Arr::get($products, $option->id), $order, $option, $data);
     }
     // Mark the order as completed.
     self::update($order, array('status' => 'completed'));
     Service_Event::trigger('customer.order.create', $customer->seller, $order->to_array());
     return $order;
 }
コード例 #3
0
ファイル: products.php プロジェクト: mehulsbhatt/volcano
 /**
  * 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);
 }