Giter Site home page Giter Site logo

angel-products's Introduction

Angel Products

This is an eCommerce module for the Laravel 4 Angel CMS.

The module works with Stripe out of the box, but you can easily extend it to use other payment gateways.

Installation

Add the following requirements to your composer.json file:

"require": {
	...
	"angel/products": "1.0.*"
},

Issue a composer update to install the package.

Add the following service provider to your providers array in app/config/app.php:

'Angel\Products\ProductsServiceProvider'

Issue the following commands:

php artisan migrate --package="angel/products"   # Run the migrations
php artisan asset:publish                        # Publish the assets
php artisan config:publish angel/products        # Publish the config

Open up your app/config/packages/angel/core/config.php and add the products and orders routes to the menu array:

'menu' => array(
	'Pages'     => 'pages',
	'Menus'     => 'menus',
	'Products'  => 'products', // <--- Add this line
	'Orders'    => 'orders',   // <--- Add this line
	'Users'     => 'users',
	'Settings'  => 'settings'
),

...and the menu-linkable models to the linkable_models array:

'linkable_models' => array(
	'Page'             => 'pages',
	'Product'          => 'products',           // <--- Add this line
	'ProductCategory'  => 'products/categories' // <--- Add this line
)

Open up your app/config/packages/angel/products/config.php and set your Stripe API keys:

'stripe' => array(
	'test' => array(
		'secret'      => 'xxxxxxxxxxxxxx',
		'publishable' => 'xxxxxxxxxxxxxx'
	),
	'live' => array(
		'secret'      => 'xxxxxxxxxxxxxx',
		'publishable' => 'xxxxxxxxxxxxxx'
	)
)

Cart Usage

The cart class stores variations of products, based on their selected options, in the session.

Add Products

$Product = App::make('Product');
$Cart    = App::make('Cart');

// Grab the user's desired product from the database.
$product = $Product::with('options')->findOrFail(Input::get('product_id'));

// Mark the selected option items by their IDs.
$product->markSelectedOptions(Input::get('options'));

// Add the product to the cart in the user's desired quantity, saving the unique key for accessing it later.
$key = $Cart->add($product, Input::get('quantity'));

Add Products with Custom Options

$Product = App::make('Product');
$Cart    = App::make('Cart');

// Grab the user's desired product from the database.
$product = $Product::findOrFail(Input::get('product_id'));

$product->addCustomOptions(array(
	'Size' => array(
		'name'  => 'Large',
		'price' => 4.50
	),
	'Color' => array(
		'name'  => 'Green',
		'price' => -2.50,
		'image' => 'assets/images/green-shirt.jpg'
	)
));

// Add the product to the cart in the user's desired quantity, saving the unique key for accessing it later.
$key = $Cart->add($product, Input::get('quantity'));

Retrieve Key

If you need to get the key for a product (i.e. to remove that product from the cart) you can do so like this:

// Retrieve the key.
$key = $Cart->key($product);

// Use the key however you wish.
$Cart->remove($key);

Remove Products

$Cart->remove($key);

Adjust the Quantity of Products

$Cart->quantity($key, 5);

Retrieve Products

$details = $Cart->get($key);

// $details then looks like this:
array(
	'product' => {String, JSON encoded product},
	'price'   => {Float, price per unit},
	'qty'     => {Int, quantity of units}
);

Loop Through Products

foreach (Session::get('cart') as $key=>$details) {
	$product = json_decode($details['product']);
	$price   = $details['price'];
	$qty     = $details['qty'];
	$total   = $Cart->totalForKey($key);
}

Get Totals

// The total for all products in the cart.
echo $Cart->total();

// The total for a specific product variation by key.
echo $Cart->totalForKey($key);

// The total number of items in the cart.  (Variations x their quantity)
echo $Cart->count();

angel-products's People

Contributors

jvmartin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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