zabicom.cz Posted December 11, 2017 Share Posted December 11, 2017 Hello, I tried to develope my custom "module" to import products from XML file. I'm using latest Prestashop 1.7.2.4, PHP version 5.4.45. Everything seems to work fine, products are added to database, all appers in back office, assigned to categories (currently to id=2 Home category) but when I look at front office there is no new(imported) product. When I go to back office to product detail and click to Preview button, it show the product normally and after that, it is even available in front office, same situation after some change (active/not active, save etc.) from back office to product. When I try to access the product detail directly with url it shows "you doesn't have permission to access this product", and after "preview" from Back office it is normally available without any other permission changes. Same situation on localhost and on live server. Tried to clear cache, reindex the search engine, regenerate images... here is part of my code for import products $getId = ('SELECT id_product FROM '._DB_PREFIX_.'product WHERE reference = \''.pSQL($reference).'\''); //sql string pro zisk ID produktu $id_product = Db::getInstance()->getValue($getId); //získání ID produktu pokud existuje stejná "reference" $product = $id_product ? new Product((int)$id_product, true) : new Product (); //podmínka pro vytvoření instance Product () s parametrem nebo "nový" product() $product->reference = $reference; $product->price = (float)$price; $product->indexed = 0; $product->active = 1; //aktivní produkt - možnost předělat na základě nějaké hodnoty z xml //$product->weight = (float)$product_xml->Weight; //$product->quantity = (int)$count; $product->minimal_quantity = 1; // minimální počet produktu pro prodej - možnost předělat na základě nějaké hodnoty z xml $product->id_category_default = $category[0]; //hlavní kategorie je 1. kategorie ze seznamu kategorií produktu $product->name[1] = $name; $product->description[1] = $description; $product->description_short[1] = $description_short; $product->ean13 = $ean13; $product->weight = $weight; $product->link_rewrite[1] = Tools::link_rewrite($name); if (!isset($product->date_add) || empty($product->date_add)) $product->date_add = date('Y-m-d H:i:s'); $product->date_upd = date('Y-m-d H:i:s'); $id_product ? $product->updateCategories($category) : $product->addToCategories($category); //$id_product ? $product->updateCategories(array(2)) : $product->addToCategories(array(2)); pokud nefunguje přidávání kategorií tak odkomentovat původní $product->save(); $insertedId = $product->id; //získání ID vloženého záznamu $id_product ? StockAvailable::setQuantity((int)$id_product, 0, (int)$stkQuantity) : StockAvailable::setQuantity((int)$insertedId, 0, (int)$stkQuantity) ; //vložení množství produktu do db /*add images to product*/ $cover = true; foreach ($images as $image_url) { var_dump($image_url); echo "<br>"; $image = new Image(); $shops = Shop::getShops(true, null, true); $image->id_product = $product->id; $image->position = Image::getHighestPosition($product->id) + 1; $image->cover = $cover; if (($image->validateFields(false, true)) === true && ($image->validateFieldsLang(false, true)) === true && $image->add()) { $image->associateTo($shops);//($product->id_shop_default); if (!copyImg($product->id, $image->id, $image_url, 'products', false)) { $image->delete(); } } if ($cover) { $cover = false; } } What can be wrong with the import? Or any other thing with prestashop what I've missing...? Sorry for my english I hope that you can understand the issue well. Thanks for any advice Link to comment Share on other sites More sharing options...
selectshop.at Posted December 11, 2017 Share Posted December 11, 2017 PHP version for PS 1.7. should be at least 5.6.30. Perhaps It is a caching problem. I had a customer with same problem. He also developed a module importing products via XML and on navigation bar the new categories didn't appeared, consequently all products in this category where also not visible, as they are depending of the category. When you add products to Prestashop there are many of dependencies. You have to check all dependencies, the most forgotten is the one on search_index, which is not feeded. The cache of navigation module should be renewed as well, for to see new categories for ex. You should take into consideration this as well on your code. Revise all dependencies. Link to comment Share on other sites More sharing options...
luCheng Posted July 10, 2020 Share Posted July 10, 2020 Hi, Have you solved the issue? I met the save problem. Link to comment Share on other sites More sharing options...
Kogkalidis Posted July 28, 2022 Share Posted July 28, 2022 Is the product assigned to every customer group? Link to comment Share on other sites More sharing options...
Mar4eloM Posted July 23, 2023 Share Posted July 23, 2023 Is anybody solve this problem? I go through all Prestashop 1.7 tables and can't find any differences between newly imported product (which don't appear in front office) and product which appears in front office after Preview button proceed. What is happen when Preview button is pressed in admin panel? In which tables or files happen "magic"? Link to comment Share on other sites More sharing options...
Mar4eloM Posted July 26, 2023 Share Posted July 26, 2023 (edited) I found the missing table which should be filled - layered_price_index table. Here is full list of needed tables: category, category_group, category_lang, category_product, category_shop, product, product_lang, product_shop, product_supplier image, image_lang, image_shop stock_available layered_price_index Edited July 26, 2023 by Mar4eloM (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now