Perch Product Importer - Indexing products

  • Hello,


    I am using the product importer to import products, but they are not indexed after import. I have to save them manually to make them show up in the webshop.
    A piece of my code:


  • After the item is imported you need to call the index function on the product.

    Code
    1.     // Import product
    2. $result = $ProductImporter->add_item($productData);
    3. $Products = new PerchShop_Products();
    4. if ($result) {
    5. $newProduct = $Products->find($result['id']);
    6. $newProduct->index();
    7. }
  • Hello Byron, thank you for the response. I tried it, but I get a PHP error:

    Code
    1. PHP Fatal error: Uncaught Error: Call to a member function index() on boolean in ......

    While using the following import code:

  • Ah ofcourse. I just edited that part but now it is giving me the following PHP errors:


    Code
    1. [Wed Sep 18 15:56:19.133775 2019] [fcgid:warn] [pid 14238:tid 140618059556608] [client 31.160.4.226:56902] mod_fcgid: stderr: PHP Warning: filesize(): stat failed for https://www.[DOMAIN].nl/uploads/products/FO1/FO1.jpg in /[ROOT]/[SITENAME]/perch/core/apps/assets/PerchAssets_Importer.class.php on line 47, referer: http://[DOMAIN]/perch/addons/apps/my_sample/
    2. [Wed Sep 18 15:56:19.133855 2019] [fcgid:warn] [pid 14238:tid 140618059556608] [client 31.160.4.226:56902] mod_fcgid: stderr: PHP Fatal error: Uncaught Error: Call to a member function find_all_tags_and_repeaters() on null in /[ROOT]/[SITENAME]/perch/core/lib/PerchBase.class.php:185, referer: http://[DOMAIN]/perch/addons/apps/my_sample/
    3. [Wed Sep 18 15:56:19.133866 2019] [fcgid:warn] [pid 14238:tid 140618059556608] [client 31.160.4.226:56902] mod_fcgid: stderr: Stack trace:, referer: http://[DOMAIN]/perch/addons/apps/my_sample/
    4. [Wed Sep 18 15:56:19.133873 2019] [fcgid:warn] [pid 14238:tid 140618059556608] [client 31.160.4.226:56902] mod_fcgid: stderr: #0 /[ROOT]/[SITENAME]/perch/templates/pages/shop/importeren.php(76): PerchBase->index(), referer: http://[DOMAIN]/perch/addons/apps/my_sample/
    5. [Wed Sep 18 15:56:19.133881 2019] [fcgid:warn] [pid 14238:tid 140618059556608] [client 31.160.4.226:56902] mod_fcgid: stderr: #1 /[ROOT]/[SITENAME]/perch/core/runway/start.php(43): include('/home/kndrxwbst...'), referer: http://[DOMAIN]/perch/addons/apps/my_sample/
    6. [Wed Sep 18 15:56:19.133888 2019] [fcgid:warn] [pid 14238:tid 140618059556608] [client 31.160.4.226:56902] mod_fcgid: stderr: #2 /[ROOT]/[SITENAME]/perch/core/runway/start.php(47): perch_runway_dispatch_page(Object(PerchRoutedPage)), referer: http://[DOMAIN]/perch/addons/apps/my_sample/
    7. [Wed Sep 18 15:56:19.133896 2019] [fcgid:warn] [pid 14238:tid 140618059556608] [client 31.160.4.226:56902] mod_fcgid: stderr: #3 {main}, referer: http://[DOMAIN]/perch/addons/apps/my_sample/
    8. [Wed Sep 18 15:56:19.133902 2019] [fcgid:warn] [pid 14238:tid 140618059556608] [client 31.160.4.226:56902] mod_fcgid: stderr: thrown in /[ROOT]/[SITENAME]/perch/core/lib/PerchBase.class.php on line 185, referer: http://[DOMAIN]/perch/addons/apps/my_sample/
  • And after deleting the AssetImport part of the code (so it is easier to just focus on the indexing of the products, without importing the assets), I get the following error:

    Code
    1. [Wed Sep 18 16:00:49.914965 2019] [fcgid:warn] [pid 14238:tid 140618135090944] [client 31.160.4.226:57320] mod_fcgid: stderr: PHP Fatal error: Uncaught Error: Call to a member function find_all_tags_and_repeaters() on null in /[ROOT]/[SITENAME]/perch/core/lib/PerchBase.class.php:185, referer: http://[DOMAIN]/perch/addons/apps/my_sample/
    2. [Wed Sep 18 16:00:49.915093 2019] [fcgid:warn] [pid 14238:tid 140618135090944] [client 31.160.4.226:57320] mod_fcgid: stderr: Stack trace:, referer: http://[DOMAIN]/perch/addons/apps/my_sample/
    3. [Wed Sep 18 16:00:49.915111 2019] [fcgid:warn] [pid 14238:tid 140618135090944] [client 31.160.4.226:57320] mod_fcgid: stderr: #0 /[ROOT]/[SITENAME]/perch/templates/pages/shop/importeren.php(76): PerchBase->index(), referer: http://[DOMAIN]/perch/addons/apps/my_sample/
    4. [Wed Sep 18 16:00:49.915124 2019] [fcgid:warn] [pid 14238:tid 140618135090944] [client 31.160.4.226:57320] mod_fcgid: stderr: #1 /[ROOT]/[SITENAME]/perch/core/runway/start.php(43): include('/home/kndrxwbst...'), referer: http://[DOMAIN]/perch/addons/apps/my_sample/
    5. [Wed Sep 18 16:00:49.915132 2019] [fcgid:warn] [pid 14238:tid 140618135090944] [client 31.160.4.226:57320] mod_fcgid: stderr: #2 /[ROOT]/[SITENAME]/perch/core/runway/start.php(47): perch_runway_dispatch_page(Object(PerchRoutedPage)), referer: http://[DOMAIN]/perch/addons/apps/my_sample/
    6. [Wed Sep 18 16:00:49.915141 2019] [fcgid:warn] [pid 14238:tid 140618135090944] [client 31.160.4.226:57320] mod_fcgid: stderr: #3 {main}, referer: http://[DOMAIN]/perch/addons/apps/my_sample/
    7. [Wed Sep 18 16:00:49.915148 2019] [fcgid:warn] [pid 14238:tid 140618135090944] [client 31.160.4.226:57320] mod_fcgid: stderr: thrown in /[ROOT]/[SITENAME]/perch/core/lib/PerchBase.class.php on line 185, referer: http://[DOMAIN]/perch/addons/apps/my_sample/
  • The find_all_tags_and_repeaters function is a method of PerchTemplate Class, so it looks like the template might not be set on the Importer for some reason. It should be set to 'shop/products/product' by default, but you can try set it manually with the following


    Code
    1. $Template = $API->get('Template');
    2. $Template->set('path/to/template', 'shop');
    3. $ProductImporter->set_template($Template);
    4. // Run importer
  • I still get the same error, but I guess it could be due to the fact that I am working in the my_sample sample app, because I see this sample function in the apps runtime (which also uses the Template function):


    Maybe I should clean up the app first...

  • Yes, ofcourse.


    Maybe not the cleanest code.

  • This is the result from the API call (only the first few products):


    Code
    1. {"data":[{"timestamp":"2019-02-03T14:46:45+01:00","productcode":"FO1","potsize":"21","height":"100","dutchname":"Areca \/ Dypsis Palm","linnaeusname":"Areca","numberperorder":"1","purchaseprice":"18.26","promotionaltext":"Groot en groen, maar niet t\u00e9 ruig. Een stijvolle plant.","description":"Goudpalm uit Madagaskar. Daar een bedreigde soort, maar onder andere op de Cara\u00efben zijn ze verwilderd en veel voorkomend. In de volle zon verkleuren de bladeren en de plant heeft gele bloemetjes: vandaar Goudpalm.\r\n\r\nDe Areca is niet makkelijk, maar wel populair in interieurs. Onder gunstige omstandigheden groeit hij tot aan het plafond. In de natuur kan hij 10 meter hoog worden.","specifications":"goudpalm; areca; pot 21 cm; hoogte 100 cm; groene plant; lichte plek in huis","caretips":"Zet de plant op een lichte plek, maar niet in de volle zon. De Goudpalm heeft ook een hekel aan tocht, en je moet er niet tegenaan lopen. Vermijd tenslotte radiatoren.\r\n\r\nGeef de palm in de zomer 2 \u00e0 3 keer per week lauwwarm water, 's winters 1 keer per week. Af en toe sproeien vindt ze fijn.\r\nDe plant groeit traag, geef haar hooguit in de groeiperiode 1 keer per maand voeding.","aboutgrower":"Fondieplant is \u00e9\u00e9n van de grootste Areca-palm kwekerijen in Europa.","branches":"","images":["https:\/\/www.floraathome.nl\/uploads\/products\/FO1\/FO1.jpg","https:\/\/www.floraathome.nl\/uploads\/products\/FO1\/FO1.3.jpg","https:\/\/www.floraathome.nl\/uploads\/products\/FO1\/FO1.2.jpg","https:\/\/www.floraathome.nl\/uploads\/products\/FO1\/FO1.4.jpg","https:\/\/www.floraathome.nl\/uploads\/products\/FO1\/FO1.5.jpg","https:\/\/www.floraathome.nl\/uploads\/products\/FO1\/FO1.6.jpg"],"grower":"Fondieplant","category":"Groene Plant"},
    2. ...
  • Hello Guys, I am a beginner in Perch and would need your help.


    I have perch (not runway) with shop, products and orders. I need to import products via csv and following this link here :

    https://docs.grabaperch.com/api/import/shop/products/

    First of all will this work with normal perch implementation ?
    Do I need to create an app to make it work ? as here


    Code
    1. $API = new PerchAPI(1.0, 'my_importer');
    2. $Importer = $API->get('PerchShopProductImporter');

    my_importer is an app, what is PerchShopProductImporter here ? Do I need to write some code for this or it is some already built functionality that I can use to add products ? Is the quoted comment complete code ?

    Please help!


    Yes, ofcourse.


    Maybe not the cleanest code.

  • Above is my code that is working with perch runway but it imports only one product at a time and also it doesn't give any error.
    Since it imports only one products so I have created a variable named $after which I get to insert row after prev row.

    Any guess?