From 0e3ae84cb87469690f20dfccacf286c64ec1e10f Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Mon, 21 Jul 2014 14:43:51 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20bugs=20and=20add=20Product=20prices=20exp?= =?UTF-8?q?ort=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Theli?= =?UTF-8?q?a/Config/Resources/export.xml=20=09modifi=C3=A9:=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20core/lib/Thelia/Controller/Admin/ImportController.p?= =?UTF-8?q?hp=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia?= =?UTF-8?q?/Core/DependencyInjection/Loader/XmlFileLoader.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/Dependen?= =?UTF-8?q?cyInjection/Loader/schema/dic/config/thelia-1.0.xsd=20=09nouvea?= =?UTF-8?q?u=20fichier:=20core/lib/Thelia/ImportExport/Export/Type/Product?= =?UTF-8?q?PricesExport.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20c?= =?UTF-8?q?ore/lib/Thelia/Tests/Controller/ImportControllerTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Config/Resources/export.xml | 15 ++++ .../Controller/Admin/ImportController.php | 12 ++- .../Loader/XmlFileLoader.php | 44 ++-------- .../Loader/schema/dic/config/thelia-1.0.xsd | 4 +- .../Export/Type/ProductPricesExport.php | 87 +++++++++++++++++++ .../Tests/Controller/ImportControllerTest.php | 8 +- 6 files changed, 126 insertions(+), 44 deletions(-) create mode 100644 core/lib/Thelia/ImportExport/Export/Type/ProductPricesExport.php diff --git a/core/lib/Thelia/Config/Resources/export.xml b/core/lib/Thelia/Config/Resources/export.xml index 890f11199..0b7da011a 100644 --- a/core/lib/Thelia/Config/Resources/export.xml +++ b/core/lib/Thelia/Config/Resources/export.xml @@ -9,6 +9,10 @@ Customers Clients + + Products + Produits + @@ -22,5 +26,16 @@ Export the last name, first name and email address of the customers and the newsletter subscribers + + + + Prix des produits + Expotez le prix de vos produits + + + Product prices + Export the prices of the products + + diff --git a/core/lib/Thelia/Controller/Admin/ImportController.php b/core/lib/Thelia/Controller/Admin/ImportController.php index f4fa11f28..2846d6854 100644 --- a/core/lib/Thelia/Controller/Admin/ImportController.php +++ b/core/lib/Thelia/Controller/Admin/ImportController.php @@ -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(), ] diff --git a/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php b/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php index f00c14193..5d1613c72 100644 --- a/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php +++ b/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php @@ -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" ); } diff --git a/core/lib/Thelia/Core/DependencyInjection/Loader/schema/dic/config/thelia-1.0.xsd b/core/lib/Thelia/Core/DependencyInjection/Loader/schema/dic/config/thelia-1.0.xsd index 91817058e..5dfb98aea 100644 --- a/core/lib/Thelia/Core/DependencyInjection/Loader/schema/dic/config/thelia-1.0.xsd +++ b/core/lib/Thelia/Core/DependencyInjection/Loader/schema/dic/config/thelia-1.0.xsd @@ -227,7 +227,7 @@ - + @@ -274,7 +274,7 @@ - + diff --git a/core/lib/Thelia/ImportExport/Export/Type/ProductPricesExport.php b/core/lib/Thelia/ImportExport/Export/Type/ProductPricesExport.php new file mode 100644 index 000000000..03a248d5d --- /dev/null +++ b/core/lib/Thelia/ImportExport/Export/Type/ProductPricesExport.php @@ -0,0 +1,87 @@ + + */ +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); + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/Controller/ImportControllerTest.php b/core/lib/Thelia/Tests/Controller/ImportControllerTest.php index ff645b6a2..d6ae59ed8 100644 --- a/core/lib/Thelia/Tests/Controller/ImportControllerTest.php +++ b/core/lib/Thelia/Tests/Controller/ImportControllerTest.php @@ -83,7 +83,13 @@ class ImportControllerTrait extends ControllerTestBase [$formatter->getHandledType()] ); - $this->assertEquals("foo", $content); + $this->assertEquals( + [ + "content" => "foo", + "formatter" => $formatter + ], + $content + ); } /**