> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://doc.common-services.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Delete and reimport an Amazon order

**Delete and reimport an Amazon order in PrestaShop**

This tutorial explains how to remove an Amazon order from PrestaShop so the module can import it again.

||| ⚠️ Important: Deleting the order only from PrestaShop order tables is not enough. You must also remove the related rows from the module marketplace tables. Otherwise the module still considers the Amazon order as already imported.

||| ⚠️ This procedure requires database access (phpMyAdmin, Adminer, or similar). Make a backup before running any DELETE query. Replace `ps_` with your shop’s table prefix if it is different.

---

## What you need before starting

From the order you want to remove, note:

* PrestaShop order ID → `id_order`
* Amazon order ID → `mp_order_id`
* Order reference → `reference` (from the `orders` table)
* Product lines from `order_detail`:
  * `id_product`
  * `id_product_attribute`
  * `product_quantity`
  * `id_shop`

You need the product lines to restock **after** the order is deleted.

---

## Step 1 – Delete the PrestaShop order in the database

Delete related rows first, then the order itself.

```sql
-- Tax lines linked to the order details
DELETE odt FROM ps_order_detail_tax odt
INNER JOIN ps_order_detail od ON od.id_order_detail = odt.id_order_detail
WHERE od.id_order = {ID_ORDER};

DELETE FROM ps_order_detail WHERE id_order = {ID_ORDER};
DELETE FROM ps_order_history WHERE id_order = {ID_ORDER};
DELETE FROM ps_order_carrier WHERE id_order = {ID_ORDER};
DELETE FROM ps_order_cart_rule WHERE id_order = {ID_ORDER};

-- Invoices (if any)
DELETE oip FROM ps_order_invoice_payment oip
INNER JOIN ps_order_invoice oi ON oi.id_order_invoice = oip.id_order_invoice
WHERE oi.id_order = {ID_ORDER};

DELETE oit FROM ps_order_invoice_tax oit
INNER JOIN ps_order_invoice oi ON oi.id_order_invoice = oit.id_order_invoice
WHERE oi.id_order = {ID_ORDER};

DELETE FROM ps_order_invoice WHERE id_order = {ID_ORDER};

-- Payments (linked by order reference, not by id_order)
DELETE FROM ps_order_payment WHERE order_reference = '{ORDER_REFERENCE}';

DELETE FROM ps_orders WHERE id_order = {ID_ORDER};
```

If this order also has returns, credit slips, or messages, delete those related rows as well.

||| ℹ️ About the cart: Amazon import also creates a PrestaShop cart. That cart does **not** block reimport. You can leave it. Removing it is optional cleanup only, not required for this procedure.

---

## Step 2 – Restock the products

After the order rows are deleted, add the stock back using the quantities you noted from `order_detail` (`product_quantity` for each product / combination / shop).

Do this **after** deleting the order, not before.

---

## Step 3 – Remove the module marketplace data

Delete all rows for this Amazon order from the module tables:

```sql
DELETE FROM ps_marketplace_order_items WHERE mp_order_id = '{MP_ORDER_ID}';
DELETE FROM ps_marketplace_order_address WHERE mp_order_id = '{MP_ORDER_ID}';
DELETE FROM ps_marketplace_orders WHERE mp_order_id = '{MP_ORDER_ID}';
```

||| ⚠️ Filter strictly on the correct `mp_order_id`. The `marketplace_orders` table can be shared with other marketplace modules.

On some older shops, if the column `mp_order_id` still exists in `ps_orders`, make sure no leftover value remains for this order.

---

## Step 4 – Reimport the order

Run the Amazon order import again (Orders tab or cron), for the correct marketplace and date range.

The module should create a new PrestaShop order for the same Amazon order ID.

---

## Summary

1. Note `id_order`, `mp_order_id`, `reference`, and product quantities
2. Delete the PrestaShop order and related order tables in the database
3. Restock the products
4. Delete rows from `marketplace_order_items`, `marketplace_order_address`, and `marketplace_orders`
5. Run order import again