Donner un prix aux fichiers

  • Posts: 163
  • Thank you received: 11
9 years 11 months ago #156730

-- url of the page with the problem -- : www.impress-3d.com
-- HikaShop version -- : 2.3.1 + Hikamarket 1.4.1
-- Joomla version -- : 3.2.2
-- PHP version -- : 5.4.22
-- Browser(s) name and version -- : Firefox 27.0.1
-- Error-message(debug-mod must be tuned on) -- : aucun message d'erreur

Bonjour,

J'ai une demande un peu particulière aujourd'hui, ne pouvant donner de prix aux différents fichiers téléchargeables dans un même produit, j'ai besoin de leur donner un prix dans la vue user/downloads

Pour cela, dans ma vue user/dowloads, je dois compter le nombre de fichiers .pdf contenu dans chaque produit acheté.
Je dois ensuite diviser le prix du produit par le nombre de fichier .pdf qu'il contient.

Pourriez vous m'indiquer une façon de faire cela proprement ?

Je vous remercie par avance pour votre aide !

Cordialement, Nossibé

Last edit: 9 years 11 months ago by nossibe63.

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

  • Posts: 12953
  • Thank you received: 1778
9 years 11 months ago #156750

Bonjour,

J'ai une demande un peu particulière aujourd'hui, ne pouvant donner de prix aux différents fichiers téléchargeables dans un même produit

La solution serai d'utiliser les caractéristiques et d'assigner un fichier par variante et donc de leurs attribuer différents prix en fonction du fichier.

Pour cela, dans ma vue user/dowloads, je dois compter le nombre de fichiers .pdf contenu dans chaque produit acheté.
Je dois ensuite diviser le prix du produit par le nombre de fichier .pdf qu'il contient.

Concernant le prix du produit vous le trouverez via la variable :
$downloadFile->order_product_price
Juste après la ligne de la boucle :
	foreach($this->downloadData as $downloadFile) {

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

  • Posts: 163
  • Thank you received: 11
9 years 11 months ago #156872

Merci beaucoup Mohamed,

Je vais étudier cette solution de près !

Cordialement, Gaëtan

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

  • Posts: 163
  • Thank you received: 11
9 years 10 months ago #158567

J'ai testé l'utilisation des options et variantes, mais ça ne convient pas à ce que je souhaite faire, il y a trop d'étapes pour la conception d'un produit et pour un site multi-vendeur c'est trop contraignant.

J'en reviens donc à ma première idée qui est de compter le nombre de fichiers payants puis de diviser le prix de l'objet par le nombre de téléchargements disponibles pour cet objet.

En attendant mieux, j'ai ajouter un custom field afin d'indiquer manuellement le nombre de fichiers téléchargeables pour chaque produit (table product). Pouvez-vous m'indiquer comment récupérer la valeur de ce custom field pour chaque produit dans ma vue user/downloads ?

Je vous remercie !
Cordialement, Nossibé

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

  • Posts: 13201
  • Thank you received: 2322
9 years 10 months ago #158609

Bonjour,

Je pense qu'il faut se placer dans un foreach sur "$downloadFile->orders" puis faire un loadFullOrder sur chaque orders pour récupérer tous les produits, et récupérer les produits complets afin d'avoir la valeur de la custom field.

Quelque chose comme:

<?php
$orderClass = hikashop_get('class.order');
foreach(downloadFile->orders as $o){
  $fullOrder = $orderClass->loadFullOrder($o->order_id);
  foreach($fullOrder->products as $p){
    $yourValue = $p->CUSTOM_FIELD_NAME;
  }
}

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

  • Posts: 163
  • Thank you received: 11
9 years 10 months ago #158816

Merci Xavier,

ça ne marche pas, peut-être est-ce parce que $orderClass n'est défini nul part ?

Cordialement, Nossibé

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

  • Posts: 2334
  • Thank you received: 403
9 years 10 months ago #158830

Bonjour Nossibé,

$orderClass est défini au début du code donné par Xavier, en revanche il manquait un $, essayez ceci:

<?php
$orderClass = hikashop_get('class.order');
foreach($downloadFile->orders as $o){
  $fullOrder = $orderClass->loadFullOrder($o->order_id);
  foreach($fullOrder->products as $p){
    $yourValue = $p->CUSTOM_FIELD_NAME;
  }
}

Et n'oubliez pas de remplacer CUSTOM_FIELD_NAME par le nom de votre custom field!

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

  • Posts: 163
  • Thank you received: 11
9 years 10 months ago #158922

Oups, désolé, à faire trop de tests j'en ai perdu de vue le code d'origine...

Voici mon code actuel qui n'affiche pas $nbr_payant ^^

$order_id = 0;
$order_date = 0;
$single_limit = $downloadFile->file_limit;
if($single_limit == 0)
$single_limit = (int)$this->config->get('download_number_limit', 50);
if(!empty($downloadFile->orders)) {
	if($single_limit > 0){
		$orderClass = hikashop_get('class.order');
		foreach($downloadFile->orders as $o) {
			$fullOrder = $orderClass->loadFullOrder($o->order_id);
			foreach($fullOrder->products as $p){
				$nbr_payant = $p->product_fichierspayants;
			}
			if(
				(empty($order_date) || $o->order_created < $order_date || (($this->download_time_limit + $o->order_created) >= time() &&  ($this->download_time_limit + $order_date) < time())) &&
				(empty($o->file_qty) || ($o->download_total < ($single_limit * (int)$o->order_product_quantity)))
			) {
				$order_id = (int)$o->order_id;
				$order_date = (int)$o->order_created;
			}
		}
	}else{
		$orderClass = hikashop_get('class.order');
		foreach($downloadFile->orders as $o) {
			$fullOrder = $orderClass->loadFullOrder($o->order_id);
			foreach($fullOrder->products as $p){
				$nbr_payant = $p->product_fichierspayants;
			}
			if(($this->download_time_limit + $o->order_created) >= time() &&  ($this->download_time_limit + $order_date) < time()){
				$order_id = (int)$o->order_id;
				$order_date = (int)$o->order_created;
			}
		}
	}
}

// ...

<p class="hikashop_order_product_name">
	<?php echo JText::_('PRODUCT'); ?> : <?php echo $downloadFile->order_product_name; ?> - <?php echo $downloadFile->order_product_price; ?> - <?php echo $nbr_payant; ?>
</p>

product_fichierspayants étant le nom du champ de mon custom field.

J'ai testé de définir la variable $nbr_payant par l'ajout de $nbr_payant = 0; en début du code ci-dessus, mais ça ne change rien. Voyez-vous ce que j'ai mal fait ?

Je vous remercie pour votre aide,
Cordialement, Nossibé

Last edit: 9 years 10 months ago by nossibe63.

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

  • Posts: 13201
  • Thank you received: 2322
9 years 10 months ago #158991

Bonjour,

Avez vous une quelconque erreur affichée ?
Il faudrait faire un debug de votre code, vérifier bien les valeurs récupérées dès le début, vérifiez si vous passez bien dans tous les "if", etc.

Comme ce n'est pas un disfonctionnement d'HikaShop mais une customisation et que nous avons beaucoup de support ces temps ci, nous ne pouvons consacrer beaucoup de temps pour ce genre de situations. Merci de votre compréhension :)

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

  • Posts: 163
  • Thank you received: 11
9 years 10 months ago #159165

Bonjour,

Je comprends tout à fait, mais ça dépasse mes compétences, aussi je poste quand même le résultat de mon dernier test en espérant que vous pourrez m’aiguiller vers la bonne voie.

J'ai repris le fichier d'origine de user/downloads (sans les modifications que j'avais apporté.

Voici donc le fichier complet de la vue :

<?php
/**
 * @package	HikaShop for Joomla!
 * @version	2.3.1
 * @author	hikashop.com
 * @copyright	(C) 2010-2014 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php
	global $Itemid;
	$url_itemid = '';
	if(!empty($Itemid)){
		$url_itemid='&Itemid='.$Itemid;
	}
	$userCurrent = hikashop_loadUser(true);
	if(hikashop_loadUser() == null){
		echo JText::_('PLEASE_LOGIN_FIRST');
	}else{
?>
<div id="hikashop_download_listing">
	<fieldset>
		<div class="header hikashop_header_title"><h1><?php echo JText::_('DOWNLOADS');?></h1></div>
		<div class="toolbar hikashop_header_buttons" id="toolbar" style="float: right;">
			<table class="hikashop_no_border">
				<tr>
					<td>
						<a onclick="javascript:submitbutton('cancel'); return false;" href="#" >
							<span class="icon-32-back" title="<?php echo JText::_('HIKA_BACK'); ?>">
							</span>
							<?php echo JText::_('HIKA_BACK'); ?>
						</a>
					</td>
				</tr>
			</table>
		</div>
	</fieldset>
	<form action="<?php echo hikashop_completeLink('user&task=downloads'.$url_itemid); ?>" method="POST" name="adminForm" id="adminForm">
		<table class="hikashop_no_border">
			<tr>
				<td width="100%">
					<?php echo JText::_( 'FILTER' ); ?>:
					<input type="text" name="search" id="hikashop_search" value="<?php echo $this->escape($this->pageInfo->search);?>" class="inputbox" onchange="document.adminForm.submit();" />
					<button class="btn" onclick="this.form.submit();"><?php echo JText::_( 'GO' ); ?></button>
					<button class="btn" onclick="document.getElementById('hikashop_search').value='';this.form.submit();"><?php echo JText::_( 'RESET' ); ?></button>
				</td>
			</tr>
		</table>
		<input type="hidden" name="option" value="<?php echo HIKASHOP_COMPONENT; ?>" />
		<input type="hidden" name="task" value="downloads" />
		<input type="hidden" name="ctrl" value="<?php echo JRequest::getCmd('ctrl'); ?>" />
		<input type="hidden" name="boxchecked" value="0" />
		<input type="hidden" name="filter_order" value="<?php echo $this->pageInfo->filter->order->value; ?>" />
		<input type="hidden" name="filter_order_Dir" value="<?php echo $this->pageInfo->filter->order->dir; ?>" />
		<?php echo JHTML::_( 'form.token' ); ?>
	</form>
	<fieldset>
		<table cellpadding="1" width="100%">
			<thead>
				<tr>
					<th class="hikashop_product_name title" align="center"><?php
						echo JHTML::_('grid.sort', JText::_('PRODUCT'), 'p.order_product_name', $this->pageInfo->filter->order->dir,$this->pageInfo->filter->order->value );
					?></th>
					<th class="hikashop_file_name title" align="center"><?php
						echo JHTML::_('grid.sort', JText::_('HIKA_FILES'), 'f.file_name', $this->pageInfo->filter->order->dir,$this->pageInfo->filter->order->value );
					?></th>
					<th class="hikashop_nb_download title" align="center"><?php
						echo JText::_('NB_DOWNLOADED');
					?></th>
					<th class="hikashop_download_limit title" align="center"><?php
						echo JHTML::_('grid.sort', JText::_('DOWNLOAD_NUMBER_LIMIT'), 'f.file_limit', $this->pageInfo->filter->order->dir,$this->pageInfo->filter->order->value );
					?></th>
					<th class="hikashop_order_date_title title" align="center"><?php
						echo JHTML::_('grid.sort', JText::_('FIRST_PURCHASED_AT'), 'min_order_created', $this->pageInfo->filter->order->dir,$this->pageInfo->filter->order->value );
					?></th>
					<th class="hikashop_order_date_title title" align="center"><?php
						echo JHTML::_('grid.sort', JText::_('LAST_PURCHASED_AT'), 'max_order_created', $this->pageInfo->filter->order->dir,$this->pageInfo->filter->order->value );
					?></th>
				</tr>
			</thead>
			<tbody>
<?php
	foreach($this->downloadData as $downloadFile) {
		$limit = -1;
		if($downloadFile->file_limit == 0)
			$limit = (int)$this->config->get('download_number_limit', 50) * $downloadFile->file_quantity;
		if($downloadFile->file_limit > 0)
			$limit = $downloadFile->file_limit * $downloadFile->file_quantity;
		$limitNotReached = true;
		$periodNotReached = true;
		if(!empty($downloadFile->file_limit) && !empty($downloadFile->download_total) && $downloadFile->file_limit != -1 && $downloadFile->file_limit == 0 && $downloadFile->download_total >= $downloadFile->file_limit ){
			$limitNotReached = false;
		}

		$order_id = 0;
		$order_date = 0;
		$single_limit = $downloadFile->file_limit;
		if($single_limit == 0)
			$single_limit = (int)$this->config->get('download_number_limit', 50);
		if(!empty($downloadFile->orders)) {
			if($single_limit > 0){
				$fullOrder = $orderClass->loadFullOrder($o->order_id);
				foreach($downloadFile->orders as $o) {
				$fullOrder = $orderClass->loadFullOrder($o->order_id);
					foreach($fullOrder->products as $p){
						$nbr_payant = $p->product_fichierspayants;
					}
					if(
					 (empty($order_date) || $o->order_created < $order_date || (($this->download_time_limit + $o->order_created) >= time() &&  ($this->download_time_limit + $order_date) < time())) &&
					 (empty($o->file_qty) || ($o->download_total < ($single_limit * (int)$o->order_product_quantity)))
					) {
						$order_id = (int)$o->order_id;
						$order_date = (int)$o->order_created;
					}
				}
			}else{
				$orderClass = hikashop_get('class.order');
				foreach($downloadFile->orders as $o) {
					$fullOrder = $orderClass->loadFullOrder($o->order_id);
					foreach($fullOrder->products as $p){
						$nbr_payant = $p->product_fichierspayants;
					}
					if(($this->download_time_limit + $o->order_created) >= time() &&  ($this->download_time_limit + $order_date) < time()){
						$order_id = (int)$o->order_id;
						$order_date = (int)$o->order_created;
					}
				}
			}
		}
		if(empty($order_id))
			$order_id = $downloadFile->order_id;
		if(empty($order_date))
			$order_date = $downloadFile->order_created;

		if(!empty($this->download_time_limit) && ($this->download_time_limit + $order_date) < time()) {
			$fileHtml = JText::_('TOO_LATE_NO_DOWNLOAD');
			$periodNotReached = false;
		}
?>
					<tr>
						<td class="hikashop_order_item_name_value">
							<?php if(!empty($downloadFile->product_id)){ ?>
								<a class="hikashop_order_product_link" href="<?php echo hikashop_completeLink('product&task=show&cid='.$downloadFile->product_id.$url_itemid); ?>">
							<?php } ?>
							<p class="hikashop_order_product_name">
								<?php echo $downloadFile->order_product_name; ?> <?php echo $nbr_payant; ?> 
							</p>
							</a>
						</td>
						<td>
<?php
		if($limitNotReached && $periodNotReached) {
			if(empty($downloadFile->file_name)) {
				if(empty($downloadFile->file_path)) {
					$downloadFile->file_name = JText::_('DOWNLOAD_NOW');
				} else {
					$downloadFile->file_name = $downloadFile->file_path;
				}
			}
			$file_pos = '';
			if(!empty($downloadFile->file_pos)) {
				$file_pos = '&file_pos='.$downloadFile->file_pos;
			}

			if(in_array(substr($downloadFile->file_path, 0, 1), array('@', '#')) && (int)$downloadFile->file_quantity > 1) {
				for($i = 1; $i <= (int)$downloadFile->file_quantity; $i++) {
					echo '<a href="'.hikashop_completeLink('order&task=download&file_id='.$downloadFile->file_id.'&order_id='.$order_id.'&file_pos='.$i.$url_itemid).'">'.$downloadFile->file_name.'</a><br/>';
				}
				$fileHtml = '';
			} else {
				$fileHtml = '<a href="'.hikashop_completeLink('order&task=download&file_id='.$downloadFile->file_id.'&order_id='.$order_id.$file_pos.$url_itemid).'">'.$downloadFile->file_name.'</a>';
			}
		} else {
			$fileHtml = $downloadFile->file_name;
		}
		echo $fileHtml;
?>
						</td>
						<td><?php
		if(in_array(substr($downloadFile->file_path, 0, 1), array('@', '#')) && (int)$downloadFile->file_quantity > 1) {
			for($i = 1; $i <= (int)$downloadFile->file_quantity; $i++) {
				if(isset($downloadFile->downloads[$i])) {
					echo $downloadFile->downloads[$i]->download_number . '<br/>';
				} else {
					echo 0 . '<br/>';
				}
			}
		} else {
			if (!empty($downloadFile->download_total))
				echo $downloadFile->download_total;
			else
				echo 0;
		}
						?></td>
						<td>
<?php
		$downloadLimit = JText::_('UNLIMITED');
		if($limit == -1 && $limitNotReached && $periodNotReached) {
			$downloadLimit = JText::_('UNLIMITED');
		} elseif($limitNotReached && $periodNotReached) {
			if(in_array(substr($downloadFile->file_path, 0, 1), array('@', '#')) && (int)$downloadFile->file_quantity > 1) {
				$downloadLimit = '';
				for($i = 1; $i <= (int)$downloadFile->file_quantity; $i++) {
					if(isset($downloadFile->downloads[$i])) {
						echo JText::sprintf('X_DOWNLOADS_LEFT', $single_limit - $downloadFile->downloads[$i]->download_number) . '<br/>';
					} else {
						$downloadLimit .= JText::sprintf('X_DOWNLOADS_LEFT', $single_limit) . '<br/>';
					}
				}
			} else {
				$downloadLimit = JText::sprintf('X_DOWNLOADS_LEFT',$limit-$downloadFile->download_total);
			}
		} elseif(!$periodNotReached) {
			$downloadLimit = JText::_('TOO_LATE_NO_DOWNLOAD');
		} elseif(!$limitNotReached) {
			$downloadLimit = JText::_('MAX_REACHED_NO_DOWNLOAD');
		}
		echo $downloadLimit;
?>
						</td>
						<td><?php
							echo date('d/m/Y', $downloadFile->min_order_created);
						?></td>
						<td><?php
							echo date('d/m/Y', $downloadFile->max_order_created);
						?></td>
					</tr>
<?php
	}
?>
			</tbody>
			<tfoot>
				<tr>
					<td colspan="10">
						<div class="pagination">
							<form action="<?php echo hikashop_completeLink('user&task=downloads'.$url_itemid); ?>" method="post" name="adminForm_bottom">
								<?php $this->pagination->form = '_bottom'; echo $this->pagination->getListFooter(); ?>
								<?php echo $this->pagination->getResultsCounter(); ?>
								<input type="hidden" name="option" value="<?php echo HIKASHOP_COMPONENT; ?>" />
								<input type="hidden" name="task" value="downloads" />
								<input type="hidden" name="ctrl" value="<?php echo JRequest::getCmd('ctrl'); ?>" />
								<input type="hidden" name="filter_order" value="<?php echo $this->pageInfo->filter->order->value; ?>" />
								<input type="hidden" name="filter_order_Dir" value="<?php echo $this->pageInfo->filter->order->dir; ?>" />
								<?php echo JHTML::_( 'form.token' ); ?>
							</form>
						</div>
					</td>
				</tr>
			</tfoot>
		</table>
	</fieldset>
<?php
	}
?>
</div>

J'obtiens un message d'erreur (répété pour chaque fichier) :

Notice: Undefined property: stdClass::$product_fichierspayants in /templates/destinyfx/html/com_hikashop/user/downloads.php on line 121

Je vous remercie,
Cordialement, Nossibé

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

  • Posts: 2334
  • Thank you received: 403
9 years 10 months ago #159496

Cela veut dire que le custom field ne semble pas être présent.
Etes vous sur que les produits en question possède quelque chose dans ce champ?
Je vous conseil de faire un var_dump($nbr_payant) juste avant les ligne ou vous utiliser la variable product_fichierspayants de façon a visualiser l'objet et voir si le champ est présent ou non.

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

  • Posts: 163
  • Thank you received: 11
9 years 10 months ago #159560

Merci Eliot,

Le var_dump retourne null.

J'ai vérifié la présence d'une entrée dans le champ produit/product_fichierspayants et une valeur est bien présente pour l'un des produits téléchargeables, j'ai modifié le niveau d'accès du champ à "Tous", j'ai supprimé la commande puis recommandé l'article pour être sûre que les nouveaux paramètres du champs étaient bien pris en compte... Mais j'ai toujours une valeur NULL pour le var_dump.

<?php
/**
 * @package	HikaShop for Joomla!
 * @version	2.3.1
 * @author	hikashop.com
 * @copyright	(C) 2010-2014 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php
	global $Itemid;
	$url_itemid = '';
	if(!empty($Itemid)){
		$url_itemid='&Itemid='.$Itemid;
	}
	$userCurrent = hikashop_loadUser(true);
	if(hikashop_loadUser() == null){
		echo JText::_('PLEASE_LOGIN_FIRST');
	}else{
?>
<div id="hikashop_download_listing">
	<fieldset>
		<div class="header hikashop_header_title"><h1><?php echo JText::_('DOWNLOADS');?></h1></div>
		<div class="toolbar hikashop_header_buttons" id="toolbar" style="float: right;">
			<table class="hikashop_no_border">
				<tr>
					<td>
						<a onclick="javascript:submitbutton('cancel'); return false;" href="#" >
							<span class="icon-32-back" title="<?php echo JText::_('HIKA_BACK'); ?>">
							</span>
							<?php echo JText::_('HIKA_BACK'); ?>
						</a>
					</td>
				</tr>
			</table>
		</div>
	</fieldset>
	<form action="<?php echo hikashop_completeLink('user&task=downloads'.$url_itemid); ?>" method="POST" name="adminForm" id="adminForm">
		<table class="hikashop_no_border">
			<tr>
				<td width="100%">
					<?php echo JText::_( 'FILTER' ); ?>:
					<input type="text" name="search" id="hikashop_search" value="<?php echo $this->escape($this->pageInfo->search);?>" class="inputbox" onchange="document.adminForm.submit();" />
					<button class="btn" onclick="this.form.submit();"><?php echo JText::_( 'GO' ); ?></button>
					<button class="btn" onclick="document.getElementById('hikashop_search').value='';this.form.submit();"><?php echo JText::_( 'RESET' ); ?></button>
				</td>
			</tr>
		</table>
		<input type="hidden" name="option" value="<?php echo HIKASHOP_COMPONENT; ?>" />
		<input type="hidden" name="task" value="downloads" />
		<input type="hidden" name="ctrl" value="<?php echo JRequest::getCmd('ctrl'); ?>" />
		<input type="hidden" name="boxchecked" value="0" />
		<input type="hidden" name="filter_order" value="<?php echo $this->pageInfo->filter->order->value; ?>" />
		<input type="hidden" name="filter_order_Dir" value="<?php echo $this->pageInfo->filter->order->dir; ?>" />
		<?php echo JHTML::_( 'form.token' ); ?>
	</form>
	<fieldset>
		<table cellpadding="1" width="100%">
			<thead>
				<tr>
					<th class="hikashop_product_name title" align="center"><?php
						echo JHTML::_('grid.sort', JText::_('PRODUCT'), 'p.order_product_name', $this->pageInfo->filter->order->dir,$this->pageInfo->filter->order->value );
					?></th>
					<th class="hikashop_file_name title" align="center"><?php
						echo JHTML::_('grid.sort', JText::_('HIKA_FILES'), 'f.file_name', $this->pageInfo->filter->order->dir,$this->pageInfo->filter->order->value );
					?></th>
					<th class="hikashop_nb_download title" align="center"><?php
						echo JText::_('NB_DOWNLOADED');
					?></th>
					<th class="hikashop_download_limit title" align="center"><?php
						echo JHTML::_('grid.sort', JText::_('DOWNLOAD_NUMBER_LIMIT'), 'f.file_limit', $this->pageInfo->filter->order->dir,$this->pageInfo->filter->order->value );
					?></th>
					<th class="hikashop_order_date_title title" align="center"><?php
						echo JHTML::_('grid.sort', JText::_('FIRST_PURCHASED_AT'), 'min_order_created', $this->pageInfo->filter->order->dir,$this->pageInfo->filter->order->value );
					?></th>
					<th class="hikashop_order_date_title title" align="center"><?php
						echo JHTML::_('grid.sort', JText::_('LAST_PURCHASED_AT'), 'max_order_created', $this->pageInfo->filter->order->dir,$this->pageInfo->filter->order->value );
					?></th>
				</tr>
			</thead>
			<tbody>
<?php
	foreach($this->downloadData as $downloadFile) {
		$limit = -1;
		if($downloadFile->file_limit == 0)
			$limit = (int)$this->config->get('download_number_limit', 50) * $downloadFile->file_quantity;
		if($downloadFile->file_limit > 0)
			$limit = $downloadFile->file_limit * $downloadFile->file_quantity;
		$limitNotReached = true;
		$periodNotReached = true;
		if(!empty($downloadFile->file_limit) && !empty($downloadFile->download_total) && $downloadFile->file_limit != -1 && $downloadFile->file_limit == 0 && $downloadFile->download_total >= $downloadFile->file_limit ){
			$limitNotReached = false;
		}

		$order_id = 0;
		$order_date = 0;
		$single_limit = $downloadFile->file_limit;
		if($single_limit == 0)
			$single_limit = (int)$this->config->get('download_number_limit', 50);
		if(!empty($downloadFile->orders)) {
			if($single_limit > 0){
				foreach($downloadFile->orders as $o) {
					if(
					 (empty($order_date) || $o->order_created < $order_date || (($this->download_time_limit + $o->order_created) >= time() &&  ($this->download_time_limit + $order_date) < time())) &&
					 (empty($o->file_qty) || ($o->download_total < ($single_limit * (int)$o->order_product_quantity)))
					) {
						$order_id = (int)$o->order_id;
						$order_date = (int)$o->order_created;
					}
				}
			}else{
				$orderClass = hikashop_get('class.order');
				foreach($downloadFile->orders as $o) {
					$fullOrder = $orderClass->loadFullOrder($o->order_id);
					foreach($fullOrder->products as $p){
						$nbr_payant = $p->product_fichierspayants;
					}
					if(($this->download_time_limit + $o->order_created) >= time() &&  ($this->download_time_limit + $order_date) < time()){
						$order_id = (int)$o->order_id;
						$order_date = (int)$o->order_created;
					}
				}
			}
		}
		if(empty($order_id))
			$order_id = $downloadFile->order_id;
		if(empty($order_date))
			$order_date = $downloadFile->order_created;

		if(!empty($this->download_time_limit) && ($this->download_time_limit + $order_date) < time()) {
			$fileHtml = JText::_('TOO_LATE_NO_DOWNLOAD');
			$periodNotReached = false;
		}
?>
					<tr>
						<td class="hikashop_order_item_name_value">
							<?php if(!empty($downloadFile->product_id)){ ?>
								<a class="hikashop_order_product_link" href="<?php echo hikashop_completeLink('product&task=show&cid='.$downloadFile->product_id.$url_itemid); ?>">
							<?php } ?>
							<p class="hikashop_order_product_name">
								<?php echo $downloadFile->order_product_name; ?><?php var_dump($nbr_payant) ?> 
							</p>
							</a>
						</td>
						<td>
<?php
		if($limitNotReached && $periodNotReached) {
			if(empty($downloadFile->file_name)) {
				if(empty($downloadFile->file_path)) {
					$downloadFile->file_name = JText::_('DOWNLOAD_NOW');
				} else {
					$downloadFile->file_name = $downloadFile->file_path;
				}
			}
			$file_pos = '';
			if(!empty($downloadFile->file_pos)) {
				$file_pos = '&file_pos='.$downloadFile->file_pos;
			}

			if(in_array(substr($downloadFile->file_path, 0, 1), array('@', '#')) && (int)$downloadFile->file_quantity > 1) {
				for($i = 1; $i <= (int)$downloadFile->file_quantity; $i++) {
					echo '<a href="'.hikashop_completeLink('order&task=download&file_id='.$downloadFile->file_id.'&order_id='.$order_id.'&file_pos='.$i.$url_itemid).'">'.$downloadFile->file_name.'</a><br/>';
				}
				$fileHtml = '';
			} else {
				$fileHtml = '<a href="'.hikashop_completeLink('order&task=download&file_id='.$downloadFile->file_id.'&order_id='.$order_id.$file_pos.$url_itemid).'">'.$downloadFile->file_name.'</a>';
			}
		} else {
			$fileHtml = $downloadFile->file_name;
		}
		echo $fileHtml;
?>
						</td>
						<td><?php
		if(in_array(substr($downloadFile->file_path, 0, 1), array('@', '#')) && (int)$downloadFile->file_quantity > 1) {
			for($i = 1; $i <= (int)$downloadFile->file_quantity; $i++) {
				if(isset($downloadFile->downloads[$i])) {
					echo $downloadFile->downloads[$i]->download_number . '<br/>';
				} else {
					echo 0 . '<br/>';
				}
			}
		} else {
			if (!empty($downloadFile->download_total))
				echo $downloadFile->download_total;
			else
				echo 0;
		}
						?></td>
						<td>
<?php
		$downloadLimit = JText::_('UNLIMITED');
		if($limit == -1 && $limitNotReached && $periodNotReached) {
			$downloadLimit = JText::_('UNLIMITED');
		} elseif($limitNotReached && $periodNotReached) {
			if(in_array(substr($downloadFile->file_path, 0, 1), array('@', '#')) && (int)$downloadFile->file_quantity > 1) {
				$downloadLimit = '';
				for($i = 1; $i <= (int)$downloadFile->file_quantity; $i++) {
					if(isset($downloadFile->downloads[$i])) {
						echo JText::sprintf('X_DOWNLOADS_LEFT', $single_limit - $downloadFile->downloads[$i]->download_number) . '<br/>';
					} else {
						$downloadLimit .= JText::sprintf('X_DOWNLOADS_LEFT', $single_limit) . '<br/>';
					}
				}
			} else {
				$downloadLimit = JText::sprintf('X_DOWNLOADS_LEFT',$limit-$downloadFile->download_total);
			}
		} elseif(!$periodNotReached) {
			$downloadLimit = JText::_('TOO_LATE_NO_DOWNLOAD');
		} elseif(!$limitNotReached) {
			$downloadLimit = JText::_('MAX_REACHED_NO_DOWNLOAD');
		}
		echo $downloadLimit;
?>
						</td>
						<td><?php
							echo date('d/m/Y', $downloadFile->min_order_created);
						?></td>
						<td><?php
							echo date('d/m/Y', $downloadFile->max_order_created);
						?></td>
					</tr>
<?php
	}
?>
			</tbody>
			<tfoot>
				<tr>
					<td colspan="10">
						<div class="pagination">
							<form action="<?php echo hikashop_completeLink('user&task=downloads'.$url_itemid); ?>" method="post" name="adminForm_bottom">
								<?php $this->pagination->form = '_bottom'; echo $this->pagination->getListFooter(); ?>
								<?php echo $this->pagination->getResultsCounter(); ?>
								<input type="hidden" name="option" value="<?php echo HIKASHOP_COMPONENT; ?>" />
								<input type="hidden" name="task" value="downloads" />
								<input type="hidden" name="ctrl" value="<?php echo JRequest::getCmd('ctrl'); ?>" />
								<input type="hidden" name="filter_order" value="<?php echo $this->pageInfo->filter->order->value; ?>" />
								<input type="hidden" name="filter_order_Dir" value="<?php echo $this->pageInfo->filter->order->dir; ?>" />
								<?php echo JHTML::_( 'form.token' ); ?>
							</form>
						</div>
					</td>
				</tr>
			</tfoot>
		</table>
	</fieldset>
<?php
	}
?>
</div>

Voici le paramétrage de mon champ :



Je vous remercie encore !

Cordialement, Nossibé

Attachments:

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

  • Posts: 12953
  • Thank you received: 1778
9 years 10 months ago #159607

Bonjour,
Avez vous bien initialisé des valeurs pour via l'option "Fichiers payants" de la page de configuration de vos produits ?

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

  • Posts: 163
  • Thank you received: 11
9 years 10 months ago #159718

Merci Mohamed,

oui le champ "Fichiers payants" est bien rempli dans le formulaire de configuration du produit, il contient la valeur "9".

Cordialement, Nossibé

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

  • Posts: 26008
  • Thank you received: 4004
  • MODERATOR
9 years 10 months ago #159764

Bonjour,

La page de download permet d'accéder à une partie de la commande et à ses produits (appelés aussi : item).
Pour être un petit peu plus claire : les champs personnalisés de type "product" ne sont pas affichés ou chargés.
Que cela doit de base dans la base "download" ou en chargeant entièrement la commande.

Il faut donc charger les produits ou les données de la table product ; afin de récupérer les valeurs du champs personnalisé.

Cordialement,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 163
  • Thank you received: 11
9 years 10 months ago #160205

Merci Jerome,

Donc en gros si je veux intégrer mon champ personnalisé je dois hacker le fichier /components/com-hikashop/views/user/view.html.php pour joindre la table product à la requête en ligne 659...

C'est un peu dommage d'avoir des champs personnalisés mais de ne pas pouvoir les appeler dans toutes les vues. :(

Voici la modification effectuée, pouvez-vous me dire si c'est correcte s'il vous plait ?

ligne 653 :

$select = 'o.order_id, o.order_created, f.*, p.*, g.* ';

$selectSum = ', MIN(o.order_created) as min_order_created, MAX(o.order_created) as max_order_created, SUM(p.order_product_quantity) as file_quantity ';

$selectUniq = ', IF( REPLACE(LEFT(f.file_path, 1) , \'#\', \'@\') = \'@\', CONCAT(f.file_id, \'@\', o.order_id), f.file_id ) as uniq_id';

$query = ' FROM '.hikashop_table('order').' AS o ' .

	' INNER JOIN '.hikashop_table('order_product').' AS p ON p.order_id = o.order_id ' .

	' INNER JOIN '.hikashop_table('file').' AS f ON p.product_id = f.file_ref_id ' .
			
	' INNER JOIN '.hikashop_table('product').' AS g ON f.file_ref_id = g.product_id ' .

	' WHERE ' . $filters;

$groupBy = ' GROUP BY uniq_id ';

Je vous remercie encore.
Cordialement, Nossibé

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

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
9 years 10 months ago #160283

Bonjour,

Vous pouvez les appelés dans toutes les vues...Il suffit d'écrire le code nécessaire pour charger les données qui vont bien. De notre coté, nous avons ajouter par défaut l'affichage des champs dans les vues où cela nous semblait logique.

Concernant votre modification, oui, c'est correct comme cela, mais si vous voulez éviter de hacker le fichier view.html.php, alors il suffit d'utiliser cela dns votre vue:

$class = hikashop_get('class.product');
$productData = $class->get($p->product_id);
echo $productData->product_fichierspayants;
Ainsi, pour chaque produit de la commande, vous aurez accès à la valeur du champs.

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

  • Posts: 163
  • Thank you received: 11
9 years 10 months ago #160529

Merci Nicolas,

J'ai testé le code que vous m'avez fourni et voici les messages d'erreur obtenus :

Notice: Undefined variable: p in /templates/destinyfx/html/com_hikashop/user/downloads.php on line 99

Notice: Trying to get property of non-object in /templates/destinyfx/html/com_hikashop/user/downloads.php on line 99

et

Notice: Trying to get property of non-object in /templates/destinyfx/html/com_hikashop/user/downloads.php on line 138

Si je comprends bien, la class.product n'est pas chargée...

vue user downloads :

<?php
/**
 * @package	HikaShop for Joomla!
 * @version	2.3.1
 * @author	hikashop.com
 * @copyright	(C) 2010-2014 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php
	global $Itemid;
	$url_itemid = '';
	if(!empty($Itemid)){
		$url_itemid='&Itemid='.$Itemid;
	}
	$userCurrent = hikashop_loadUser(true);
	if(hikashop_loadUser() == null){
		echo JText::_('PLEASE_LOGIN_FIRST');
	}else{
?>
<div id="hikashop_download_listing">
	<fieldset>
		<div class="header hikashop_header_title"><h1><?php echo JText::_('DOWNLOADS');?></h1></div>
		<div class="toolbar hikashop_header_buttons" id="toolbar" style="float: right;">
			<table class="hikashop_no_border">
				<tr>
					<td>
						<a onclick="javascript:submitbutton('cancel'); return false;" href="#" >
							<span class="icon-32-back" title="<?php echo JText::_('HIKA_BACK'); ?>">
							</span>
							<?php echo JText::_('HIKA_BACK'); ?>
						</a>
					</td>
				</tr>
			</table>
		</div>
	</fieldset>
	<form action="<?php echo hikashop_completeLink('user&task=downloads'.$url_itemid); ?>" method="POST" name="adminForm" id="adminForm">
		<table class="hikashop_no_border">
			<tr>
				<td width="100%">
					<?php echo JText::_( 'FILTER' ); ?>:
					<input type="text" name="search" id="hikashop_search" value="<?php echo $this->escape($this->pageInfo->search);?>" class="inputbox" onchange="document.adminForm.submit();" />
					<button class="btn" onclick="this.form.submit();"><?php echo JText::_( 'GO' ); ?></button>
					<button class="btn" onclick="document.getElementById('hikashop_search').value='';this.form.submit();"><?php echo JText::_( 'RESET' ); ?></button>
				</td>
			</tr>
		</table>
		<input type="hidden" name="option" value="<?php echo HIKASHOP_COMPONENT; ?>" />
		<input type="hidden" name="task" value="downloads" />
		<input type="hidden" name="ctrl" value="<?php echo JRequest::getCmd('ctrl'); ?>" />
		<input type="hidden" name="boxchecked" value="0" />
		<input type="hidden" name="filter_order" value="<?php echo $this->pageInfo->filter->order->value; ?>" />
		<input type="hidden" name="filter_order_Dir" value="<?php echo $this->pageInfo->filter->order->dir; ?>" />
		<?php echo JHTML::_( 'form.token' ); ?>
	</form>
	<fieldset>
		<table cellpadding="1" width="100%">
			<thead>
				<tr>
					<th class="hikashop_product_name title" align="center"><?php
						echo JHTML::_('grid.sort', JText::_('PRODUCT'), 'p.order_product_name', $this->pageInfo->filter->order->dir,$this->pageInfo->filter->order->value );
					?></th>
					<th class="hikashop_file_name title" align="center"><?php
						echo JHTML::_('grid.sort', JText::_('HIKA_FILES'), 'f.file_name', $this->pageInfo->filter->order->dir,$this->pageInfo->filter->order->value );
					?></th>
					<th class="hikashop_nb_download title" align="center"><?php
						echo JText::_('NB_DOWNLOADED');
					?></th>
					<th class="hikashop_download_limit title" align="center"><?php
						echo JHTML::_('grid.sort', JText::_('DOWNLOAD_NUMBER_LIMIT'), 'f.file_limit', $this->pageInfo->filter->order->dir,$this->pageInfo->filter->order->value );
					?></th>
					<th class="hikashop_order_date_title title" align="center"><?php
						echo JHTML::_('grid.sort', JText::_('FIRST_PURCHASED_AT'), 'min_order_created', $this->pageInfo->filter->order->dir,$this->pageInfo->filter->order->value );
					?></th>
					<th class="hikashop_order_date_title title" align="center"><?php
						echo JHTML::_('grid.sort', JText::_('LAST_PURCHASED_AT'), 'max_order_created', $this->pageInfo->filter->order->dir,$this->pageInfo->filter->order->value );
					?></th>
				</tr>
			</thead>
			<tbody>
<?php
	foreach($this->downloadData as $downloadFile) {
		$limit = -1;
		if($downloadFile->file_limit == 0)
			$limit = (int)$this->config->get('download_number_limit', 50) * $downloadFile->file_quantity;
		if($downloadFile->file_limit > 0)
			$limit = $downloadFile->file_limit * $downloadFile->file_quantity;
		$limitNotReached = true;
		$periodNotReached = true;
		if(!empty($downloadFile->file_limit) && !empty($downloadFile->download_total) && $downloadFile->file_limit != -1 && $downloadFile->file_limit == 0 && $downloadFile->download_total >= $downloadFile->file_limit ){
			$limitNotReached = false;
		}

		$order_id = 0;
		$order_date = 0;
		$single_limit = $downloadFile->file_limit;
		$class = hikashop_get('class.product');
		$productData = $class->get($p->product_id);
		if($single_limit == 0)
			$single_limit = (int)$this->config->get('download_number_limit', 50);
		if(!empty($downloadFile->orders)) {
			if($single_limit > 0){
				foreach($downloadFile->orders as $o) {
					if(
					 (empty($order_date) || $o->order_created < $order_date || (($this->download_time_limit + $o->order_created) >= time() &&  ($this->download_time_limit + $order_date) < time())) &&
					 (empty($o->file_qty) || ($o->download_total < ($single_limit * (int)$o->order_product_quantity)))
					) {
						$order_id = (int)$o->order_id;
						$order_date = (int)$o->order_created;
					}
				}
			}else{
				foreach($downloadFile->orders as $o) {
					if(($this->download_time_limit + $o->order_created) >= time() &&  ($this->download_time_limit + $order_date) < time()){
						$order_id = (int)$o->order_id;
						$order_date = (int)$o->order_created;
					}
				}
			}
		}
		if(empty($order_id))
			$order_id = $downloadFile->order_id;
		if(empty($order_date))
			$order_date = $downloadFile->order_created;

		if(!empty($this->download_time_limit) && ($this->download_time_limit + $order_date) < time()) {
			$fileHtml = JText::_('TOO_LATE_NO_DOWNLOAD');
			$periodNotReached = false;
		}
?>
					<tr>
						<td class="hikashop_order_item_name_value">
							<?php if(!empty($downloadFile->product_id)){ ?>
								<a class="hikashop_order_product_link" href="<?php echo hikashop_completeLink('product&task=show&cid='.$downloadFile->product_id.$url_itemid); ?>">
							<?php } ?>
							<p class="hikashop_order_product_name">
								<?php echo $downloadFile->order_product_name; ?> <?php echo $productData->product_fichierspayants; ?>
							</p>
							</a>
						</td>
						<td>
<?php
		if($limitNotReached && $periodNotReached) {
			if(empty($downloadFile->file_name)) {
				if(empty($downloadFile->file_path)) {
					$downloadFile->file_name = JText::_('DOWNLOAD_NOW');
				} else {
					$downloadFile->file_name = $downloadFile->file_path;
				}
			}
			$file_pos = '';
			if(!empty($downloadFile->file_pos)) {
				$file_pos = '&file_pos='.$downloadFile->file_pos;
			}

			if(in_array(substr($downloadFile->file_path, 0, 1), array('@', '#')) && (int)$downloadFile->file_quantity > 1) {
				for($i = 1; $i <= (int)$downloadFile->file_quantity; $i++) {
					echo '<a href="'.hikashop_completeLink('order&task=download&file_id='.$downloadFile->file_id.'&order_id='.$order_id.'&file_pos='.$i.$url_itemid).'">'.$downloadFile->file_name.'</a><br/>';
				}
				$fileHtml = '';
			} else {
				$fileHtml = '<a href="'.hikashop_completeLink('order&task=download&file_id='.$downloadFile->file_id.'&order_id='.$order_id.$file_pos.$url_itemid).'">'.$downloadFile->file_name.'</a>';
			}
		} else {
			$fileHtml = $downloadFile->file_name;
		}
		echo $fileHtml;
?>
						</td>
						<td><?php
		if(in_array(substr($downloadFile->file_path, 0, 1), array('@', '#')) && (int)$downloadFile->file_quantity > 1) {
			for($i = 1; $i <= (int)$downloadFile->file_quantity; $i++) {
				if(isset($downloadFile->downloads[$i])) {
					echo $downloadFile->downloads[$i]->download_number . '<br/>';
				} else {
					echo 0 . '<br/>';
				}
			}
		} else {
			if (!empty($downloadFile->download_total))
				echo $downloadFile->download_total;
			else
				echo 0;
		}
						?></td>
						<td>
<?php
		$downloadLimit = JText::_('UNLIMITED');
		if($limit == -1 && $limitNotReached && $periodNotReached) {
			$downloadLimit = JText::_('UNLIMITED');
		} elseif($limitNotReached && $periodNotReached) {
			if(in_array(substr($downloadFile->file_path, 0, 1), array('@', '#')) && (int)$downloadFile->file_quantity > 1) {
				$downloadLimit = '';
				for($i = 1; $i <= (int)$downloadFile->file_quantity; $i++) {
					if(isset($downloadFile->downloads[$i])) {
						echo JText::sprintf('X_DOWNLOADS_LEFT', $single_limit - $downloadFile->downloads[$i]->download_number) . '<br/>';
					} else {
						$downloadLimit .= JText::sprintf('X_DOWNLOADS_LEFT', $single_limit) . '<br/>';
					}
				}
			} else {
				$downloadLimit = JText::sprintf('X_DOWNLOADS_LEFT',$limit-$downloadFile->download_total);
			}
		} elseif(!$periodNotReached) {
			$downloadLimit = JText::_('TOO_LATE_NO_DOWNLOAD');
		} elseif(!$limitNotReached) {
			$downloadLimit = JText::_('MAX_REACHED_NO_DOWNLOAD');
		}
		echo $downloadLimit;
?>
						</td>
						<td><?php
							echo date('d/m/Y', $downloadFile->min_order_created);
						?></td>
						<td><?php
							echo date('d/m/Y', $downloadFile->max_order_created);
						?></td>
					</tr>
<?php
	}
?>
			</tbody>
			<tfoot>
				<tr>
					<td colspan="10">
						<div class="pagination">
							<form action="<?php echo hikashop_completeLink('user&task=downloads'.$url_itemid); ?>" method="post" name="adminForm_bottom">
								<?php $this->pagination->form = '_bottom'; echo $this->pagination->getListFooter(); ?>
								<?php echo $this->pagination->getResultsCounter(); ?>
								<input type="hidden" name="option" value="<?php echo HIKASHOP_COMPONENT; ?>" />
								<input type="hidden" name="task" value="downloads" />
								<input type="hidden" name="ctrl" value="<?php echo JRequest::getCmd('ctrl'); ?>" />
								<input type="hidden" name="filter_order" value="<?php echo $this->pageInfo->filter->order->value; ?>" />
								<input type="hidden" name="filter_order_Dir" value="<?php echo $this->pageInfo->filter->order->dir; ?>" />
								<?php echo JHTML::_( 'form.token' ); ?>
							</form>
						</div>
					</td>
				</tr>
			</tfoot>
		</table>
	</fieldset>
<?php
	}
?>
</div>

Cordialement, Nossibé

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

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
9 years 10 months ago #160584

Bonjour,

Ces erreurs n'ont rien à voir avec class.product.
Elles signifie que la variable $p n'existe pas.
Mon code suppose que la variable $p contient les infos du produit dans la commande. Je vous ai donné un exemple à adapter à vos besoins, pas la solution finale à copier/coller.
Je me suis basé sur votre code de ce post:
www.hikashop.com/forum/5-support-en-fran...fichiers.html#158830
Ce code contient bien la variable $p et donc c'est là ou vous utilisez $p dans votre code pour qu'au lieu de chercher la valeur du champs dans le produit de la commande, vous le cherchiez dans les infos principales du produit.
En clair, il faut mettre mon cote à la place de la ligne:
$nbr_payant = $p->product_fichierspayants;

Et bien sûr, au lieu de mon code:
echo $productData->product_fichierspayants;
vous voulez:
$nbr_payant = $productData->product_fichierspayants;

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

  • Posts: 163
  • Thank you received: 11
9 years 10 months ago #160704

Génial !!!

Merci pour votre patience !!!

Cordialement, Nossibé :)

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

Time to create page: 0.131 seconds
Powered by Kunena Forum