Add taxed prices export
modifié: core/lib/Thelia/Config/Resources/export.xml modifié: core/lib/Thelia/ImportExport/Export/Type/ProductPricesExport.php nouveau fichier: core/lib/Thelia/ImportExport/Export/Type/ProductTaxedPricesExport.php nouveau fichier: core/lib/Thelia/Tests/ImportExport/Export/ProductTaxedPricesExportTest.php
This commit is contained in:
@@ -17,6 +17,11 @@
|
|||||||
<title locale="en_US">Content</title>
|
<title locale="en_US">Content</title>
|
||||||
<title locale="fr_FR">Contenu</title>
|
<title locale="fr_FR">Contenu</title>
|
||||||
</export_category>
|
</export_category>
|
||||||
|
|
||||||
|
<export_category id="thelia.export.orders">
|
||||||
|
<title locale="en_US">Orders</title>
|
||||||
|
<title locale="fr_FR">Commandes</title>
|
||||||
|
</export_category>
|
||||||
</export_categories>
|
</export_categories>
|
||||||
|
|
||||||
<exports>
|
<exports>
|
||||||
@@ -53,6 +58,17 @@
|
|||||||
</export_descriptive>
|
</export_descriptive>
|
||||||
</export>
|
</export>
|
||||||
|
|
||||||
|
<export id="thelia.export.taxed_prices" class="Thelia\ImportExport\Export\Type\ProductTaxedPricesExport" category_id="thelia.export.products">
|
||||||
|
<export_descriptive locale="fr_FR">
|
||||||
|
<title>Prix des produits TTC</title>
|
||||||
|
<description>Expotez le prix TTC de vos produits</description>
|
||||||
|
</export_descriptive>
|
||||||
|
<export_descriptive locale="en_US">
|
||||||
|
<title>Product prices including taxes</title>
|
||||||
|
<description>Export the prices of the products including taxes</description>
|
||||||
|
</export_descriptive>
|
||||||
|
</export>
|
||||||
|
|
||||||
<export id="thelia.export.product_seo" class="Thelia\ImportExport\Export\Type\ProductSEOExport" category_id="thelia.export.products">
|
<export id="thelia.export.product_seo" class="Thelia\ImportExport\Export\Type\ProductSEOExport" category_id="thelia.export.products">
|
||||||
<export_descriptive locale="en_US">
|
<export_descriptive locale="en_US">
|
||||||
<title>Product SEO information</title>
|
<title>Product SEO information</title>
|
||||||
@@ -83,5 +99,20 @@
|
|||||||
</description>
|
</description>
|
||||||
</export_descriptive>
|
</export_descriptive>
|
||||||
</export>
|
</export>
|
||||||
|
|
||||||
|
<export id="thelia.export.orders" class="Thelia\ImportExport\Export\Type\OrderExport" category_id="thelia.export.orders">
|
||||||
|
<export_descriptive locale="en_US">
|
||||||
|
<title>Full orders</title>
|
||||||
|
<description>
|
||||||
|
Export your orders.
|
||||||
|
</description>
|
||||||
|
</export_descriptive>
|
||||||
|
<export_descriptive locale="fr_FR">
|
||||||
|
<title>Commandes complètes</title>
|
||||||
|
<description>
|
||||||
|
Exportez vos commandes
|
||||||
|
</description>
|
||||||
|
</export_descriptive>
|
||||||
|
</export>
|
||||||
</exports>
|
</exports>
|
||||||
</config>
|
</config>
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ class ProductPricesExport extends ExportHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Lang $lang
|
* @param Lang $lang
|
||||||
* @return FormatterData
|
* @return array|\Propel\Runtime\ActiveQuery\ModelCriteria|\Thelia\Core\Template\Element\BaseLoop
|
||||||
*/
|
*/
|
||||||
public function buildDataSet(Lang $lang)
|
public function buildDataSet(Lang $lang)
|
||||||
{
|
{
|
||||||
@@ -86,6 +86,7 @@ class ProductPricesExport extends ExportHandler
|
|||||||
\PDO::PARAM_STR
|
\PDO::PARAM_STR
|
||||||
)
|
)
|
||||||
->addAsColumn("product_TITLE", ProductI18nTableMap::TITLE)
|
->addAsColumn("product_TITLE", ProductI18nTableMap::TITLE)
|
||||||
|
->addAsColumn("product_ID", ProductTableMap::ID)
|
||||||
->endUse()
|
->endUse()
|
||||||
->addAsColumn("product_sale_elements_REF", ProductSaleElementsTableMap::REF)
|
->addAsColumn("product_sale_elements_REF", ProductSaleElementsTableMap::REF)
|
||||||
->addAsColumn("product_sale_elements_EAN_CODE", ProductSaleElementsTableMap::EAN_CODE)
|
->addAsColumn("product_sale_elements_EAN_CODE", ProductSaleElementsTableMap::EAN_CODE)
|
||||||
@@ -118,6 +119,21 @@ class ProductPricesExport extends ExportHandler
|
|||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getOrder()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
"product_id",
|
||||||
|
"ref",
|
||||||
|
"title",
|
||||||
|
"attributes",
|
||||||
|
"ean",
|
||||||
|
"price",
|
||||||
|
"promo_price",
|
||||||
|
"currency",
|
||||||
|
"promo",
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
protected function getAliases()
|
protected function getAliases()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
<?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 Propel\Runtime\ActiveQuery\Criteria;
|
||||||
|
use Propel\Runtime\ActiveQuery\Join;
|
||||||
|
use Thelia\Model\Country;
|
||||||
|
use Thelia\Model\CurrencyQuery;
|
||||||
|
use Thelia\Model\Lang;
|
||||||
|
use Thelia\Model\Map\AttributeCombinationTableMap;
|
||||||
|
use Thelia\Model\Map\CurrencyTableMap;
|
||||||
|
use Thelia\Model\Map\ProductSaleElementsTableMap;
|
||||||
|
use Thelia\Model\Map\ProductTableMap;
|
||||||
|
use Thelia\Model\Map\TaxRuleI18nTableMap;
|
||||||
|
use Thelia\Model\Map\TaxRuleTableMap;
|
||||||
|
use Thelia\Model\ProductSaleElementsQuery;
|
||||||
|
use Thelia\Model\TaxRuleQuery;
|
||||||
|
use Thelia\TaxEngine\Calculator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ProductTaxedPricesExport
|
||||||
|
* @package Thelia\ImportExport\Export\Type
|
||||||
|
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||||
|
*/
|
||||||
|
class ProductTaxedPricesExport extends ProductPricesExport
|
||||||
|
{
|
||||||
|
public function buildDataSet(Lang $lang)
|
||||||
|
{
|
||||||
|
/** @var \Thelia\Model\AttributeCombinationQuery $query */
|
||||||
|
$query = parent::buildDataSet($lang);
|
||||||
|
|
||||||
|
|
||||||
|
$pseJoin = new Join(AttributeCombinationTableMap::PRODUCT_SALE_ELEMENTS_ID, ProductSaleElementsTableMap::ID);
|
||||||
|
$pseJoin->setRightTableAlias("pse_tax_join");
|
||||||
|
|
||||||
|
$productJoin = new Join(ProductSaleElementsTableMap::ID, ProductTableMap::ID);
|
||||||
|
$productJoin->setRightTableAlias("product_tax_join");
|
||||||
|
|
||||||
|
$taxJoin = new Join("`product_tax_join`.TAX_RULE_ID", TaxRuleTableMap::ID, Criteria::LEFT_JOIN);
|
||||||
|
$taxI18nJoin = new Join(TaxRuleTableMap::ID, TaxRuleI18nTableMap::ID, Criteria::LEFT_JOIN);
|
||||||
|
|
||||||
|
$query
|
||||||
|
->addJoinObject($pseJoin, "pse_tax_join")
|
||||||
|
->addJoinObject($productJoin, "product_tax_join")
|
||||||
|
->addJoinObject($productJoin)
|
||||||
|
->addJoinObject($taxJoin)
|
||||||
|
->addJoinObject($taxI18nJoin)
|
||||||
|
->addAsColumn("product_TAX_TITLE", TaxRuleI18nTableMap::TITLE)
|
||||||
|
->addAsColumn("tax_ID", TaxRuleTableMap::ID)
|
||||||
|
->select($query->getSelect() + [
|
||||||
|
"product_TAX_TITLE",
|
||||||
|
"tax_ID",
|
||||||
|
])
|
||||||
|
;
|
||||||
|
|
||||||
|
$this->addI18nCondition(
|
||||||
|
$query,
|
||||||
|
TaxRuleI18nTableMap::TABLE_NAME,
|
||||||
|
TaxRuleTableMap::ID,
|
||||||
|
TaxRuleI18nTableMap::ID,
|
||||||
|
TaxRuleI18nTableMap::LOCALE,
|
||||||
|
$lang->getLocale()
|
||||||
|
);
|
||||||
|
|
||||||
|
$dataSet = $query
|
||||||
|
->keepQuery(true)
|
||||||
|
->find()
|
||||||
|
->toArray()
|
||||||
|
;
|
||||||
|
|
||||||
|
$productSaleElements = ProductSaleElementsQuery::create()
|
||||||
|
->find()
|
||||||
|
->toKeyIndex("Ref")
|
||||||
|
;
|
||||||
|
|
||||||
|
$currencies = CurrencyQuery::create()
|
||||||
|
->find()
|
||||||
|
->toKeyIndex("Code")
|
||||||
|
;
|
||||||
|
|
||||||
|
foreach ($dataSet as &$line) {
|
||||||
|
/** @var \Thelia\Model\ProductSaleElements $pse */
|
||||||
|
$pse = $productSaleElements[$line["product_sale_elements_REF"]];
|
||||||
|
|
||||||
|
$pricesTools = $pse->getPricesByCurrency($currencies[$line["currency_CODE"]]);
|
||||||
|
$line["price_PRICE"] = $pricesTools->getPrice();
|
||||||
|
$line["price_PROMO_PRICE"] = $pricesTools->getPromoPrice();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $dataSet;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?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\Tests\ImportExport\Export;
|
||||||
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
|
use Thelia\Core\Translation\Translator;
|
||||||
|
use Thelia\ImportExport\Export\Type\ProductTaxedPricesExport;
|
||||||
|
use Thelia\Model\CurrencyQuery;
|
||||||
|
use Thelia\Model\Lang;
|
||||||
|
use Thelia\Model\ProductSaleElementsQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ProductTaxedPricesExportTest
|
||||||
|
* @package Thelia\Tests\ImportExport\Export
|
||||||
|
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||||
|
*/
|
||||||
|
class ProductTaxedPricesExportTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testPrices()
|
||||||
|
{
|
||||||
|
$container = new Container();
|
||||||
|
new Translator($container);
|
||||||
|
|
||||||
|
$handler = new ProductTaxedPricesExport($container);
|
||||||
|
|
||||||
|
$lang = Lang::getDefaultLanguage();
|
||||||
|
$data = $handler->buildData($lang)->getData();
|
||||||
|
|
||||||
|
foreach ($data as $line) {
|
||||||
|
$product = ProductSaleElementsQuery::create()->findOneByRef($line["ref"]);
|
||||||
|
$currency = CurrencyQuery::create()->findOneByCode($line["currency"]);
|
||||||
|
|
||||||
|
$this->assertNotNull($product);
|
||||||
|
|
||||||
|
$prices = $product->getPricesByCurrency($currency);
|
||||||
|
|
||||||
|
$this->assertEquals($prices->getPrice(), $line["price"]);
|
||||||
|
$this->assertEquals($prices->getPromoPrice(), $line["promo_price"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user