Aller au contenu

codage requete PHP pour boutique osc


loulou74

Sujets conseillés

Bonjour à tous,

J'espère être au bon endroit dans le forum pour poster ce message.

Je travaille actuellement sur une boutique de vente de séjours osc avec paiement par CB. 3 types de paiement sont possibles: en 1 fois, 2 fois, 3 fois.

Le paiement en 1 fois est toujours possible, en 2 fois si l'achat du séjour est fait de 30 à 60 jours avant, en 3 fois si l'achat a lieu 60+ jours avant.

Le client choisit sa date comme une option dans un menu déroulant.

Les options sont présentes en format DATE en tant que products_options_values_name dans la TABLE_PRODUCTS_OPTIONS_VALUES.

La date choisie par le client est reprise dans son panier par ce code (si j'ai bien compris):

if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) {
reset($products[$i]['attributes']);
while (list($option, $value) = each($products[$i]['attributes'])) {
$products_name .= '<br><small><i> - ' . $products[$i][$option]['products_options_name'] . ' ' . $products[$i][$option]['products_options_values_name'] . '</i></small>';
}
}

J'ai besoin de connaitre le nombre de jours entre la date d'achat (=aujourd'hui) et la date de début de séjour choisie par le client et je ne sais pas comment coder ça, en particulier comment aller chercher puis transformer la date choisie en variable.

J'ai fait plein d'essais de code mais ils ne marchent pas, par exemple ça:

// Paiement pour séjour réservé 60 jours ou plus à l'avance
$timestamp = mktime();
$timestamp2 = $order->info['products_options_values_name'];
// différence
$diff = $timestamp2 - $timestamp;
$ecart_jours = floor($diff /86400);

if ($ecart_jours > 59) {
$this->enabled = MODULE_PAYMENT_ATOS3FOIS_STATUS == 'True' ? true : false;;
}

Je fais cette boutique pour aider quelqu'un, mais je ne suis pas développeur pro, alors votre aide est vraiment bienvenue, je galère carrément là... :wacko:

Merci!

Lien vers le commentaire
Partager sur d’autres sites

Salut ;)

Une fonction :

function JourDiff($date) {

$tDeb = explode("-", $date);
$tFin = explode("-", date("Y-m-d"));

$diff = mktime(0, 0, 0, $tFin[1], $tFin[2], $tFin[0]) -
mktime(0, 0, 0, $tDeb[1], $tDeb[2], $tDeb[0]);

return(($diff / 86400));

}

Cependant, je lui préfère celle-là, en récursif (même si je sais pas combien elle demande en temps de calcul) :

// Renvoie le nombre de jours entre deux dates..
function nb_jours($datej, $compt=0)
{
if ($datej == date("Y-m-d")) RETURN $compt;
ELSE RETURN nb_jours(date("Y-m-d", strtotime("$datej + 1 day")), $compt+1);
}

Pour les deux fonctions, tu dois donner une date de la forme AAAA-MM-JJ...

Voili voilà ;)

Lien vers le commentaire
Partager sur d’autres sites

Salut Sarc,

et merci pour ta réponse!

La variable $timestamp c'est la date d'achat de mon client, donc toujours la date d'aujourd'hui par définition, c'est pour ça que j'ai utilisé mktime() pour cette variable

Je pense que la logique de calcul de jours est bonne, mais à mon avis c'est la définition de ma variable $timestamp2 qui met le souk, je pense que je ne vais pas correctement la chercher

Pour le format, comme je suis en format DATE sous MySql, a priori le format AAAA-MM-JJ est respecté si je ne me trompe pas.

Qu'en penses tu? tu pourrais éventuellement m'aider à définir cette variable $timestamp2 stp?

Merci beaucoup pour ton coup de pouce! :)

Modifié par loulou74
Lien vers le commentaire
Partager sur d’autres sites

Ah, j'avais mal lu le bout de code que tu avais donné.. Je sais pas si tu as choisi le bon pour le choix de la date !

Essaye d'afficher ce que te renvoie $timestamp2... Et puis sinon, essaye d'afficher le contenu du tableau $order->info. C'est pas facile avec le petit bout de code qu'on a là de voir où est la date... ;)

Lien vers le commentaire
Partager sur d’autres sites

C'est sur...

Je te donne le source de shopping_cart.php, excuse moi il est un peu long...mais je pense que ça te permet de tout voir.

3 tables sont utilisées pour less options par cette page:

La table qui contient la valeur des options s'appelle:

TABLE_PRODUCTS_OPTIONS_VALUES

et comporte les colonnes:

products_options_values_id language_id products_options_values_name

C'est dans cette dernière colonne que sont reprises toutes les dates de tous les séjours

Textes complets products_options_values_id language_id products_options_values_name

Modifier Effacer 1 2 2008-01-08

Modifier Effacer 2 2 2008-01-15

Modifier Effacer 3 2 2008-01-23

Modifier Effacer 4 2 2007-12-23

Modifier Effacer 5 2 2007-07-25

Modifier Effacer 6 2 2007-08-20

TABLE_PRODUCTS_OPTIONS

comporte les colonnes:

products_options_id language_id products_options_name

Ici, une seule option id=1, un seul langage=2 et donc un seul nom d'option: Dates

TABLE_PRODUCTS_ATTRIBUTES

comporte les colonnes:

Textes complets products_attributes_id products_id options_id options_values_id options_values_price price_prefix

Modifier Effacer 181 39 1 3 0.0000 +

Modifier Effacer 182 39 1 1 0.0000 +

Modifier Effacer 183 39 1 2 0.0000 +

Modifier Effacer 184 36 1 3 0.0000 +

donc là on voit que le produit à l'id 39 présente 3 choix de dates possibles pour le début du sejour.

Si options_values_id N°3 est le 22 juin 2008, cette date de début de séjour est possible pour le sejour 39 et pour le sejour 36.

Voilà, qu'est ce que je pourrais te donner pour etre plus complet...?

un sincère merci pour ton aide dans ma requete.

SOURCE SHOPPING CART

<?php
/*
$Id: shopping_cart.php,v 1.73 2003/06/09 23:03:56 hpdl Exp $

osCommerce, Open Source E-Commerce Solutions
[url="http://www.oscommerce.com"]http://www.oscommerce.com[/url]

Copyright © 2003 osCommerce

Released under the GNU General Public License
*/

require("includes/application_top.php");

require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SHOPPING_CART);

$breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_SHOPPING_CART));
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><?php echo TITLE; ?></title>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<style type="text/css">
<!--

-->
</style></head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<div align="center">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
</div>
<table width="925" border="0" align="center" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF" class="bordertableau">
<tr>
<td width="<?php echo BOX_WIDTH; ?>" valign="top" class="backgroundmenu"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
</table></td>
<!-- body_text //-->
<td width="100%" valign="top"><?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_SHOPPING_CART, 'action=update_product')); ?><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
<td class="pageHeading" align="right"></td>
</tr>
</table></td>
</tr>
<tr>
<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>
<?php
if ($cart->count_contents() > 0) {
?>
<tr>
<td>
<?php
$info_box_contents = array();
$info_box_contents[0][] = array('align' => 'center',
'params' => 'class="productListing-heading"',
'text' => TABLE_HEADING_REMOVE);

$info_box_contents[0][] = array('params' => 'class="productListing-heading"',
'text' => TABLE_HEADING_PRODUCTS);

$info_box_contents[0][] = array('align' => 'center',
'params' => 'class="productListing-heading"',
'text' => TABLE_HEADING_QUANTITY);

$info_box_contents[0][] = array('align' => 'right',
'params' => 'class="productListing-heading"',
'text' => TABLE_HEADING_TOTAL);

$any_out_of_stock = 0;
$products = $cart->get_products();
for ($i=0, $n=sizeof($products); $i<$n; $i++) {
// Push all attributes information in an array
if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) {
while (list($option, $value) = each($products[$i]['attributes'])) {
echo tep_draw_hidden_field('id[' . $products[$i]['id'] . '][' . $option . ']', $value);
$attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix
from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa
where pa.products_id = '" . (int)$products[$i]['id'] . "'
and pa.options_id = '" . (int)$option . "'
and pa.options_id = popt.products_options_id
and pa.options_values_id = '" . (int)$value . "'
and pa.options_values_id = poval.products_options_values_id
and popt.language_id = '" . (int)$languages_id . "'
and poval.language_id = '" . (int)$languages_id . "'");
$attributes_values = tep_db_fetch_array($attributes);

$products[$i][$option]['products_options_name'] = $attributes_values['products_options_name'];
$products[$i][$option]['options_values_id'] = $value;
$products[$i][$option]['products_options_values_name'] = $attributes_values['products_options_values_name'];
$products[$i][$option]['options_values_price'] = $attributes_values['options_values_price'];
$products[$i][$option]['price_prefix'] = $attributes_values['price_prefix'];
}
}
}

for ($i=0, $n=sizeof($products); $i<$n; $i++) {
if (($i/2) == floor($i/2)) {
$info_box_contents[] = array('params' => 'class="productListing-even"');
} else {
$info_box_contents[] = array('params' => 'class="productListing-odd"');
}

$cur_row = sizeof($info_box_contents) - 1;

$info_box_contents[$cur_row][] = array('align' => 'center',
'params' => 'class="productListing-data" valign="top"',
'text' => tep_draw_checkbox_field('cart_delete[]', $products[$i]['id'],'','class="input_2"'));

$products_name = '<table border="0" cellspacing="2" cellpadding="2">' .
' <tr>' .
' <td class="img" align="center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products[$i]['id']) . '">' . tep_image(DIR_WS_IMAGES . $products[$i]['image'], $products[$i]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></td>' .
' <td class="productListing-data" valign="top"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products[$i]['id']) . '"><b>' . $products[$i]['name'] . '</b></a>';

if (STOCK_CHECK == 'true') {
$stock_check = tep_check_stock($products[$i]['id'], $products[$i]['quantity']);
if (tep_not_null($stock_check)) {
$any_out_of_stock = 1;

$products_name .= $stock_check;
}
}

if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) {
reset($products[$i]['attributes']);
while (list($option, $value) = each($products[$i]['attributes'])) {
$products_name .= '<br><small><i> - ' . $products[$i][$option]['products_options_name'] . ' ' . $products[$i][$option]['products_options_values_name'] . '</i></small>';
}
}

$products_name .= ' </td>' .
' </tr>' .
'</table>';

$info_box_contents[$cur_row][] = array('params' => 'class="productListing-data"',
'text' => $products_name);

$info_box_contents[$cur_row][] = array('align' => 'center',
'params' => 'class="productListing-data" valign="top"',
'text' => tep_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4"') . tep_draw_hidden_field('products_id[]', $products[$i]['id']));

$info_box_contents[$cur_row][] = array('align' => 'right',
'params' => 'class="productListing-data" valign="top"',
'text' => '<b>' . $currencies->display_price($products[$i]['final_price'], tep_get_tax_rate($products[$i]['tax_class_id']), $products[$i]['quantity']) . '</b>');
}
?>
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="TEXTAREA"><!--OU BORDERTABLEAU -->
<tr><td>
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="height:44px;" class="table_3_1">
<tr>
<td width="80" align="center" style=" vertical-align:middle; " height="44"><i><?=TABLE_HEADING_REMOVE?></i></td>
<td width="249" align="center" style=" vertical-align:middle; "><i><?=TABLE_HEADING_PRODUCTS?></i></td>
<td width="71" align="center" style=" vertical-align:middle; "><i><?=TABLE_HEADING_QUANTITY?></i></td>
<td width="89" align="center" style=" vertical-align:middle; "><i><?=TABLE_HEADING_TOTAL?></i></td>
</tr>
<tr>
<td style="background-color:#ffffff;"><?php echo tep_draw_separator('spacer.gif', '1', '1'); ?></td>
<td style="background-color:#ffffff;"><?php echo tep_draw_separator('spacer.gif', '1', '1'); ?></td>
<td style="background-color:#ffffff;"><?php echo tep_draw_separator('spacer.gif', '1', '1'); ?></td>
<td style="background-color:#ffffff;"><?php echo tep_draw_separator('spacer.gif', '1', '1'); ?></td>
</tr>
<?

for ($i=1;$i<count($info_box_contents);$i++) {
$rowline=$info_box_contents[$i];
$product_query = tep_db_query("select products_description from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$products[$i-1]['id'] . "' and language_id = '" . (int)$languages_id . "'");
$product = tep_db_fetch_array($product_query);
$description=$product['products_description'];

?>
<tr>
<td align="center" height="106"><br/><?=$rowline[0]['text']?><input type="hidden" name="products_id[]" value="<?=$products[$i-1]['id']?>"/></td>
<td style=" vertical-align:top; padding:5px;text-align:justify;"><br/><div style="text-align:center;"><?=$rowline[1]['text']?></div><!-- php?=$description?>--></td>
<td align="center"><br/><input type="text" name="cart_quantity[]" class="input_3" value="<?=$products[$i-1]['quantity']?>"></td>
<td align="center" style="padding:9px 0px 0px 0px; "><br/><?=$rowline[3]['text']?></td>
</tr>
<? } ?>

<?
// new productListingBox($info_box_contents);
?>
</table>
</td></tr>
<tr>
<td></td>
</tr>
</table> </td>
</tr>

<tr>
<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>
<?php
if ($any_out_of_stock == 1) {
if (STOCK_ALLOW_CHECKOUT == 'true') {
?>
<tr>
<td class="stockWarning" align="center"><br>
<?php echo OUT_OF_STOCK_CAN_CHECKOUT; ?></td>
</tr>
<?php
} else {
?>
<tr>
<td class="stockWarning" align="center"><br><?php echo OUT_OF_STOCK_CANT_CHECKOUT; ?></td>
</tr>
<?php
}
}
?>
<tr>
<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>
<tr>
<td><table border="0" width="100%" cellspacing="1" cellpadding="2">
<tr class="infoBoxContents">
<td><table border="0" width="100%" cellspacing="4" cellpadding="2">
<tr>
<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
<td class="main"><?php echo tep_image_submit('button_update_cart.gif', IMAGE_BUTTON_UPDATE_CART); ?></td>
<?php
$back = sizeof($navigation->path)-2;
if (isset($navigation->path[$back])) {
?>
<td class="main"><?php echo '<a href="' . tep_href_link($navigation->path[$back]['page'], tep_array_to_string($navigation->path[$back]['get'], array('action')), $navigation->path[$back]['mode']) . '">' . tep_image_button('button_continue_shopping.gif', IMAGE_BUTTON_CONTINUE_SHOPPING) . '</a>'; ?></td>
<?php
}
?>
<td align="right" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '">' . tep_image_button('button_checkout.gif', IMAGE_BUTTON_CHECKOUT) . '</a>'; ?></td>
<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<?php
} else {
?>
<tr>
<td align="center" class="main"><?php new infoBox(array(array('text' => TEXT_CART_EMPTY))); ?></td>
</tr>
<tr>
<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>
<tr>
<td><table border="0" width="80%" cellspacing="1" cellpadding="2">
<tr>
<td><table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
<td align="right" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>'; ?></td>
<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<?php
}
?>
</table>
</form></td>
<!-- body_text_eof //-->
<td width="30" valign="top">
<table border="0" width="30" cellspacing="0" cellpadding="2">
<!-- right_navigation
<?php //require(DIR_WS_INCLUDES . 'column_right.php'); ?>
right_navigation_eof //-->
</table></td>
</tr>
</table>
<div align="center">
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</div>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

Lien vers le commentaire
Partager sur d’autres sites

Veuillez vous connecter pour commenter

Vous pourrez laisser un commentaire après vous êtes connecté.



Connectez-vous maintenant
×
×
  • Créer...