# Google Sheets sync

DZBuild's Google Sheets integration keeps a spreadsheet of your store data. Orders and abandoned carts land in it as they happen; products and customers reach it through the manual export described below.

## Setup

1. Go to `/dashboard/addons/google-sheets`.
2. Click **Connect Google** and authorize via Google OAuth.
3. Click **Create new sheet** (or link an existing sheet the app created). The form asks whether to copy your past orders in (**Add all past orders**) or start with an empty sheet that fills from the next order (**Only new orders**), and where new orders go: **Bottom (oldest first)**, the default, or **Top (newest first)**. The background sync starts immediately.

If the token expires later, the page will prompt you to reconnect.

## What syncs

| Data type       | Columns written                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Orders          | order number, date, customer name, phone, wilaya, commune, address, products, variants, quantity, unit price, subtotal, shipping cost, discount, total, status, offer name — plus optional columns you can switch on: notes, promo code, delivery type, SKU, wilaya number. Courier and tracking number are **not** exported to Sheets.                                                                                                                             |
| Products        | product id, name, price, old price, stock, category, has-variants flag, variants, status — plus one optional column you can switch on: SKU.                                                                                                                                                                                                                                                                                                                         |
| Customers       | customer id, name, phone, email, wilaya, commune, number of orders, total spent, registration date                                                                                                                                                                                                                                                                                                                                                                  |
| Stock updates   | Nothing is written automatically. The per-sheet **stock updates** switch saves a setting that has no effect today: a stock change does not touch the sheet. The quantity in the **Products** tab is whatever the last full export wrote, so re-run **export now** when you need current numbers. There is no separate Inventory tab, and variant-level stock is never written (the Products tab's *variants* column is a text summary written by that same export). |
| Abandoned carts | cart id, phone, name, wilaya, commune, products, item count, cart total, status, created date, last activity — plus optional columns you can switch on: source page, email, wilaya number, variants, SKU.                                                                                                                                                                                                                                                           |

The first sheet you connect syncs all of the above. Additional sheets default to **orders-only**.

Only orders and abandoned carts are written as they happen. Products and customers reach the sheet through the manual **export now** run described below, not as you edit them.

## Per-sheet settings and columns

Every connected sheet has its own settings, so one sheet can be an orders log for your call-confirm team while another is a full catalogue export:

* **Which data types it receives** — orders, products, customers, stock updates, abandoned carts, or orders-only.
* **Auto-sync on or off** for that sheet.
* **Which columns appear, and in what order.** Three drag-and-drop lists with a switch on every row: 22 order columns, 10 product columns and 16 abandoned-cart columns. Order number is locked on and cannot be switched off. Customers have no column list at all, only the whole-sheet switch above; their 9 columns are fixed.

When you create a sheet you can also scope it to a **specific list of products** instead of the whole catalogue.

## Exporting everything at once

Besides the live sync, there is a manual **export now** action that pushes existing data into the sheet in one pass — orders, products, customers, abandoned carts, orders + carts, or all of it. It runs in the background with a progress bar and is limited to 10 runs per minute.

## Status changes are written back

When you change an order's status in the dashboard, DZBuild updates that order's **existing row** in the sheet rather than appending a duplicate. The same applies to abandoned carts (`abandoned`, `contacted`, `recovered`, `expired`), and abandoned-cart rows are colour-coded by status.

## Active-sheet limits by plan

| Plan       | Max active sheets |
| ---------- | ----------------- |
| Free       | 1                 |
| Pro        | 6                 |
| Unlimited  | 10                |
| Enterprise | 30                |

If you hit the limit you'll see: *"لقد وصلت إلى الحد الأقصى للأوراق المفعلة"*. Disconnect an unused sheet or upgrade your plan.

## Troubleshooting

| Issue                                               | Fix                                                                       |
| --------------------------------------------------- | ------------------------------------------------------------------------- |
| "Token expired" / reconnect prompt                  | Click Reconnect and re-authorize Google                                   |
| Sheet stops updating                                | Check connection status; Google revokes tokens after prolonged inactivity |
| Can't create more sheets                            | Plan limit reached — see table above                                      |
| Page says "not connected" although you connected it | The stored token could not be read; just re-link via **Connect Google**   |

**Disconnect** does more than clear the link: it also revokes DZBuild's access on Google's side and wipes the stored tokens, so reconnecting means authorizing from scratch.

## Octomatic

[Octomatic](https://octomatic.shop) is a third-party fulfillment tool that connects to DZBuild **via Google Sheets**. Set up Google Sheets first, then follow the guide at `/dashboard/addons/octomatic`. Octomatic reads the **Delivery type** cell word for word, so the text DZBuild writes there must be one of the words it recognises (for example `desk` or `مكتب`). Change that text for home, desk and pickup orders under **Delivery type text in the sheet** on the Google Sheets page; orders written after the change use it.

📺 [Google Sheets setup tutorial](https://www.youtube.com/watch?v=YymREJXr53k)
