public function deleteCart() { $model = new tmsModel(); $carts = $model->getTable('carts'); if (!empty($this->virtuemart_cart_id)) { $carts->delete($this->virtuemart_cart_id, 'virtuemart_cart_id'); } else { $currentUser = JFactory::getUser(); if (!empty($currentUser->id)) { $carts->delete($currentUser->id); } } }
/** * Save a rating * @author Max Milbers */ public function saveRating($data = 0) { //Check user_rating $maxrating = tsmConfig::get('vm_maximum_rating_scale', 5); $tsmart_product_id = vRequest::getInt('tsmart_product_id', 0); $app = JFactory::getApplication(); if ($app->isSite()) { $user = JFactory::getUser(); $userId = $user->id; $allowReview = $this->allowReview($tsmart_product_id); $allowRating = $this->allowRating($tsmart_product_id); } else { $userId = $data['created_by']; $allowReview = true; $allowRating = true; } if (!empty($tsmart_product_id)) { //if ( !empty($data['tsmart_product_id']) && !empty($userId)){ if (empty($data)) { $data = vRequest::getPost(); } if ($allowRating) { //normalize the rating if ($data['vote'] < 0) { $data['vote'] = 0; } if ($data['vote'] > $maxrating + 1) { $data['vote'] = $maxrating; } $data['lastip'] = $_SERVER['REMOTE_ADDR']; $data['vote'] = (int) $data['vote']; $rating = $this->getRatingByProduct($data['tsmart_product_id']); vmdebug('$rating', $rating); $vote = $this->getVoteByProduct($data['tsmart_product_id'], $userId); vmdebug('$vote', $vote); $data['tsmart_rating_vote_id'] = empty($vote->tsmart_rating_vote_id) ? 0 : $vote->tsmart_rating_vote_id; if (isset($data['vote'])) { $votesTable = $this->getTable('rating_votes'); $res = $votesTable->bindChecknStore($data, TRUE); if (!$res) { vmError(get_class($this) . '::Error store votes '); } } if (!empty($rating->rates) && empty($vote)) { $data['rates'] = $rating->rates + $data['vote']; $data['ratingcount'] = $rating->ratingcount + 1; } else { if (!empty($rating->rates) && !empty($vote->vote)) { $data['rates'] = $rating->rates - $vote->vote + $data['vote']; $data['ratingcount'] = $rating->ratingcount; } else { $data['rates'] = $data['vote']; $data['ratingcount'] = 1; } } if (empty($data['rates']) || empty($data['ratingcount'])) { $data['rating'] = 0; } else { $data['rating'] = $data['rates'] / $data['ratingcount']; } $data['tsmart_rating_id'] = empty($rating->tsmart_rating_id) ? 0 : $rating->tsmart_rating_id; vmdebug('saveRating $data', $data); $rating = $this->getTable('ratings'); $res = $rating->bindChecknStore($data, TRUE); if (!$res) { vmError(get_class($this) . '::Error store rating '); } } if ($allowReview and !empty($data['comment'])) { //if(!empty($data['comment'])){ $data['comment'] = substr($data['comment'], 0, tsmConfig::get('vm_reviews_maximum_comment_length', 2000)); // no HTML TAGS but permit all alphabet $value = preg_replace('@<[\\/\\!]*?[^<>]*?>@si', '', $data['comment']); //remove all html tags $value = (string) preg_replace('#on[a-z](.+?)\\)#si', '', $value); //replace start of script onclick() onload()... $value = trim(str_replace('"', ' ', $value), "'"); $data['comment'] = (string) preg_replace('#^\'#si', '', $value); //replace ' at start $data['comment'] = nl2br($data['comment']); // keep returns //set to defaut value not used (prevent hack) $data['review_ok'] = 0; $data['review_rating'] = 0; $data['review_editable'] = 0; // Check if ratings are auto-published (set to 0 prevent injected by user) // $app = JFactory::getApplication(); if ($app->isSite()) { if (tsmConfig::get('reviews_autopublish', 1)) { $data['published'] = 1; } else { $model = new tmsModel(); $product = $model->getTable('products'); $product->load($data['tsmart_product_id']); $vendorId = vmAccess::isSuperVendor(); if (!vmAccess::manager() or $vendorId != $product->tsmart_vendor_id) { $data['published'] = 0; } } } $review = $this->getReviewByProduct($data['tsmart_product_id'], $userId); if (!empty($review->review_rates)) { $data['review_rates'] = $review->review_rates + $data['vote']; } else { $data['review_rates'] = $data['vote']; } if (!empty($review->review_ratingcount)) { $data['review_ratingcount'] = $review->review_ratingcount + 1; } else { $data['review_ratingcount'] = 1; } $data['review_rating'] = $data['review_rates'] / $data['review_ratingcount']; $data['tsmart_rating_review_id'] = empty($review->tsmart_rating_review_id) ? 0 : $review->tsmart_rating_review_id; $reviewTable = $this->getTable('rating_reviews'); $res = $reviewTable->bindChecknStore($data, TRUE); if (!$res) { vmError(get_class($this) . '::Error store review '); } } return $data['tsmart_rating_review_id']; } else { vmError('Cant save rating/review/vote without vote/product_id'); return FALSE; } }