Merge branch 'ticket-14698-sensefuel' into develop

This commit is contained in:
Michael RICOIS 2017-11-28 10:22:46 +01:00
commit 4f77ded6df

View File

@ -76,10 +76,12 @@ class SenseFuelFluxExport
$this->hydrateProducts($type, $language);
echo 'Getting categories' . "\n";
$this->hydrateProductCategories($language);
echo 'Getting brands' . "\n";
$this->hydrateProductBrands();
//echo 'Getting brands' . "\n";
//$this->hydrateProductBrands();
echo 'Getting menu tags' . "\n";
$this->hydrateTagCategories($language);
echo "Getting family\n";
$this->hydrateProductFamily($language);
echo 'Getting availability' . "\n";
$this->hydrateProductStock();
try {
@ -239,10 +241,12 @@ class SenseFuelFluxExport
$categories = Db::getInstance()->ExecuteQ($sql);
$tmpArray = array();
$this->products[$i]['classic_categories'] = array();
$this->products[$i]['categories_id'] = array();
foreach ($categories as $currentEnrichingCategory) {
$id = (int)$currentEnrichingCategory['id_category'];
$tmpArray[$id] = $currentEnrichingCategory;
$this->products[$i]['classic_categories'][(int)$currentEnrichingCategory['level_depth']] = $currentEnrichingCategory['name'];
$this->products[$i]['categories_id'][(int)$currentEnrichingCategory['level_depth']] = $currentEnrichingCategory['id_category'];
}
$categoryTree = $this->parseTree($tmpArray, 1);
if (is_array($categoryTree)) {
@ -296,19 +300,109 @@ class SenseFuelFluxExport
}
$iMax = count($this->products);
for ($i = 0; $i < $iMax; $i++) {
if (
isset($this->products[$i]['id_manufacturer']) &&
(int)$this->products[$i]['id_manufacturer'] !== 0
) {
if(array_key_exists((int)$this->products[$i]['id_manufacturer'],$tmpArray)){
$this->products[$i]['brand'] = $tmpArray[(int)$this->products[$i]['id_manufacturer']];
}else{
$this->products[$i]['brand'] = self::GENERIC_BRAND;
}
if (isset($this->products[$i]['id_manufacturer'])
&& (int)$this->products[$i]['id_manufacturer'] !== 0) {
if(array_key_exists((int)$this->products[$i]['id_manufacturer'],$tmpArray)){
$this->products[$i]['brand'] = $tmpArray[(int)$this->products[$i]['id_manufacturer']];
} else {
$this->products[$i]['brand'] = self::GENERIC_BRAND;
}
}
}
unset($tmpArray);
}
private function hydrateProductFamily($language)
{
//$familyTree = $this->getFamilyTree($language->id);
$familyFlat = $this->getFamilyAll($language->id);
// Get all family tree
$iMax = count($this->products);
for ($i = 0; $i < $iMax; $i++) {
$this->products[$i]['family'] = 'Not found';
if (count($this->products[$i]['categories_id']) > 0) {
// Family
$id_category = end($this->products[$i]['categories_id']);
$sql = "SELECT id_category_family FROM `"._DB_PREFIX_."category_family_association`
WHERE id_category = ".$id_category;
$id_category_family = Db::getInstance()->getValue($sql);
if (!empty($id_category_family) && array_key_exists($id_category_family, $familyFlat)) {
$get = $this->parseForParent($id_category_family, $familyFlat);
if ($get !== false) {
$familyPath = $get;
}
$this->products[$i]['family'] = $familyPath;
}
}
}
}
private function parseForParent($id_category_family, $family)
{
$name = '';
if (!array_key_exists($id_category_family, $family)) {
return false;
}
$name = $family[$id_category_family]['name'];
$id_category_family = $family[$id_category_family]['id_parent'];
if ($id_category_family == 0) {
return $name;
}
$get = $this->parseForParent($id_category_family, $family);
if ($get !== false) {
$name = $get.' > '.$name;
}
return $name;
}
private function getFamilyAll($id_lang)
{
$sql = "SELECT *
FROM `"._DB_PREFIX_."category_family` cf, `"._DB_PREFIX_."category_family_lang` cfl
WHERE cf.id_category_family=cfl.id_category_family AND cfl.id_lang=".$id_lang;
$result = Db::getInstance()->ExecuteS($sql);
$family = array();
if (count($result)) {
foreach ($result as $r) {
$family[$r['id_category_family']] = $r;
}
}
return $family;
}
private function getFamilyTree($id_lang)
{
return $this->recurseFamily(0, $id_lang);
}
private function recurseFamily($id_family, $id_lang)
{
$data = array();
$sql = "SELECT *
FROM `"._DB_PREFIX_."category_family` cf, `"._DB_PREFIX_."category_family_lang` cfl
WHERE cf.id_category_family=cfl.id_category_family AND cfl.id_lang=".$id_lang.
" AND cf.id_parent=".$id_family." ORDER BY cf.position ASC";
$result = Db::getInstance()->ExecuteS($sql);
if (count($result) > 0) {
foreach ($result as $c) {
$item = array(
'id_category_family' => $c['id_category_family'],
'name' => $c['name'],
'children' => $this->recurseFamily($c['id_category_family'], $id_lang),
);
$data[] = $item;
}
}
return $data;
}
private function buildXML($language)
{
@ -382,21 +476,32 @@ class SenseFuelFluxExport
} else {
//classic products in sales
if (isset($currentProduct['classic_categories'])) {
// Bebeboutik : brand
$firstKey = key($currentProduct['classic_categories']);
if ($key !== null) {
$this->addContentLine($currentProduct['classic_categories'][$firstKey], 'g:brand');
}
foreach ($currentProduct['classic_categories'] as $depth => $name) {
if ($depth > 1) {
$this->addContentLine($name, 'c:category' . ($depth - 2));
}
}
}
if (isset($currentProduct['tags'])) {
/*if (isset($currentProduct['tags'])) {
foreach ($currentProduct['tags'] as $product_type) {
$this->addContentLine($product_type . ' > ' . $currentProduct['catname'],
'g:product_type');
}
}
// Bebeboutik : force categories
foreach ($currentProduct['conso_categories'] as $currentCategory) {
$this->addContentLine($currentCategory, 'g:product_type');
}*/
// Bebeboutik : Add Family as product_type
$this->addContentLine($currentProduct['family'], 'g:product_type');
// Bebeboutik : Force categories
if (isset($currentProduct['conso_categories'])) {
foreach ($currentProduct['conso_categories'] as $currentCategory) {
//$this->addContentLine($currentCategory, 'g:product_type');
}
}
$this->addContentLine('Ventes privées', 'c:sale_type');