diff --git a/core/lib/Thelia/Config/Resources/export.xml b/core/lib/Thelia/Config/Resources/export.xml
index 6c023d3d2..897d5a0f8 100644
--- a/core/lib/Thelia/Config/Resources/export.xml
+++ b/core/lib/Thelia/Config/Resources/export.xml
@@ -37,5 +37,21 @@
Export the prices of the products excluding taxes
+
+
+
+ Product SEO information
+
+ Export the SEO information ( rewritten url, meta description and keywords, page title ) of your products
+
+
+
+ Informations SEO des produits
+
+ Exportez les informations SEO de vos produits
+ ( url réécrites, meta description et mots clés, titre ) de vos produits
+
+
+
diff --git a/core/lib/Thelia/Controller/Admin/ExportController.php b/core/lib/Thelia/Controller/Admin/ExportController.php
index a1e53c66a..50aac7713 100644
--- a/core/lib/Thelia/Controller/Admin/ExportController.php
+++ b/core/lib/Thelia/Controller/Admin/ExportController.php
@@ -180,7 +180,10 @@ class ExportController extends BaseAdminController
if ($archiveBuilder === null) {
$this->dispatch(TheliaEvents::EXPORT_BEFORE_ENCODE, $event);
- $formattedContent = $formatter->encode($data);
+ $formattedContent = $formatter
+ ->setOrder($handler->getOrder())
+ ->encode($data)
+ ;
$this->dispatch(TheliaEvents::EXPORT_AFTER_ENCODE, $event->setContent($formattedContent));
@@ -197,7 +200,10 @@ class ExportController extends BaseAdminController
$event->setArchiveBuilder($archiveBuilder);
$this->dispatch(TheliaEvents::EXPORT_BEFORE_ENCODE, $event);
- $formattedContent = $formatter->encode($data);
+ $formattedContent = $formatter
+ ->setOrder($handler->getOrder())
+ ->encode($data)
+ ;
$this->dispatch(TheliaEvents::EXPORT_AFTER_ENCODE, $event->setContent($formattedContent));
diff --git a/core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php b/core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php
index 7ac923956..92d40aa11 100644
--- a/core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php
+++ b/core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php
@@ -30,10 +30,41 @@ abstract class AbstractFormatter implements FormatInterface, FormatterInterface
/** @var \Thelia\Log\Tlog */
protected $logger;
+ /** @var array */
+ protected $order;
+
public function __construct()
{
$this->translator = Translator::getInstance();
$this->logger = Tlog::getInstance();
}
+
+ public function getOrder()
+ {
+ return $this->order;
+ }
+
+ public function setOrder(array $order)
+ {
+ $this->order = $order;
+
+ return $this;
+ }
+
+ public function checkOrders(array $values)
+ {
+ foreach($this->order as $order) {
+ if (!array_key_exists($order, $values)) {
+ throw new \ErrorException(
+ $this->translator->trans(
+ "The column %column that you want to sort doesn't exist",
+ [
+ "%column" => $order
+ ]
+ )
+ );
+ }
+ }
+ }
}
diff --git a/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/CSVFormatter.php b/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/CSVFormatter.php
index 96b8ca4d7..fc526bb0f 100644
--- a/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/CSVFormatter.php
+++ b/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/CSVFormatter.php
@@ -77,10 +77,18 @@ class CSVFormatter extends AbstractFormatter
{
$string = "";
+ /**
+ * Get the first row and delimiters lengths
+ */
$firstRow = $data->getRow();
$delimiterLength = strlen($this->delimiter);
$lineReturnLength = strlen($this->lineReturn);
+ /**
+ * check if $this->order doesn't have non-existing rows
+ */
+ $this->checkOrders($firstRow);
+
if (false !== $firstRow) {
$rawKeys = array_keys($firstRow);
$keys = [];
@@ -93,20 +101,43 @@ class CSVFormatter extends AbstractFormatter
array_unshift($values, $keys);
while (null !== $row = array_shift($values)) {
- foreach ($keys as $key) {
- if (!is_scalar($row[$key])) {
- $row[$key] = serialize($row[$key]);
- }
+ /**
+ * First put the sorted ones
+ */
+ foreach ($this->order as $order) {
+ $string .= $this->formatField($row[$order]);
+ unset($row[$order]);
+ }
- $string .= $this->stringDelimiter . addslashes($row[$key]) . $this->stringDelimiter . $this->delimiter;
+ /**
+ * Then place the fields,
+ * order by name
+ */
+ ksort($row);
+
+ foreach ($keys as $key) {
+ $string .= $this->formatField($row[$key]);
}
$string = substr($string,0, -$delimiterLength) . $this->lineReturn;
}
+ } else {
+ $lineReturnLength = 0;
}
- return substr($string,0, -$lineReturnLength);
+ return substr($string, 0, -$lineReturnLength);
+ }
+
+ protected function formatField($value)
+ {
+ if($value === null) {
+ $value = "";
+ } else if (!is_scalar($value)) {
+ $value = serialize($value);
+ }
+
+ return $this->stringDelimiter . addslashes($value) . $this->stringDelimiter . $this->delimiter;
}
/**
diff --git a/core/lib/Thelia/ImportExport/Export/ExportHandler.php b/core/lib/Thelia/ImportExport/Export/ExportHandler.php
index 2a0be8579..54caa232b 100644
--- a/core/lib/Thelia/ImportExport/Export/ExportHandler.php
+++ b/core/lib/Thelia/ImportExport/Export/ExportHandler.php
@@ -11,8 +11,6 @@
/*************************************************************************************/
namespace Thelia\ImportExport\Export;
-use Propel\Runtime\ActiveQuery\Criteria;
-use Propel\Runtime\ActiveQuery\Join;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Thelia\Model\Lang;
use Thelia\ImportExport\AbstractHandler;
@@ -26,6 +24,9 @@ abstract class ExportHandler extends AbstractHandler
{
protected $locale;
+ /** @var array */
+ protected $order;
+
public function addI18nCondition(
ModelCriteria $query,
$i18nTableName,
@@ -80,6 +81,42 @@ abstract class ExportHandler extends AbstractHandler
return $return;
}
+ /**
+ * @return array
+ *
+ * You may override this method to return an array, containing
+ * the order that you want to have for your columns.
+ * The order appliance depends on the formatter
+ */
+ protected function getDefaultOrder()
+ {
+ return array();
+ }
+
+ /**
+ * @return array
+ *
+ * Use this method to access the order.
+ *
+ */
+ public function getOrder()
+ {
+ $order = $this->getDefaultOrder();
+
+ if (empty($order)) {
+ $order = $this->order;
+ }
+
+ return $order;
+ }
+
+ public function setOrder(array $order)
+ {
+ $this->order = $order;
+
+ return $this;
+ }
+
/**
* @param \Thelia\Model\Lang $lang
* @return \Thelia\Core\FileFormat\Formatting\FormatterData
diff --git a/core/lib/Thelia/ImportExport/Export/Type/ProductSEOExport.php b/core/lib/Thelia/ImportExport/Export/Type/ProductSEOExport.php
index 8113cc2a7..c5f1437cb 100644
--- a/core/lib/Thelia/ImportExport/Export/Type/ProductSEOExport.php
+++ b/core/lib/Thelia/ImportExport/Export/Type/ProductSEOExport.php
@@ -116,11 +116,24 @@ class ProductSEOExport extends ExportHandler
])
;
- $a = $query->toString();
-
$data = new FormatterData($aliases);
return $data->loadModelCriteria($query);
}
+ protected function getDefaultOrder()
+ {
+ return [
+ "ref",
+ "product_title",
+ "visible",
+ "url",
+ "content_title",
+ "meta_description",
+ "meta_keywords",
+ ];
+ }
+
+
+
}
\ No newline at end of file