Refactor i18n export methods
modifié: core/lib/Thelia/ImportExport/Export/ExportHandler.php modifié: core/lib/Thelia/ImportExport/Export/Type/MailingExport.php modifié: core/lib/Thelia/ImportExport/Export/Type/ProductPricesExport.php nouveau fichier: core/lib/Thelia/ImportExport/Export/Type/ProductSEOExport.php
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\ImportExport\Export;
|
||||
use Propel\Runtime\ActiveQuery\ModelCriteria;
|
||||
use Thelia\Model\Lang;
|
||||
use Thelia\ImportExport\AbstractHandler;
|
||||
|
||||
@@ -21,6 +22,59 @@ use Thelia\ImportExport\AbstractHandler;
|
||||
*/
|
||||
abstract class ExportHandler extends AbstractHandler
|
||||
{
|
||||
public function addI18nCondition(
|
||||
ModelCriteria $query,
|
||||
$i18nTableName,
|
||||
$tableIdColumn,
|
||||
$i18nIdColumn,
|
||||
$localeColumn,
|
||||
$locale
|
||||
) {
|
||||
|
||||
$locale = $this->real_escape($locale);
|
||||
$defaultLocale = $this->real_escape(Lang::getDefaultLanguage()->getLocale());
|
||||
|
||||
$query
|
||||
->_and()
|
||||
->where(
|
||||
"CASE WHEN ".$tableIdColumn." IN".
|
||||
"(SELECT DISTINCT ".$i18nIdColumn." ".
|
||||
"FROM `".$i18nTableName."` ".
|
||||
"WHERE locale=$locale) ".
|
||||
|
||||
"THEN ".$localeColumn." = $locale ".
|
||||
"ELSE ".$localeColumn." = $defaultLocale ".
|
||||
"END"
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $str
|
||||
* @return string
|
||||
*
|
||||
* Really escapes a string for SQL request.
|
||||
*/
|
||||
protected function real_escape($str)
|
||||
{
|
||||
$return = "CONCAT(";
|
||||
$len = strlen($str);
|
||||
|
||||
for($i = 0; $i < $len; ++$i) {
|
||||
$return .= "CHAR(".ord($str[$i])."),";
|
||||
}
|
||||
|
||||
if ($i > 0) {
|
||||
$return = substr($return, 0, -1);
|
||||
} else {
|
||||
$return = "\"\"";
|
||||
}
|
||||
$return .= ")";
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Thelia\Model\Lang $lang
|
||||
* @return \Thelia\Core\FileFormat\Formatting\FormatterData
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
namespace Thelia\ImportExport\Export\Type;
|
||||
use Thelia\Core\FileFormat\Formatting\FormatterData;
|
||||
use Thelia\Core\FileFormat\FormatType;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\ImportExport\Export\ExportHandler;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
use Thelia\Model\Lang;
|
||||
|
||||
@@ -74,8 +74,7 @@ class ProductPricesExport extends ExportHandler
|
||||
"product_sale_elements_PROMO" => "promo",
|
||||
];
|
||||
|
||||
$locale = $this->real_escape($lang->getLocale());
|
||||
$defaultLocale = $this->real_escape(Lang::getDefaultLanguage()->getLocale());
|
||||
$locale = $lang->getLocale();
|
||||
|
||||
$query = AttributeCombinationQuery::create()
|
||||
->useProductSaleElementsQuery()
|
||||
@@ -113,57 +112,30 @@ class ProductPricesExport extends ExportHandler
|
||||
"product_TITLE",
|
||||
"attribute_av_i18n_ATTRIBUTES",
|
||||
])
|
||||
->where(
|
||||
"CASE WHEN ".ProductTableMap::ID." IN".
|
||||
"(SELECT DISTINCT ".ProductI18nTableMap::ID." ".
|
||||
"FROM `".ProductI18nTableMap::TABLE_NAME."` ".
|
||||
"WHERE locale=$locale) ".
|
||||
|
||||
"THEN ".ProductI18nTableMap::LOCALE." = $locale ".
|
||||
"ELSE ".ProductI18nTableMap::LOCALE." = $defaultLocale ".
|
||||
"END"
|
||||
)
|
||||
->_and()
|
||||
->where(
|
||||
"CASE WHEN ".AttributeAvTableMap::ID." IN".
|
||||
"(SELECT DISTINCT ".AttributeAvI18nTableMap::ID." ".
|
||||
"FROM `".AttributeAvI18nTableMap::TABLE_NAME."` ".
|
||||
"WHERE locale=$locale)".
|
||||
"THEN ".AttributeAvI18nTableMap::LOCALE." = $locale ".
|
||||
"ELSE ".AttributeAvI18nTableMap::LOCALE." = $defaultLocale ".
|
||||
"END"
|
||||
)
|
||||
->groupBy("product_sale_elements_REF")
|
||||
;
|
||||
|
||||
$this->addI18nCondition(
|
||||
$query,
|
||||
ProductI18nTableMap::TABLE_NAME,
|
||||
ProductTableMap::ID,
|
||||
AttributeAvI18nTableMap::ID,
|
||||
ProductI18nTableMap::LOCALE,
|
||||
$locale
|
||||
);
|
||||
|
||||
$this->addI18nCondition(
|
||||
$query,
|
||||
AttributeAvI18nTableMap::TABLE_NAME,
|
||||
AttributeAvTableMap::ID,
|
||||
AttributeAvI18nTableMap::ID,
|
||||
AttributeAvI18nTableMap::LOCALE,
|
||||
$locale
|
||||
);
|
||||
|
||||
$data = new FormatterData($aliases);
|
||||
|
||||
return $data->loadModelCriteria($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $str
|
||||
* @return string
|
||||
*
|
||||
* Really escapes a string for SQL request.
|
||||
*/
|
||||
protected function real_escape($str)
|
||||
{
|
||||
$return = "CONCAT(";
|
||||
$len = strlen($str);
|
||||
|
||||
for($i = 0; $i < $len; ++$i) {
|
||||
$return .= "CHAR(".ord($str[$i])."),";
|
||||
}
|
||||
|
||||
if ($i > 0) {
|
||||
$return = substr($return, 0, -1);
|
||||
} else {
|
||||
$return = "\"\"";
|
||||
}
|
||||
$return .= ")";
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* 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. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\ImportExport\Export\Type;
|
||||
use Thelia\Core\FileFormat\FormatType;
|
||||
use Thelia\ImportExport\Export\ExportHandler;
|
||||
use Thelia\Model\Lang;
|
||||
|
||||
/**
|
||||
* Class ProductSEOExport
|
||||
* @package Thelia\ImportExport\Export\Type
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class ProductSEOExport extends ExportHandler
|
||||
{
|
||||
/**
|
||||
* @return string|array
|
||||
*
|
||||
* Define all the type of formatters that this can handle
|
||||
* return a string if it handle a single type ( specific exports ),
|
||||
* or an array if multiple.
|
||||
*
|
||||
* Thelia types are defined in \Thelia\Core\FileFormat\FormatType
|
||||
*
|
||||
* example:
|
||||
* return array(
|
||||
* FormatType::TABLE,
|
||||
* FormatType::UNBOUNDED,
|
||||
* );
|
||||
*/
|
||||
public function getHandledTypes()
|
||||
{
|
||||
return array(
|
||||
FormatType::TABLE,
|
||||
FormatType::UNBOUNDED,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Thelia\Model\Lang $lang
|
||||
* @return \Thelia\Core\FileFormat\Formatting\FormatterData
|
||||
*
|
||||
* The method builds the FormatterData for the formatter
|
||||
*/
|
||||
public function buildFormatterData(Lang $lang)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user