Jump to content

Uprava php skriptu v module na automaticky XML Feed, HELP, ponukam odmenu


KerbeusSlovakia

Recommended Posts

Natrafil som na jeden modul ktory dokaze automaticky generovat xml subory, len ten modul mal/ma par chybičiek krasy. Nedokazalo to povodne generovat vsetko co pozaduju porovnavace, teraz uz zrejme ano, nedostal som sa zatial k vsetkym porovnavacom. Porovnavace vyzaduju aby kategorie tovaru ktore sa nachadzaju v obchode boli napriklad oddelene / Ja som po chvili prisiel na to ako ich oddelit cim potrebujem, trebars ich viem oddelit aj * ale problem je, ze ono to oddeli nie len medzi kategoriami, ale aj na konci kategorie.

Priklad:

Porovnavace vyzaduju nieco taketo Titulka/Dámske vône
Mne to oddeli takto Titulka/Dámske vône/


Uz netusim, ako to upravit a ci to vobec ide upravit. Prikladam aj zdrojak.


Stare skripty mi dokazu bez problemu kategorie oddelit v strede, lenze nedokazu vytvarat automaticky feed. Skusal som aj skombinovat nejake veci zo starych skriptov, ale jedine v com som bol uspesny, ze som dostal do tohto noveho skriptu generovanie vyrobcov. Dobrej dusi co pomoze, ak to bude fungovat, ponukam funkcny modul, ktory dokaze vygenerovat feedy do 10 slovenskych porovnavacou podla vyberu, pripadne ten modul upravim aby generoval feedy do 10 ceskych porovnavacou podla vyberu.



<?php
require_once("cFeed.php");
 class FeedTovar extends cFeed {

 public function CreateFeed($products, $feeddir) {
 global $link;    
 global $id_lang; 

$output="";
$feedpath =$feeddir."/tovar.xml";

if(file_exists($feedpath))
unlink($feedpath);
$fp=fopen($feedpath, "w+");
if(!$fp) {
 echo "failed to open ".$feedpath;  
}

fputs($fp,  "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
fputs($fp,  "\n"); 


   foreach ($products AS $product)
   {
       $image = Image::getImages(intval($id_lang), $product['id_product']); 
        $description=substr($product['description_short'], 0, 510); 

        $item= "\t\t\n";
        $item.= "\t\t\t".htmlspecialchars($product['name'])."\n";
        $item.= "\t\t\t".htmlspecialchars($description)."\n";
        $item.= "\t\t\t".htmlspecialchars($link->getproductLink($product['id_product'], $product['link_rewrite'], Tools::getValue('id_category')).$affiliate)."\n";
       if($image[0]['id_product']) { 
        $item.="\t\t\t".htmlspecialchars(_PS_BASE_URL_.__PS_BASE_URI__."img/p/".$image[0]['id_product']."-".$image[0]['id_image']).".jpg";
       } 
        $item.= "\t\t\t".htmlspecialchars($product['price'])."\n"; 
        $item.= "\t\t\t".htmlspecialchars($this->get_categorytext($product))."\n";
        $item.= "\t\t\t".htmlspecialchars($product['manufacturer_name'])."\n";       
       $item.="\t\t\n";
       fputs($fp,  $item);
   }
fputs($fp,  "");  
fclose($fp);  
        }

 private function  get_categorytext($product) {
     global $id_lang; 
        $cats= Db::getInstance()->ExecuteS('
       SELECT '._DB_PREFIX_.'category_lang.name  

       FROM
         '._DB_PREFIX_.'category_product LEFT JOIN  '._DB_PREFIX_.'category_lang ON
       '._DB_PREFIX_.'category_product.id_category =  '._DB_PREFIX_.'category_lang.id_category
       LEFT JOIN  '._DB_PREFIX_.'category ON
       '._DB_PREFIX_.'category_product.id_category =  '._DB_PREFIX_.'category.id_category

           WHERE '._DB_PREFIX_.'category_product.id_product = '.intval($product["id_product"])
         .' AND    '._DB_PREFIX_.'category_lang.id_lang= '.$id_lang
          .' AND    '._DB_PREFIX_.'category.active= 1 ORDER BY  '._DB_PREFIX_.'category.level_depth ASC '
           ); 
     $retval="";
     foreach($cats as $cat) {
       $retval.=$cat["name"]."/";  
     }
    return $retval;
 }

 }
?>

Link to comment
Share on other sites

tak skus nahradit

$retval="";
     foreach($cats as $cat) {
       $retval.=$cat["name"]."/";  
     }



tymto

$retval="";
$i = 0;
     foreach($cats as $cat) {
       $i++;
       if ($i == sizeof($cats)) {$retval.=$cat["name"]; }
                           else {$retval.=$cat["name"]."/"; }
     }



pisala som to len z hlavy, ale malo by ti to spravit to, ze ked pripajas poslednu kategoriu, tak tam nepripoji aj "/"

jasne, ze sa to da aj inak, ale tu je len mala uprava do tvojho skriptu

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...