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:
@@ -120,9 +120,9 @@ class ExportController extends BaseAdminController
|
||||
$formatter,
|
||||
$export->getHandleClassInstance($this->container),
|
||||
$archiveBuilder,
|
||||
$lang,
|
||||
$boundForm->get("images")->getData(),
|
||||
$boundForm->get("documents")->getData(),
|
||||
$lang
|
||||
$boundForm->get("documents")->getData()
|
||||
);
|
||||
|
||||
} catch (FormValidationException $e) {
|
||||
@@ -168,7 +168,11 @@ class ExportController extends BaseAdminController
|
||||
* Build an event containing the formatter and the handler.
|
||||
* 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);
|
||||
|
||||
$filename = $formatter::FILENAME . "." . $formatter->getExtension();
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\ImportExport\Export;
|
||||
use Thelia\Model\Lang;
|
||||
use Thelia\ImportExport\AbstractHandler;
|
||||
|
||||
/**
|
||||
@@ -21,10 +22,11 @@ use Thelia\ImportExport\AbstractHandler;
|
||||
abstract class ExportHandler extends AbstractHandler
|
||||
{
|
||||
/**
|
||||
* @param \Thelia\Model\Lang $lang
|
||||
* @return \Thelia\Core\FileFormat\Formatting\FormatterData
|
||||
*
|
||||
* The method builds the FormatterData for the formatter
|
||||
*/
|
||||
abstract public function buildFormatterData();
|
||||
abstract public function buildFormatterData(Lang $lang);
|
||||
|
||||
}
|
||||
@@ -11,13 +11,19 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\ImportExport\Export\Type;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Propel\Runtime\Propel;
|
||||
use Thelia\Core\FileFormat\Formatting\FormatterData;
|
||||
use Thelia\Core\FileFormat\FormatType;
|
||||
use Thelia\ImportExport\Export\ExportHandler;
|
||||
use Thelia\Model\Base\ProductSaleElementsQuery;
|
||||
use Thelia\Model\Lang;
|
||||
use Thelia\Model\Map\CurrencyTableMap;
|
||||
use Thelia\Model\Map\ProductI18nTableMap;
|
||||
use Thelia\Model\Map\ProductPriceTableMap;
|
||||
use Thelia\Model\Map\ProductSaleElementsTableMap;
|
||||
use Thelia\Model\ProductI18nQuery;
|
||||
use Thelia\Model\Tools\ModelCriteriaTools;
|
||||
|
||||
/**
|
||||
* Class ProductPricesExport
|
||||
@@ -50,19 +56,25 @@ class ProductPricesExport extends ExportHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Lang $lang
|
||||
* @return \Thelia\Core\FileFormat\Formatting\FormatterData
|
||||
*
|
||||
* The method builds the FormatterData for the formatter
|
||||
*/
|
||||
public function buildFormatterData()
|
||||
public function buildFormatterData(Lang $lang)
|
||||
{
|
||||
$aliases = [
|
||||
ProductSaleElementsTableMap::REF => "ref",
|
||||
ProductSaleElementsTableMap::EAN_CODE => "ean",
|
||||
"price_PRICE" => "price",
|
||||
"price_PROMO_PRICE" => "promo_price",
|
||||
"currency_CODE" => "currency",
|
||||
"product_TITLE" => "title",
|
||||
];
|
||||
|
||||
$locale = $this->real_escape($lang->getLocale());
|
||||
$defaultLocale = $this->real_escape(Lang::getDefaultLanguage()->getLocale());
|
||||
|
||||
$query = ProductSaleElementsQuery::create()
|
||||
->useProductPriceQuery()
|
||||
->useCurrencyQuery()
|
||||
@@ -71,12 +83,26 @@ class ProductPricesExport extends ExportHandler
|
||||
->addAsColumn("price_PRICE", ProductPriceTableMap::PRICE)
|
||||
->addAsColumn("price_PROMO_PRICE", ProductPriceTableMap::PROMO_PRICE)
|
||||
->endUse()
|
||||
->useProductQuery()
|
||||
->useProductI18nQuery(null, Criteria::LEFT_JOIN)
|
||||
->addAsColumn("product_TITLE", ProductI18nTableMap::TITLE)
|
||||
->endUse()
|
||||
->endUse()
|
||||
->select([
|
||||
ProductSaleElementsTableMap::REF,
|
||||
ProductSaleElementsTableMap::EAN_CODE,
|
||||
"price_PRICE",
|
||||
"price_PROMO_PRICE",
|
||||
"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);
|
||||
@@ -84,4 +110,19 @@ class ProductPricesExport extends ExportHandler
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user