Fix bugs and add Product prices export
modifié: core/lib/Thelia/Config/Resources/export.xml modifié: core/lib/Thelia/Controller/Admin/ImportController.php modifié: core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php modifié: core/lib/Thelia/Core/DependencyInjection/Loader/schema/dic/config/thelia-1.0.xsd nouveau fichier: core/lib/Thelia/ImportExport/Export/Type/ProductPricesExport.php modifié: core/lib/Thelia/Tests/Controller/ImportControllerTest.php
This commit is contained in:
@@ -9,6 +9,10 @@
|
||||
<title locale="en_US">Customers</title>
|
||||
<title locale="fr_FR">Clients</title>
|
||||
</export_category>
|
||||
<export_category id="thelia.export.products">
|
||||
<title locale="en_US">Products</title>
|
||||
<title locale="fr_FR">Produits</title>
|
||||
</export_category>
|
||||
</export_categories>
|
||||
|
||||
<exports>
|
||||
@@ -22,5 +26,16 @@
|
||||
<description>Export the last name, first name and email address of the customers and the newsletter subscribers</description>
|
||||
</export_descriptive>
|
||||
</export>
|
||||
|
||||
<export id="thelia.export.prices" class="Thelia\ImportExport\Export\Type\ProductPricesExport" category_id="thelia.export.products">
|
||||
<export_descriptive locale="fr_FR">
|
||||
<title>Prix des produits</title>
|
||||
<description>Expotez le prix de vos produits</description>
|
||||
</export_descriptive>
|
||||
<export_descriptive locale="en_US">
|
||||
<title>Product prices</title>
|
||||
<description>Export the prices of the products</description>
|
||||
</export_descriptive>
|
||||
</export>
|
||||
</exports>
|
||||
</config>
|
||||
|
||||
@@ -106,11 +106,14 @@ class ImportController extends BaseAdminController
|
||||
*/
|
||||
$archiveBuilder = $archiveBuilder->loadArchive($file->getPathname());
|
||||
|
||||
$content = $this->getFileContentInArchive(
|
||||
$contentAndFormat = $this->getFileContentInArchive(
|
||||
$archiveBuilder,
|
||||
$formatterManager,
|
||||
$tools["types"]
|
||||
);
|
||||
|
||||
$formatter = $contentAndFormat["formatter"];
|
||||
$content = $contentAndFormat["content"];
|
||||
} elseif ($formatter !== null) {
|
||||
/**
|
||||
* If the file isn't an archive
|
||||
@@ -195,7 +198,10 @@ class ImportController extends BaseAdminController
|
||||
);
|
||||
}
|
||||
|
||||
return $content;
|
||||
return array(
|
||||
"formatter" => $formatter,
|
||||
"content" => $content,
|
||||
);
|
||||
}
|
||||
|
||||
public function retrieveFormatTools(
|
||||
@@ -302,7 +308,7 @@ class ImportController extends BaseAdminController
|
||||
}
|
||||
|
||||
return $this->getTranslator()->trans(
|
||||
"Import successfully done, %numb row(s) have been imported",
|
||||
"Import successfully done, %numb row(s) have been changed",
|
||||
[
|
||||
"%numb" => $handler->getImportedRows(),
|
||||
]
|
||||
|
||||
@@ -365,12 +365,7 @@ class XmlFileLoader extends FileLoader
|
||||
|
||||
if (!class_exists($class)) {
|
||||
throw new \ErrorException(
|
||||
Translator::getInstance()->trans(
|
||||
"The class \"%class\" doesn't exist",
|
||||
[
|
||||
"%class" => $class
|
||||
]
|
||||
)
|
||||
"The class \"$class\" doesn't exist"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -378,13 +373,7 @@ class XmlFileLoader extends FileLoader
|
||||
|
||||
if (!$classInstance instanceof ExportHandler) {
|
||||
throw new \ErrorException(
|
||||
Translator::getInstance()->trans(
|
||||
"The class \"%class\" must extend %baseClass",
|
||||
[
|
||||
"%class" => $class,
|
||||
"%baseClass" => "Thelia\\ImportExport\\Export\\ExportHandler",
|
||||
]
|
||||
)
|
||||
"The class \"$class\" must extend Thelia\\ImportExport\\Export\\ExportHandler"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -392,12 +381,7 @@ class XmlFileLoader extends FileLoader
|
||||
|
||||
if (null === $category) {
|
||||
throw new \ErrorException(
|
||||
Translator::getInstance()->trans(
|
||||
"The export category \"%category\" doesn't exist",
|
||||
[
|
||||
"%category" => $categoryRef
|
||||
]
|
||||
)
|
||||
"The export category \"$categoryRef\" doesn't exist"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -518,12 +502,7 @@ class XmlFileLoader extends FileLoader
|
||||
|
||||
if (!class_exists($class)) {
|
||||
throw new \ErrorException(
|
||||
Translator::getInstance()->trans(
|
||||
"The class \"%class\" doesn't exist",
|
||||
[
|
||||
"%class" => $class
|
||||
]
|
||||
)
|
||||
"The class \"$class\" doesn't exist"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -531,13 +510,7 @@ class XmlFileLoader extends FileLoader
|
||||
|
||||
if (!$classInstance instanceof ImportHandler) {
|
||||
throw new \ErrorException(
|
||||
Translator::getInstance()->trans(
|
||||
"The class \"%class\" must extend %baseClass",
|
||||
[
|
||||
"%class" => $class,
|
||||
"%baseClass" => "Thelia\\ImportImport\\ImportHandler",
|
||||
]
|
||||
)
|
||||
"The class \"$class\" must extend Thelia\\ImportImport\\ImportHandler"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -545,12 +518,7 @@ class XmlFileLoader extends FileLoader
|
||||
|
||||
if (null === $category) {
|
||||
throw new \ErrorException(
|
||||
Translator::getInstance()->trans(
|
||||
"The import category \"%category\" doesn't exist",
|
||||
[
|
||||
"%category" => $categoryRef
|
||||
]
|
||||
)
|
||||
"The import category \"$categoryRef\" doesn't exist"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -227,7 +227,7 @@
|
||||
<xsd:element name="title" type="export_category_title" />
|
||||
</xsd:choice>
|
||||
|
||||
<xsd:attribute name="id" type="xsd:string" />
|
||||
<xsd:attribute name="id" use="required" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="export_category_title">
|
||||
@@ -274,7 +274,7 @@
|
||||
<xsd:element name="title" type="import_category_title" />
|
||||
</xsd:choice>
|
||||
|
||||
<xsd:attribute name="id" type="xsd:string" />
|
||||
<xsd:attribute name="id" use="required" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="import_category_title">
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
<?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\Formatting\FormatterData;
|
||||
use Thelia\Core\FileFormat\FormatType;
|
||||
use Thelia\ImportExport\Export\ExportHandler;
|
||||
use Thelia\Model\Base\ProductSaleElementsQuery;
|
||||
use Thelia\Model\Map\CurrencyTableMap;
|
||||
use Thelia\Model\Map\ProductPriceTableMap;
|
||||
use Thelia\Model\Map\ProductSaleElementsTableMap;
|
||||
|
||||
/**
|
||||
* Class ProductPricesExport
|
||||
* @package Thelia\ImportExport\Export\Type
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class ProductPricesExport 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,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Core\FileFormat\Formatting\FormatterData
|
||||
*
|
||||
* The method builds the FormatterData for the formatter
|
||||
*/
|
||||
public function buildFormatterData()
|
||||
{
|
||||
$aliases = [
|
||||
ProductSaleElementsTableMap::REF => "ref",
|
||||
"price_PRICE" => "price",
|
||||
"price_PROMO_PRICE" => "promo_price",
|
||||
"currency_CODE" => "currency",
|
||||
];
|
||||
|
||||
$query = ProductSaleElementsQuery::create()
|
||||
->useProductPriceQuery()
|
||||
->useCurrencyQuery()
|
||||
->addAsColumn("currency_CODE", CurrencyTableMap::CODE)
|
||||
->endUse()
|
||||
->addAsColumn("price_PRICE", ProductPriceTableMap::PRICE)
|
||||
->addAsColumn("price_PROMO_PRICE", ProductPriceTableMap::PROMO_PRICE)
|
||||
->endUse()
|
||||
->select([
|
||||
ProductSaleElementsTableMap::REF,
|
||||
"price_PRICE",
|
||||
"price_PROMO_PRICE",
|
||||
"currency_CODE",
|
||||
])
|
||||
;
|
||||
|
||||
$data = new FormatterData($aliases);
|
||||
|
||||
return $data->loadModelCriteria($query);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -83,7 +83,13 @@ class ImportControllerTrait extends ControllerTestBase
|
||||
[$formatter->getHandledType()]
|
||||
);
|
||||
|
||||
$this->assertEquals("foo", $content);
|
||||
$this->assertEquals(
|
||||
[
|
||||
"content" => "foo",
|
||||
"formatter" => $formatter
|
||||
],
|
||||
$content
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user