Fix join to get translation in export
modifié: core/lib/Thelia/ImportExport/Export/ExportHandler.php modifié: core/lib/Thelia/ImportExport/Export/Type/ProductPricesExport.php modifié: core/lib/Thelia/ImportExport/Export/Type/ProductSEOExport.php nouveau fichier: core/lib/Thelia/Tests/ImportExport/Export/ProductSEOExportTest.php
This commit is contained in:
@@ -11,6 +11,8 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
|
||||||
namespace Thelia\ImportExport\Export;
|
namespace Thelia\ImportExport\Export;
|
||||||
|
use Propel\Runtime\ActiveQuery\Criteria;
|
||||||
|
use Propel\Runtime\ActiveQuery\Join;
|
||||||
use Propel\Runtime\ActiveQuery\ModelCriteria;
|
use Propel\Runtime\ActiveQuery\ModelCriteria;
|
||||||
use Thelia\Model\Lang;
|
use Thelia\Model\Lang;
|
||||||
use Thelia\ImportExport\AbstractHandler;
|
use Thelia\ImportExport\AbstractHandler;
|
||||||
@@ -22,6 +24,8 @@ use Thelia\ImportExport\AbstractHandler;
|
|||||||
*/
|
*/
|
||||||
abstract class ExportHandler extends AbstractHandler
|
abstract class ExportHandler extends AbstractHandler
|
||||||
{
|
{
|
||||||
|
protected $locale;
|
||||||
|
|
||||||
public function addI18nCondition(
|
public function addI18nCondition(
|
||||||
ModelCriteria $query,
|
ModelCriteria $query,
|
||||||
$i18nTableName,
|
$i18nTableName,
|
||||||
@@ -49,7 +53,6 @@ abstract class ExportHandler extends AbstractHandler
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $str
|
* @param $str
|
||||||
* @return string
|
* @return string
|
||||||
@@ -58,6 +61,8 @@ abstract class ExportHandler extends AbstractHandler
|
|||||||
*/
|
*/
|
||||||
protected function real_escape($str)
|
protected function real_escape($str)
|
||||||
{
|
{
|
||||||
|
$str = trim($str, "\"'");
|
||||||
|
|
||||||
$return = "CONCAT(";
|
$return = "CONCAT(";
|
||||||
$len = strlen($str);
|
$len = strlen($str);
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
namespace Thelia\ImportExport\Export\Type;
|
namespace Thelia\ImportExport\Export\Type;
|
||||||
use Propel\Runtime\ActiveQuery\Criteria;
|
use Propel\Runtime\ActiveQuery\Criteria;
|
||||||
|
use Propel\Runtime\ActiveQuery\Join;
|
||||||
use Thelia\Core\FileFormat\Formatting\FormatterData;
|
use Thelia\Core\FileFormat\Formatting\FormatterData;
|
||||||
use Thelia\Core\FileFormat\FormatType;
|
use Thelia\Core\FileFormat\FormatType;
|
||||||
use Thelia\ImportExport\Export\ExportHandler;
|
use Thelia\ImportExport\Export\ExportHandler;
|
||||||
@@ -76,6 +77,9 @@ class ProductPricesExport extends ExportHandler
|
|||||||
|
|
||||||
$locale = $lang->getLocale();
|
$locale = $lang->getLocale();
|
||||||
|
|
||||||
|
$productJoin = new Join(ProductTableMap::ID, ProductI18nTableMap::ID, Criteria::LEFT_JOIN);
|
||||||
|
$attributeAvJoin = new Join(AttributeAvTableMap::ID, AttributeAvI18nTableMap::ID, Criteria::LEFT_JOIN);
|
||||||
|
|
||||||
$query = AttributeCombinationQuery::create()
|
$query = AttributeCombinationQuery::create()
|
||||||
->useProductSaleElementsQuery()
|
->useProductSaleElementsQuery()
|
||||||
->useProductPriceQuery()
|
->useProductPriceQuery()
|
||||||
@@ -86,22 +90,25 @@ class ProductPricesExport extends ExportHandler
|
|||||||
->addAsColumn("price_PROMO_PRICE", ProductPriceTableMap::PROMO_PRICE)
|
->addAsColumn("price_PROMO_PRICE", ProductPriceTableMap::PROMO_PRICE)
|
||||||
->endUse()
|
->endUse()
|
||||||
->useProductQuery()
|
->useProductQuery()
|
||||||
->useProductI18nQuery()
|
->addJoinObject($productJoin, "product_join")
|
||||||
|
->addJoinCondition("product_join", ProductI18nTableMap::LOCALE . "=" . $this->real_escape($locale))
|
||||||
->addAsColumn("product_TITLE", ProductI18nTableMap::TITLE)
|
->addAsColumn("product_TITLE", ProductI18nTableMap::TITLE)
|
||||||
->endUse()
|
->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)
|
||||||
->addAsColumn("product_sale_elements_PROMO", ProductSaleElementsTableMap::PROMO)
|
->addAsColumn("product_sale_elements_PROMO", ProductSaleElementsTableMap::PROMO)
|
||||||
->endUse()
|
->endUse()
|
||||||
->useAttributeAvQuery()
|
->useAttributeAvQuery()
|
||||||
->useAttributeAvI18nQuery(null, Criteria::INNER_JOIN)
|
->addJoinObject($attributeAvJoin, "attribute_av_join")
|
||||||
|
->addJoinCondition(
|
||||||
|
"attribute_av_join",
|
||||||
|
AttributeAvI18nTableMap::LOCALE . "=" . $this->real_escape($locale)
|
||||||
|
)
|
||||||
->addAsColumn(
|
->addAsColumn(
|
||||||
"attribute_av_i18n_ATTRIBUTES",
|
"attribute_av_i18n_ATTRIBUTES",
|
||||||
"GROUP_CONCAT(DISTINCT ".AttributeAvI18nTableMap::TITLE.")"
|
"GROUP_CONCAT(DISTINCT ".AttributeAvI18nTableMap::TITLE.")"
|
||||||
)
|
)
|
||||||
->endUse()
|
->endUse()
|
||||||
->endUse()
|
|
||||||
->select([
|
->select([
|
||||||
"product_sale_elements_REF",
|
"product_sale_elements_REF",
|
||||||
"product_sale_elements_EAN_CODE",
|
"product_sale_elements_EAN_CODE",
|
||||||
@@ -115,24 +122,6 @@ class ProductPricesExport extends ExportHandler
|
|||||||
->groupBy("product_sale_elements_REF")
|
->groupBy("product_sale_elements_REF")
|
||||||
;
|
;
|
||||||
|
|
||||||
$this->addI18nCondition(
|
|
||||||
$query,
|
|
||||||
ProductI18nTableMap::TABLE_NAME,
|
|
||||||
ProductTableMap::ID,
|
|
||||||
AttributeAvI18nTableMap::ID,
|
|
||||||
ProductI18nTableMap::LOCALE,
|
|
||||||
$locale
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->addI18nCondition(
|
|
||||||
$query,
|
|
||||||
AttributeAvI18nTableMap::TABLE_NAME,
|
|
||||||
AttributeAvTableMap::ID,
|
|
||||||
AttributeAvI18nTableMap::ID,
|
|
||||||
AttributeAvI18nTableMap::LOCALE,
|
|
||||||
$locale
|
|
||||||
);
|
|
||||||
|
|
||||||
$data = new FormatterData($aliases);
|
$data = new FormatterData($aliases);
|
||||||
|
|
||||||
return $data->loadModelCriteria($query);
|
return $data->loadModelCriteria($query);
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
|
||||||
namespace Thelia\ImportExport\Export\Type;
|
namespace Thelia\ImportExport\Export\Type;
|
||||||
|
use Propel\Runtime\ActiveQuery\Criteria;
|
||||||
|
use Propel\Runtime\ActiveQuery\Join;
|
||||||
use Thelia\Core\FileFormat\Formatting\FormatterData;
|
use Thelia\Core\FileFormat\Formatting\FormatterData;
|
||||||
use Thelia\Core\FileFormat\FormatType;
|
use Thelia\Core\FileFormat\FormatType;
|
||||||
use Thelia\ImportExport\Export\ExportHandler;
|
use Thelia\ImportExport\Export\ExportHandler;
|
||||||
@@ -18,6 +20,8 @@ use Thelia\Model\Map\ContentI18nTableMap;
|
|||||||
use Thelia\Model\Map\ContentTableMap;
|
use Thelia\Model\Map\ContentTableMap;
|
||||||
use Thelia\Model\Map\ProductI18nTableMap;
|
use Thelia\Model\Map\ProductI18nTableMap;
|
||||||
use Thelia\Model\Map\ProductTableMap;
|
use Thelia\Model\Map\ProductTableMap;
|
||||||
|
use Thelia\Model\Map\RewritingUrlTableMap;
|
||||||
|
use Thelia\Model\Product;
|
||||||
use Thelia\Model\ProductAssociatedContentQuery;
|
use Thelia\Model\ProductAssociatedContentQuery;
|
||||||
use Thelia\Model\Lang;
|
use Thelia\Model\Lang;
|
||||||
|
|
||||||
@@ -63,58 +67,56 @@ class ProductSEOExport extends ExportHandler
|
|||||||
"product_REF" => "ref",
|
"product_REF" => "ref",
|
||||||
"product_VISIBLE" => "visible",
|
"product_VISIBLE" => "visible",
|
||||||
"product_i18n_TITLE" => "product_title",
|
"product_i18n_TITLE" => "product_title",
|
||||||
"content_URL" => "url",
|
"product_URL" => "url",
|
||||||
"content_TITLE" => "page_title",
|
"content_TITLE" => "content_title",
|
||||||
"content_META_DESCRIPTION" => "meta_description",
|
"content_META_DESCRIPTION" => "meta_description",
|
||||||
"content_META_KEYWORDS" => "meta_keywords",
|
"content_META_KEYWORDS" => "meta_keywords",
|
||||||
];
|
];
|
||||||
|
|
||||||
$locale = $lang->getLocale();
|
$locale = $this->locale = $lang->getLocale();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Join objects
|
||||||
|
*/
|
||||||
|
$urlJoin = new Join(ProductTableMap::ID, RewritingUrlTableMap::VIEW_ID, Criteria::LEFT_JOIN);
|
||||||
|
$contentJoin = new Join(ContentTableMap::ID, ContentI18nTableMap::ID, Criteria::LEFT_JOIN);
|
||||||
|
$productJoin = new Join(ProductTableMap::ID, ProductI18nTableMap::ID, Criteria::LEFT_JOIN);
|
||||||
|
|
||||||
$query = ProductAssociatedContentQuery::create()
|
$query = ProductAssociatedContentQuery::create()
|
||||||
->useContentQuery()
|
->useContentQuery()
|
||||||
->useContentI18nQuery()
|
->addJoinObject($contentJoin, "content_join")
|
||||||
->addAsColumn("content_URL", "")
|
->addJoinCondition("content_join", ContentI18nTableMap::LOCALE . "=" . $this->real_escape($locale))
|
||||||
->addAsColumn("content_TITLE", ContentI18nTableMap::TITLE)
|
->addAsColumn("content_TITLE", ContentI18nTableMap::TITLE)
|
||||||
->addAsColumn("content_META_DESCRIPTION", ContentI18nTableMap::META_DESCRIPTION)
|
->addAsColumn("content_META_DESCRIPTION", ContentI18nTableMap::META_DESCRIPTION)
|
||||||
->addAsColumn("content_META_KEYWORDS", ContentI18nTableMap::META_KEYWORDS)
|
->addAsColumn("content_META_KEYWORDS", ContentI18nTableMap::META_KEYWORDS)
|
||||||
->endUse()
|
->endUse()
|
||||||
->endUse()
|
|
||||||
->useProductQuery()
|
->useProductQuery()
|
||||||
->useProductI18nQuery()
|
->addJoinObject($productJoin, "product_join")
|
||||||
|
->addJoinCondition("product_join", ProductI18nTableMap::LOCALE . "=" . $this->real_escape($locale))
|
||||||
->addAsColumn("product_i18n_TITLE", ProductI18nTableMap::TITLE)
|
->addAsColumn("product_i18n_TITLE", ProductI18nTableMap::TITLE)
|
||||||
->endUse()
|
|
||||||
->addAsColumn("product_REF", ProductTableMap::REF)
|
->addAsColumn("product_REF", ProductTableMap::REF)
|
||||||
->addAsColumn("product_VISIBLE", ProductTableMap::VISIBLE)
|
->addAsColumn("product_VISIBLE", ProductTableMap::VISIBLE)
|
||||||
->endUse()
|
->endUse()
|
||||||
|
->addJoinObject($urlJoin, "rewriting_url_join")
|
||||||
|
->addJoinCondition("rewriting_url_join", RewritingUrlTableMap::VIEW_LOCALE . "=" . $this->real_escape($locale))
|
||||||
|
->addJoinCondition(
|
||||||
|
"rewriting_url_join",
|
||||||
|
RewritingUrlTableMap::VIEW . "=" . $this->real_escape((new Product())->getRewrittenUrlViewName())
|
||||||
|
)
|
||||||
|
->addJoinCondition("rewriting_url_join", "ISNULL(".RewritingUrlTableMap::REDIRECTED.")")
|
||||||
|
->addAsColumn("product_URL", RewritingUrlTableMap::URL)
|
||||||
->select([
|
->select([
|
||||||
"product_REF",
|
"product_REF",
|
||||||
"product_VISIBLE",
|
"product_VISIBLE",
|
||||||
"product_i18n_TITLE",
|
"product_i18n_TITLE",
|
||||||
"content_URL",
|
"product_URL",
|
||||||
"content_TITLE",
|
"content_TITLE",
|
||||||
"content_META_DESCRIPTION",
|
"content_META_DESCRIPTION",
|
||||||
"content_META_KEYWORDS",
|
"content_META_KEYWORDS",
|
||||||
])
|
])
|
||||||
;
|
;
|
||||||
|
|
||||||
$this->addI18nCondition(
|
$a = $query->toString();
|
||||||
$query,
|
|
||||||
ContentI18nTableMap::TABLE_NAME,
|
|
||||||
ContentTableMap::ID,
|
|
||||||
ContentI18nTableMap::ID,
|
|
||||||
ContentI18nTableMap::LOCALE,
|
|
||||||
$locale
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->addI18nCondition(
|
|
||||||
$query,
|
|
||||||
ProductI18nTableMap::TABLE_NAME,
|
|
||||||
ProductTableMap::ID,
|
|
||||||
ProductI18nTableMap::ID,
|
|
||||||
ProductI18nTableMap::LOCALE,
|
|
||||||
$locale
|
|
||||||
);
|
|
||||||
|
|
||||||
$data = new FormatterData($aliases);
|
$data = new FormatterData($aliases);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
<?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\ProductSEOExport;
|
||||||
|
use Thelia\Model\Base\ProductAssociatedContentQuery;
|
||||||
|
use Thelia\Model\ContentI18nQuery;
|
||||||
|
use Thelia\Model\ContentQuery;
|
||||||
|
use Thelia\Model\Lang;
|
||||||
|
use Thelia\Model\ProductAssociatedContent;
|
||||||
|
use Thelia\Model\ProductQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ProductSEOExportTest
|
||||||
|
* @package Thelia\Tests\ImportExport\Export
|
||||||
|
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||||
|
*/
|
||||||
|
class ProductSEOExportTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testQuery()
|
||||||
|
{
|
||||||
|
new Translator(new Container());
|
||||||
|
$export = new ProductSEOExport(new Container());
|
||||||
|
|
||||||
|
$data = $export->buildFormatterData(Lang::getDefaultLanguage());
|
||||||
|
|
||||||
|
$keys=["ref","visible","product_title","url","content_title","meta_description","meta_keywords",];
|
||||||
|
sort($keys);
|
||||||
|
$rawData = $data->getData();
|
||||||
|
|
||||||
|
$max = count($rawData);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If there's more that 50 entries,
|
||||||
|
* just pick 50, it would be faster and as tested as if we test 1000 entries.
|
||||||
|
*/
|
||||||
|
if ($max > 50) {
|
||||||
|
$max = 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ($i = 0; $i < $max; ++$i)
|
||||||
|
{
|
||||||
|
$row = $rawData[$i];
|
||||||
|
$rowKeys = array_keys($row);
|
||||||
|
|
||||||
|
$this->assertTrue(sort($rowKeys));
|
||||||
|
$this->assertEquals($keys, $rowKeys);
|
||||||
|
|
||||||
|
$product = ProductQuery::create()->findOneByRef($row["ref"]);
|
||||||
|
$this->assertNotNull($product);
|
||||||
|
|
||||||
|
$contentI18n = ContentI18nQuery::create()
|
||||||
|
->filterByTitle($row["content_title"])
|
||||||
|
->filterByLocale("en_US")
|
||||||
|
->findOne();
|
||||||
|
|
||||||
|
$contentsObj = ProductAssociatedContentQuery::create()
|
||||||
|
->filterByProduct($product)
|
||||||
|
;
|
||||||
|
|
||||||
|
if (null !== $contentI18n) {
|
||||||
|
$contentsObj->filterByContentId($contentI18n->getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
$contentsObj->findOne();
|
||||||
|
|
||||||
|
$this->assertEquals($product->getVisible(), $row["visible"]);
|
||||||
|
$this->assertEquals($product->getTitle(), $row["product_title"]);
|
||||||
|
|
||||||
|
$this->assertEquals($contentI18n->getMetaDescription(), $row["meta_description"]);
|
||||||
|
$this->assertEquals($contentI18n->getMetaKeywords(), $row["meta_keywords"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user