Refactor ProductPriceImport -> ProductPricesImport

modifié:         core/lib/Thelia/Config/Resources/import.xml
	renommé:         core/lib/Thelia/ImportExport/Import/Type/ProductPriceImport.php -> core/lib/Thelia/ImportExport/Import/Type/ProductPricesImport.php
	modifié:         core/lib/Thelia/Tests/ImportExport/Import/ProductPriceImportTest.php
This commit is contained in:
Benjamin Perche
2014-07-21 14:53:19 +02:00
parent 0e3ae84cb8
commit a54ce50eb1
3 changed files with 44 additions and 42 deletions

View File

@@ -20,7 +20,7 @@
</import_descriptive> </import_descriptive>
</import> </import>
<import id="thelia.import.price" class="Thelia\ImportExport\Import\Type\ProductPriceImport" category_id="thelia.import.products"> <import id="thelia.import.price" class="Thelia\ImportExport\Import\Type\ProductPricesImport" category_id="thelia.import.products">
<import_descriptive locale="fr_FR"> <import_descriptive locale="fr_FR">
<title>Importez vos prix</title> <title>Importez vos prix</title>
</import_descriptive> </import_descriptive>

View File

@@ -22,11 +22,11 @@ use Thelia\Model\ProductPriceQuery;
use Thelia\Model\ProductSaleElementsQuery; use Thelia\Model\ProductSaleElementsQuery;
/** /**
* Class ProductPriceImport * Class ProductPricesImport
* @package Thelia\ImportExport\Import\Type * @package Thelia\ImportExport\Import\Type
* @author Benjamin Perche <bperche@openstudio.fr> * @author Benjamin Perche <bperche@openstudio.fr>
*/ */
class ProductPriceImport extends ImportHandler class ProductPricesImport extends ImportHandler
{ {
/** /**
* @return string|array * @return string|array
@@ -63,51 +63,53 @@ class ProductPriceImport extends ImportHandler
$translator = Translator::getInstance(); $translator = Translator::getInstance();
while (null !== $row = $data->popRow()) { while (null !== $row = $data->popRow()) {
$obj = ProductSaleElementsQuery::create()->findOneByRef($row["ref"]); if (count($row) > 1) {
$obj = ProductSaleElementsQuery::create()->findOneByRef($row["ref"]);
if ($obj === null) { if ($obj === null) {
$errorMessage = $translator->trans( $errorMessage = $translator->trans(
"The product sale element reference %ref doesn't exist", "The product sale element reference %ref doesn't exist",
[ [
"%ref" => $row["ref"] "%ref" => $row["ref"]
] ]
); );
$errors[] = $errorMessage ; $errors[] = $errorMessage ;
} else { } else {
$currency = null; $currency = null;
if (isset($row["currency"])) { if (isset($row["currency"])) {
$currency = CurrencyQuery::create()->findOneByCode($row["currency"]); $currency = CurrencyQuery::create()->findOneByCode($row["currency"]);
} }
if ($currency === null) { if ($currency === null) {
$currency = Currency::getDefaultCurrency(); $currency = Currency::getDefaultCurrency();
} }
$price = ProductPriceQuery::create() $price = ProductPriceQuery::create()
->filterByProductSaleElementsId($obj->getId()) ->filterByProductSaleElementsId($obj->getId())
->findOneByCurrencyId($currency->getId()) ->findOneByCurrencyId($currency->getId())
;
if ($price === null) {
$price = new ProductPrice();
$price
->setProductSaleElements($obj)
->setCurrency($currency)
; ;
if ($price === null) {
$price = new ProductPrice();
$price
->setProductSaleElements($obj)
->setCurrency($currency)
;
}
$price->setPrice($row["price"]);
if (isset($row["promo_price"])) {
$price->setPromoPrice($row["promo_price"]);
}
$price->save();
$this->importedRows++;
} }
$price->setPrice($row["price"]);
if (isset($row["promo_price"])) {
$price->setPromoPrice($row["promo_price"]);
}
$price->save();
$this->importedRows++;
} }
} }

View File

@@ -14,7 +14,7 @@ namespace Thelia\Tests\ImportExport\Import;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
use Thelia\Controller\Admin\ImportController; use Thelia\Controller\Admin\ImportController;
use Thelia\Core\FileFormat\Formatting\Formatter\JsonFormatter; use Thelia\Core\FileFormat\Formatting\Formatter\JsonFormatter;
use Thelia\ImportExport\Import\Type\ProductPriceImport; use Thelia\ImportExport\Import\Type\ProductPricesImport;
use Thelia\Model\Currency; use Thelia\Model\Currency;
use Thelia\Model\ProductSaleElementsQuery; use Thelia\Model\ProductSaleElementsQuery;
use Thelia\Tests\Controller\ControllerTestBase; use Thelia\Tests\Controller\ControllerTestBase;
@@ -49,7 +49,7 @@ class ProductPriceImportTest extends ControllerTestBase
{ {
parent::setUp(); parent::setUp();
$this->import = new ProductPriceImport($this->container); $this->import = new ProductPricesImport($this->container);
} }