Changeset 118994 in spip-zone
- Timestamp:
- Dec 11, 2019, 12:54:27 PM (15 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
_plugins_/prix/trunk/inc/prix.php
r117622 r118994 7 7 * Permet d'obtenir le prix HT d'un objet SPIP. C'est le résultat de cette fonction qui est utilisée pour calculer le prix TTC. 8 8 * 9 * @param string $ type_objet Le type de l'objet9 * @param string $objet Le type de l'objet 10 10 * @param int $id_objet L'identifiant de l'objet 11 11 * @return float Retourne le prix HT de l'objet sinon 0 12 12 */ 13 function inc_prix_ht_dist($ type_objet, $id_objet, $arrondi = 2, $serveur = ''){13 function inc_prix_ht_dist($objet, $id_objet, $arrondi = 2, $serveur = ''){ 14 14 $prix_ht = 0; 15 15 16 // Cherchons d'abord si l'objet existe bien 16 if ($type_objet 17 if ( 18 $objet 17 19 and $id_objet = intval($id_objet) 18 20 and include_spip('base/connect_sql') 19 and $ type_objet = objet_type($type_objet)20 and $table_sql = table_objet_sql($ type_objet,$serveur)21 and $cle_objet = id_table_objet($ type_objet,$serveur)21 and $objet = objet_type($objet) 22 and $table_sql = table_objet_sql($objet, $serveur) 23 and $cle_objet = id_table_objet($objet, $serveur) 22 24 and $ligne = sql_fetsel('*', $table_sql, "$cle_objet = $id_objet",'','','','',$serveur) 23 25 ){ 24 26 // Existe-t-il une fonction précise pour le prix HT de ce type d'objet : prix_<objet>_ht() dans prix/<objet>.php 25 if ($fonction_ht = charger_fonction('ht', "prix/$ type_objet", true)){27 if ($fonction_ht = charger_fonction('ht', "prix/$objet", true)){ 26 28 // On passe la ligne SQL en paramètre pour ne pas refaire la requête 27 29 $prix_ht = $fonction_ht($id_objet, $ligne); 28 30 } 29 31 // S'il n'y a pas de fonction, regardons s'il existe des champs normalisés, ce qui évite d'écrire une fonction pour rien 30 elseif (!empty($ligne['prix_ht'])) 32 elseif (!empty($ligne['prix_ht'])) { 31 33 $prix_ht = $ligne['prix_ht']; 32 elseif ($ligne['prix']) 34 } 35 elseif ($ligne['prix']) { 33 36 $prix_ht = $ligne['prix']; 37 } 34 38 35 39 // Enfin on passe dans un pipeline pour modifier le prix HT … … 38 42 array( 39 43 'args' => array( 44 'objet' => $objet, 40 45 'id_objet' => $id_objet, 41 'type_objet' => $ type_objet,46 'type_objet' => $objet, // déprécié, utiliser plutôt "objet" 42 47 'prix_ht' => $prix_ht 43 48 ), … … 48 53 49 54 // Si on demande un arrondi, on le fait 50 if ($arrondi) 55 if ($arrondi) { 51 56 $prix_ht = round($prix_ht, $arrondi); 57 } 52 58 53 59 return $prix_ht; … … 57 63 * Permet d'obtenir le prix final TTC d'un objet SPIP quel qu'il soit. 58 64 * 59 * @param string $ type_objet Le type de l'objet65 * @param string $objet Le type de l'objet 60 66 * @param int $id_objet L'identifiant de l'objet 61 67 * @return float Retourne le prix TTC de l'objet sinon 0 62 68 */ 63 function inc_prix_dist($ type_objet, $id_objet, $arrondi = 2, $serveur = ''){69 function inc_prix_dist($objet, $id_objet, $arrondi = 2, $serveur = ''){ 64 70 include_spip('base/connect_sql'); 65 71 66 72 // On va d'abord chercher le prix HT. On délègue le test de présence de l'objet dans cette fonction. 67 73 $fonction_prix_ht = charger_fonction('ht', 'inc/prix'); 68 $type_objet = objet_type($type_objet); 69 $prix = $prix_ht = $fonction_prix_ht($type_objet, $id_objet, 0, $serveur); 74 $objet = objet_type($objet); 75 $prix = $prix_ht = $fonction_prix_ht($objet, $id_objet, 0, $serveur); 76 $taxes = array(); 70 77 71 // On cherche maintenant s'il existe une personnalisation pour le s taxes: prix_<objet>() dans prix/<objet>.php72 if ($fonction_prix_objet = charger_fonction($ type_objet, 'prix/', true)){78 // On cherche maintenant s'il existe une personnalisation pour le prix total TTC : prix_<objet>() dans prix/<objet>.php 79 if ($fonction_prix_objet = charger_fonction($objet, 'prix/', true)){ 73 80 $prix = $fonction_prix_objet($id_objet, $prix_ht); 81 } 82 // Sinon on appelle une fonction générique pour trouver les taxes d'un objet, et on ajoute au HT 83 elseif ($fonction_taxes = charger_fonction('taxes', 'inc/', true)) { 84 $taxes = $fonction_taxes($objet, $id_objet); 85 $taxes_total = array_sum(array_column($taxes, 'montant')); 86 $prix = $prix_ht + $taxes_total; 74 87 } 75 88 … … 79 92 array( 80 93 'args' => array( 94 'objet' => $objet, 81 95 'id_objet' => $id_objet, 82 'type_objet' => $ type_objet,96 'type_objet' => $objet, // déprécié, utiliser plutôt "objet" 83 97 'prix_ht' => $prix_ht, 84 'prix' => $prix 98 'prix' => $prix, 99 'taxes' => $taxes, 85 100 ), 86 101 'data' => $prix … … 89 104 90 105 // Si on demande un arrondi, on le fait 91 if ($arrondi) 106 if ($arrondi) { 92 107 $prix = round($prix, $arrondi); 108 } 93 109 94 110 // Et c'est fini
Note: See TracChangeset
for help on using the changeset viewer.