angel/products 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

angel/products

Composer 安装命令:

composer require angel/products

包简介

An Angel CMS module for products.

README 文档

README

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();

统计信息

  • 总下载量: 242
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 6
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2014-06-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固