Écrit par : mihelicjm 9 Oct 2016, 01:31
Bonjour,
Je pense avoir peut-être compris ce que voulais supposer "SurMonVentre" à l'époque pour vouloir moi-même actuellement faire en sorte que les avis soient indépendants des fiches produits. J'envisage par exemple, suite à un achat, de suggérer au client de mettre une note sur les produits reçus où les avis seraient indépendants des fiches produits puisque liés alors au suivi de "l'après commande". De ce que j'ai pu constater pour l'instant on ne peut noter un produit que par product_reviews_write.php - donc par la fiche produit - ce qui implique plusieurs manipes en l'occurrence pour le client qui voudrait noter plusieurs produits reçus. Faîtes le test sur 5 à 7 produits déjà pour voir comme c'est fastidieux...
Je propose de partager ce que j'ai commencé à mettre en place sur une version OsCommerce 2.3.4.
J' ai dupliqué product_reviews_write.php que j'ai nommé product_reviews_write_order.php au contenu modifié de la façon suivante:
CODE
<?php
/*
$Id$
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright © 2012 osCommerce
Released under the GNU General Public License
*/
require('includes/application_top.php');
if (!tep_session_is_registered('customer_id')) {
$navigation->set_snapshot();
tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
}
$customer_query = tep_db_query("select c.customers_firstname, c.customers_lastname, ab.entry_city from " . TABLE_ADDRESS_BOOK . " ab, " . TABLE_CUSTOMERS . " c where ab.customers_id = '" . (int)$customer_id . "' and c.customers_id = '" . (int)$customer_id . "'");
$customer = tep_db_fetch_array($customer_query);
if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'process') && isset($HTTP_POST_VARS['formid']) && ($HTTP_POST_VARS['formid'] == $sessiontoken)) {
$rating = tep_db_prepare_input($HTTP_POST_VARS['rating']);
$review = tep_db_prepare_input($HTTP_POST_VARS['review']);
$error = false;
if (strlen($review) < REVIEW_TEXT_MIN_LENGTH) {
$error = true;
$messageStack->add('review', JS_REVIEW_TEXT);
}
if (($rating < 1) || ($rating > 5)) {
$error = true;
$messageStack->add('review', JS_REVIEW_RATING);
}
if ($error == false) {
tep_db_query("insert into " . TABLE_REVIEWS . " (products_id, customers_id, customers_name, reviews_rating, date_added) values ('" . (int)$HTTP_GET_VARS['products_id'] . "', '" . (int)$customer_id . "', '" . tep_db_input($customer['customers_firstname']) . ' ' . tep_db_input($customer['customers_lastname']) . "', '" . tep_db_input($rating) . "', now())");
tep_db_input(ucfirst(strtolower($customer['customers_firstname']))) . ' ' .
tep_db_input(strtoupper(substr($customer['customers_lastname'], 0, 1))) . '. de ' .
tep_db_input(ucfirst(strtolower($customer['entry_city'])) . "', '" . tep_db_input($rating) . "', now())");
$insert_id = tep_db_insert_id();
tep_db_query("insert into " . TABLE_REVIEWS_DESCRIPTION . " (reviews_id, languages_id, reviews_text) values ('" . (int)$insert_id . "', '" . (int)$languages_id . "', '" . tep_db_input($review) . "')");
if ((USE_POINTS_SYSTEM == 'true') && (tep_not_null(USE_POINTS_FOR_REVIEWS))) {
$points_toadd = USE_POINTS_FOR_REVIEWS;
$comment = 'TEXT_DEFAULT_REVIEWS';
$points_type = 'RV';
tep_add_pending_points($customer_id, $product_info['products_id'], $points_toadd, $comment, $points_type);
}
$messageStack->add_session('product_reviews', TEXT_REVIEW_RECEIVED, 'success');
tep_redirect(tep_href_link(FILENAME_PRODUCT_REVIEWS, tep_get_all_get_params(array('action'))));
}
}
if (!isset($HTTP_GET_VARS['order_id']) || (isset($HTTP_GET_VARS['order_id']) && !is_numeric($HTTP_GET_VARS['order_id']))) {
tep_redirect(tep_href_link('product_reviews_whrite_order.php', 'order_id=' . $HTTP_GET_VARS['order_id'], 'SSL'));
}
$customer_info_query = tep_db_query("select o.customers_id from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_STATUS . " s where o.orders_id = '". (int)$HTTP_GET_VARS['order_id'] . "' and o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and s.public_flag = '1'");
$customer_info = tep_db_fetch_array($customer_info_query);
require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_PRODUCT_REVIEWS_WRITE_ORDER);
$breadcrumb->add('Mon compte', tep_href_link(FILENAME_ACCOUNT, '', 'SSL'));
$breadcrumb->add('Historique des commandes', tep_href_link(FILENAME_ACCOUNT_HISTORY, '', 'SSL'));
$breadcrumb->add(sprintf('Noter les produits reçus', $HTTP_GET_VARS['order_id']), tep_href_link(FILENAME_PRODUCT_REVIEWS_WRITE_ORDER, 'order_id=' . $HTTP_GET_VARS['order_id'], 'SSL'));
require(DIR_WS_CLASSES . 'order.php');
$order = new order($HTTP_GET_VARS['order_id']);
require(DIR_WS_INCLUDES . 'template_top.php');
?>
<script type="text/javascript"><!--
function checkForm() {
var error = 0;
var error_message = "<?php echo JS_ERROR; ?>";
var review = document.product_reviews_write_order.review.value;
if (review.length < <?php echo REVIEW_TEXT_MIN_LENGTH; ?>) {
error_message = error_message + "<?php echo JS_REVIEW_TEXT; ?>";
error = 1;
}
if ((document.product_reviews_write_order.rating[0].checked) || (document.product_reviews_write_order.rating[1].checked) || (document.product_reviews_write_order.rating[2].checked) || (document.product_reviews_write_order.rating[3].checked) || (document.product_reviews_write_order.rating[4].checked)) {
} else {
error_message = error_message + "<?php echo JS_REVIEW_RATING; ?>";
error = 1;
}
if (error == 1) {
alert(error_message);
return false;
} else {
return true;
}
}
//--></script>
<?php
for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
$products_name = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $order->products[$i]['id']) . '">'.$order->products[$i]['name'].'</a><br>'.$order->products[$i]['qty'] . ' pièce(s)';
$products_id = $order->products[$i]['id'];
$prodimage_query = tep_db_query("select products_image from " . TABLE_PRODUCTS . " where products_id = '" . (int)$order->products[$i]['id'] . "'");
$prodimage = tep_db_fetch_array($prodimage_query);
$products_image = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_id) . '">' . tep_image(DIR_WS_CATALOG_IMAGES . $prodimage['products_image'], $order->products[$i]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"'). '</a>';
if (sizeof($order->info['tax_groups']) > 1) {
echo ' ' . tep_display_tax_value($order->products[$i]['tax']) . '%' . "\n";
}
$products_price = $currencies->format(tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']) * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']);
}
?>
<div id="reviewsWrite" class="contentContainer">
<div class="productinfo-leftwrapper">
<div class="review_writeimage">
<div class="productMainImage">
<?php echo $products_image;?>
</div>
</div>
</div>
<div class="productinfo-rightwrapper">
<div class="product_title">
<h3><?php echo $products_name; ?></h3>
</div>
<div class="review_details">
<div class="product_price">
<div class="price_amount" style="display:inline-block">
<span class="price_amount">
<?php echo $products_price; ?>
</span>
</div>
</div>
<?php if (tep_not_null($product_info['products_image'])) { ?>
<div class="cart_button"><?php echo tep_draw_button(IMAGE_BUTTON_IN_CART, 'cart', tep_href_link(basename($PHP_SELF),
tep_get_all_get_params(array('action')) . 'action=buy_now')); ?>
</div>
<?php } ?>
</div>
<?php
if ($messageStack->size('review') > 0) {
echo $messageStack->output('review');
}
?>
<?php echo tep_draw_form('product_reviews_write_order', tep_href_link(FILENAME_PRODUCT_REVIEWS_WRITE_ORDER, 'action=process&products_id=' . $products_id),
'post', 'onsubmit="return checkForm();"', true); ?>
<div class="review_from">
<span class="bold">
<?php echo SUB_TITLE_WRITTEN; ?>
<span class="user_name">
<?php echo tep_output_string_protected(ucfirst(strtolower($customer['customers_firstname'] . ' ' . (strtoupper(substr($customer['customers_lastname'], 0, 1))))) . '. de ' . (strtoupper($customer['entry_city']))); ?>
</span>
</span>
</div>
<div class="review_text_ratting">
<?php echo "Choisissez une note pour cet article."; ?>
</div>
<div class="review_rating">
<label class="ratting_review"><?php echo tep_draw_radio_field('rating', '1'); ?><?php echo tep_image(DIR_WS_IMAGES.'stars_1_small.gif')?></label>
<label class="ratting_review"><?php echo tep_draw_radio_field('rating', '2'); ?><?php echo tep_image(DIR_WS_IMAGES.'stars_2_small.gif')?></label>
<label class="ratting_review"><?php echo tep_draw_radio_field('rating', '3'); ?><?php echo tep_image(DIR_WS_IMAGES.'stars_3_small.gif')?></label>
<label class="ratting_review"><?php echo tep_draw_radio_field('rating', '4'); ?><?php echo tep_image(DIR_WS_IMAGES.'stars_4_small.gif')?></label>
<label class="ratting_review"><?php echo tep_draw_radio_field('rating', '5'); ?><?php echo tep_image(DIR_WS_IMAGES.'stars_5_small.gif')?></label>
</div>
</div>
<div class="content_box">
<div class="review_textarea">
<span class="review_title_text">
<?php echo SUB_TITLE_REVIEW_TEXT; ?>
</span>
<?php echo tep_draw_textarea_field('review', 'soft', 55, 5, NULL, 'required aria-required="true"'); ?>
</div>
<div class="buttonSet">
<span class="button"><?php echo tep_draw_button(IMAGE_BUTTON_BACK, 'triangle-1-w', tep_href_link(FILENAME_ACCOUNT_HISTORY, tep_get_all_get_params(array('reviews_id', 'action')))); ?></span>
<span class="buttonAction" style="margin-right:10px"><?php echo tep_draw_button(IMAGE_BUTTON_CONTINUE, 'triangle-1-e', null, 'primary'); ?></span>
</div>
</div>
</form>
</div>
<?php
require(DIR_WS_INCLUDES . 'template_bottom.php');
require(DIR_WS_INCLUDES . 'application_bottom.php');
?>
Idem dans includes/language/french/product_reviews_write_order.php au contenu suivant:
CODE
<?php
/*
$Id$
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright © 2012 osCommerce
Released under the GNU General Public License
*/
define('NAVBAR_TITLE', 'Avis des clients');
define('SUB_TITLE_FROM', 'De :');
define('SUB_TITLE_REVIEW', 'Votre avis :');
define('SUB_TITLE_RATING', 'Classement :');
define('TEXT_NO_HTML', '<small><font color="#ff0000"><strong>REMARQUE :</strong></font></small> Le code HTML n\'est pas pris en compte !');
define('TEXT_BAD', '<small><font color="#ff0000"><strong>MAUVAIS</strong></font></small>');
define('TEXT_GOOD', '<small><font color="#ff0000"><strong>BON</strong></font></small>');
define('TEXT_CLICK_TO_ENLARGE', 'Cliquez pour agrandir');
//define('TEXT_REVIEW_RECEIVED', 'Merci d\'avoir donné votre avis. Il a été soumis pour être publié prochainement.');
define('SUB_TITLE_REVIEW_TEXT','Veuillez transcrire ce que vous pensez même brièvement et partagez vos opinions avec d\'autres. Assurez-vous de concentrer vos commentaires sur le produit.');
define('SUB_TITLE_WRITTEN', 'Rédigé par:');
?>
Dans includes/filenames.php l'ajout suivant:
CODE
define('FILENAME_PRODUCT_REVIEWS_WRITE_ORDER', 'product_reviews_write_order.php');
Dans account_history.php apparition d'un bouton là où on veut qu'il soit dès que la commande est envoyée:
CODE
<?php
if ($history['orders_status_id'] == 3) {
?>
<div class="content_box">
<span class="title"><?php echo 'Ma Note pour les produits de la commande #' . $history['orders_id']; ?>
</span>
<table border="0" width="100%" cellspacing="2" cellpadding="2">
<tr>
<td width="50%" valign="top"></td>
<td width="30%" valign="top"></td>
<td width="20%" align="right"><?php echo tep_draw_button('Donner une note', 'document', tep_href_link(FILENAME_PRODUCT_REVIEWS_WRITE_ORDER, (isset($HTTP_GET_VARS['page']) ? 'page=' . $HTTP_GET_VARS['page'] . '&' : '') . 'order_id=' . $history['orders_id'], 'SSL'), 'primary'); ?></td>
</tr>
</table>
</div>
<?php } ?>
A ce stade le fonctionnement est bon mais pour un seul produit commandé. Pour une commande qui comporterait plusieurs produits commandés le fichier product_reviews_write_order.php est à optimiser... mais je cale.
Si quelqu'un peut m'aider???
J'ai fait une tentative dans cette direction sinon:
CODE
<?php
/*
$Id$
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright © 2012 osCommerce
Released under the GNU General Public License
*/
require('includes/application_top.php');
if (!tep_session_is_registered('customer_id')) {
$navigation->set_snapshot();
tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
}
$customer_query = tep_db_query("select c.customers_firstname, c.customers_lastname, ab.entry_city from " . TABLE_ADDRESS_BOOK . " ab, " . TABLE_CUSTOMERS . " c where ab.customers_id = '" . (int)$customer_id . "' and c.customers_id = '" . (int)$customer_id . "'");
$customer = tep_db_fetch_array($customer_query);
if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'process') && isset($HTTP_POST_VARS['formid']) && ($HTTP_POST_VARS['formid'] == $sessiontoken)) {
$rating = tep_db_prepare_input($HTTP_POST_VARS['rating']);
$review = tep_db_prepare_input($HTTP_POST_VARS['review']);
$error = false;
if (strlen($review) < REVIEW_TEXT_MIN_LENGTH) {
$error = true;
$messageStack->add('review', JS_REVIEW_TEXT);
}
if (($rating < 1) || ($rating > 5)) {
$error = true;
$messageStack->add('review', JS_REVIEW_RATING);
}
if ($error == false) {
tep_db_query("insert into " . TABLE_REVIEWS . " (products_id, customers_id, customers_name, reviews_rating, date_added) values ('" . (int)$HTTP_GET_VARS['products_id'] . "', '" . (int)$customer_id . "', '" . tep_db_input($customer['customers_firstname']) . ' ' . tep_db_input($customer['customers_lastname']) . "', '" . tep_db_input($rating) . "', now())");
tep_db_input(ucfirst(strtolower($customer['customers_firstname']))) . ' ' .
tep_db_input(strtoupper(substr($customer['customers_lastname'], 0, 1))) . '. de ' .
tep_db_input(ucfirst(strtolower($customer['entry_city'])) . "', '" . tep_db_input($rating) . "', now())");
$insert_id = tep_db_insert_id();
tep_db_query("insert into " . TABLE_REVIEWS_DESCRIPTION . " (reviews_id, languages_id, reviews_text) values ('" . (int)$insert_id . "', '" . (int)$languages_id . "', '" . tep_db_input($review) . "')");
if ((USE_POINTS_SYSTEM == 'true') && (tep_not_null(USE_POINTS_FOR_REVIEWS))) {
$points_toadd = USE_POINTS_FOR_REVIEWS;
$comment = 'TEXT_DEFAULT_REVIEWS';
$points_type = 'RV';
tep_add_pending_points($customer_id, $product_info['products_id'], $points_toadd, $comment, $points_type);
}
$messageStack->add_session('product_reviews', TEXT_REVIEW_RECEIVED, 'success');
tep_redirect(tep_href_link(FILENAME_PRODUCT_REVIEWS, tep_get_all_get_params(array('action'))));
}
}
if (!isset($HTTP_GET_VARS['order_id']) || (isset($HTTP_GET_VARS['order_id']) && !is_numeric($HTTP_GET_VARS['order_id']))) {
tep_redirect(tep_href_link('product_reviews_whrite_order.php', 'order_id=' . $HTTP_GET_VARS['order_id'], 'SSL'));
}
$customer_info_query = tep_db_query("select o.customers_id from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_STATUS . " s where o.orders_id = '". (int)$HTTP_GET_VARS['order_id'] . "' and o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and s.public_flag = '1'");
$customer_info = tep_db_fetch_array($customer_info_query);
require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_PRODUCT_REVIEWS_WRITE_ORDER);
$breadcrumb->add('Mon compte', tep_href_link(FILENAME_ACCOUNT, '', 'SSL'));
$breadcrumb->add('Historique des commandes', tep_href_link(FILENAME_ACCOUNT_HISTORY, '', 'SSL'));
$breadcrumb->add(sprintf('Noter les produits reçus', $HTTP_GET_VARS['order_id']), tep_href_link(FILENAME_PRODUCT_REVIEWS_WRITE_ORDER, 'order_id=' . $HTTP_GET_VARS['order_id'], 'SSL'));
require(DIR_WS_CLASSES . 'order.php');
$order = new order($HTTP_GET_VARS['order_id']);
require(DIR_WS_INCLUDES . 'template_top.php');
?>
<script type="text/javascript"><!--
function checkForm() {
var error = 0;
var error_message = "<?php echo JS_ERROR; ?>";
var review = document.product_reviews_write_order.review.value;
if (review.length < <?php echo REVIEW_TEXT_MIN_LENGTH; ?>) {
error_message = error_message + "<?php echo JS_REVIEW_TEXT; ?>";
error = 1;
}
if ((document.product_reviews_write_order.rating[0].checked) || (document.product_reviews_write_order.rating[1].checked) || (document.product_reviews_write_order.rating[2].checked) || (document.product_reviews_write_order.rating[3].checked) || (document.product_reviews_write_order.rating[4].checked)) {
} else {
error_message = error_message + "<?php echo JS_REVIEW_RATING; ?>";
error = 1;
}
if (error == 1) {
alert(error_message);
return false;
} else {
return true;
}
}
//--></script>
<div id="reviewsWrite" class="contentContainer">
<?php
for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
$products_name = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $order->products[$i]['id']) . '">'.$order->products[$i]['name'].'</a><br>'.$order->products[$i]['qty'] . ' pièce(s)';
$products_id = $order->products[$i]['id'];
$prodimage_query = tep_db_query("select products_image from " . TABLE_PRODUCTS . " where products_id = '" . (int)$order->products[$i]['id'] . "'");
$prodimage = tep_db_fetch_array($prodimage_query);
$products_image = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_id) . '">' . tep_image(DIR_WS_CATALOG_IMAGES . $prodimage['products_image'], $order->products[$i]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"'). '</a>';
echo ' <div class="productinfo-leftwrapper"><div class="review_writeimage"><div class="productMainImage">
<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $order->products[$i]['id']) . '">' . tep_image(DIR_WS_CATALOG_IMAGES . $prodimage['products_image'], $order->products[$i]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"'). '</a>
</div></div></div><div class="productinfo-rightwrapper"><div class="product_title">' . $order->products[$i]['name'];
echo '</div><div class="review_details"><div class="product_price"><div class="price_amount" style="display:inline-block"><span class="price_amount">'.$currencies->format(tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']) * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']).'</span></div></div>
</div>
<div class="review_from"><span class="bold">'.SUB_TITLE_WRITTEN.'<span class="user_name">'.tep_output_string_protected(ucfirst(strtolower($customer['customers_firstname'] . ' ' . (strtoupper(substr($customer['customers_lastname'], 0, 1))))) . '. de ' . (strtoupper($customer['entry_city']))).'</span></span></div>
<div class="review_text_ratting">
Choisissez une note pour cet article.
</div>
<div class="review_rating">
<label class="ratting_review">'. tep_draw_radio_field('rating', '1') . ''. tep_image(DIR_WS_IMAGES.'stars_1_small.gif') . '</label>
<label class="ratting_review">'. tep_draw_radio_field('rating', '2') . ''. tep_image(DIR_WS_IMAGES.'stars_2_small.gif') . '</label>
<label class="ratting_review">'. tep_draw_radio_field('rating', '3') . ''. tep_image(DIR_WS_IMAGES.'stars_3_small.gif') . '</label>
<label class="ratting_review">'. tep_draw_radio_field('rating', '4') . ''. tep_image(DIR_WS_IMAGES.'stars_4_small.gif') . '</label>
<label class="ratting_review">'. tep_draw_radio_field('rating', '5') . ''. tep_image(DIR_WS_IMAGES.'stars_5_small.gif') . '</label>
</div>
</div>
<div class="content_box">
<div class="review_textarea">
<span class="review_title_text">
'.SUB_TITLE_REVIEW_TEXT.'
</span>
'.tep_draw_textarea_field('review', 'soft', 55, 5, NULL, 'required aria-required="true"').'
</div>
' . "\n";
echo '</div>' . "\n";
}
?>
<?php
if ($messageStack->size('review') > 0) {
echo $messageStack->output('review');
}
?>
<?php echo tep_draw_form('product_reviews_write_order', tep_href_link(FILENAME_PRODUCT_REVIEWS_WRITE_ORDER, 'action=process&products_id=' . $products_id),
'post', 'onsubmit="return checkForm();"', true); ?>
<div class="buttonSet">
<span class="button"><?php echo tep_draw_button(IMAGE_BUTTON_BACK, 'triangle-1-w', tep_href_link(FILENAME_ACCOUNT_HISTORY, tep_get_all_get_params(array('reviews_id', 'action')))); ?></span>
<span class="buttonAction" style="margin-right:10px"><?php echo tep_draw_button(IMAGE_BUTTON_CONTINUE, 'triangle-1-e', null, 'primary'); ?></span>
</div>
</form>
</div>
<?php
require(DIR_WS_INCLUDES . 'template_bottom.php');
require(DIR_WS_INCLUDES . 'application_bottom.php');
?>
Là une page s'affiche avec l'image de chaque produit, à coté de chacune le prix, la zone de commentaire... en bas le bouton retour + continuer... tout se présente presque bien sauf qu'on ne peut noter qu'un seul produit mais aussi que l'envoi du formulaire échoue sur un "ERR_TOO_MANY_REDIRECTS" (à cause de echo tep_draw_form qui est mal placé je pense).