Override classes

  • Posts: 444
  • Thank you received: 30
  • Hikamarket Multivendor Hikashop Business
1 year 7 months ago #349763

Bonjour,

ca faisait longtemps :)

J'ai aujourd'hui un souci d'override de classes car je souhaite que les utilisateurs connectés puissent choisir eux même le pseudo affiché sur leur vote puisque dans ce site (comme beaucoup) les vrais pseudos sont les emails.

J'ai pourtant fait mon fichier templates/mon_template/html/com_hikashop/administrator/classes/vote.php

pour y écrire ce code :

<?php

/**
 * @package	HikaShop for Joomla!
 * @version	4.7.0
 * @author	hikashop.com
 * @copyright	(C) 2010-2022 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php
	class hikashopVoteClassOverride extends hikashopClass
	{

		function checkVote(&$element)
		{
			$safeHtmlFilter = JFilterInput::getInstance(array(), array(), 1, 1);

			if (empty($element->vote_ref_id) || (int)$element->vote_ref_id == 0) {
				$this->error = array('code' => '505001', 'message' => hikashop_display(JText::_('HIKA_VOTE_ITEM_ID_MISSING'), 'error', true));
				return false;
			}

			if ((!isset($element->vote_type) || empty($element->vote_type)) && (!hikashop_isClient('administrator') || hikashop_isClient('administrator') && $element->vote_id == 0)) {
				$this->error = array('code' => '505015', 'message' =>  hikashop_display(JText::_('HIKA_VOTE_TYPE_MISSING'), 'error', true));
				return false;
			}

			$allowedVoteType = $this->config->get('enable_status_vote', 'nothing');
			$element->vote_rating = (isset($element->vote_rating)) ? $element->vote_rating : 0;
			$element->vote_comment = trim($safeHtmlFilter->clean(strip_tags((isset($element->vote_comment)) ? $element->vote_comment : ''), 'string'));
			$correctRating = 1;
			if ((int)$element->vote_rating == 0 || (int)$element->vote_rating > $this->config->get('vote_star_number', 5))
				$correctRating = 0;

			$user = hikashop_loadUser(true);
			if ($this->config->get('access_vote', 'public') == 'registered' && empty($user->user_cms_id)) {
				$this->error = array('code' => '505017', 'message' => hikashop_display(JText::_('ONLY_REGISTERED_CAN_VOTE'), 'error', true));
				return false;
			}

			if (hikashop_isClient('administrator')) {
				$element->vote_user_id = hikashop_getIP();
			} else {
				if (!empty($user->user_cms_id)) {
					$element->vote_user_id = (int)$user->user_id;
					$element->vote_pseudo = trim($safeHtmlFilter->clean(strip_tags((isset($element->vote_pseudo)) ? $element->vote_pseudo : ''), 'string'));
					$element->vote_email = $user->email;
				} else {
					$element->vote_user_id = hikashop_getIP();
					$element->vote_pseudo = trim($safeHtmlFilter->clean(strip_tags((isset($element->vote_pseudo)) ? $element->vote_pseudo : ''), 'string'));

					if ((!$correctRating || $allowedVoteType == 'both') && !empty($element->vote_comment)) {
						if (!$element->vote_pseudo) {
							$this->error = array('code' => '505011', 'message' => hikashop_display(JText::_('HIKA_VOTE_PSEUDO_REQUIRED'), 'error', true));
							return false;
						}

						if ($this->config->get('email_comment', '1')) {
							$element->vote_email = trim($safeHtmlFilter->clean(strip_tags((isset($element->vote_email)) ? $element->vote_email : ''), 'string'));
							if (!$element->vote_email || empty($element->vote_email)) {
								$this->error = array('code' => '505012', 'message' => hikashop_display(JText::_('HIKA_VOTE_EMAIL_REQUIRED'), 'error', true));
								return false;
							}
						}
					}
				}

				if ($this->config->get('access_vote', 'public') != 'public' && empty($user->user_cms_id)) {
					$this->error = array('code' => '505002', 'message' => hikashop_display(JText::_('HIKA_VOTE_REGISTRATION_REQUIRED'), 'error', true));
					return false;
				}

				if ($element->vote_type == 'product' && $this->config->get('access_vote', 'public') == 'buyed') {
					$hasBought = $this->hasBought($element->vote_ref_id, $user->user_id);
					if (!$hasBought) {
						$this->error = array('code' => '505003', 'message' => hikashop_display(JText::_('HIKA_VOTE_ITEM_BOUGHT_REQUIRED'), 'error', true));
						return false;
					}
				}
			}


			if (in_array($allowedVoteType, array('vote', 'two')) && $element->vote_rating != 0)
				$element->vote_comment = '';

			if ($allowedVoteType == 'nothing') {
				$this->error = array('code' => '505005', 'message' => hikashop_display(JText::_('HIKA_VOTE_NOT_ALLOWED'), 'error', true));
				return false;
			}

			if ($allowedVoteType == 'vote' && !$correctRating) {
				$this->error = array('code' => '505006', 'message' => hikashop_display(JText::_('HIKA_VOTE_WRONG_RATING_VALUE'), 'error', true));
				return false;
			}

			if ($allowedVoteType == 'comment' && $element->vote_comment == '') {
				$this->error = array('code' => '505007', 'message' => hikashop_display(JText::_('HIKA_VOTE_EMPTY_COMMENT'), 'error', true));
				return false;
			}

			if ($allowedVoteType == 'two' && $element->vote_comment == '' && !$correctRating) {
				$this->error = array('code' => '505008', 'message' => hikashop_display(JText::_('HIKA_VOTE_WRONG_VOTE_COMMENT_VALUE'), 'error', true));
				return false;
			}

			if ($allowedVoteType == 'both' && ($element->vote_comment == '' || !$correctRating)) {
				$this->error = array('code' => '505009', 'message' => hikashop_display(JText::_('HIKA_VOTE_MISSING_VOTE_COMMENT_VALUE'), 'error', true));
				return false;
			}

			if (!empty($element->vote_comment) && (!isset($element->vote_id) || $element->vote_id == 0)) {
				$nbComment = $this->commentPassed($element->vote_type, $element->vote_ref_id, $element->vote_user_id);
				if (in_array($allowedVoteType, array('comment', 'two', 'both')) && !empty($element->vote_comment) && $nbComment >= $this->config->get('comment_by_person_by_product', '30')) {
					$this->error = array('code' => '505010', 'message' => hikashop_display(JText::_('HIKA_VOTE_LIMIT_REACHED'), 'error', true));
					return false;
				}
			}
			return true;
		}
	}

ma modification n'est pas prise en compte alors que si je la fait directement dans la classe vote elle l'est.

Je ne comprends pas il me semble pourtant avoir respecté la procédure :huh:

Si jamais vous voyez mon erreur, c'est super parce que moi pas.

Merci d'avance :)

Please Log in or Create an account to join the conversation.

  • Posts: 82590
  • Thank you received: 13298
  • MODERATOR
1 year 7 months ago #349771

Bonjour,

Le fichier doit être templates/mon_template/html/com_hikashop/administrator/classes/vote.override.php

Aussi, il faut reprendre tout le code le la classe d'origine. Si vous avez juste la fonction checkVote cela ne va pas fonctionner.

Ou alors, il faut rajouter un include du fichier d'origine, et au lieu d'extend hikashopClass il faut extend hikashopVoteClass pour ainsi récupérer implicitement toutes les fonctions du fichier d'origine.

Please Log in or Create an account to join the conversation.

  • Posts: 444
  • Thank you received: 30
  • Hikamarket Multivendor Hikashop Business
1 year 7 months ago #349781

Bonjour,

super, merci Nicolas.

tout fonctionne nickel, je suis retournée sur la doc, effectivement j'avais raté le .override ...

Par contre, la doc ne mentionne pas l'include à l'extend de la class, je l'ai mis quand même, ca m'a donné un :
Fatal error: Cannot declare class hikashopVoteClass, because the name is already in use in xxx/administrator/components/com_hikashop/classes/vote.php on line 12

J'ai retiré l'include et l'override fonctionne :dry: :cheer:

Merci :)

Last edit: 1 year 7 months ago by Minie.

Please Log in or Create an account to join the conversation.

Time to create page: 0.059 seconds
Powered by Kunena Forum