// PDF override

This commit is contained in:
fBrignoli
2012-03-28 15:28:29 +00:00
parent 20d848e74b
commit a20e175495
7 changed files with 45 additions and 49 deletions
+15 -13
View File
@@ -184,24 +184,26 @@ class TranslateCore
global $_LANGPDF; global $_LANGPDF;
$iso = Context::getContext()->language->iso_code; $iso = Context::getContext()->language->iso_code;
if (!Validate::isLanguageIsoCode($iso))
throw PrestaShopException('Invalid iso lang!');
$filename = _PS_THEME_DIR_.'pdf/lang/'.$iso.'.php'; if (!Validate::isLangIsoCode($iso))
Tools::displayError(sprintf('Invalid iso lang (%s)', Tools::safeOutput($iso)));
if (Tools::file_exists_cache($filename)) $override_i18n_file = _PS_THEME_DIR_.'pdf/lang/'.$iso.'.php';
@include_once($filename); $i18n_file = _PS_TRANSLATIONS_DIR_.$iso.'/pdf.php';
if (file_exists($override_i18n_file))
$i18n_file = $override_i18n_file;
$key = 'PDF'.md5($string); if (!include($i18n_file))
$lang_array = $_LANGPDF; Tools::displayError(sprintf('Cannot include PDF translation language file : %s', $i18n_file));
$msg = $string; if (!isset($_LANGPDF) || !is_array($_LANGPDF))
if (is_array($lang_array) && key_exists($key, $lang_array)) return str_replace('"', '"', $string);
$msg = $lang_array[$key];
elseif (is_array($lang_array) && key_exists(Tools::strtolower($key), $lang_array))
$msg = $lang_array[Tools::strtolower($key)];
return $msg; $key = md5(str_replace('\'', '\\\'', $string));
$str = (key_exists('PDF'.$key, $_LANGPDF) ? $_LANGPDF['PDF'.$key] : $string);
return $str;
} }
} }
+1 -21
View File
@@ -177,27 +177,7 @@ abstract class HTMLTemplateCore
*/ */
protected static function l($string) protected static function l($string)
{ {
$iso = Context::getContext()->language->iso_code; return Translate::getPdfTranslation($string);
if (!Validate::isLangIsoCode($iso))
Tools::displayError(sprintf('Invalid iso lang (%s)', Tools::safeOutput($iso)));
$override_i18n_file = _PS_THEME_DIR_.'pdf/lang/'.$iso.'.php';
$i18n_file = _PS_TRANSLATIONS_DIR_.$iso.'/pdf.php';
if (file_exists($override_i18n_file))
$i18n_file = $override_i18n_file;
if (!include($i18n_file))
Tools::displayError(sprintf('Cannot include PDF translation language file : %s', $i18n_file));
if (!isset($_LANGPDF) || !is_array($_LANGPDF))
return str_replace('"', '"', $string);
$key = md5(str_replace('\'', '\\\'', $string));
$str = (key_exists('PDF'.$key, $_LANGPDF) ? $_LANGPDF['PDF'.$key] : $string);
return $str;
} }
} }
+1 -1
View File
@@ -70,7 +70,7 @@ class HTMLTemplateDeliverySlipCore extends HTMLTemplate
'order_invoice' => $this->order_invoice 'order_invoice' => $this->order_invoice
)); ));
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/delivery-slip.tpl'); return $this->smarty->fetch($this->getTemplate('delivery-slip'));
} }
/** /**
+2 -1
View File
@@ -71,7 +71,7 @@ class HTMLTemplateOrderReturnCore extends HTMLTemplate
'invoice_address' => $formatted_invoice_address, 'invoice_address' => $formatted_invoice_address,
'shop_address' => AddressFormat::generateAddress($this->address, array(), '<br />', ' ') 'shop_address' => AddressFormat::generateAddress($this->address, array(), '<br />', ' ')
)); ));
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/order-return.tpl'); return $this->smarty->fetch($this->getTemplate('order-return'));
} }
/** /**
@@ -92,3 +92,4 @@ class HTMLTemplateOrderReturnCore extends HTMLTemplate
return 'invoices.pdf'; return 'invoices.pdf';
} }
} }
+3 -2
View File
@@ -110,7 +110,7 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice
'tax_tab' => '', 'tax_tab' => '',
)); ));
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/order-slip.tpl'); return $this->smarty->fetch($this->getTemplate('order-slip'));
} }
/** /**
@@ -130,4 +130,5 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice
{ {
return 'order-slip-'.sprintf('%06d', $this->order_slip->id).'.pdf'; return 'order-slip-'.sprintf('%06d', $this->order_slip->id).'.pdf';
} }
} }
+5 -3
View File
@@ -72,7 +72,8 @@ class HTMLTemplateSupplyOrderFormCore extends HTMLTemplate
'tax_order_summary' => $tax_order_summary, 'tax_order_summary' => $tax_order_summary,
'currency' => $currency, 'currency' => $currency,
)); ));
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/supply-order.tpl');
return $this->smarty->fetch($this->getTemplate('supply-order'));
} }
/** /**
@@ -135,7 +136,7 @@ class HTMLTemplateSupplyOrderFormCore extends HTMLTemplate
'shop_name' => $shop_name 'shop_name' => $shop_name
)); ));
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/supply-order-header.tpl'); return $this->smarty->fetch($this->getTemplate('supply-order-header'));
} }
/** /**
@@ -155,7 +156,7 @@ class HTMLTemplateSupplyOrderFormCore extends HTMLTemplate
'shop_details' => Configuration::get('PS_SHOP_DETAILS'), 'shop_details' => Configuration::get('PS_SHOP_DETAILS'),
'free_text' => $free_text, 'free_text' => $free_text,
)); ));
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/supply-order-footer.tpl'); return $this->smarty->fetch($this->getTemplate('supply-order-footer'));
} }
/** /**
@@ -188,3 +189,4 @@ class HTMLTemplateSupplyOrderFormCore extends HTMLTemplate
$supply_order->total_ti = Tools::ps_round($supply_order->total_ti, 2); $supply_order->total_ti = Tools::ps_round($supply_order->total_ti, 2);
} }
} }
+18 -8
View File
@@ -260,16 +260,26 @@ class AdminInvoicesControllerCore extends AdminController
'name' => 'invoice' 'name' => 'invoice'
) )
); );
$d = dir(_PS_THEME_DIR_.'/pdf/');
while (false !== ($entry = $d->read())) $templates_override = $this->getInvoicesModelsFromDir(_PS_THEME_DIR_.'pdf/');
$templates_default = $this->getInvoicesModelsFromDir(_PS_PDF_DIR_);
foreach (array_merge($templates_default, $templates_override) as $template)
{ {
if (preg_match('`^(invoice-[a-z0-9]+)\.tpl$`', $entry, $matches)) $template_name = basename($template, '.tpl');
$models[] = array( $models[] = array('value' => $template_name, 'name' => $template_name);
'value' => $matches[1],
'name' => $matches[1]
);
} }
$d->close();
return $models; return $models;
} }
protected function getInvoicesModelsFromDir($directory)
{
$templates = array();
if (is_dir($directory))
$templates = glob($directory.'invoice-*.tpl');
return $templates;
}
} }