Giter Site home page Giter Site logo

digitalsilk-testplugin's Introduction

DigitalSilk - Test Plugin

Continuous Integration Latest Stable Version Latest Unstable Version

A WordPress plugin that imports products from DummyJSON into WooCommerce. Intended to pass a DigitalSilk test.

Requirements

  • PHP >= 7.4;
  • WordPress >= 6.1;
  • WooCommerce >= 7.9;

Setup From Source

  1. Ensure you have a working Docker setup with Docker Compose.
  2. Obtain contents of the repo.
  3. Follow basic setup instructions:
    1. Copy .env.example to .env. Usually, defaults work well.
    2. Build environment: docker compose build.
    3. Spin it up with docker compose up wp_dev, ensuring the procedure is complete: the DB, webserver, WP, etc. should be automatically set up.
  4. Visit the local site, and ensure it is ready (WC setup, etc). The admin credentials are admin/admin.
  5. To test a distributable version of the plugin, build it by running docker compose run --rm build make release. Find the dist archive in build/release.

Usage

All configuration is done on the WooCommerce > DummyJSON page in the admin. In order to save it, press the "Save" button at the bottom. This will override any defaults by assigning explicit values.

API

In order to access the remote API's endpoints that require authentication, the Username and Password settings must be configured with respective user credentials.

Import

Press the Import Now! button to schedule an import for executing ASAP in the background.

Important: The speed and amount of products that can be imported in one batch greatly depends on the resources available on the server. For this reason, each product has a certain amount of time to be imported, after which the execution timeout resets. Theoretically, this should allow any number of products to be imported in one batch.

This is independent of the execution timeout of the rest of the script, but requires PHP to be able to set INI values with ini_set()

During import, the plugin will access the products endpoint of the API, and attempt to use its data to create new products. The specification explicitly says to leave out the id field while importing, and this prevents synchronisation of existing products: on every import, each product will be created anew. This includes images, which are downloaded and registered in the Media Library.

All importing happens on a separate server thread via WP Cron. During import, if the API reports that there are more products that have been processed, the process will schedule itself to continue importing the next batch. This helps avoid timeouts.

The response of the API is streamed. During import, product data is read item by item from the response, each one is converted to a model on the fly, and given to the importer. This means that there at most a few kilobytes of memory are used per product entry from the API, and the response is never loaded in its entirety. Given sufficient time, this means that a very large dataset can potentially be imported without running out of memory.

  • The Batch Size setting controls the max amount of products to process per batch. When this number is reached, another batch will be scheduled, and will continue where the previous one stopped.
  • The Import Limit setting controls the total number of items that can be processed per import. When this number is reached, import concludes, and no more batches are scheduled. This is very useful for testing, because it helps avoid importing a large number of items.

Together, these settings allow for fine control over import scope and resources used.

Troubleshooting

Because the plugin already requires WooCommerce, it integrates with its logging system. During import, it will generate entries in the digitalsilk-wc-import log. Entries will be generated for every import, for every batch, and for every product. This provides helpful information on the progress, and can help determine whether importing has finished, or encountered a problem.

Notes

  • This package was created from wp-oop/plugin-boilerplate. Please refer to its documentation for startup instructions and other related technical information.
  • This project uses a modular system. It is therefore a demonstration of how application concerns may be separated, and interact in explicit ways. Please refer to "Cross-Platform Modularity in PHP" for a detailed explanation of approach and features.
  • It took a great deal of effort to read product JSON from the API in a streaming way.
  • There are many checks in place that ensure a high level of Engineering Excellence. That includes automated tests and static analysis. See build logs for more details.
  • The dist build procedure allows this plugin to be easily tested on a separate site. I used InstaWP to test in a pristine and separate environment, and it worked on the first try.

digitalsilk-testplugin's People

Contributors

xedinunknown avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.