diff --git a/core/lib/Thelia/Config/Resources/import.xml b/core/lib/Thelia/Config/Resources/import.xml index 2e775cef7..bf52deddb 100644 --- a/core/lib/Thelia/Config/Resources/import.xml +++ b/core/lib/Thelia/Config/Resources/import.xml @@ -20,7 +20,7 @@ - + Importez vos prix diff --git a/core/lib/Thelia/ImportExport/Import/Type/ProductPriceImport.php b/core/lib/Thelia/ImportExport/Import/Type/ProductPricesImport.php similarity index 59% rename from core/lib/Thelia/ImportExport/Import/Type/ProductPriceImport.php rename to core/lib/Thelia/ImportExport/Import/Type/ProductPricesImport.php index 09b04f13e..ea056fa9d 100644 --- a/core/lib/Thelia/ImportExport/Import/Type/ProductPriceImport.php +++ b/core/lib/Thelia/ImportExport/Import/Type/ProductPricesImport.php @@ -22,11 +22,11 @@ use Thelia\Model\ProductPriceQuery; use Thelia\Model\ProductSaleElementsQuery; /** - * Class ProductPriceImport + * Class ProductPricesImport * @package Thelia\ImportExport\Import\Type * @author Benjamin Perche */ -class ProductPriceImport extends ImportHandler +class ProductPricesImport extends ImportHandler { /** * @return string|array @@ -63,51 +63,53 @@ class ProductPriceImport extends ImportHandler $translator = Translator::getInstance(); while (null !== $row = $data->popRow()) { - $obj = ProductSaleElementsQuery::create()->findOneByRef($row["ref"]); + if (count($row) > 1) { + $obj = ProductSaleElementsQuery::create()->findOneByRef($row["ref"]); - if ($obj === null) { - $errorMessage = $translator->trans( - "The product sale element reference %ref doesn't exist", - [ - "%ref" => $row["ref"] - ] - ); + if ($obj === null) { + $errorMessage = $translator->trans( + "The product sale element reference %ref doesn't exist", + [ + "%ref" => $row["ref"] + ] + ); - $errors[] = $errorMessage ; - } else { + $errors[] = $errorMessage ; + } else { - $currency = null; + $currency = null; - if (isset($row["currency"])) { - $currency = CurrencyQuery::create()->findOneByCode($row["currency"]); - } + if (isset($row["currency"])) { + $currency = CurrencyQuery::create()->findOneByCode($row["currency"]); + } - if ($currency === null) { - $currency = Currency::getDefaultCurrency(); - } + if ($currency === null) { + $currency = Currency::getDefaultCurrency(); + } - $price = ProductPriceQuery::create() - ->filterByProductSaleElementsId($obj->getId()) - ->findOneByCurrencyId($currency->getId()) - ; - - if ($price === null) { - $price = new ProductPrice(); - - $price - ->setProductSaleElements($obj) - ->setCurrency($currency) + $price = ProductPriceQuery::create() + ->filterByProductSaleElementsId($obj->getId()) + ->findOneByCurrencyId($currency->getId()) ; + + 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++; } } diff --git a/core/lib/Thelia/Tests/ImportExport/Import/ProductPriceImportTest.php b/core/lib/Thelia/Tests/ImportExport/Import/ProductPriceImportTest.php index 83d8f6683..1a6adbbf5 100644 --- a/core/lib/Thelia/Tests/ImportExport/Import/ProductPriceImportTest.php +++ b/core/lib/Thelia/Tests/ImportExport/Import/ProductPriceImportTest.php @@ -14,7 +14,7 @@ namespace Thelia\Tests\ImportExport\Import; use Symfony\Component\DependencyInjection\ContainerBuilder; use Thelia\Controller\Admin\ImportController; 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\ProductSaleElementsQuery; use Thelia\Tests\Controller\ControllerTestBase; @@ -49,7 +49,7 @@ class ProductPriceImportTest extends ControllerTestBase { parent::setUp(); - $this->import = new ProductPriceImport($this->container); + $this->import = new ProductPricesImport($this->container); }