Giter Site home page Giter Site logo

divineomega / exiguous-ecommerce Goto Github PK

View Code? Open in Web Editor NEW
8.0 5.0 0.0 72 KB

๐Ÿ›’ A super simple ecommerce library, that uses flat files and takes a very minimalistic approach.

License: GNU Lesser General Public License v3.0

PHP 100.00%
ecommerce basket cart flat-file php-library

exiguous-ecommerce's Introduction

๐Ÿ›’ Exiguous Ecommerce

Exiguous Ecommerce is a super simple ecommerce library, that uses flat files and takes a very minimalistic approach.

Installation

Just run the following Composer command to download/install Exiguous Ecommerce and create relevant autoload files.

composer require divineomega/exiguous-ecommerce

If your framework does not already do so, you must add require_once "vendor/autoload.php" to any files in which you wish to use Exiguous Ecommerce.

Configuration

Exiguous Ecommerce stores all of its data within a data directory. An example data directory is provided in this package.

Before use, you should then copy the data directory to another location and then specify this location your project's environment. If you are using Laravel, this can be done by setting an EXIGUOUS_ECOMMERCE_DATA_DIRECTORY variable in your .env file, as follows.

EXIGUOUS_ECOMMERCE_DATA_DIRECTORY=/var/www/ecommerce-site/path-to-data-directory/

If you are not using a framework that supports this, you can use the standard PHP function putenv to set this environment variable. Alternatively, you could use dotenv-loader to add .env file support to your project.

Please note that it is important the EXIGUOUS_ECOMMERCE_DATA_DIRECTORY variable is set with a trailing slash present.

For security reasons, you should place the data directory in a location which is not web-accessible. In case the data directory is placed in a web accessible location by accident, a .htaccess file is provided that should deny web users access to the directory's content in most common web server configurations.

Quick Start Examples

Getting products and categories:

$category = \DivineOmega\ExiguousEcommerce\Category::findBySlug("fluffy-things");
$products = $category->products();

foreach($products as $product) {
    echo $product->data->name;
}
$product = \DivineOmega\ExiguousEcommerce\Product::findBySlug("teddy-bear");
$categories = $product->categories();

$mainCategoryName = $categories[0]->data->name;

Getting the current user's basket and adding a product to it:

$product = \DivineOmega\ExiguousEcommerce\Product::findBySlug("teddy-bear");

$basket = \DivineOmega\ExiguousEcommerce\Basket::findCurrent();

$basket->addProduct($product); // Add one Teddy Bear

$basket->addProduct($product, 2); // Add another two Teddy Bears!

var_dump($basket->items); // Outputs an array of, you guessed it, basket items! ^_^

// ^ This would show 1 basket item with a quantity of 3 teddy bears.

Removing a product from a basket:

$product = \DivineOmega\ExiguousEcommerce\Product::findBySlug("teddy-bear");

$basket = \DivineOmega\ExiguousEcommerce\Basket::findCurrent();

$basket->removeProduct($product); // Removes all teddy bears from the basket

Setting/Offsetting the quantity of a product in the basket:

$product = \DivineOmega\ExiguousEcommerce\Product::findBySlug("teddy-bear");

$basket = \DivineOmega\ExiguousEcommerce\Basket::findCurrent();

$basket->addProduct($product); // Add one Teddy Bear

$basket->setProductQuantity($product, 10); // Set the number of Teddy Bears in the basket to ten

$basket->offsetProductQuantity($product, 10); // Add ten more Teddy Bears

$basket->offsetProductQuantity($product, -5); // Remove five of those Teddy Bears

Migrating the basket to an order:

$basket = \DivineOmega\ExiguousEcommerce\Basket::findCurrent();

$basket->convertToOrder();

Getting and using settings:

// Retrieves settings from the core.json file within the .settings directory
$coreSettings = \DivineOmega\ExiguousEcommerce\Settings::find('core');

echo $coreSettings->data->primaryCurrency; // Output the ecommerce's primary currency setting

exiguous-ecommerce's People

Contributors

divineomega avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

exiguous-ecommerce's Issues

Add type hints

As title, I think we need to add the type hints or using the PHPDoc style to add the type hints of annotation comments.

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.