Jump to content

Onglet supplémentaire dans la fiche produit de l'administration


Recommended Posts

Bonjour,

 

j'ai développé des modules permettant d'ajouter des éléments supplémentaire au produit.

 

Je vous mets un exemple avec le module permettant d'ajouter 2 dates sur un produit.

 

Pour être sûr que nous nous comprenions bien je vous mets une capture d'écran de ce que donne le module en back-office.

 

post-359967-0-25601100-1399984717_thumb.jpg

 

Mon problème se situe au moment de l'enregistrement des informations.

 

Pour enregistrer mes informations je passe par les "hook" suivants selon si il s'agit d'une création ou d'une mise à jour du produit :

- actionProductAdd

- actionProductUpdate

 

L'enregistrement se fait parfois correctement et parfois non.

 

J'ai cru déceler que l'enregistrement ne faisait pas lorsque l'onglet dans la fiche produit n'était pas consulté. Exemple, je rentre sur ma fiche produit, je modifie le prix, et les dates ne sont pas enregistrées.

 

Comment puis-je résoudre ce problème?

 

Je vous donne le début du code du fichier php du module :

if (!defined('_PS_VERSION_')) {
    exit;
}

require_once(dirname(__FILE__) . '/classes/productdate.php');
require_once(dirname(__FILE__) . '/classes/orderproductdate.php');

class productdate extends Module {

    public function __construct() {
        $this->name = 'productdate';
        $this->tab = 'front_office_features';
        $this->version = '1.0.0';
        $this->author = 'Awak Studio';
        $this->need_instance = 0;
        $this->module_key = "";

        parent::__construct();

        $this->displayName = $this->l('Date produit');
        $this->description = $this->l('Permet de definir une date pour un produit');
    }
	
    public function install() {
        $sql = array();
	
        $sql[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'product_date` (
                  `id_product_date` int(10) unsigned NOT NULL AUTO_INCREMENT,
                  `id_product` INT(11) UNSIGNED NOT NULL,
                  `date_deb` DATE NOT NULL,
				  `date_fin` DATE NOT NULL,
				  
				  `date_deb_nb_day` VARCHAR(20) NOT NULL,
				  `date_deb_num_day` VARCHAR(20) NOT NULL,
				  `date_deb_lettre_day` VARCHAR(20) NOT NULL,
				  `date_deb_month` VARCHAR(20) NOT NULL,
				  `date_deb_lettre_month` VARCHAR(20) NOT NULL,
				  `date_deb_year` VARCHAR(20) NOT NULL,
				  
				  `date_fin_nb_day` VARCHAR(20) NOT NULL,
				  `date_fin_num_day` VARCHAR(20) NOT NULL,
				  `date_fin_lettre_day` VARCHAR(20) NOT NULL,
				  `date_fin_month` VARCHAR(20) NOT NULL,
				  `date_fin_lettre_month` VARCHAR(20) NOT NULL,
				  `date_fin_year` VARCHAR(20) NOT NULL,
				  
				  `date_deb_heure_deb` TIME NOT NULL,
				  `date_deb_heure_fin` TIME NOT NULL,
				  `date_fin_heure_deb` TIME NOT NULL,
				  `date_fin_heure_fin` TIME NOT NULL,
				  
                  PRIMARY KEY (`id_product_date`),
                  UNIQUE  `DATE_PRODUCT_UNIQ` (  `id_product` )
                ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8';
        
		$sql[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'order_product_date` (
                  `id_order_product_date` int(10) unsigned NOT NULL AUTO_INCREMENT,
                  `id_order` INT(11) UNSIGNED NOT NULL,
				  `id_product_attribute` INT(11) UNSIGNED NOT NULL,
				  `id_product` INT(11) UNSIGNED NOT NULL,
                  `date_deb` DATE NOT NULL,
				  `date_fin` DATE NOT NULL,
				  `date_deb_heure_deb` TIME NOT NULL,
				  `date_deb_heure_fin` TIME NOT NULL,
				  `date_fin_heure_deb` TIME NOT NULL,
				  `date_fin_heure_fin` TIME NOT NULL,
                  PRIMARY KEY (`id_order_product_date`)
                ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8';
		
        if (!parent::install() OR 
            !$this->registerHook('displayAdminProductsExtra') OR
            !$this->registerHook('actionProductUpdate') OR
			!$this->registerHook('actionProductAdd') OR
			!$this->registerHook('actionProductDelete') OR
			!$this->registerHook('actionProductListOverride') OR
            !$this->registerHook('displayFooterProduct') OR
			!$this->registerHook('displayDateProduct') OR
			!$this->registerHook('displayHorairesProduct') OR
			!$this->registerHook('actionValidateOrder') OR
			!$this->registerHook('actionUpdateAdminOrderProduct') OR
			!$this->registerHook('actionDeleteAdminOrderProduct') OR
			!$this->registerHook('actionInsertInfoMail') OR
            !$this->runSql($sql)
        ) {
            return false;
        }
        
        return true;
    }
    
    public function uninstall() {
        $sql = array();
	
        $sql[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'product_date`';
		$sql[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'order_product_date`';
        if (!parent::uninstall() OR
            !$this->runSql($sql) 
        ) {
            return false;
        }

        return true;
    }
    
    public function runSql($sql) {
        foreach ($sql as $s) {
			if (!Db::getInstance()->Execute($s)){
				return false;
			}
        }
        
        return true;
    }
    
    public function hookDisplayAdminProductsExtra($params) {
        $id_product = Tools::getValue('id_product');
        $productDateObj = productdateModel::loadByIdProduct($id_product);
        if(!empty($productDateObj) && isset($productDateObj->id)){
		
			//conversion date format francais
			$productDateObj->date_deb = $this->convertDateToFr($productDateObj->date_deb);
			$productDateObj->date_fin = $this->convertDateToFr($productDateObj->date_fin);
			
			//die($productDateObj->date_deb);
            $this->context->smarty->assign(array(
                'date_deb' => $productDateObj->date_deb,
				'date_fin' => $productDateObj->date_fin,
				
				'date_deb_heure_deb' => $productDateObj->date_deb_heure_deb,
				'date_deb_heure_fin' => $productDateObj->date_deb_heure_fin,
				'date_fin_heure_deb' => $productDateObj->date_fin_heure_deb,
				'date_fin_heure_fin' => $productDateObj->date_fin_heure_fin,
            ));
        }
        
        return $this->display(__FILE__, 'views/admin/productdate.tpl');
    }
    
	public function hookActionProductAdd($params) {

        $id_product = $params['product']->id;
        $productDateObj = productdateModel::loadByIdProduct($id_product);
        $productDateObj->date_deb = $this->convertDateToEn(Tools::getValue('date_deb'));
		$productDateObj->date_fin = $this->convertDateToEn(Tools::getValue('date_fin'));
		
		$productDateObj->date_deb_nb_day = $this->getNbDay($productDateObj->date_deb);
		$productDateObj->date_deb_num_day = $this->getNumDay($productDateObj->date_deb);
		$productDateObj->date_deb_lettre_day = $this->getLettreDay($productDateObj->date_deb);
		$productDateObj->date_deb_month = $this->getMonth($productDateObj->date_deb);
		$productDateObj->date_deb_lettre_month = $this->getLettreMonth($productDateObj->date_deb);
		$productDateObj->date_deb_year = $this->getYear($productDateObj->date_deb);
		
		$productDateObj->date_fin_nb_day = $this->getNbDay($productDateObj->date_fin);
		$productDateObj->date_fin_num_day = $this->getNumDay($productDateObj->date_fin);
		$productDateObj->date_fin_lettre_day = $this->getLettreDay($productDateObj->date_fin);
		$productDateObj->date_fin_month = $this->getMonth($productDateObj->date_fin);
		$productDateObj->date_fin_lettre_month = $this->getLettreMonth($productDateObj->date_fin);
		$productDateObj->date_fin_year = $this->getYear($productDateObj->date_fin);
		
		$productDateObj->date_deb_heure_deb = Tools::getValue('date_deb_heure_deb');
		$productDateObj->date_deb_heure_fin = Tools::getValue('date_deb_heure_fin');
		$productDateObj->date_fin_heure_deb = Tools::getValue('date_fin_heure_deb');
		$productDateObj->date_fin_heure_fin = Tools::getValue('date_fin_heure_fin');
		
        $productDateObj->id_product = $id_product;
		if(!empty($productDateObj) && isset($productDateObj->id)){
			$productDateObj->update();
		} else {
			$productDateObj->add();
		}
    }
	
    public function hookActionProductUpdate($params) {
        $id_product = Tools::getValue('id_product');
        $productDateObj = productdateModel::loadByIdProduct($id_product);
        $productDateObj->date_deb = $this->convertDateToEn(Tools::getValue('date_deb'));
		$productDateObj->date_fin = $this->convertDateToEn(Tools::getValue('date_fin'));
		
		$productDateObj->date_deb_nb_day = $this->getNbDay($productDateObj->date_deb);
		$productDateObj->date_deb_num_day = $this->getNumDay($productDateObj->date_deb);
		$productDateObj->date_deb_lettre_day = $this->getLettreDay($productDateObj->date_deb);
		$productDateObj->date_deb_month = $this->getMonth($productDateObj->date_deb);
		$productDateObj->date_deb_lettre_month = $this->getLettreMonth($productDateObj->date_deb);
		$productDateObj->date_deb_year = $this->getYear($productDateObj->date_deb);
		
		$productDateObj->date_fin_nb_day = $this->getNbDay($productDateObj->date_fin);
		$productDateObj->date_fin_num_day = $this->getNumDay($productDateObj->date_fin);
		$productDateObj->date_fin_lettre_day = $this->getLettreDay($productDateObj->date_fin);
		$productDateObj->date_fin_month = $this->getMonth($productDateObj->date_fin);
		$productDateObj->date_fin_lettre_month = $this->getLettreMonth($productDateObj->date_fin);
		$productDateObj->date_fin_year = $this->getYear($productDateObj->date_fin);
		
		$productDateObj->date_deb_heure_deb = Tools::getValue('date_deb_heure_deb');
		$productDateObj->date_deb_heure_fin = Tools::getValue('date_deb_heure_fin');
		$productDateObj->date_fin_heure_deb = Tools::getValue('date_fin_heure_deb');
		$productDateObj->date_fin_heure_fin = Tools::getValue('date_fin_heure_fin');
		
        $productDateObj->id_product = $id_product;
		if(!empty($productDateObj) && isset($productDateObj->id)){
			$productDateObj->update();
		} else {
			$productDateObj->add();
		}
    }
	
	public function hookActionProductDelete($params){
		$id_product = $params['product']->id;
		$productDateObj = productdateModel::loadByIdProduct($id_product);
		$productDateObj->delete();
	}
}

Merci d'avance.

 

Ma version de prestashop est la 1.5.6.1.

post-359967-0-25601100-1399984717_thumb.jpg

Link to comment
Share on other sites

Ou à défaut si vous pouvez m'indiquer une bonne manière pour débugguer dans le back-office?

 

J'avais déjà activé le mode développement dans le fichier defines.inc.php, mais là je n'ai plus d'erreurs php qui pourraient m'aider.

 

Merci

Edited by Gery59 (see edit history)
Link to comment
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...