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

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

2条回答 默认 最新

  • dongtan5811 2017-09-19 08:26
    关注

    You can clear cache programatically executing:

    Tools::clearSmartyCache();
    Tools::clearXMLCache();
    Media::clearCache();
    Tools::generateIndex();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里