Etablir une connexion PHP

Fermé
romain-rom Messages postés 6 Date d'inscription mardi 3 avril 2012 Statut Membre Dernière intervention 6 avril 2012 - Modifié par romain-rom le 4/04/2012 à 13:38
romain-rom Messages postés 6 Date d'inscription mardi 3 avril 2012 Statut Membre Dernière intervention 6 avril 2012 - 5 avril 2012 à 09:37
Bonjour,
Est ce que quelqu'un pourrait m'expliquer en quoi consiste le code ci dessous svp ?


$Cart = new Cart( $session_cart_id );  

$where = "cart_id = ".$session_cart_id;  
$where = " OR customers_id = ".$customer_id;  

$new_cart['customers_id'] = $customer_id;  
     
$cart_id = $Cart->verif_exist( $where );  
     
$_SESSION['cart_id'] = ( ($cart_id) ? $cart_id : 0 );  



Merci d'avance. Rom


1 réponse

flav1313 Messages postés 751 Date d'inscription mardi 24 août 2010 Statut Membre Dernière intervention 22 octobre 2012 100
5 avril 2012 à 09:24
Sachant que la Classe Cart n'est pas présente, c'est impossible.

La première ligne :
$Cart = new Cart( $session_cart_id ); 
est l'instanciation d'une variable de type Cart.
0
romain-rom Messages postés 6 Date d'inscription mardi 3 avril 2012 Statut Membre Dernière intervention 6 avril 2012
5 avril 2012 à 09:27
La classe Cart est définie dans une autre page php.
0
flav1313 Messages postés 751 Date d'inscription mardi 24 août 2010 Statut Membre Dernière intervention 22 octobre 2012 100
5 avril 2012 à 09:30
Et donc pour comprendre le code, il faut avoir la classe Cart à disposition, nous ne pouvons la deviner.
0
romain-rom Messages postés 6 Date d'inscription mardi 3 avril 2012 Statut Membre Dernière intervention 6 avril 2012
5 avril 2012 à 09:37
<?php
class Cart extends CRUDL {
	public $cart_id;
	public $customers_id;
	public $cart_date_added;
	public $cart_date_update;
	public $list_item;
	public $totalTva;
	public $totalHt;
	public $totalTtc;
	public $FP_Ttc;
	public $getTotal;
	public $getEconomieTotal;

	public $getRemise;

	public $nbItemTotal;
	public $nbItemDiff;

	public $remise_Ttc;

	public function __construct( $id = '' ) {
		global $_SESSION, $content;

        $this->_table = array(
		    'val' => TABLE_CARTS,
		    'alias' => 'ca',
		    'key' => 'cart_id'
		    );

		if ( $id != '' ) {
			$appli = array();
            $appli['where'] = $this->_table['key'] . " = '" . (int)$id . "'";

			parent::__construct( $appli );

			$Cart_item = new Cart_item();

            $appli2 = array();
			$appli2['where'][] = "cai.cart_id = '$id'";
			$this->list_item = $Cart_item->listes( $appli2 );
		}
	}

	public function add ( $array ) {
		$array['cart_date_added'] = 'now()';

		return parent::add( $array );
	}

	public function is_modified ($id) {
		if ( $id != '' )
        {
            if ( count( $this->list_item ) > 0 ) {
    			$Cart_item = new Cart_item();

    			// mode doit etre une variable qui dit si on peut faire des commandes hors stock ( choix de l'ecommercant )
    			$mode = 'restriction';

    			if ( $mode != 'noCheckStock' ) {
    				$flag = 0;
    				foreach ( $this->list_item as $list_item ) {
    					if ( $list_item['products_attributes_id'] > 0 ) {
    						$ProductsAttribut = new ProductsAttribut( $list_item['products_attributes_id'] );
    						$qty_en_stock = $ProductsAttribut->qty;
    					}
    					else {
    						$Product = new Product( $list_item['products_id'] );
    						$qty_en_stock = $Product->qty;
    					}

    					if ( $mode == 'restriction' ) {
    						if ( $qty_en_stock  == 0 ) {
    							// on supprime la ligne de commande
    							$Cart_item->delete( $list_item['cart_item_id'] );
    							$flag = 1;
    						}
    						elseif ( $qty_en_stock < $list_item['cart_item_qty'] ) {
    							// on enleve autant de qty  que nécessaire
    							$update_ci = array();
    							$update_ci['cart_item_qty'] = $qty_en_stock;
    							$Cart_item->save( $list_item['cart_item_id'], $update_ci );
    							$flag = 1;
    						}
    					}
    					elseif ( $mode == 'supression' ) {
    						$Cart_item->delete( $list_item['cart_item_id'] );
    						$flag = 1;
    					}
    				}

    				if ( !isset( $_SESSION['partie_admin'] ) && ( $flag > 0 ) ) {
    					tep_redirect(tep_href_link(FILENAME_CART, 'message=produit_supprime'));
    				}
                    $appli2 = array();
			        $appli2['where'][] = "cai.cart_id = '$id'";
    				$this->list_item = $Cart_item->listes( $appli2 );
    			}
    		}
		}
	}

	public function save ( $id, $array ) {
		$array['cart_date_update'] = 'now()';

		parent::save( $id, $array );
	}

	public function delete ( $id ) {
		parent::delete( $id );
		$Cart_item = new Cart_item();
		$params2 = array();
		$params2[] = "cart_id = ".$id;
		$Cart_item->delete_where($params2);
	}

	public function nbItemTotal () {
		if ( count( $this->list_item ) > 0 ) {
			$nbItemTotal = 0;
			foreach ( $this->list_item as $list_item ) {
				$nbItemTotal += $list_item['cart_item_qty'];
			}
		}

		$this->nbItemTotal = $nbItemTotal;

		return $this->nbItemTotal;
	}

	public function nbItemDiff () {
		$nbItemDiff = count( $this->list_item );
		$this->nbItemDiff = $nbItemDiff;
		return $this->nbItemDiff;
	}

	public function totalTva () {
		$Currencies = new Currencies();

		$this->totalTtc();
		$this->totalHt();

		$totalTva = round( $this->totalTtc / $this->totalHt, 3 );
		$this->totalTva = $totalTva;

		return $Currencies->format( $this->totalTva );
	}

	public function totalHt () {
		$Currencies = new Currencies();

		if ( count( $this->list_item ) > 0 ) {
			$totalHt = 0;
			foreach ( $this->list_item as $list_item ) {
				$products_id = $list_item['products_id'];

				$Product = new Product( $products_id );

				$totalHt += $Product->normal_price * $list_item['cart_item_qty'];
			}

			$this->totalHt = $totalHt;
		}

		return $Currencies->format( $this->totalHt );
	}

	public function totalTtc () {
		$Currencies = new Currencies();

		$totalTtc_applique = 0;
		$totalTtc_normal = 0;

		if ( count( $this->list_item ) > 0 ) {
			foreach ( $this->list_item as $list_item ) {
				$products_id = $list_item['products_id'];
				$products_attributes_id = $list_item['products_attributes_id'];

				$Product = new Product( $products_id );
				$ProductsAttribut = new ProductsAttribut( $products_attributes_id );

				if ( $products_attributes_id > 0 ) {
					$cart_item_final_price = $ProductsAttribut->pa_price_actif_ttc;
					$cart_item_normal_price = $ProductsAttribut->price_ttc;
				}
				else {
					$cart_item_final_price = $Product->products_price_actif_ttc;
					$cart_item_normal_price = $Product->products_price_ttc;
				}

				$totalTtc_applique += $cart_item_final_price * $list_item['cart_item_qty'];
				$totalTtc_normal += $cart_item_normal_price * $list_item['cart_item_qty'];
			}

			$this->totalTtc = $totalTtc_applique;
			$this->totalTtc_normal = $totalTtc_normal;

			$this->getRemise();
			if ( $this->remise_Ttc > 0 )
			{
    		    $this->totalTtc -= $this->remise_Ttc;
    		    $this->totalTtc_normal -= $this->remise_Ttc;
            }
		}

		return $Currencies->format( $this->totalTtc );
	}

	public function totalWeight () {
		$totalWeight = 0;
		if ( count( $this->list_item ) > 0 ) {
			foreach ( $this->list_item as $list_item ) {
				$products_id = $list_item['products_id'];

				$Product = new Product( $products_id );

				$totalWeight += $Product->products_weight_brut * $list_item['cart_item_qty'];
			}
			$this->totalWeight = $totalWeight;
		}

		return $this->totalWeight;
	}

	public function FP_Ttc () {
		global $_SESSION;

		$this->totalWeight();
		$this->totalTtc();

		$Currencies = new Currencies();

		$affiche_prix_livraison = 0;

		if ( count( $this->list_item ) > 0 ) {
			if ( isset( $_SESSION['customer_country_id'] ) ) {
				$selected_country = $_SESSION['customer_country_id'];
			}
			else {
				$selected_country = 73;
			}

			$Countries = new Countries( $selected_country );

			if ( ( $this->totalTtc > $Countries->free_shipping ) && ( $Countries->free_shipping > 0 ) ) {
				$affiche_prix_livraison_surcharge = 'offert';
			}
			else {
				$CatShipping = new CatShipping();
				$Shipping = new Shipping();

				$appli = array();
				$appli['where']['parent_id'] = 0;
				$list_catshipping = $CatShipping->lists( $appli );

				if ( count( $list_catshipping ) > 0 ) {
					foreach( $list_catshipping as $catshippings ) {
						$nb_select = 0;

						$appli = array();
						$appli['where']['catshippingies_id'] = $catshippings['catshippingies_id'];

						$list_shipping = $Shipping->lists( $appli );
						if ( count( $list_shipping ) > 0 ) {
							foreach( $list_shipping as $shippings ) {
								if ( $nb_select < 1 ) {
									$list_countries = pipe2array( $shippings['shippings_list'] );
									if ( in_array ( $selected_country, $list_countries ) ) {
										$a++;

										$shipping_tax = rate_calcul_shipping( $shippings['shippings_tax_class_id'], $selected_country, $Countries->geo_zone_id );
										if ( $shippings['shippings_table'] != '' ) {
											$tableau_poids = split( "[:,]" , $shippings['shippings_table'] );
											for ( $i = 0; $i < count( $tableau_poids ); $i += 2 ) {
												if ( ( $this->totalWeight < $tableau_poids[$i] ) && ( $nb_select < 1 ) ) {
													$prix_livraison = tep_add_tax( $tableau_poids[$i + 1], $shipping_tax );
													$affiche_prix_livraison = $prix_livraison;
													$nb_select++;
												}
											}
										}
										elseif ( $shippings['shippings_price'] != '' ) {
											$tableau_price = split( "[:,]" , $shippings['shippings_price'] );
											for ( $i = 0; $i < count( $tableau_price ); $i += 2 ) {
												if ( ( $this->totalTtc < $tableau_price[$i] ) && ( $nb_select < 1 ) ) {
													$prix_livraison = tep_add_tax( $tableau_price[$i + 1], $shipping_tax );
													$affiche_prix_livraison = $prix_livraison;
													$nb_select++;
												}
											}
										}
										elseif ( $shippings['shippings_table_qty'] != '' ) {
											$tableau_qty = split( "[:,]" , $shippings['shippings_table_qty'] );
											for ( $i = 0; $i < count( $tableau_qty ); $i += 2 ) {
												if ( ( $cart->count_contents() == $tableau_qty[$i] ) && ( $nb_select < 1 ) ) {
													$prix_livraison = tep_add_tax( $tableau_qty[$i + 1], $shipping_tax );
													$affiche_prix_livraison = $prix_livraison;
													$nb_select++;
												}
											}
										}
										elseif ( $nb_select < 1 ) {
											$prix_livraison = tep_add_tax( $shippings['shippings_forfait'], $shipping_tax );
											$affiche_prix_livraison = $prix_livraison;
											$nb_select++;
										}
									}
								}
							}
						}
					}

					if ( $affiche_prix_livraison_surcharge != '' ) {
						$affiche_prix_livraison = $affiche_prix_livraison_surcharge;
					}
					else {
						$total_panier += $prix_livraison;
					}
				}
			}
		}

		$this->FP_Ttc = $affiche_prix_livraison;

		return $Currencies->format( $this->FP_Ttc );
	}

	public function getTotal () {
		$Currencies = new Currencies();

		$this->totalTtc();
		$this->FP_Ttc();

		$this->getTotal = $this->totalTtc + $this->FP_Ttc;

        return $Currencies->format( $this->getTotal );
	}

    public function setRemise ($array) {
		$this->remise_Ttc = $array['value'];
	}

    public function getRemise () {
		$Currencies = new Currencies();
		return $Currencies->format( $this->remise_Ttc );
	}

	public function getEconomieTotal () {
		$Currencies = new Currencies();

		$this->totalTtc();
		$this->getRemise();

        $this->getEconomieTotal = $this->totalTtc_normal - $this->totalTtc + $this->remise_Ttc;

		return $Currencies->format( $this->getEconomieTotal );
	}
	
	public function verif_exist ( $where ) {
		return parent::verif_exist ( $where );
	}
	
}


Je comprendrais si tu abandonnais ^^
J'espère que tu sauras m'aider avec ceci.
0