Jump to content
jamindoStar

Récupérer un produit depuis l'id

Recommended Posts

Bonjour, je suis novice en développement Prestashop et Php. J'ai une classe Bid qui possède un produit (id_produit stocké dans la base).

Dans la class Bid.php j'aimerais récupérer l'ensemble des informations sur le produit grace a l'id_produit depuis la méthode construct.

Malheuresement ca ne marche pas , je comprend pas pourquoi..

En espérant que quelqu'un puisse m'aider, et désolé si ma question est bidon.

<?php

class BidCore extends ObjectModel
{
	/** @var integer id */
	public $id;
	
	/** @var integer Product id */
	public $id_product;
	
	/** @var  String product */
	public $product;
	
	/** @var integer Type */
	public $type;
	
	/** @var date Expiration date */
	public $expiration_date;
	
	/** @var date Start date */
	public $start_date;
	
	/** @var integer lowest bid */
	public $lowest_bid;
	
	public static $definition = array(
			'table' => 'bid',
			'primary' => 'id_bid',
			'fields' => array(
					'id_product' => 			array('type' => self::TYPE_INT),
					'type' => 					array('type' => self::TYPE_INT),
					'expiration_date' => 		array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat'),
					'start_date' => 		    array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat'),
					'lowest_bid' => 			array('type' => self::TYPE_INT),
					),
		);
	
	
	/**
	 * Build a bid
	 *
	 * @param integer $id_product
	 */
	public	function __construct($id_shop = null, $id_lang = null)
	{
		parent::__construct($id_product);
	
		if ($this->id)
			$this->product = new Product($id_product, true, $id_lang, $id_shop);
	}
	
	/**
 	* Get All Bids from db
 	*/
	public static function getAllBids(){
		return Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'bid`');
	}
	
	/**
	 * Count number of bids
	 */
	public static function countBids()
	{
		return $nb_of_bids = (int)Db::getInstance()->getValue('
				SELECT COUNT(`id_bid`)
				FROM `'._DB_PREFIX_.'bid`');
	}
}

Share this post


Link to 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

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More