以编程方式添加的Prestashop产品未显示在首页上

以编程方式添加的Prestashop产品未显示在首页上

问题描述:

This is the first time I am working on prestashop. I am adding product using New Product() and its working fine and showing product in prestashop admin panel even show if I tried to see the product page by direct link. But its not showing on home(front) page, The weird thing here is when I click that product edit and save it again without any change in prestashop backoffice its appears at front page. Here is my code

<?php
include('config/config.inc.php');
    include('init.php'); 
    $reference = rand();
    $sql = "SELECT id_product FROM pssf_product WHERE reference='$reference'";
    $res = Db::getInstance()->getValue($sql);
    if (!empty($res)) {
        echo "already exist";
    }
    else {
        $product = new Product();
        $product->reference = $reference;
        $product->price = "100.00";
        $product->quantity = 10;
        $product->active = 1;
        $product->id_category = 2;
        $product->id_category_default = 2;
        $product->name[1] = "Sampel Product".$reference;
        $product->description[1] = "Description".$reference;
        $product->link_rewrite[1] = Tools::link_rewrite($reference);
        $product->save();
        $product->addToCategories(array(2));
        StockAvailable::setQuantity((int)$product->id, 0, $product->quantity);
        echo $product->id;
        }
    ?>

这是我第一次使用prestashop。 我正在使用 New Product() code>添加产品,它的工作正常并在prestashop管理面板中显示产品甚至显示我是否试图通过直接链接查看产品页面。 但它没有在主页(前面)显示,这里奇怪的是当我点击该产品编辑并再次保存它而没有任何更改prestashop backoffice它出现在首页。 这是我的代码 p> \ n

 &lt;?php 
include('config / config.inc.php'); 
 include('init.php');  
 $ reference = rand(); 
 $ sql =“SELECT id_product FROM pssf_product WHERE reference ='$ reference'”; 
 $ res = Db :: getInstance() - &gt; getValue($ sql); 
  if(!empty($ res)){
 echo“已经存在”; 
} 
 else {
 $ product = new Product(); 
 $ product-&gt; reference = $ reference; 
 $  product-&gt; price =“100.00”; 
 $ product-&gt; quantity = 10; 
 $ product-&gt; active = 1; 
 $ product-&gt; id_category = 2; 
 $ product-&gt;  id_category_default = 2; 
 $ product-&gt; name [1] =“Sampel Product”。$ reference; 
 $ product-&gt; description [1] =“Description”。$ reference; 
 $ product-&gt;  link_rewrite [1] = Tools :: link_rewrite($ reference); 
 $ product-&gt; save(); 
 $ product-&gt; addToCategories(array(2)); 
 StockAvailable :: setQuantity((int)  $ product-&gt; id,0,$ product-&gt; quantity); 
 echo $ product-&gt; id; 
} 
?&gt; 
  code>  pre> 
  div  >

You can clear cache programatically executing:

Tools::clearSmartyCache();
Tools::clearXMLCache();
Media::clearCache();
Tools::generateIndex();

Problem solved by clearing caches under Advance Parameters > Performance > Clear cache.