Esempio n. 1
0
 /**
  * Returns boolean true if user can review product
  * otherwise, returns string error message  
  * 
  * @param \Users\Models\Users $user
  * @param \Shop\Models\Products $product
  * @return string|boolean
  */
 public static function canUserReview(\Users\Models\Users $user, \Shop\Models\Products $product)
 {
     if (empty($user->id)) {
         return false;
     }
     $settings = \Shop\Models\Settings::fetch();
     switch ($settings->{'reviews.eligibile'}) {
         case "identified":
             // has the user already reviewed it?
             $has_reviewed = static::collection()->count(array('product_id' => $product->id, 'user_id' => $user->id));
             if (!$has_reviewed) {
                 return true;
             }
             break;
         case "purchasers":
         default:
             // has the user purchased this item?
             if (\Shop\Models\Customers::hasUserPurchasedProduct($user, $product)) {
                 // has the user already reviewed it?
                 $has_reviewed = static::collection()->count(array('product_id' => $product->id, 'user_id' => $user->id));
                 if (!$has_reviewed) {
                     return true;
                 }
             }
             break;
     }
     return false;
 }