Jump to content

création de produit avec attachement (php)


zakaria99

Recommended Posts

Salut, je travail sur une solution personnalise de prestashop, j'ai cree un controller backend qui ajoute une page speical qui permi de cree un produit avec fichier pdf.

 

mon probleme est que j'arrive a cree mon produit puis un attachement qui va avec, seulement quand je telecharge le fichier, il est a 0octect de taille.

 

est ce que peut avoir d'aide sur la classe AttachmementCore et ce bout de code : 

 

$atch = new AttachmentCore();
            $atch->file = $file['tmp_name'];
            $atch->file_name = $file['rename'];
            $atch->mime = $file['mime'];
            $atch->name = [ConfigurationCore::get('PS_LANG_DEFAULT') => 'Prod_n' . $prod_numero];
            $atch->file_size = $file['size'];
            $atch->add();
            $atch->attachProduct($prod->id);
            //$atch->save(); 
 
 
merci.
Link to comment
Share on other sites

Problème résolut , je laisse la solution au cas ou : 

 

$file = Tools::fileAttachment('myfile');

            

file_put_contents(_PS_DOWNLOAD_DIR_ . $file['rename'], $file['content']);

            

$atch = new AttachmentCore();

$atch->file = $file['rename'];

$atch->file_name = $file['rename'];

$atch->mime = $file['mime'];

$atch->name = [ConfigurationCore::get('PS_LANG_DEFAULT') => 'document name'];

$atch->add();

$atch->attachProduct($prod->id); //en attach le fichier au produit

 

merci.

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...