dongluan7821
2017-09-18 20:08
浏览 35
已采纳

以编程方式添加的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;
        }
    ?>

图片转代码服务由CSDN问答提供 功能建议

这是我第一次使用prestashop。 我正在使用 New Product()添加产品,它的工作正常并在prestashop管理面板中显示产品甚至显示我是否试图通过直接链接查看产品页面。 但它没有在主页(前面)显示,这里奇怪的是当我点击该产品编辑并再次保存它而没有任何更改prestashop backoffice它出现在首页。 这是我的代码 \ 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; 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongtan5811 2017-09-19 08:26
    已采纳

    You can clear cache programatically executing:

    Tools::clearSmartyCache();
    Tools::clearXMLCache();
    Media::clearCache();
    Tools::generateIndex();
    
    点赞 评论
  • duanliusong6395 2017-09-18 21:15

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

    点赞 评论

相关推荐 更多相似问题