Insertion d'une nouvelle fonction dans display_product

3 posts in this topic

Posted · Report post

Bonjour

Je cherche a ajouter une information de date de livraison sur mes pages produit, en dessous de l'affichage de l'état de stock.
J'ai un script php avec plusieurs fonctions qui fonctionne bien mais il me faut maintenant l'intégrer à peel (je suis sur une 7.0.0)

J'ai ajouter mon code dans display_product.php, créé un tpl->assign avec une variable à utiliser ensuite dans critere_stock.tpl
mais j'ai désormais une erreur fatal : 
Fatal error: Call to undefined function addOpenDays() in /home/www/ledsboutique/lib/fonctions/display_product.php on line 787

comment définir cette fonction ?
Suis-je sur la bonne piste ? ou est-ce que j'ai tout faux ?
Est-ce juste que je ne place pas les code au bons endroits ?

 

Voici le script : 

function addOpenDays($startDate, $daysNumber = 0) {
    if (isset($startDate) && !is_null($startDate)) {
        $startDate = (is_string($startDate)) ? strtotime($startDate) : $startDate;

        $year     = 0;
        $holidays = array();

        $date = $startDate;

        for ($i = $daysNumber; $i > 0; $i--) {
            if ($year != date('Y', $date)) {
                $year     = date('Y', $date);
                $holidays = getHolidays($year);
            }

            while (!isOpenDay($date) || isHoliday($date, $holidays)) {
                $date = strtotime(date('Y-m-d', $date) . ' + 1 days');
            }

            $date = strtotime(date('Y-m-d', $date) . ' + 1 days');
        }

        while (!isOpenDay($date) || isHoliday($date, $holidays)) {
            $date = strtotime(date('Y-m-d', $date) . ' + 1 days');
        }
    }

    return strtotime(date('Y-m-d', $date));
}

// Get all holidays for a given year
function getHolidays($year) {
    // Holidays array
    $holidays = array();

    if (isset($year) && !is_null($year) && $year > 1970) {

        // List of basic known holidays
        $holidays[] = '1_1_' . $year; // New year day
        $holidays[] = '1_5_' . $year; // Fête du travail
        $holidays[] = '8_5_' . $year; // Victoire 1945
        $holidays[] = '14_7_' . $year; // Fête nationale
        $holidays[] = '15_8_' . $year; // Assomption
        $holidays[] = '1_11_' . $year; // Toussaint
        $holidays[] = '11_11_' . $year; // Armistice 1918
        $holidays[] = '25_12_' . $year; // Christmas

        // Get the easter date
        $easter = easter_date($year);

        // From the easter date, when can compute le jour de l'ascension and pentecôte
        $holidays[] = date('j_n_' . $year, $easter + 86400); // Easter
        $holidays[] = date('j_n_' . $year, $easter + (86400 * 39)); // Ascension
        $holidays[] = date('j_n_' . $year, $easter + (86400 * 50)); // Pentecôte
    }

    return $holidays;
}

// Check if a given date is holiday
function isHoliday($date, $holidays = null) {
    if (isset($date) && !is_null($date)) {
        $date = (is_string($date)) ? strtotime($date) : $date;

        $holidays = (!isset($holidays) || is_null($holidays)) ? getHolidays(date('Y', $date)) : $holidays;

        if (isset($holidays) && !is_null($holidays)) {
            return in_array(date('j_n_' . date('Y', $date), $date), $holidays);
        }
    }

    return false;
}

// Check if a given day is an open day
function isOpenDay($date) {
    if (isset($date) && !is_null($date)) {
        $date = (is_string($date)) ? strtotime($date) : $date;

        return !in_array(date('w', $date), array(0, 6));
    }

    return false;
}

// Selection de la langue
setlocale(LC_TIME, 'fr_FR'); // fr_FR pour le français

 

Voici ma ligne d'assignation de la variable pour le tpl :

$tpl->assign('affiche_date_livraison', strftime('%A %e %B %Y', addOpenDays(date('Y-m-d'), 3));

Et donc j'utilise la variable {$affiche_date_livraison} dans le fichier .tpl

Merci  de votre aide.

François.
 

Share this post


: post
Share on other sites

Posted · Report post

Bonjour,

Pour inclure de nouvelles fonctions, vous pouvez utiliser le fichier modeles/peel7/display_custom.php
La modification de la fonction critere_stock et du fichier tpl semble bonne.

Share this post


: post
Share on other sites

Posted · Report post

C'est tout bon.
Merci.

Share this post


: post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

Twitter Advisto ecommerce

Facebook PEEL Shopping