THELIA Forum

Welcome to the THELIA support and discusssion forum

Announcement

Rejoignez la communauté sur le Discord Thelia : https://discord.gg/YgwpYEE3y3

Offline


Bonjour la communauté,

J'ai un soucis pour calculer le poids total des produits. (/templates/pdf/default/invoice.html)
L'idéal serait d'assigner chaque poids dans un tableau array et de faire un array_sum comme dans php.
Bon là avec smarty je suis pommé.
{assign "productWeight" $WEIGHT}
{assign "productWeight" $productWeight+$WEIGHT}

                    {loop type="product" name="product-order" ref=$REF limit=1}
                        {assign "productOrderId" $ID}
                        {assign "productWeight" $WEIGHT}
                        {assign "productWeight" {$productWeight=$productWeight+$WEIGHT}}
                      {loop type="feature" name="order-features" order="alpha" product=$productOrderId}
                           {$TITLE}:
                        {loop type="feature_value" name="order-feature-value" feature=$ID product=$productOrderId limit=1}
                          {$TITLE}
                          {if empty($TITLE)}
                            <span style="color:#CC0000;">ERREUR</span>
                          {/if}
                         {/loop}                       
                      {/loop}       
                    {/loop}   

(empty ne fonctionne pas non plus j'ai l'impression que invoice n'accepte pas les fonctions  php!)
Merci de votre aide.

Last edited by fredodefrance (09-10-2017 01:29:29)


C'est en faisant qu'on apprends.

Offline


Bon heu je suis trop nul aujourd'hui. (Un peu fatigué).
Elle était évidente celle là.

{$productWeight=$productWeight+$WEIGHT}

                    {loop type="product" name="product-order" ref=$REF limit=1}
                        {assign "productOrderId" $ID}
                        {$productWeight=$productWeight+$WEIGHT}
                      {loop type="feature" name="order-features" order="alpha" product=$productOrderId}
                        &nbsp;&nbsp;&nbsp;{$TITLE}:
                        {loop type="feature_value" name="order-feature-value" feature=$ID product=$productOrderId limit=1}
                          {$TITLE}
                          {if empty($TITLE)}
                            <span style="color:#CC0000;">ERREUR</span>
                          {/if}
                         {/loop}                       
                      {/loop}       
                    {/loop}   

Reste que pour empty celà ne fonctionne toujours pas.

Last edited by fredodefrance (29-09-2017 18:12:01)


C'est en faisant qu'on apprends.

Offline


Tu peux utiliser des fonctions PHP dans Smarty, donc dans tous les templates Thelia.

Que veux-tu dire par "empty ne fonctionne pas" ?


OpenStudio Toulouse

Offline


J'ai trouvé pour les poids.

Pour le empty ça a fonctionné partiellement (sur 1 des 6 variables surveillées).
En fait j'ai fait la mise au point sur un serveur non sécurisé https avec un site non relié aux dns.
J'éditais en https alors que le protocle n'était pas installé.
Du coup le fichier sur lequel je travaillais s'enregistrait sur un autre virtualhost.
Donc ça m'a enregistré aléatoirement le fichier invoice.html sur les deux autres virtualhosts boutiques Thelia.
Une bizzarerie du serveur apache qui ne gère pas les domaines en https pour les virtualhosts.
Je vais réessayer dans pas longtemps car j'ai du travailler sur un autre projet.


C'est en faisant qu'on apprends.

Offline


invoice.html ne supporte par smarty {php} {/php}


Whoops, looks like something went wrong.
1/1 SmartyCompilerException in smarty_internal_templatecompilerbase.php line 301: Syntax error in template "/var/www/clients/client0/web3/web/templates/pdf/default/invoice.html" on line 301 "{php}" unknown tag "php"

    in smarty_internal_templatecompilerbase.php line 301
    at Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown tag "php"', '301') in smarty_internal_templatecompilerbase.php line 547
    at Smarty_Internal_TemplateCompilerBase->compileTag('php', array()) in smarty_internal_templateparser.php line 3570
    at Smarty_Internal_Templateparser->yy_r39() in smarty_internal_templateparser.php line 4392
    at Smarty_Internal_Templateparser->yy_reduce('39') in smarty_internal_templateparser.php line 4493
    at Smarty_Internal_Templateparser->doParse('3', '}') in smarty_internal_smartytemplatecompiler.php line 118
    at Smarty_Internal_SmartyTemplateCompiler->doCompile('{*************************************************************************************/ /* This file is part of the Thelia package. */ /* */ /* Copyright (c) OpenStudio */ /* email : dev@thelia.net */ /* web : http://www.thelia.net */ /* */ /* For the full copyright and license information, please view the LICENSE.txt */ /* file that was distributed with this source code. */ /*************************************************************************************} {* Set the default translation domain, that will be used by {intl} when the 'd' parameter is not set *} {default_translation_domain domain='pdf.default'} {literal} <style> h1, h2, h3, h4 { color:#000044; margin: .5em 0; } h1 { font-size: 48px; } h2 { font-size: 16px; } h3 { font-size: 14px; } h4 { color:#ffffff; font-size: 12px; } h5 { color:#ffffff; font-size: 12px; } p, td { color:#333333; font-size: 10px; } p { margin: .5em 0; } span { font-size: 9px; } table { border-collapse: collapse; width: 100%; } tr { width: 100%; } td { vertical-align: top; } .table-info h3 { font-size: 18px; color: #000044; margin-top: 0; margin-bottom: 15px; } .table-info h3 span { font-size: 18px; color: #f6993c; } .table-0 span { font-size: 12px; } .table-1 td { background: #000044; border:solid 1px #bcbdc0; } .table-2 td { border:solid 1px #bcbdc0; } .table-3-1, .table-3-2 { border: solid 1px #bcbdc0; } .table-3-1 p { font-size: 10px; } .table-3-2 p { font-size: 9px; color: #333333; } .table-3-module h3 { margin-top: 1.5em; } .table-3-module span { font-size: 11px; } .align-left { text-align: left; } .align-center { text-align: center; } .align-right{ text-align: right; } .clear { padding: 0.5%; border-bottom:solid 1px #dddddd; } .clear-none { padding: 0.5%; } {hook name="invoice.css"} </style> {/literal} <page backtop="10mm" backleft="10mm" backright="10mm" backbottom="10mm"> <page_header> {hook name="invoice.header" order=$order_id} </page_header> <page_footer> {hook name="invoice.footer-top" order=$order_id} <table> <col style="width: 80%; padding: 1mm; border: none; text-align: left;" /> <col style="width: 20%; padding: 1mm; border: none; text-align: right;" /> <tbody> <tr> <td> {hook name="invoice.imprint" order=$order_id} {elsehook rel="invoice.imprint"} <!-- Imprint --> {config key="store_name"} {$addresses="{config key="store_address1"} {config key="store_address2"} {config key="store_address3"}"} {$city="{config key="store_zipcode"} {config key="store_city"}"} {if $addresses != " "}- {$addresses}{/if} {if $city != " " }- {$city}{/if} {if {config key="store_country"} } {loop type="country" visible="*" name="address.country.title" id={config key="store_country"}} - {$TITLE}{/loop} {/if} {if {config key="store_business_id"} } - {config key="store_business_id"} {/if} {if {config key="store_phone"} } - {intl l="Phone: "}{config key="store_phone"} {/if} {if {config key="store_email"} } {intl l="Email: "}{config key="store_email"} {/if} {/elsehook} </td> <td>{intl l="page"} [[page_cu]]/[[page_nb]]</td> </tr> </tbody> </table> {hook name="invoice.footer-bottom" order=$order_id} </page_footer> {$taxes = []} {loop name="order.invoice" type="order" id=$order_id customer="*"} <table class="table-info"> <col style="width: 100%; padding: 0mm;" /> <tr> <td> <table style="border: 0mm;"> <tr> <td> {$image = {image file='img/logo.png' failsafe=true}} <img src="{$image}" alt="{$store_name}"> </td> <td style="vertical-align: middle;"> <span style="font-size: 7mm; color: #000044; text-transform:uppercase;">{config key="store_name"}</span> <br /> <span style="font-size: 5.1mm; text-transform:uppercase;">{config key="store_description"}</span> </td> </tr> </table> </td> </tr> <tr> <td> <h2>{intl l="INVOICE"}</h2> </td> </tr> <tr> <td>{intl l="Invoice date"} : {format_date date=$INVOICE_DATE output="date"}</td> </tr> <tr> <td>{intl l="Invoice REF"} : {$REF}</td> </tr> {loop type="customer" name="customer.invoice" id=$CUSTOMER current="0"} <tr> <td>{intl l="Customer Number"} : {$REF}</td> </tr> <tr> <td>{intl l="Phone"} : {loop type="address" name="phone.default" customer=$ID default="true"}{$PHONE} - {$CELLPHONE}{/loop}</td> </tr> <tr> <td>{intl l="Email"} : {loop type="address" name="email.default" customer=$ID default="true"}{$EMAIL}{/loop}</td> </tr> {/loop} {hookblock name="invoice.information" order=$order_id fields="title,value"} {forhook rel="invoice.information"} <tr> <td><h3>{$title} : <span>{$value}</span></h3></td> </tr> {/forhook} {/hookblock} <tr> <td><br><br></td> </tr> </table> {hook name="invoice.after-information" order=$order_id} <table class="table-0"> <col style="width: 50%; padding: 3mm; clear: inherit;" /> <col style="width: 50%; padding: 3mm; clear: inherit;" /> <tr> <td style="border-left: solid 1mm #000044;"> <h3>{intl l="Delivery address"}</h3> {ifhook rel="invoice.delivery-address"} {* delivery module can customize the delivery address *} <span>{hook name="invoice.delivery-address" module={$DELIVERY_MODULE} order=$order_id}</span> {/ifhook} {elsehook rel="invoice.delivery-address"} <span>{format_address order_address=$DELIVERY_ADDRESS locale=$locale}</span> {/elsehook} </td> <td style="border-left: solid 1mm #000044;"> <h3>{intl l="Invoice address"}</h3> <span style="font-size: 7mm;">{format_address order_address=$INVOICE_ADDRESS locale=$locale}</span> </td> </tr> </table> {hook name="invoice.after-addresses" order=$order_id} <table cellspacing="0" cellpadding="0" style="padding-top: 2mm;"> <col style="width: 62%; padding: 1mm;" /> <col style="width: 14%; padding: 1mm;" /> <col style="width: 12%; padding: 1mm;" /> <col style="width: 12%; padding: 1mm;" /> <tr class="table-1"> <td><h5>{intl l="Product"}</h5></td> <td><h5 class="align-center">{intl l="Unit. price"}</h5></td> <td><h5 class="align-center">{intl l="Quantity"}</h5></td> <td style="background:#dddddd"><h5 style="color:#000044;" class="align-center">{intl l="Taxed total"}</h5></td> </tr> {loop type="order_product" name="order-products" order=$ID} {if $WAS_IN_PROMO == 1} {assign "realPrice" $PROMO_PRICE} {assign "realTotalPrice" $TOTAL_TAXED_PROMO_PRICE} {else} {assign "realPrice" $PRICE} {assign "realTotalPrice" $TOTAL_TAXED_PRICE} {/if} {$taxes[{$TAX_RULE_TITLE}][] = $realTax * $QUANTITY} <tr class="table-2"> <td> <p>{$TITLE} </p> {ifloop rel="combinations"} {loop type="order_product_attribute_combination" name="combinations" order_product=$ID} {$ATTRIBUTE_TITLE} - {$ATTRIBUTE_AVAILABILITY_TITLE}<br> {/loop} {/ifloop} {loop type="product" name="product-order" ref=$REF limit=1} {assign "productOrderId" $ID} {$productWeight=$productWeight+$WEIGHT} {$REF} {loop type="feature" name="order-features" order="alpha" product=$productOrderId} &nbsp;&nbsp;&nbsp;{$TITLE}: {loop type="feature_value" name="order-feature-value" feature=$ID product=$productOrderId limit=1} {$TITLE} {if $TITLE != ""} {$TITLE} {else} <span style="color:#CC0000;">ERREUR</span> {/if} {php} {/php} echo "well"; {/loop} {/loop} {/loop} </td> <td><p class="align-right">{format_money number=$realPrice currency_id=$CURRENCY}</p></td> <td><p class="align-center">{$QUANTITY}</p></td> <td><p class="align-right">{format_money number=$realTotalPrice currency_id=$CURRENCY}</p></td> </tr> {hook name="invoice.order-product" order="{$order_id}" order_product="{$ID}"} {/loop} {$packingWeight=$smarty.get.poids} {$totalWeight=($productWeight+$packingWeight)} <tr class="table-2"> <td><p>{intl l="Net weight"} {$productWeight} {intl l="Net weight kg"}<br />{intl l="Gross weight"} {$totalWeight} {intl l="Gross weight kg"}</p></td> <td><p class="align-right"></p></td> <td><p class="align-center"></p></td> <td><p class="align-right"></p></td> </tr> <tr class="table-2"> <td><p>{intl l="Incoterm"}<br /><br /><br />{intl l="Date"} {format_date date=$INVOICE_DATE output="date"}&emsp;&emsp;{intl l="Place"} {config key="store_city"}&emsp;&emsp;{intl l="Signature"}</p></td> <td><p class="align-right"></p></td> <td><p class="align-center"></p></td> <td><p class="align-right"></p></td> </tr> </table> {hook name="invoice.after-products" order=$order_id} <table cellspacing="0" cellpadding="0" style="padding-top: 5mm;"> <col style="width: 35%; padding: 1mm;" /> <col style="width: 25%; padding: 1mm;" /> <col style="width: 40%; padding: 1mm;" /> <tr> <td> <table cellspacing="0" cellpadding="0" style="padding-top: 2mm;"> <col style="width: 90%; padding: 1mm;" /> <tr> <td style="background:#eeeeee"><h5 style="color:#777777;">{intl l="Stamp"}</h5></td> </tr> </table> </td> <td class="table-3-module"> {loop name="statusorder" type="order" customer="*" id=$order_id} <h3>{intl l="Payment module"}</h3> <span>{loop name="payment-module" type="module" id=$PAYMENT_MODULE}{$TITLE}{/loop}</span> {hook name="invoice.after-payment-module" order=$order_id module_id=$PAYMENT_MODULE} <h3>{intl l="Delivery module"}</h3> <span>{loop name="delivery-module" type="module" id=$DELIVERY_MODULE}{$TITLE}{/loop}</span> {hook name="invoice.after-delivery-module" order=$order_id module_id=$DELIVERY_MODULE} <h3>{intl l="Order status"}</h3> <span>{intl l="Paid"}</span> {/loop} </td> <td> <table class="table-3"> <col style="width: 50%; padding: 1mm;"> <col style="width: 50%; padding: 1mm;"> {if $DISCOUNT} <tr> <td class="table-3-1"><p>{intl l="Discount"}</p></td> <td class="table-3-1 align-right"><p>{format_money number=$DISCOUNT currency_id=$CURRENCY}</p></td> </tr> {/if} <tr> <td class="table-3-1"><p>{intl l="Total without tax"}</p></td> <td class="table-3-1 align-right"><p>{format_money number={$TOTAL_AMOUNT - $POSTAGE_UNTAXED} currency_id=$CURRENCY}</p></td> </tr> <tr> <td class="table-3-1"><p>{intl l="Postage"}</p></td> <td class="table-3-1 align-right"><p>{format_money number=$POSTAGE currency_id=$CURRENCY}</p></td> </tr> <tr> <td class="table-3-1" style="background:#000044;"><h3 style="color:white;">{intl l="Total"}</h3></td> <td class="table-3-1 align-right" style="background:#000044;"><h3 style="color:white;">{format_money number=$TOTAL_TAXED_AMOUNT currency_id=$CURRENCY}</h3></td> </tr> </table> </td> </tr> <tr> <td></td><td></td><td></td> </tr> <tr> <td></td><td></td> <td> <table class="table-3"> <col style="width: 50%; padding: 1mm;"> <col style="width: 50%; padding: 1mm;"> <tr> <td class="table-3-1 align-left" style="clear:both; vertical-align:bottom;"><p>{intl l="Custom valor"}</p></td> <td class="table-3-1 align-right" style="vertical-align:top;"><p> {if $CURRENCY == 2} {format_money number=$TOTAL_TAXED_AMOUNT currency_id=2} {else} {loop type="currency" name="custom-currency" id=2} {format_money number=$TOTAL_TAXED_AMOUNT*$RATE currency_id=2} {/loop} {/if}</p> </td> </tr> </table> </td> </tr> </table> {hook name="invoice.after-summary" order=$order_id} {/loop} </page> ') in smarty_internal_templatecompilerbase.php line 283
    at Smarty_Internal_TemplateCompilerBase->compileTemplate(object(Smarty_Internal_Template)) in smarty_internal_template.php line 197
    at Smarty_Internal_Template->compileTemplateSource() in smarty_internal_templatebase.php line 155
    at Smarty_Internal_TemplateBase->fetch('file:invoice.html') in SmartyParser.php line 371
    at SmartyParser->internalRenderer('file', 'invoice.html', array('order_id' => '209', 'locale' => 'en_US', 'lang_code' => 'en', 'lang_id' => '2', 'edit_language_id' => '2', 'edit_language_locale' => 'en_US', 'edit_currency_id' => '1', 'current_url' => 'https://xxx.com/index_dev.php/admin/ord … ds=0%2C250'), true) in SmartyParser.php line 395
    at SmartyParser->render('invoice.html', array('order_id' => '209', 'locale' => 'en_US', 'lang_code' => 'en', 'lang_id' => '2', 'edit_language_id' => '2', 'edit_language_locale' => 'en_US', 'edit_currency_id' => '1', 'current_url' => 'https://xxx.com/index_dev.php/admin/ord … ds=0%2C250')) in BaseAdminController.php line 399
    at BaseAdminController->renderRaw('invoice', array('order_id' => '209'), object(TemplateDefinition)) in BaseController.php line 282
    at BaseController->generateOrderPdf('209', 'invoice', true, true, '1') in OrderController.php line 231
    at OrderController->generateBackOfficeOrderPdf('209', 'invoice', '1') in OrderController.php line 218
    at OrderController->generateInvoicePdf('209', '1')
    at call_user_func_array(array(object(OrderController), 'generateInvoicePdf'), array('209', '1')) in HttpKernel.php line 139
    at HttpKernel->handleRaw(object(Request), '1') in HttpKernel.php line 62
    at HttpKernel->handle(object(Request), '1', true) in TheliaHttpKernel.php line 76
    at TheliaHttpKernel->handle(object(Request), '1', true) in ParamInitMiddleware.php line 87
    at ParamInitMiddleware->handle(object(Request), '1', true) in SessionMiddleware.php line 80
    at SessionMiddleware->handle(object(Request), '1', true) in StackedHttpKernel.php line 23
    at StackedHttpKernel->handle(object(Request), '1', true) in Kernel.php line 185
    at Kernel->handle(object(Request)) in index_dev.php line 37

Last edited by fredodefrance (08-10-2017 22:20:33)


C'est en faisant qu'on apprends.

Offline


invoice.html ne supporte par smarty {php} {/php}

Depuis Smarty 3.1, ce tag n'est plus supporté: https://www.smarty.net/docs/en/language … on.php.tpl


OpenStudio Toulouse

Offline


Quelque fois ça fait du bien de relire la doc.
J'aurais du penser aux boucles conditionnelles.
http://doc.thelia.net/en/documentation/ … ional-loop


                    {assign "val" value=0}
                    {loop type="product" name="product-order" ref=$REF limit=1}
                        {assign "productOrderId" $ID}
                        {$productWeight=$productWeight+$WEIGHT}
                      {loop type="feature" name="order-features" order="alpha" product=$productOrderId}
                        {$TITLE}:
                        {ifloop rel="order-feature-value"}
                        {loop type="feature_value" name="order-feature-value" feature=$ID product=$productOrderId limit=1}
                          {$TITLE}
                        {/loop}
                        {/ifloop}
                        {elseloop rel="order-feature-value"}
                          <span style="color:#CC0000;">ERREUR</span>
                        {/elseloop}
                        {assign "val" value=$val+1}
                        {if $val ne 6}
                          &nbsp;-&nbsp;&nbsp;   
                        {/if}
                      {/loop}
                    {/loop}

Last edited by fredodefrance (09-10-2017 01:30:49)


C'est en faisant qu'on apprends.