NEW Preview product list when we choose model layout Commerce (#30185)

* New update for templateMail by creating files

* New updating for get php content

* Update html.formmail.class.php

* Fix updating content news

* Fix CTI Errors

* NEW function for Preview In CKeditor products

* edit html file for news

* Add automaticaly subject value to editor

* Update html.formmail.class.php

* FIX name and path of file

* Fix path for files

* Fix errors variables

* replace file in ajax folder

* rename path

* Fix return function in product class

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
lamrani abdelwadoud
2024-08-15 17:39:15 +02:00
committed by GitHub
parent c7f8a8c06d
commit 1bd3d1877e
7 changed files with 89 additions and 41 deletions

View File

@@ -21,6 +21,7 @@
* \brief File to return Ajax response on location_incoterms request
*/
// Just for display errors in editor
ini_set('display_errors', 1);

View File

@@ -1560,7 +1560,6 @@ class FormMail extends Form
// Remplacer la variable de substitution dans le contenu HTML
contentHtml = contentHtml.replace(/__SUBJECT__/g, subject);
// Envoyer le contenu HTML à process_template.php pour traitement PHP
$.ajax({
type: "POST",

View File

@@ -41,6 +41,8 @@ function getHtmlOfLayout($name)
'__USERSIGNATURE__' => !empty($user->signature) ? dol_htmlentities($user->signature) : '',
'__GRAY_RECTANGLE__' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAIAAABM5OhcAAABGklEQVR4nO3SwQ3AIBDAsNLJb3SWIEJC9gR5ZM3MB6f9twN4k7FIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIvEBtxYAkgpLmAeAAAAAElFTkSuQmCC',
'__LAST_NEWS__' => $langs->trans('LastNews'),
'__LIST_PRODUCTS___' => $langs->trans('ListProducts'),
);
$substitutionarray = array_merge($commonSubstitutionArray, $specificSubstitutionArray);

View File

@@ -1,45 +1,44 @@
<h1 style="margin-left:120px;">Lorem, ipsum dolor sit amet consectetur adipisicing elit sit amet consectetur</h1>
<h1 style="margin-left:120px;">__LIST_PRODUCTS___</h1>
<h2 style="margin-left:120px;">Lorem, ipsum dolor sit amet consectetur adipisicing elitsit amet consectetur adipisicing </h2>
<div style="font-family: Arial, sans-serif; background-color: #f7f7f7; padding: 16px; max-width: 600px; margin: 0 auto; box-sizing: border-box;">
<div style="display: flex;">
<div style="margin-bottom: 50px; flex: 1; padding-right: 8px;">
<div>
<img alt="Gray rectangle" style="margin-left:120px;margin-top:30px;" width="350px" height="100px" src="__GRAY_RECTANGLE__">
</div>
<div style="margin-left:120px;background-color: #e0e0e0; padding: 8px; margin-bottom: 8px; text-indent: 50px;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit<br>Lorem ipsum dolor sit amet, consectetur adipiscing elit...
</div>
</div>
<!-- PHP_START -->
require_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
<div style="margin-bottom: 10px; flex: 1; padding-left: 8px;">
<div>
<img alt="Gray rectangle" style="margin-left:120px;margin-top:30px;" width="350px" height="100px" src="__GRAY_RECTANGLE__">
</div>
<div style="margin-left:120px;background-color: #e0e0e0; padding: 8px; margin-bottom: 8px; text-indent: 50px;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit<br>Lorem ipsum dolor sit amet, consectetur adipiscing elit...
</div>
</div>
$user = new User($db);
$product = new Product($db);
$products = $product->getProductsToPreviewInEmail(4);
if (empty($products)){
print '<p>No Products</p>';
}else {
foreach($products as $product){
if ($i % 2 == 0) {
print '<div style="display: flex; justify-content: space-between; margin-bottom: 20px;">';
}
print '<div style="flex: 1; padding-right: 10px;">
<div>
<img alt="Gray rectangle" style="margin-left: 120px; margin-top: 30px;" width="350px" height="100px" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=produit&file='.$product['ref'].'/'.$product['filename'].'" />
</div>
<div style="margin-left: 120px; background-color: #e0e0e0; padding: 8px; margin-bottom: 8px; text-indent: 50px;">
<h3>'.$product["ref"].'</h3>
<p>'.$product["description"].'</p>
</div>
</div>';
if ($i % 2 == 1 || $i == $num - 1) {
print '</div>';
}
$i++;
}
}
<!-- PHP_END -->
</div>
<div style="display: flex;">
<div style="margin-bottom: 50px; flex: 1; padding-right: 8px;">
<div>
<img alt="Gray rectangle" style="margin-left:120px;margin-top:30px;" width="350px" height="100px" src="__GRAY_RECTANGLE__">
</div>
<div style="margin-left:120px;background-color: #e0e0e0; padding: 8px; margin-bottom: 8px; text-indent: 50px;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit<br>Lorem ipsum dolor sit amet, consectetur adipiscing elit...
</div>
</div>
<div style="margin-bottom: 10px; flex: 1; padding-left: 8px;">
<div>
<img alt="Gray rectangle" style="margin-left:120px;margin-top:30px;" width="350px" height="100px" src="__GRAY_RECTANGLE__">
</div>
<div style="margin-left:120px;background-color: #e0e0e0; padding: 8px; margin-bottom: 8px; text-indent: 50px;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit<br>Lorem ipsum dolor sit amet, consectetur adipiscing elit...
</div>
</div>
</div>
</div>
</div>

View File

@@ -4,3 +4,4 @@
<!-- NEWS_START -->
__NEWS_LIST__
<!-- NEWS_END -->

View File

@@ -197,4 +197,5 @@ YouCanChooseAModelForYouMailContent= You can choose one of template models or ge
TitleOfMailHolder=Title of the e-mail goes here
ContentOfMailHolder=Content of email goes here...
LastNews=Last News
ListProducts= List of products
PasswordReset=Password reset

View File

@@ -6944,6 +6944,51 @@ class Product extends CommonObject
$return .= '</div>';
return $return;
}
/**
* Retrieve and display products.
*
* @param int $limit The maximum number of results to return.
* @return array<int, array<string, mixed>>|int return array if OK, -1 if KO
*/
public function getProductsToPreviewInEmail($limit)
{
if (!is_numeric($limit)) {
return -1;
}
$sql = "SELECT p.rowid, p.ref, p.label, p.description, p.entity, ef.filename
FROM ".MAIN_DB_PREFIX."product AS p
JOIN ".MAIN_DB_PREFIX."ecm_files AS ef ON p.rowid = ef.src_object_id
WHERE ef.entity IN (".getEntity('product').")
AND (ef.filename LIKE '%.png' OR ef.filename LIKE '%.jpeg' OR ef.filename LIKE '%.svg')
GROUP BY p.rowid, p.ref, p.label, p.description, p.entity, ef.filename
ORDER BY p.datec ASC
LIMIT " . ((int) $limit);
$resql = $this->db->query($sql);
$products = array();
if ($resql) {
while ($obj = $this->db->fetch_object($resql)) {
$products[] = array(
'rowid' => $obj->rowid,
'ref' => $obj->ref,
'label' => $obj->label,
'description' => $obj->description,
'entity' => $obj->entity,
'filename' => $obj->filename
);
}
} else {
dol_print_error($this->db);
}
if (empty($products)) {
return -1;
}
return $products;
}
}
/**