コード例 #1
0
ファイル: order.php プロジェクト: mehulsbhatt/volcano
 /**
  * Creates a new validation instance for order create.
  *
  * @param Model_Customer $customer The ordering customer.
  *
  * @return Validation
  */
 public static function create(Model_Customer $customer)
 {
     $validator = Validation::forge('order');
     $validator->add('products', 'Products')->add_rule('required')->add_rule(array('invalid_products' => function ($products) use($customer) {
         $ids = array_keys($products);
         foreach ($ids as $id) {
             if (!is_numeric($id)) {
                 return false;
             }
             $product_option = Service_Product_Option::find_one($id);
             if (!$product_option || $product_option->product->seller != $customer->seller) {
                 return false;
             }
         }
         return true;
     }));
     $validator->add('paymentmethod', 'Paymentmethod')->add_rule(array('invalid_paymentmethod' => function ($paymentmethod) use($customer) {
         if (!$paymentmethod) {
             return true;
         }
         $paymentmethod = Service_Customer_Paymentmethod::find_one($paymentmethod);
         if (!$paymentmethod || $paymentmethod->customer != $customer) {
             return false;
         }
         return true;
     }));
     return $validator;
 }
コード例 #2
0
 /**
  * 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;
 }