Fix export controller and add ean in export prices

modifié:         core/lib/Thelia/Controller/Admin/ExportController.php
	modifié:         core/lib/Thelia/ImportExport/Export/ExportHandler.php
	modifié:         core/lib/Thelia/ImportExport/Export/Type/ProductPricesExport.php
This commit is contained in:
Benjamin Perche
2014-07-22 11:08:13 +02:00
parent abde3799d5
commit ad3c1ce387
3 changed files with 52 additions and 5 deletions

View File

@@ -120,9 +120,9 @@ class ExportController extends BaseAdminController
$formatter, $formatter,
$export->getHandleClassInstance($this->container), $export->getHandleClassInstance($this->container),
$archiveBuilder, $archiveBuilder,
$lang,
$boundForm->get("images")->getData(), $boundForm->get("images")->getData(),
$boundForm->get("documents")->getData(), $boundForm->get("documents")->getData()
$lang
); );
} catch (FormValidationException $e) { } catch (FormValidationException $e) {
@@ -168,7 +168,11 @@ class ExportController extends BaseAdminController
* Build an event containing the formatter and the handler. * Build an event containing the formatter and the handler.
* Used for specific configuration (e.g: XML node names) * Used for specific configuration (e.g: XML node names)
*/ */
$data = $handler->buildFormatterData()->setLang($lang); $data = $handler
->buildFormatterData($lang)
->setLang($lang)
;
$event = new ImportExportEvent($formatter, $handler , $data); $event = new ImportExportEvent($formatter, $handler , $data);
$filename = $formatter::FILENAME . "." . $formatter->getExtension(); $filename = $formatter::FILENAME . "." . $formatter->getExtension();

View File

@@ -11,6 +11,7 @@
/*************************************************************************************/ /*************************************************************************************/
namespace Thelia\ImportExport\Export; namespace Thelia\ImportExport\Export;
use Thelia\Model\Lang;
use Thelia\ImportExport\AbstractHandler; use Thelia\ImportExport\AbstractHandler;
/** /**
@@ -21,10 +22,11 @@ use Thelia\ImportExport\AbstractHandler;
abstract class ExportHandler extends AbstractHandler abstract class ExportHandler extends AbstractHandler
{ {
/** /**
* @param \Thelia\Model\Lang $lang
* @return \Thelia\Core\FileFormat\Formatting\FormatterData * @return \Thelia\Core\FileFormat\Formatting\FormatterData
* *
* The method builds the FormatterData for the formatter * The method builds the FormatterData for the formatter
*/ */
abstract public function buildFormatterData(); abstract public function buildFormatterData(Lang $lang);
} }

View File

@@ -11,13 +11,19 @@
/*************************************************************************************/ /*************************************************************************************/
namespace Thelia\ImportExport\Export\Type; namespace Thelia\ImportExport\Export\Type;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Propel;
use Thelia\Core\FileFormat\Formatting\FormatterData; use Thelia\Core\FileFormat\Formatting\FormatterData;
use Thelia\Core\FileFormat\FormatType; use Thelia\Core\FileFormat\FormatType;
use Thelia\ImportExport\Export\ExportHandler; use Thelia\ImportExport\Export\ExportHandler;
use Thelia\Model\Base\ProductSaleElementsQuery; use Thelia\Model\Base\ProductSaleElementsQuery;
use Thelia\Model\Lang;
use Thelia\Model\Map\CurrencyTableMap; use Thelia\Model\Map\CurrencyTableMap;
use Thelia\Model\Map\ProductI18nTableMap;
use Thelia\Model\Map\ProductPriceTableMap; use Thelia\Model\Map\ProductPriceTableMap;
use Thelia\Model\Map\ProductSaleElementsTableMap; use Thelia\Model\Map\ProductSaleElementsTableMap;
use Thelia\Model\ProductI18nQuery;
use Thelia\Model\Tools\ModelCriteriaTools;
/** /**
* Class ProductPricesExport * Class ProductPricesExport
@@ -50,19 +56,25 @@ class ProductPricesExport extends ExportHandler
} }
/** /**
* @param Lang $lang
* @return \Thelia\Core\FileFormat\Formatting\FormatterData * @return \Thelia\Core\FileFormat\Formatting\FormatterData
* *
* The method builds the FormatterData for the formatter * The method builds the FormatterData for the formatter
*/ */
public function buildFormatterData() public function buildFormatterData(Lang $lang)
{ {
$aliases = [ $aliases = [
ProductSaleElementsTableMap::REF => "ref", ProductSaleElementsTableMap::REF => "ref",
ProductSaleElementsTableMap::EAN_CODE => "ean",
"price_PRICE" => "price", "price_PRICE" => "price",
"price_PROMO_PRICE" => "promo_price", "price_PROMO_PRICE" => "promo_price",
"currency_CODE" => "currency", "currency_CODE" => "currency",
"product_TITLE" => "title",
]; ];
$locale = $this->real_escape($lang->getLocale());
$defaultLocale = $this->real_escape(Lang::getDefaultLanguage()->getLocale());
$query = ProductSaleElementsQuery::create() $query = ProductSaleElementsQuery::create()
->useProductPriceQuery() ->useProductPriceQuery()
->useCurrencyQuery() ->useCurrencyQuery()
@@ -71,12 +83,26 @@ class ProductPricesExport extends ExportHandler
->addAsColumn("price_PRICE", ProductPriceTableMap::PRICE) ->addAsColumn("price_PRICE", ProductPriceTableMap::PRICE)
->addAsColumn("price_PROMO_PRICE", ProductPriceTableMap::PROMO_PRICE) ->addAsColumn("price_PROMO_PRICE", ProductPriceTableMap::PROMO_PRICE)
->endUse() ->endUse()
->useProductQuery()
->useProductI18nQuery(null, Criteria::LEFT_JOIN)
->addAsColumn("product_TITLE", ProductI18nTableMap::TITLE)
->endUse()
->endUse()
->select([ ->select([
ProductSaleElementsTableMap::REF, ProductSaleElementsTableMap::REF,
ProductSaleElementsTableMap::EAN_CODE,
"price_PRICE", "price_PRICE",
"price_PROMO_PRICE", "price_PROMO_PRICE",
"currency_CODE", "currency_CODE",
"product_TITLE"
]) ])
->where(
"CASE WHEN `product`.ID IN".
"(SELECT DISTINCT id FROM product_i18n WHERE locale=$locale)".
"THEN product_i18n.locale = $locale ".
"ELSE product_i18n.locale = $defaultLocale ".
"END"
)
; ;
$data = new FormatterData($aliases); $data = new FormatterData($aliases);
@@ -84,4 +110,19 @@ class ProductPricesExport extends ExportHandler
return $data->loadModelCriteria($query); return $data->loadModelCriteria($query);
} }
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);
}
$return .= ")";
return $return;
}
} }