GithubHelp home page GithubHelp logo

shoppingcart's Introduction

ShoppingCart

This model is a simple ZF2 Shopping Cart solution. Provide basic functionality to create and modify Shopping Cart with any content in it. Easy to extend, just create your own Cart Entity and push it during Cart initialisation.

Inspired by

I was inspired to create the ShoppingCart by great job of Vincenzo Provenza and Concetto Vecchio (http://github.com/vikey89/ZendCart). Keeped the same idea behind but made it more flexible, easier to extend and simplier to change.

Installation

For the installation uses composer composer. Add this project in your composer.json:

"require": {
    "cyrkulewski/shopping-cart": "dev-master"
}

Post Installation

Configuration:

  • Add the module of config/application.config.php under the array modules, insert ShoppingCart.
  • Copy a file named shoppingcart.global.php.dist to config/autoload/ and change name to shoppingcart.global.php.
  • Modify config to fit your expectations.

Examples

Insert

You can insert as many items to the cart as you want. Each entry in cart will have unique token to work with. Example with one product:

$product = array(
    'id'      => 'XYZ',
    'qty'     => 1,
    'price'   => 15.15,
    'product' => 'Book: ZF2 for beginners',
);
$this->ShoppingCart()->insert($product);

Example with 2 products:

$products = array(
    array(
        'id'      => 'XYZ',
        'qty'     => 1,
        'price'   => 15.15,
        'product' => 'Book: ZF2 for beginners',
    ),
    array(
        'id'      => 'ZYX',
        'qty'     => 3,
        'price'   => 19.99,
        'product' => 'Book: ZF2 for advanced users',
    )
);
$this->ShoppingCart()->insert($products);

Remove

$token => '4b848870240fd2e976ee59831b34314f7cfbb05b';
$this->ShoppingCart()->remove($token);

Destroy

Erase Shopping Cart completely.

$this->ShoppingCart()->destroy();

Cart

Get all content of Cart.

$this->ShoppingCart()->cart();

Total Sum

$this->ShoppingCart()->total_sum();

Total Items

$this->ShoppingCart()->total_items();

Example in controller

return new ViewModel(array(
    'cart' => $this->ShoppingCart()->cart(),
    'total_items' => $this->ShoppingCart()->total_items(),
    'total_sum' => $this->ShoppingCart()->total_sum(),
));

How to change/extend Shopping Cart

Provided Shopping Cart Entity is really basic one. You can change the structure of it. For example, if you need to add options to each item in the cart or to provide discount field and so on. What you should do:

  • copy ShoppingCart/Entity/ShoppingCartEntity to your module
  • modify YourModule/Entity/ShoppingCartEntity: add any fields you need to have
  • during Shopping Cart initialisation provide your YourModule/Entity/ShoppingCartEntity
$this->ShoppingCart()->setEntityPrototype(new YourModule/Entity/ShoppingCartEntity());

FunctionsReference

Function Description
$this->ShoppingCart()->insert();Add item(s) to cart.
$this->ShoppingCart()->remove();Delete the item from the cart.
$this->ShoppingCart()->destroy();Delete all items from the cart.
$this->ShoppingCart()->cart();Extracts all items from the cart.
$this->ShoppingCart()->total_sum();Counts the total sum of all items in the cart.
$this->ShoppingCart()->total_items();Counts the total number of all items in the cart.

Contributors

Aleksander Cyrkulewski - [email protected]

shoppingcart's People

Contributors

martyshka 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.