Μετάβαση στο περιεχόμενο
Πίσω στα Άρθρα

PrestaShop → Google Sheets: product export με Webservice και Apps Script

Live catalogue reports & lightweight data workflows
JAVASCRIPT
const url = shopUrl +
  '/api/products';

const res = UrlFetchApp.fetch(url, {
  headers: {
    Authorization: 'Basic ' + token
  }
});
Automation
Intermediate
PrestaHacks 3 min read

Ένα Google Sheet μπορεί να γίνει πολύ περισσότερο από ένα manual export.

Με το PrestaShop Webservice και Apps Script μπορείς να δημιουργήσεις ένα repeatable catalogue report χωρίς να κατεβάζεις CSV κάθε φορά.

Το workflow

TEXT
PRESTASHOP
    ↓
WEBSERVICE API
    ↓
APPS SCRIPT
    ↓
NORMALIZE
    ↓
GOOGLE SHEETS

1. Ξεκίνα read-only

Για reporting workflow το API key δεν χρειάζεται write permissions.

Tip

Δώσε μόνο τα permissions που χρειάζεται πραγματικά το integration.

2. Ζήτησε συγκεκριμένα fields

API
/api/products?display=[id,reference,price,active]&output_format=JSON

3. Apps Script configuration

JS
const CONFIG = {
  baseUrl: 'https://shop.example',
  apiKey: 'YOUR_WEBSERVICE_KEY',
  batchSize: 100
};

4. HTTP request

JS
function fetchProducts() {
  const url =
    CONFIG.baseUrl +
    '/api/products' +
    '?display=[id,reference,price,active]' +
    '&output_format=JSON' +
    '&limit=0,' + CONFIG.batchSize;

  const auth = Utilities.base64Encode(CONFIG.apiKey + ':');

  const response = UrlFetchApp.fetch(url, {
    method: 'get',
    headers: {
      Authorization: 'Basic ' + auth
    },
    muteHttpExceptions: true
  });

  if (response.getResponseCode() !== 200) {
    throw new Error(
      'PrestaShop HTTP ' + response.getResponseCode()
    );
  }

  return JSON.parse(response.getContentText());
}

5. Normalize πρώτα

JS
function productsToRows(products) {
  return products.map(product => [
    product.id,
    product.reference,
    product.price,
    product.active
  ]);
}

6. Write σε μία operation

JS
function writeProducts(rows) {
  const sheet =
    SpreadsheetApp.getActive()
      .getSheetByName('Products');

  sheet.clearContents();

  const values = [
    ['ID', 'Reference', 'Price', 'Active'],
    ...rows
  ];

  sheet
    .getRange(1, 1, values.length, values[0].length)
    .setValues(values);
}

7. Identifier strategy

Για internal reporting:

TEXT
id_product

Για ERP / supplier integrations:

TEXT
reference / SKU

8. Products ≠ stock

Για stock report χρειάζεσαι και:

API
/api/stock_availables

με join σε:

TEXT
id_product
id_product_attribute

9. Products με combinations

Πριν το coding αποφάσισε:

TEXT
ONE ROW PER PRODUCT

ή:

TEXT
ONE ROW PER COMBINATION

10. Sync metadata

Κράτα:

TEXT
Last sync
HTTP status
Rows imported
Duration

Πού είναι ιδανικό το Sheet

  • reporting,
  • review,
  • mappings,
  • manual overrides,
  • lightweight automations.

Δεν χρειάζεται να γίνει η primary database σου.

[SCREENSHOT PLACEHOLDER 01]

Google Sheet με normalized Products tab.

[SCREENSHOT PLACEHOLDER 02]

Apps Script με UrlFetchApp.fetch().

Καλό πρώτο automation

TEXT
PrestaShop
    ↓
Daily read-only sync
    ↓
Google Sheet
    ↓
Catalogue review

Πριν γράψεις data πίσω στο shop, φτιάξε πρώτα ένα αξιόπιστο read/reporting pipeline.

Τι να κάνεις μετά

Εξέλιξε το read-only report σε supplier-feed transformation pipeline, κρατώντας χωριστά το raw input και το mapped output. Για μεγαλύτερα catalogues, εφάρμοσε Webservice pagination πριν προγραμματίσεις επαναλαμβανόμενα syncs.

ΜΕΙΝΕ ΕΝΗΜΕΡΩΜΕΝΟΣ

Πρακτικά PrestaShop hacks κατευθείαν στο inbox σου.

ΑΝΕΝΕΡΓΟ