Sama
Sama

Reputation: 351

Prestashop Product added programatically is not showing on front page

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;
        }
    ?>

Upvotes: 0

Views: 1524

Answers (2)

idnovate
idnovate

Reputation: 1022

You can clear cache programatically executing:

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

Upvotes: 1

Sama
Sama

Reputation: 351

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

Upvotes: 0

Related Questions