BigBuy integration module for PrestaShop

PrestaBuy MinSync is a BigBuy integration module designed to provide essential synchronization functionalities with the BigBuy dropshipping supplier.

Main Goals: Convenient Import of categories and product catalog into “CMS PrestaShop 1.8” using the “BigBuy” REST API

MVP Module: BigBuy Minimal Sync. Main MVP Functions:

  • Settings: Input of the BigBuy API key with the ability to select the environment (Production, sandbox). Selection of the main language for synchronization (from those installed in PS)
  • Import of Categories (Cron/Manually): (Mandatory on the first module launch) Creation/update and mapping of selected categories from BigBuy to PrestaShop, taking into account multilingualism (for all active PS languages).
  • Synchronization of Products (Cron/Manually): Creation/update of products from selected (previously created) BigBuy categories in PrestaShop.
    • Synchronization/update of only the fields selected in the settings (name, description, price, stock, image, etc.).
    • Taking into account multilingualism for text fields.
    • Synchronization of basic prices (retail, wholesale prices, without special markup rules for MVP).
    • Synchronization of stock levels.
  • Sending Orders to BigBuy: Automatic sending of orders containing products from BigBuy upon their confirmation in PrestaShop.
  • Logging: Basic logging of synchronization operations and API requests (as in the layout).

2. Technical Stack and Architecture:

  • PrestaShop: > 8.2
  • PHP: Pure PHP, PrestaShop standards.
  • JavaScript/AJAX: Minimum (ideally only for non-critical UI improvements, if very necessary, but page reloading can suffice for MVP).
  • Module Structure (bbminsync):
    • bbminsync.php: Main module class. Installation/removal, hook registration, configuration entry point.
    • /controllers/admin/AdminBbminsyncConfigController.php: Configuration page controller.
    • /classes/ (or /src/ for PS 8+):
      • /Service/BigBuyApiService.php: Encapsulates all logic for interaction with the BigBuy REST API (authentication, requests to category, product, order endpoints, response and error handling).
      • /Service/CategorySyncService.php: Category synchronization logic.
      • /Service/ProductSyncService.php: Product synchronization logic, including prices and stock levels.
      • /Service/OrderSyncService.php: Logic for processing and sending orders to BigBuy.
      • /Repository/MappingRepository.php: Working with the mapping table (PrestaShop ID <-> BigBuy ID relation).
      • /Form/ConfigurationFormProvider.php: (Optional, can be in the controller) Preparing data for the configuration form.
      • /Handler/ConfigurationFormHandler.php: (Optional, can be in the controller) Processing configuration form data.
      • /Logger/FileLogger.php: Simple service for writing logs to files.
    • /views/templates/admin/configure.tpl: Configuration page template (based on the layout).
    • /sql/install.sql: SQL for creating the mapping table.
    • /sql/uninstall.sql: SQL for deleting the mapping table.
    • cron.php: Script for launching background synchronization tasks (requires server configuration and passing a secret token).

3. Database (Minimum):

  • One table for mapping: PREFIX_bbminsync_mapping
    • id_mapping INT AUTO_INCREMENT PRIMARY KEY
    • entity_type ENUM(‘category’, ‘product’) NOT NULL
    • id_prestashop INT UNSIGNED NOT NULL
    • id_bigbuy VARCHAR(255) NOT NULL
    • date_add DATETIME NOT NULL
    • date_upd DATETIME NOT NULL
    • INDEX idx_entity_prestashop (entity_type, id_prestashop)
    • INDEX idx_entity_bigbuy (entity_type, id_bigbuy)
  • All settings are stored in the standard PrestaShop PREFIX_configuration table.

4. Settings Page (Based on BoardMVP1.png layout):

  • Controller (AdminBbminsyncConfigController):
    • __construct(): Set basic controller parameters.
    • renderForm(): Use HelperForm.
      • Select Environment: Select type. Different BigBuy endpoint URLs are used to switch between Sandbox and Production environments.
      • API Key: Text type.
      • Select language: Select type. Options are generated from Language::getLanguages(true, $this->context->shop->id). Default value is the context language or the first active one.
      • Category selection (multiselector): Select type with the multiple attribute. Options are dynamically loaded from the BigBuy API (/rest/catalog/categories in the selected language) after saving a valid API key. For MVP, it can be loaded on each form rendering if the key exists.
      • Products selection (multiselector): After categories are created, we select categories into which products will be imported.
      • Products filter (checkboxes): Group of checkbox type fields. Names correspond to BigBuy/PrestaShop fields (name, short_description, long_description, price, Qty, weights, sizes, condition, image, manufacturer, sku, ean13).
      • Buttons: Standard “Save” button from HelperForm. “sync now”, “clear logs” buttons will be processed in postProcess. “stop all” – excluded from MVP due to the complexity of implementation without JS/background processes.
      • Logs: Textarea type fields (readonly). Filled with the last N lines from log files (Sync log, API log).
    • postProcess():
      • Saving processing (submitAddbbminsync): Data validation. Saving settings (API Key, language, selected categories, attribute filters) via Configuration::updateValue(). Checking the connection with the API when saving the key.
      • Processing “sync now”: Calling the corresponding synchronization services (CategorySyncService, ProductSyncService).
      • Processing “clear logs”: Clearing log files.

5. Key Implementation Points:

  • Localization:
    • When synchronizing categories/products, get data from BigBuy for each active language in PrestaShop (Language::getLanguages(true)).
    • Save data in PrestaShop for the corresponding languages ($product->name[$id_lang] = $name_from_api;).
    • The language selected in the settings can be used as the main language or for getting the category list.
  • Cron (cron.php):
    • Accepts a secret token as a GET parameter for security.
    • Reads settings from Configuration.
    • Calls CategorySyncService->syncSelectedCategories() and ProductSyncService->syncSelectedProducts().
    • Add a simple locking mechanism (e.g., writing the process PID to a file or a flag in Configuration) to prevent simultaneous launch.
  • Sending Orders (hookActionValidateOrder):
    • Get the Order object.
    • Get the order products.
    • Check via MappingRepository if there are products from BigBuy.
    • If yes: Form data for the BigBuy API (delivery address, BigBuy product IDs, quantity).
    • Call BigBuyApiService->createOrder().
    • Write the result to the log and, possibly, to a private order message.
  • Identification of BigBuy Products: When creating a product in PrestaShop, save the id_prestashop <-> id_bigbuy relation in the bbminsync_mapping table. This will allow you to quickly determine which products need to be sent to BigBuy in hookActionValidateOrder.
  • Error Handling: Log API errors and errors when creating/updating PrestaShop entities.

6. Simplifications for MVP:

  • No complex markup rules (the price is taken from BigBuy as is or with a simple general markup “wholesalePrice”: 8.98, “retailPrice”: 9.98,).
  • No synchronization of order statuses from BigBuy to PrestaShop.
  • No handling of product combinations (variants).
  • No automatic creation of manufacturers, attributes, features (it is assumed that the basics already exist or are created manually, or products are imported as simple ones). Although creating a manufacturer by name from the BigBuy API can be added, it’s not difficult.
  • No UI for viewing and managing

Demo store

Login: Demo

Pass: Demo.cloud

The module does NOT support multi-stores!!!!

Leave a comment