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;
        }
    ?>
  • 写回答

2条回答 默认 最新

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

    You can clear cache programatically executing:

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

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助