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:
@@ -20,7 +20,7 @@
|
||||
</import_descriptive>
|
||||
</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">
|
||||
<title>Importez vos prix</title>
|
||||
</import_descriptive>
|
||||
|
||||
@@ -22,11 +22,11 @@ use Thelia\Model\ProductPriceQuery;
|
||||
use Thelia\Model\ProductSaleElementsQuery;
|
||||
|
||||
/**
|
||||
* Class ProductPriceImport
|
||||
* Class ProductPricesImport
|
||||
* @package Thelia\ImportExport\Import\Type
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user